Offer Complete
This commit is contained in:
+245
-163
@@ -1,8 +1,9 @@
|
|||||||
using Microsoft.Online.SharePoint.TenantAdministration;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Microsoft.Online.SharePoint.TenantAdministration;
|
||||||
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 PnP.Core.Model.SharePoint;
|
//using PnP.Core.Model.SharePoint;
|
||||||
using System;
|
using System;
|
||||||
//using PnP.Core.Model.SharePoint;
|
//using PnP.Core.Model.SharePoint;
|
||||||
//using PnP.Core.Services;
|
//using PnP.Core.Services;
|
||||||
@@ -55,9 +56,9 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
#region General Variable
|
#region General Variable
|
||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string varProjSiteName = $"Commesse {year}";
|
string tenantName = $"Commesse {year}";
|
||||||
string projectsYear = varProjSiteName.Replace(" ", string.Empty);
|
string projectsYear = tenantName.Replace(" ", string.Empty);
|
||||||
string listTitle = $"Lista {varProjSiteName}";
|
string listTitle = $"Lista {tenantName}";
|
||||||
string ssProjectTitle = "CT0016";
|
string ssProjectTitle = "CT0016";
|
||||||
string[] ssSubProjectTitle = { "CT0016-0001", "CT0016-0002", "CT0016-0003" };
|
string[] ssSubProjectTitle = { "CT0016-0001", "CT0016-0002", "CT0016-0003" };
|
||||||
|
|
||||||
@@ -67,12 +68,12 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
#region Project
|
#region Project
|
||||||
//ProjectsByYearSite(listTitle, varProjSiteName, svcUser, site, svcUserPsw);
|
//ProjectsByYearSite(listTitle, varProjSiteName, svcUser, site, svcUserPsw);
|
||||||
Project(siteCollection, svcUser, svcUserPsw);
|
//Project(siteCollection, svcUser, svcUserPsw);
|
||||||
//SubProject(siteCollection, svcUser, svcUserPsw);
|
//SubProject(siteCollection, svcUser, svcUserPsw);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Offer
|
#region Offer
|
||||||
//Offer(siteCollection, svcUser, svcUserPsw);
|
Offer(siteCollection, svcUser, svcUserPsw);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,12 +86,9 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
if (spc.SiteExist(ctx) == false)
|
if (spc.SiteExist(ctx) == false)
|
||||||
{
|
{
|
||||||
//spc.TenantCreation(varProjSiteName, site, user, psw);
|
spc.TenantCreation(varProjSiteName, site, user, psw);
|
||||||
//spc.DomainGroupRights(ctx, string.Empty);
|
spc.PalCustomField(ctx, spc.FieldType.Project);
|
||||||
//spc.OnenoteSPFeature(ctx, string.Empty, string.Empty);
|
spc.ProjectsYList(listTitle, ctx);
|
||||||
//spc.PalCustomField(ctx, spc.FieldType.Project);
|
|
||||||
//spc.ProjectsYList(listTitle, ctx);
|
|
||||||
//spc.ProjectsYListView(listTitle, ctx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +96,8 @@ namespace SharePointOnlineUtils
|
|||||||
public static async Task Project(string siteCollection, string user, SecureString psw)
|
public static async Task Project(string siteCollection, string user, SecureString psw)
|
||||||
{
|
{
|
||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string projectsYear = $"Commesse{year}";
|
string tenantName = $"Commesse {year}";
|
||||||
|
string projectsYear = tenantName.Replace(" ", string.Empty);
|
||||||
string listTitle = $"Lista Commesse {year}";
|
string listTitle = $"Lista Commesse {year}";
|
||||||
string ssProjectTitle = "CT0016";
|
string ssProjectTitle = "CT0016";
|
||||||
|
|
||||||
@@ -111,20 +110,20 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
spc.AddWebPart(ctx, "/sites/Commesse2022/CT0008/SitePages/homepage.aspx");
|
spc.AddWebPart(ctx, "/sites/Commesse2022/CT0008/SitePages/homepage.aspx");
|
||||||
|
|
||||||
//if (spc.SiteExist(ctx) == true && spc.SiteExist(sCtx) == false)
|
if (spc.SiteExist(ctx) == true && spc.SiteExist(sCtx) == false)
|
||||||
//{
|
{
|
||||||
// #region Site Context
|
#region Site Context
|
||||||
// spc.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
|
spc.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
|
||||||
// spc.OnenoteSPFeature(ctx, year, ssProjectTitle);
|
spc.OnenoteSPFeature(ctx, tenantName, ssProjectTitle); //TODO verificare
|
||||||
// spc.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
|
spc.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
|
||||||
// #endregion
|
#endregion
|
||||||
//
|
|
||||||
// #region SubSite Context
|
#region SubSite Context
|
||||||
// spc.ProjectDocLib(ssProjectTitle, sCtx);
|
spc.ProjectDocLib(ssProjectTitle, sCtx);
|
||||||
// spc.ProjectSubProjList(ssProjectTitle, sCtx);
|
spc.ProjectSubProjList(ssProjectTitle, sCtx);
|
||||||
// spc.ProjectQuickMenu(ssProjectTitle, subSite.ToString(), sCtx);
|
spc.ProjectQuickMenu(ssProjectTitle, subSite.ToString(), sCtx);
|
||||||
// #endregion
|
#endregion
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task SubProject(string siteCollection, string user, SecureString psw)
|
public static async Task SubProject(string siteCollection, string user, SecureString psw)
|
||||||
@@ -152,24 +151,28 @@ namespace SharePointOnlineUtils
|
|||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string tenantName = "Offerte";
|
string tenantName = "Offerte";
|
||||||
string docLibName = $"{tenantName} {year}";
|
string docLibName = $"{tenantName} {year}";
|
||||||
|
string quotationName = $"OF0004";
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
spc.OnenoteSPFeature(ctx, string.Empty, string.Empty);
|
||||||
|
|
||||||
//if (spc.SiteExist(ctx) == false)
|
if (!spc.SiteExist(ctx))
|
||||||
//{
|
{
|
||||||
// spc.TenantCreation(tenantName, site, user, psw);
|
spc.TenantCreation(tenantName, site, user, psw);
|
||||||
// spc.PalCustomField(ctx, spc.FieldType.Quotation);
|
}
|
||||||
//}
|
else if (spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) == false)
|
||||||
|
{
|
||||||
//if (spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) == false)
|
spc.PalCustomField(ctx, spc.FieldType.Quotation);
|
||||||
//{
|
spc.OfferDocLib(docLibName, ctx);
|
||||||
// spc.ProjectsYField(ctx, source);
|
}
|
||||||
// spc.OfferDocLib(year, ctx);
|
else if (spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) && !spc.FolderExistsInsideList(ctx, docLibName, quotationName))
|
||||||
//}
|
{
|
||||||
|
spc.OfferDocSet(quotationName, docLibName, tenantName, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -275,52 +278,52 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static async Task TenantCreation(string siteName, Uri site, string user, SecureString psw)
|
#region Tenant Creation
|
||||||
|
public static async Task TenantCreation(string tenantName, 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 '../{tenantName.Replace(" ", string.Empty)}'.");
|
||||||
|
|
||||||
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
||||||
|
|
||||||
Uri path = new Uri(siteAdmin);
|
Uri path = new Uri(siteAdmin);
|
||||||
|
|
||||||
using (var authenticationManager = new AuthenticationManager())
|
var authMgr = new AuthenticationManager();
|
||||||
using (var ctx = authenticationManager.GetContext(path, user, psw))
|
var tenantCtx = authMgr.GetContext(path, user, psw);
|
||||||
{
|
var ctx = authMgr.GetContext(site, user, psw);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var tenant = new Tenant(ctx);
|
var tenant = new Tenant(tenantCtx);
|
||||||
var scp = new SiteCreationProperties();
|
var scp = new SiteCreationProperties();
|
||||||
|
|
||||||
scp.Url = site.ToString();
|
scp.Url = site.ToString();
|
||||||
scp.Title = siteName;
|
scp.Title = tenantName;
|
||||||
scp.Owner = user;
|
scp.Owner = user;
|
||||||
scp.Template = "SITEPAGEPUBLISHING#0";
|
scp.Template = "SITEPAGEPUBLISHING#0";
|
||||||
|
|
||||||
SpoOperation spo = tenant.CreateSite(scp);
|
SpoOperation spo = tenant.CreateSite(scp);
|
||||||
|
|
||||||
ctx.Load(tenant);
|
tenantCtx.Load(tenant);
|
||||||
ctx.Load(spo, i => i.IsComplete);
|
tenantCtx.Load(spo, i => i.IsComplete);
|
||||||
ctx.ExecuteQuery();
|
tenantCtx.ExecuteQuery();
|
||||||
|
|
||||||
while (!spo.IsComplete)
|
while (!spo.IsComplete)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di pubblicazione.");
|
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di pubblicazione.");
|
||||||
System.Threading.Thread.Sleep(30000);
|
System.Threading.Thread.Sleep(30000);
|
||||||
spo.RefreshLoad();
|
spo.RefreshLoad();
|
||||||
await ctx.ExecuteQueryAsync();
|
await tenantCtx.ExecuteQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"> Il sito è stato creato con successo. ({site})");
|
Console.WriteLine($"> Il sito è stato creato con successo. ({site})");
|
||||||
|
|
||||||
|
DomainGroupRights(ctx, tenantName, string.Empty);
|
||||||
|
|
||||||
|
OnenoteSPFeature(ctx, string.Empty, string.Empty);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto nella creazione della pagina. ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Projects Years
|
|
||||||
public static async Task PalCustomField(ClientContext ctx, FieldType et)
|
public static async Task PalCustomField(ClientContext ctx, FieldType et)
|
||||||
{
|
{
|
||||||
Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>();
|
Dictionary<string, string[]> fieldList = new Dictionary<string, string[]>();
|
||||||
@@ -342,7 +345,7 @@ namespace SharePointOnlineUtils
|
|||||||
case FieldType.Quotation:
|
case FieldType.Quotation:
|
||||||
fieldList = new 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_Quotation_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_ID_Quotation", new string[] { "Text", "ID Offerta", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
|
{ "PAL_ID_Quotation", new string[] { "Text", "ID Offerta", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
|
||||||
{ "PAL_Quotation_Name", new string[] { "Text", "Fornitore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
|
{ "PAL_Quotation_Name", new string[] { "Text", "Fornitore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
|
||||||
{ "PAL_Authors", new string[] { "Text", "Autore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }
|
{ "PAL_Authors", new string[] { "Text", "Autore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }
|
||||||
@@ -370,14 +373,57 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{ Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task OnenoteSPFeature(ClientContext ctx, string siteName, string onGroupSection) //TODO: predisposizione per offerte
|
||||||
|
{
|
||||||
|
var featureName = "SiteNotebook";
|
||||||
|
Guid featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(onGroupSection))
|
||||||
|
{
|
||||||
|
#region Feature Activate
|
||||||
|
if (!SiteFeaturesExist(ctx, featureName))
|
||||||
|
{
|
||||||
|
ctx.Web.ActivateFeature(featureId);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
Console.WriteLine($"> La Feature {featureName} è ora attiva!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#region Note Group Section
|
||||||
|
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione della sezione {onGroupSection} in OneNote.");
|
||||||
|
|
||||||
|
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
|
||||||
|
ctx.Load(list, l => l.RootFolder);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
var rPath = ResourcePath.FromDecodedUrl($"{siteName} Notebook/{onGroupSection}");
|
||||||
|
list.RootFolder.AddSubFolderUsingPath(rPath);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Completata la fase di creazione della sezione {onGroupSection} in OneNote.");
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Projects Years
|
||||||
public static async Task ProjectsYList(string listTitle, ClientContext ctx)
|
public static async Task ProjectsYList(string listTitle, ClientContext ctx)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#region New List
|
||||||
Console.WriteLine($"> Inizializzata la fase di creazione della lista '{listTitle}'.");
|
Console.WriteLine($"> Inizializzata la fase di creazione della lista '{listTitle}'.");
|
||||||
|
|
||||||
Web web = ctx.Web;
|
Web web = ctx.Web;
|
||||||
@@ -385,13 +431,13 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
creationInfo.Title = listTitle;
|
creationInfo.Title = listTitle;
|
||||||
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
|
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
|
||||||
List list = web.Lists.Add(creationInfo);
|
List oList = web.Lists.Add(creationInfo);
|
||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
ctx.Load(list, l => l.Fields);
|
ctx.Load(oList, l => l.Fields);
|
||||||
|
|
||||||
var fld = list.Fields.GetByInternalNameOrTitle("Title");
|
var fld = oList.Fields.GetByInternalNameOrTitle("Title");
|
||||||
if (fld != null)
|
if (fld != null)
|
||||||
{
|
{
|
||||||
fld.Required = false;
|
fld.Required = false;
|
||||||
@@ -399,23 +445,13 @@ namespace SharePointOnlineUtils
|
|||||||
fld.SetShowInEditForm(false);
|
fld.SetShowInEditForm(false);
|
||||||
fld.SetShowInNewForm(false);
|
fld.SetShowInNewForm(false);
|
||||||
|
|
||||||
list.Update();
|
oList.Update();
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"> La lista '{listTitle}' è stato creato con successo.");
|
Console.WriteLine($"> La lista '{listTitle}' è stato creato con successo.");
|
||||||
}
|
#endregion
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto nella creazione della lista. ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task ProjectsYListView(string listTitle, ClientContext ctx)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
#region Field
|
#region Field
|
||||||
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{listTitle}'.");
|
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{listTitle}'.");
|
||||||
|
|
||||||
@@ -476,13 +512,8 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
Console.WriteLine($"> Impostata come HomePage di '{viewCreation.Title}'");
|
Console.WriteLine($"> Impostata come HomePage di '{viewCreation.Title}'");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto nella creazione della ListView. ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -499,18 +530,13 @@ namespace SharePointOnlineUtils
|
|||||||
wci.Title = ssProjectTitle;
|
wci.Title = ssProjectTitle;
|
||||||
wci.UseSamePermissionsAsParentSite = true;
|
wci.UseSamePermissionsAsParentSite = true;
|
||||||
wci.WebTemplate = "SITEPAGEPUBLISHING#0";
|
wci.WebTemplate = "SITEPAGEPUBLISHING#0";
|
||||||
//wci.Language = 1040;
|
|
||||||
|
|
||||||
Web web = ctx.Site.RootWeb.Webs.Add(wci);
|
Web web = ctx.Site.RootWeb.Webs.Add(wci);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
Console.WriteLine($"> Il sito {ssProjectTitle} è stato creato con successo!");
|
Console.WriteLine($"> Il sito {ssProjectTitle} è stato creato con successo!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectListEntry(string ssProjectTitle, string listTitle, string projectsYear, ClientContext ctx) //TODO: PP var
|
public static async Task ProjectListEntry(string ssProjectTitle, string listTitle, string projectsYear, ClientContext ctx) //TODO: PP var
|
||||||
@@ -535,11 +561,7 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
Console.WriteLine($"> La Commessa {ssProjectTitle} è stata aggiunta alla lista {listTitle} con successo!");
|
Console.WriteLine($"> La Commessa {ssProjectTitle} è stata aggiunta alla lista {listTitle} con successo!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectDocLib(string ssProjectTitle, ClientContext ctx) //TODO: Da testare
|
public static async Task ProjectDocLib(string ssProjectTitle, ClientContext ctx) //TODO: Da testare
|
||||||
@@ -569,7 +591,7 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
if (kvp.Key.Contains("Commerciale")) DomainGroupRights(ctx, kvp.Key);
|
if (kvp.Key.Contains("Commerciale")) DomainGroupRights(ctx, string.Empty, kvp.Key);
|
||||||
Console.WriteLine($"> '{kvp.Key}' è stato creato con successo.");
|
Console.WriteLine($"> '{kvp.Key}' è stato creato con successo.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,11 +626,7 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"> {kvp.Key} creato con successo in {kvp.Value}.");
|
Console.WriteLine($"> {kvp.Key} creato con successo in {kvp.Value}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,11 +689,7 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectQuickMenu(string ssProjectTitle, string subSiteUrl, ClientContext ctx)
|
public static async Task ProjectQuickMenu(string ssProjectTitle, string subSiteUrl, ClientContext ctx)
|
||||||
@@ -716,8 +730,7 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{ Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -804,21 +817,15 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{
|
|
||||||
Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Offer
|
#region Offer
|
||||||
public static async Task OfferDocLib(string year, ClientContext ctx)
|
public static async Task OfferDocLib(string docLibName, ClientContext ctx) // TODO: enable one note function
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
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}'.");
|
||||||
|
|
||||||
@@ -828,20 +835,71 @@ namespace SharePointOnlineUtils
|
|||||||
ListCreationInformation lci = new ListCreationInformation();
|
ListCreationInformation lci = new ListCreationInformation();
|
||||||
lci.Title = docLibName;
|
lci.Title = docLibName;
|
||||||
lci.TemplateType = (int)ListTemplateType.DocumentLibrary;
|
lci.TemplateType = (int)ListTemplateType.DocumentLibrary;
|
||||||
List list = web.Lists.Add(lci);
|
web.Lists.Add(lci);
|
||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
Console.WriteLine($"> Completata la fase di creazione '{docLibName}'.");
|
Console.WriteLine($"> Completata la fase di creazione '{docLibName}'.");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
DomainGroupRights(ctx, docLibName);
|
#region Field
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{docLibName}'.");
|
||||||
|
|
||||||
|
List list = ctx.Web.Lists.GetByTitle(docLibName);
|
||||||
|
var siteField = ctx.Site.RootWeb;
|
||||||
|
ctx.Load(list, l => l.Fields);
|
||||||
|
ctx.Load(siteField, s => s.Fields);
|
||||||
|
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
string[] fieldName = { "ID Offerta", "Fornitore", "Causale", "Autore" };
|
||||||
|
|
||||||
|
foreach (var fn in fieldName)
|
||||||
|
{
|
||||||
|
var Fields = siteField.Fields.GetByTitle(fn);
|
||||||
|
list.Fields.Add(Fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Completata la fase di importazione dei campi '{docLibName}'.");
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region View
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{docLibName}'.");
|
||||||
|
|
||||||
|
var views = list.Views;
|
||||||
|
|
||||||
|
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
||||||
|
|
||||||
|
viewCreation.SetAsDefaultView = true;
|
||||||
|
viewCreation.Title = docLibName;
|
||||||
|
viewCreation.ViewTypeKind = ViewType.None;
|
||||||
|
viewCreation.ColumnWidth = "350";
|
||||||
|
viewCreation.ViewFields = new string[] { "Type", "Name", "ID Offerta", "Fornitore", "Causale", "Autore" };
|
||||||
|
|
||||||
|
var view = views.Add(viewCreation);
|
||||||
|
|
||||||
|
ctx.Load(view);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Completata la fase di creazione della ListView '{viewCreation.Title}'.");
|
||||||
|
|
||||||
|
var customView = views.GetByTitle(viewCreation.Title);
|
||||||
|
customView.MobileView = true;
|
||||||
|
customView.MobileDefaultView = true;
|
||||||
|
|
||||||
|
customView.Update();
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
||||||
|
#endregion
|
||||||
|
|
||||||
#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();
|
||||||
|
|
||||||
newNavNode.Title = $"{docLibName}";
|
newNavNode.Title = $"{docLibName}";
|
||||||
newNavNode.Url = $"{web.Url}/Offerte%20{year}";
|
newNavNode.Url = $"{web.Url}/{docLibName.Replace(" ", "%20")}";
|
||||||
newNavNode.AsLastNode = true;
|
newNavNode.AsLastNode = true;
|
||||||
spNavNodeColl.Add(newNavNode);
|
spNavNodeColl.Add(newNavNode);
|
||||||
|
|
||||||
@@ -850,24 +908,23 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamemento a {docLibName} è ora disponibile.");
|
Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamemento a {docLibName} è ora disponibile.");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
{ Console.WriteLine($"!> Qualcosa è andato storto... {ex.Message}"); return; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task OfferDocSet(string year, ClientContext ctx)
|
public static async Task OfferDocSet(string quotationName, string docLibName, string tenantName, ClientContext ctx) //TODO: add onenote on creation of
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var listTitle = $"Offerte {year}";
|
#region Context
|
||||||
var web = ctx.Web;
|
var web = ctx.Web;
|
||||||
ctx.Load(web, w => w.Url);
|
ctx.Load(web, w => w.Url);
|
||||||
var list = web.Lists.GetByTitle(listTitle);
|
List list = web.Lists.GetByTitle(docLibName);
|
||||||
ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled);
|
ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
list.ContentTypesEnabled = true;
|
list.ContentTypesEnabled = true;
|
||||||
list.Update();
|
list.Update();
|
||||||
|
|
||||||
if (ListContentTypeExist(ctx, listTitle, "Set di documenti") == false)
|
if (ListContentTypeExist(ctx, docLibName, "Set di documenti") == false)
|
||||||
{
|
{
|
||||||
var documentCT = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5");
|
var documentCT = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5");
|
||||||
ctx.Load(documentCT);
|
ctx.Load(documentCT);
|
||||||
@@ -888,58 +945,56 @@ namespace SharePointOnlineUtils
|
|||||||
var contentType = ctData.FirstOrDefault();
|
var contentType = ctData.FirstOrDefault();
|
||||||
ctx.Load(contentType);
|
ctx.Load(contentType);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SPFeature
|
|
||||||
public static async Task OnenoteSPFeature(ClientContext ctx, string year, string ssProjectTitle) //TODO: predisposizione per offerte
|
|
||||||
{
|
|
||||||
var featureName = "SiteNotebook";
|
|
||||||
Guid featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(ssProjectTitle))
|
Console.WriteLine($"> Inizializzata la fase di creazione per {quotationName}.");
|
||||||
{
|
|
||||||
#region Feature Activate
|
#region DocSet Field Entry
|
||||||
try
|
DocumentSet.Create(ctx, list.RootFolder, quotationName, contentType.Id);
|
||||||
{
|
|
||||||
if (!SiteFeaturesExist(ctx, featureName))
|
|
||||||
{
|
|
||||||
ctx.Web.ActivateFeature(featureId);
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
Console.WriteLine($"> La Feature {featureName} è ora attiva!");
|
|
||||||
}
|
Console.WriteLine($"> DocumentSet {quotationName} creata.");
|
||||||
}
|
|
||||||
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
|
var dsItem = list.RootFolder.Folders.GetByUrl(quotationName).ListItemAllFields;
|
||||||
|
|
||||||
|
dsItem["PAL_ID_Quotation"] = "valueItemCode";
|
||||||
|
dsItem["PAL_Quotation_Name"] = "valueItemDescription";
|
||||||
|
dsItem["PAL_Quotation_Reason"] = "NC NON CONFORMITÁ";
|
||||||
|
dsItem["PAL_Authors"] = "Test";
|
||||||
|
|
||||||
|
dsItem.Update();
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Field value update.");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#region Note Section
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.WriteLine($"> Inizializzata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
|
|
||||||
|
|
||||||
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
|
#region Quotation Folder
|
||||||
ctx.Load(list, l => l.RootFolder);
|
string rev = "Rev. 1";
|
||||||
ctx.ExecuteQuery();
|
string[] folderName = { rev, $"{rev}/01_Costificazione", $"{rev}/02_Offerta", $"{rev}/03_Meeting", $"{rev}/04_Corrispondenza", $"{rev}/08_Specifiche_Tecniche", $"{rev}/10_Fornitori", $"{rev}/11_Documenti_Tecnici", $"{rev}/14_Foto" };
|
||||||
|
|
||||||
var rPath = ResourcePath.FromDecodedUrl($"Commesse {year} Notebook/{ssProjectTitle}");
|
foreach (string name in folderName)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"La sotto cartella {name} verrà creata in {quotationName}");
|
||||||
|
var rPath = ResourcePath.FromDecodedUrl($"{quotationName}/{name}");
|
||||||
list.RootFolder.AddSubFolderUsingPath(rPath);
|
list.RootFolder.AddSubFolderUsingPath(rPath);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
Console.WriteLine($"> Completata la fase di creazione della sezione {ssProjectTitle} in OneNote.");
|
OnenoteSPFeature(ctx, tenantName, quotationName);
|
||||||
}
|
|
||||||
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
|
Console.WriteLine($"Le sotto cartelle sono state create con successo in {quotationName}");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Console.WriteLine($"> {quotationName} creato con successo in Offerte/{docLibName}.");
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Rights
|
#region Rights
|
||||||
public static async Task DomainGroupRights(ClientContext ctx, string docLibName)
|
public static async Task DomainGroupRights(ClientContext ctx, string tenantName, string docLibName)
|
||||||
{
|
{
|
||||||
#region Groups & Privileges
|
#region Groups & Privileges
|
||||||
Dictionary<string, string> itsADGruopRole = new Dictionary<string, string>()
|
Dictionary<string, string> itsADGruopRole = new Dictionary<string, string>()
|
||||||
@@ -963,9 +1018,9 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(docLibName))
|
if (tenantName.Contains("Commesse"))
|
||||||
{
|
{
|
||||||
#region Site Permission
|
#region Site Permission Project
|
||||||
Web web = ctx.Web;
|
Web web = ctx.Web;
|
||||||
|
|
||||||
foreach (KeyValuePair<string, string> role in itsADGruopRole)
|
foreach (KeyValuePair<string, string> role in itsADGruopRole)
|
||||||
@@ -985,7 +1040,29 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine("> Completata la fase di assegnazione dei ruoli.");
|
Console.WriteLine("> Completata la fase di assegnazione dei ruoli.");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
else
|
else if (tenantName.Contains("Offerte"))
|
||||||
|
{
|
||||||
|
#region Site Permission Quotation
|
||||||
|
Web web = ctx.Web;
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, string> role in itsADGruopSalesRole)
|
||||||
|
{
|
||||||
|
var adGroup = web.EnsureUser(role.Key);
|
||||||
|
ctx.Load(adGroup);
|
||||||
|
|
||||||
|
var roleD = web.RoleDefinitions.GetByName(role.Value);
|
||||||
|
RoleDefinitionBindingCollection roleDB = new RoleDefinitionBindingCollection(ctx);
|
||||||
|
roleDB.Add(roleD);
|
||||||
|
|
||||||
|
web.RoleAssignments.Add(adGroup, roleDB);
|
||||||
|
web.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
Console.WriteLine("> Completata la fase di assegnazione dei ruoli.");
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(docLibName))
|
||||||
{
|
{
|
||||||
#region DocLib Permission
|
#region DocLib Permission
|
||||||
Web web = ctx.Web;
|
Web web = ctx.Web;
|
||||||
@@ -1013,7 +1090,7 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} {ex.StackTrace} )"); return; }
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1061,7 +1138,7 @@ namespace SharePointOnlineUtils
|
|||||||
limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, "Left", 1);
|
limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, "Left", 1);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
}
|
}
|
||||||
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )\n[\n{ex.StackTrace}\n]"); return; }
|
catch (Exception ex) { Logger.ConsoleMessage(ex); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWebPart(ClientContext ctx)
|
public static void GetWebPart(ClientContext ctx)
|
||||||
@@ -1073,6 +1150,11 @@ namespace SharePointOnlineUtils
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Logger
|
||||||
|
{
|
||||||
|
public static void ConsoleMessage(Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )\n[\n{ex.StackTrace}\n]"); return; }
|
||||||
|
}
|
||||||
|
|
||||||
public class AuthenticationManager : IDisposable
|
public class AuthenticationManager : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user