Offer minor update

This commit is contained in:
Kalarumeth
2022-08-29 18:31:56 +02:00
parent 4c36154297
commit ba397104a7
+51 -38
View File
@@ -2,10 +2,12 @@
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet;
using Microsoft.SharePoint.Client.WebParts;
using System;
//using PnP.Core.Model.SharePoint;
//using PnP.Core.Services;
using System.Collections.Concurrent;
using System.Net;
using System.Reflection.PortableExecutable;
using System.Security;
using System.Text;
using System.Text.Json;
@@ -16,6 +18,7 @@ using spc = SharePointOnlineUtils.SharePointCustomOperation;
namespace SharePointOnlineUtils
{
#region External Variable
// TODO: Import variable from PP [C:\Sources\VS\web_portal\webapp_italsort\DataItalsortGestionale\ProjTable.cs]
public class ParentProj
{
public string ProjId { get; set; }
@@ -23,7 +26,7 @@ namespace SharePointOnlineUtils
public string Customer { get; set; }
public string DeliveryReason { get; set; }
public List<SubProj> SubProjects { get; set; }
}// TODO: Import variable from PP [C:\Sources\VS\web_portal\webapp_italsort\DataItalsortGestionale\ProjTable.cs]
}
public class SubProj
{
@@ -40,7 +43,6 @@ namespace SharePointOnlineUtils
public class Program
{
public static async Task Main()
{
#region SPO Credential
@@ -61,8 +63,6 @@ namespace SharePointOnlineUtils
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
#endregion
spc.ProjectsYSite(varProjSiteName, site, svcUser, svcUserPsw);
#region Project
//ProjectsByYearSite(listTitle, varProjSiteName, svcUser, site, svcUserPsw);
//Project(siteCollection, svcUser, svcUserPsw);
@@ -83,7 +83,7 @@ namespace SharePointOnlineUtils
if (spc.SiteExist(ctx) == false)
{
spc.ProjectsYSite(varProjSiteName, site, user, psw);
spc.TenantCreation(varProjSiteName, site, user, psw);
spc.DomainGroupRights(ctx, string.Empty);
spc.OnenoteSPFeature(ctx, string.Empty, string.Empty);
spc.ProjectsYField(ctx);
@@ -136,7 +136,8 @@ namespace SharePointOnlineUtils
using (var authMgr = new AuthenticationManager())
using (var ctx = authMgr.GetContext(subSite, user, psw))
{
spc.SubProjectDocSet(ssProjectTitle, ssSubProjectTitle, ctx); //TODO: Controlare prima se esiste la commessa
if ( spc.SiteExist(ctx) )
spc.SubProjectDocSet(ssProjectTitle, ssSubProjectTitle, ctx);
}
}
#endregion
@@ -144,17 +145,23 @@ namespace SharePointOnlineUtils
#region Offer
public static async Task Offer(string siteCollection, string user, SecureString psw)
{
string year = "2021";//DateTime.Now.Year.ToString();
string docLibName = $"Offerte {year}";
string year = DateTime.Now.Year.ToString();
string tenantName = "Offerte";
string docLibName = $"{tenantName} {year}";
Uri site = new Uri($"{siteCollection}/sites/Offerte");
var authMgr = new AuthenticationManager();
var ctx = authMgr.GetContext(site, user, psw);
if ( spc.SiteExist(ctx) == false) // Inutile
{
spc.TenantCreation(tenantName, site, user, psw);
}
if ( spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) == false )
{
spc.OfferDocLib(year, ctx);
//spc.OfferDocLib(year, ctx);
}
}
#endregion
@@ -255,8 +262,7 @@ namespace SharePointOnlineUtils
}
#endregion
#region Projects Years
public static async Task ProjectsYSite(string siteName, Uri site, string user, SecureString psw)
public static async Task TenantCreation(string siteName, Uri site, string user, SecureString psw)
{
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{siteName.Replace(" ", string.Empty)}'.");
@@ -301,6 +307,7 @@ namespace SharePointOnlineUtils
}
}
#region Projects Years
public static async Task ProjectsYField(ClientContext ctx)
{
Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>()
@@ -473,7 +480,7 @@ namespace SharePointOnlineUtils
}
}
public static async Task ProjectListEntry(string ssProjectTitle, string listTitle, string projectsYear, ClientContext ctx)
public static async Task ProjectListEntry(string ssProjectTitle, string listTitle, string projectsYear, ClientContext ctx) //TODO: PP var
{
try
{
@@ -502,29 +509,37 @@ namespace SharePointOnlineUtils
}
}
public static async Task ProjectDocLib(string ssProjectTitle, ClientContext ctx)
public static async Task ProjectDocLib(string ssProjectTitle, ClientContext ctx) //TODO: Da testare
{
#region DocLib
try
{
string[] docLibName = { $"Documenti {ssProjectTitle}", $"Media {ssProjectTitle}", $"SottoCommesse {ssProjectTitle}", $"Commerciale {ssProjectTitle}" };
foreach (string libName in docLibName)
Dictionary<string, Int32> docLibNames = new Dictionary<string, Int32>
{
Console.WriteLine($"> Inizializzata la fase di creazione '{libName}'.");
{ $"Documenti {ssProjectTitle}", (int)ListTemplateType.DocumentLibrary },
{ $"Media {ssProjectTitle}", (int)ListTemplateType.PictureLibrary },
{ $"SottoCommesse {ssProjectTitle}", (int)ListTemplateType.DocumentLibrary },
{ $"Commerciale {ssProjectTitle}", (int)ListTemplateType.DocumentLibrary },
};
//string[] docLibName = { $"Documenti {ssProjectTitle}", $"Media {ssProjectTitle}", $"SottoCommesse {ssProjectTitle}", $"Commerciale {ssProjectTitle}" };
foreach (KeyValuePair<string, Int32> kvp in docLibNames)
{
Console.WriteLine($"> Inizializzata la fase di creazione '{kvp.Key}'.");
Web web = ctx.Web;
ctx.Load(web);
ListCreationInformation lci = new ListCreationInformation();
lci.Title = libName;
lci.TemplateType = (int)ListTemplateType.DocumentLibrary; // TODO: PictureLibrary x Media
lci.Title = kvp.Key;
lci.TemplateType = kvp.Value; //(int)ListTemplateType.DocumentLibrary; // TO-DO: PictureLibrary x Media
List list = web.Lists.Add(lci);
ctx.ExecuteQuery();
if (libName.Contains("Commerciale")) DomainGroupRights(ctx, libName);
Console.WriteLine($"> '{libName}' è stato creato con successo.");
if (kvp.Key.Contains("Commerciale")) DomainGroupRights(ctx, kvp.Key);
Console.WriteLine($"> '{kvp.Key}' è stato creato con successo.");
}
#endregion
@@ -676,7 +691,7 @@ namespace SharePointOnlineUtils
#endregion
#region Sub Project
public static async Task SubProjectDocSet(string ssProjectTitle, string[] ssSubProjectTitle, ClientContext ctx)
public static async Task SubProjectDocSet(string ssProjectTitle, string[] ssSubProjectTitle, ClientContext ctx) //TODO: Set variabili da PP
{
try
{
@@ -720,7 +735,6 @@ namespace SharePointOnlineUtils
Console.WriteLine($"> Inizializzata la fase di creazione per {spt}.");
#region DocSet Field Entry
DocumentSet.Create(ctx, list.RootFolder, spt, contentType.Id);
ctx.ExecuteQuery();
@@ -768,13 +782,18 @@ namespace SharePointOnlineUtils
#endregion
#region Offer
public static async Task OfferField(ClientContext ctx) // Set to run manualy or if Offerte doesn't exist (se non dovesse essistere qualche mano lesta lo ha cancellato)
public static async Task OfferSite() // TODO: Da creare?? contiene la base di crazione del tenant e le impostazioni base in caso devesse essere cancellata
{
}
public static async Task OfferField(ClientContext ctx)
{
try
{
Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>()
{
{ "PAL_Offers_Reason", new string[] { "Choice", "Causale", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "<CHOICES><CHOICE>01 VENDITA MACCHINE / IMPIANTI</CHOICE><CHOICE>02 VENDITA RICAMBI</CHOICE><CHOICE>04 VENDITA SERVIZI FUORI COMMESSA</CHOICE><CHOICE>08 VENDITA RIPARAZIONI</CHOICE><CHOICE>09 ENGINEERING</CHOICE><CHOICE>11 VENDITA E LAVORAZ.CONTO TERZI</CHOICE><CHOICE>55 PREVENDITE</CHOICE><CHOICE>NC NON CONFORMITÁ</CHOICE></CHOICES>" } },
{ "PAL_Offers_Reason", new string[] { "Choice", "Causale", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", $"<CHOICES><CHOICE>01 VENDITA MACCHINE / IMPIANTI</CHOICE><CHOICE>02 VENDITA RICAMBI</CHOICE><CHOICE>04 VENDITA SERVIZI FUORI COMMESSA</CHOICE><CHOICE>08 VENDITA RIPARAZIONI</CHOICE><CHOICE>09 ENGINEERING</CHOICE><CHOICE>11 VENDITA E LAVORAZ.CONTO TERZI</CHOICE><CHOICE>55 PREVENDITE</CHOICE><CHOICE>NC NON CONFORMITÁ</CHOICE></CHOICES>" } },
{ "PAL_Customer", new string[] { "Text", "Cliente", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_ID_Offer", new string[] { "Text", "Codice Articolo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_Offers_Name", new string[] { "Text", "Item", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
@@ -804,6 +823,7 @@ namespace SharePointOnlineUtils
try
{
string docLibName = $"Offerte {year}";
#region New DocLib
Console.WriteLine($"> Inizializzata la fase di creazione '{docLibName}'.");
@@ -822,7 +842,6 @@ namespace SharePointOnlineUtils
DomainGroupRights(ctx, docLibName);
#region Shortcut on Quickmenu
NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch;
NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
@@ -844,7 +863,6 @@ namespace SharePointOnlineUtils
{
try
{
#region Context
var listTitle = $"Offerte {year}";
var web = ctx.Web;
ctx.Load(web, w => w.Url);
@@ -875,13 +893,9 @@ namespace SharePointOnlineUtils
var contentType = ctData.FirstOrDefault();
ctx.Load(contentType);
ctx.ExecuteQuery();
#endregion
}
catch (Exception ex)
{
Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )");
return;
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
}
#endregion
@@ -891,9 +905,9 @@ namespace SharePointOnlineUtils
var featureName = "SiteNotebook";
Guid featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f");
#region Feature Activate
if (string.IsNullOrEmpty(ssProjectTitle))
{
#region Feature Activate
try
{
if (!SiteFeaturesExist(ctx, featureName))
@@ -904,12 +918,11 @@ namespace SharePointOnlineUtils
}
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
}
#endregion
#region Note Section
}
else
{
#region Note Section
try
{
Console.WriteLine($"> Inizializzata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
@@ -925,9 +938,9 @@ namespace SharePointOnlineUtils
Console.WriteLine($"> Completata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
}
#endregion
}
}
#endregion
#region Rights