Offer minor update

This commit is contained in:
Kalarumeth
2022-08-29 18:31:56 +02:00
parent 4c36154297
commit ba397104a7
+58 -45
View File
@@ -2,10 +2,12 @@
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet; using Microsoft.SharePoint.Client.DocumentSet;
using Microsoft.SharePoint.Client.WebParts; using Microsoft.SharePoint.Client.WebParts;
using System;
//using PnP.Core.Model.SharePoint; //using PnP.Core.Model.SharePoint;
//using PnP.Core.Services; //using PnP.Core.Services;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Net; using System.Net;
using System.Reflection.PortableExecutable;
using System.Security; using System.Security;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@@ -16,6 +18,7 @@ using spc = SharePointOnlineUtils.SharePointCustomOperation;
namespace SharePointOnlineUtils namespace SharePointOnlineUtils
{ {
#region External Variable #region External Variable
// TODO: Import variable from PP [C:\Sources\VS\web_portal\webapp_italsort\DataItalsortGestionale\ProjTable.cs]
public class ParentProj public class ParentProj
{ {
public string ProjId { get; set; } public string ProjId { get; set; }
@@ -23,7 +26,7 @@ namespace SharePointOnlineUtils
public string Customer { get; set; } public string Customer { get; set; }
public string DeliveryReason { get; set; } public string DeliveryReason { get; set; }
public List<SubProj> SubProjects { 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 public class SubProj
{ {
@@ -40,7 +43,6 @@ namespace SharePointOnlineUtils
public class Program public class Program
{ {
public static async Task Main() public static async Task Main()
{ {
#region SPO Credential #region SPO Credential
@@ -61,8 +63,6 @@ namespace SharePointOnlineUtils
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}"); Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
#endregion #endregion
spc.ProjectsYSite(varProjSiteName, site, svcUser, svcUserPsw);
#region Project #region Project
//ProjectsByYearSite(listTitle, varProjSiteName, svcUser, site, svcUserPsw); //ProjectsByYearSite(listTitle, varProjSiteName, svcUser, site, svcUserPsw);
//Project(siteCollection, svcUser, svcUserPsw); //Project(siteCollection, svcUser, svcUserPsw);
@@ -83,7 +83,7 @@ namespace SharePointOnlineUtils
if (spc.SiteExist(ctx) == false) if (spc.SiteExist(ctx) == false)
{ {
spc.ProjectsYSite(varProjSiteName, site, user, psw); spc.TenantCreation(varProjSiteName, site, user, psw);
spc.DomainGroupRights(ctx, string.Empty); spc.DomainGroupRights(ctx, string.Empty);
spc.OnenoteSPFeature(ctx, string.Empty, string.Empty); spc.OnenoteSPFeature(ctx, string.Empty, string.Empty);
spc.ProjectsYField(ctx); spc.ProjectsYField(ctx);
@@ -136,7 +136,8 @@ namespace SharePointOnlineUtils
using (var authMgr = new AuthenticationManager()) using (var authMgr = new AuthenticationManager())
using (var ctx = authMgr.GetContext(subSite, user, psw)) 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 #endregion
@@ -144,17 +145,23 @@ namespace SharePointOnlineUtils
#region Offer #region Offer
public static async Task Offer(string siteCollection, string user, SecureString psw) public static async Task Offer(string siteCollection, string user, SecureString psw)
{ {
string year = "2021";//DateTime.Now.Year.ToString(); string year = DateTime.Now.Year.ToString();
string docLibName = $"Offerte {year}"; string tenantName = "Offerte";
string docLibName = $"{tenantName} {year}";
Uri site = new Uri($"{siteCollection}/sites/Offerte"); Uri site = new Uri($"{siteCollection}/sites/Offerte");
var authMgr = new AuthenticationManager(); var authMgr = new AuthenticationManager();
var ctx = authMgr.GetContext(site, user, psw); 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 ) if ( spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) == false )
{ {
spc.OfferDocLib(year, ctx); //spc.OfferDocLib(year, ctx);
} }
} }
#endregion #endregion
@@ -255,8 +262,7 @@ namespace SharePointOnlineUtils
} }
#endregion #endregion
#region Projects Years public static async Task TenantCreation(string siteName, Uri site, string user, SecureString psw)
public static async Task ProjectsYSite(string siteName, Uri site, string user, SecureString psw)
{ {
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{siteName.Replace(" ", string.Empty)}'."); 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) public static async Task ProjectsYField(ClientContext ctx)
{ {
Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>() 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 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 #region DocLib
try try
{ {
string[] docLibName = { $"Documenti {ssProjectTitle}", $"Media {ssProjectTitle}", $"SottoCommesse {ssProjectTitle}", $"Commerciale {ssProjectTitle}" }; Dictionary<string, Int32> docLibNames = new Dictionary<string, Int32>
foreach (string libName in docLibName)
{ {
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; Web web = ctx.Web;
ctx.Load(web); ctx.Load(web);
ListCreationInformation lci = new ListCreationInformation(); ListCreationInformation lci = new ListCreationInformation();
lci.Title = libName; lci.Title = kvp.Key;
lci.TemplateType = (int)ListTemplateType.DocumentLibrary; // TODO: PictureLibrary x Media lci.TemplateType = kvp.Value; //(int)ListTemplateType.DocumentLibrary; // TO-DO: PictureLibrary x Media
List list = web.Lists.Add(lci); List list = web.Lists.Add(lci);
ctx.ExecuteQuery(); ctx.ExecuteQuery();
if (libName.Contains("Commerciale")) DomainGroupRights(ctx, libName); if (kvp.Key.Contains("Commerciale")) DomainGroupRights(ctx, kvp.Key);
Console.WriteLine($"> '{libName}' è stato creato con successo."); Console.WriteLine($"> '{kvp.Key}' è stato creato con successo.");
} }
#endregion #endregion
@@ -676,7 +691,7 @@ namespace SharePointOnlineUtils
#endregion #endregion
#region Sub Project #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 try
{ {
@@ -720,7 +735,6 @@ namespace SharePointOnlineUtils
Console.WriteLine($"> Inizializzata la fase di creazione per {spt}."); Console.WriteLine($"> Inizializzata la fase di creazione per {spt}.");
#region DocSet Field Entry #region DocSet Field Entry
DocumentSet.Create(ctx, list.RootFolder, spt, contentType.Id); DocumentSet.Create(ctx, list.RootFolder, spt, contentType.Id);
ctx.ExecuteQuery(); ctx.ExecuteQuery();
@@ -768,18 +782,23 @@ namespace SharePointOnlineUtils
#endregion #endregion
#region Offer #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 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>" } }, Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>()
{ "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_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_Name", new string[] { "Text", "Item", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_Customer", new string[] { "Text", "Cliente", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_Authors", new string[] { "Text", "Descrizione Articolo", "PAL Field", "FALSE", "FALSE", "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 } },
{ "PAL_Authors", new string[] { "Text", "Descrizione Articolo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }
};
var site = ctx.Site; var site = ctx.Site;
ctx.Load(site, w => w.RootWeb, w => w.RootWeb.Fields); ctx.Load(site, w => w.RootWeb, w => w.RootWeb.Fields);
@@ -804,6 +823,7 @@ namespace SharePointOnlineUtils
try try
{ {
string docLibName = $"Offerte {year}"; string docLibName = $"Offerte {year}";
#region New DocLib #region New DocLib
Console.WriteLine($"> Inizializzata la fase di creazione '{docLibName}'."); Console.WriteLine($"> Inizializzata la fase di creazione '{docLibName}'.");
@@ -822,7 +842,6 @@ namespace SharePointOnlineUtils
DomainGroupRights(ctx, docLibName); DomainGroupRights(ctx, docLibName);
#region Shortcut on Quickmenu #region Shortcut on Quickmenu
NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch; NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch;
NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation(); NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
@@ -844,7 +863,6 @@ namespace SharePointOnlineUtils
{ {
try try
{ {
#region Context
var listTitle = $"Offerte {year}"; var listTitle = $"Offerte {year}";
var web = ctx.Web; var web = ctx.Web;
ctx.Load(web, w => w.Url); ctx.Load(web, w => w.Url);
@@ -875,13 +893,9 @@ namespace SharePointOnlineUtils
var contentType = ctData.FirstOrDefault(); var contentType = ctData.FirstOrDefault();
ctx.Load(contentType); ctx.Load(contentType);
ctx.ExecuteQuery(); 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 #endregion
@@ -891,9 +905,9 @@ namespace SharePointOnlineUtils
var featureName = "SiteNotebook"; var featureName = "SiteNotebook";
Guid featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f"); Guid featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f");
#region Feature Activate
if (string.IsNullOrEmpty(ssProjectTitle)) if (string.IsNullOrEmpty(ssProjectTitle))
{ {
#region Feature Activate
try try
{ {
if (!SiteFeaturesExist(ctx, featureName)) if (!SiteFeaturesExist(ctx, featureName))
@@ -904,12 +918,11 @@ namespace SharePointOnlineUtils
} }
} }
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; } catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
#endregion
} }
#endregion
#region Note Section
else else
{ {
#region Note Section
try try
{ {
Console.WriteLine($"> Inizializzata la fase di creazione della sezione {ssProjectTitle} in OneNote."); Console.WriteLine($"> Inizializzata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
@@ -925,8 +938,8 @@ namespace SharePointOnlineUtils
Console.WriteLine($"> Completata la fase di creazione della sezione {ssProjectTitle} in OneNote."); Console.WriteLine($"> Completata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
} }
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; } catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
#endregion
} }
#endregion
} }
#endregion #endregion