Major Update
Crea il site Commesse [Anno], crea la lista per le commesse con realtivi Campi
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.vs
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+174
-14
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.SharePoint;
|
using Microsoft.SharePoint;
|
||||||
using Microsoft.SharePoint.Client;
|
using Microsoft.SharePoint.Client;
|
||||||
|
using SP = Microsoft.SharePoint.Client;
|
||||||
using Microsoft.Online.SharePoint.TenantAdministration;
|
using Microsoft.Online.SharePoint.TenantAdministration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
@@ -29,19 +30,28 @@ namespace SharePointOnlineUtils
|
|||||||
{
|
{
|
||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string projectsYear = "Commesse" + year;
|
string projectsYear = "Commesse" + year;
|
||||||
Uri site = new Uri(siteCollection + "/sites/" + projectsYear);
|
var listTitle = "Lista Commesse " + year;
|
||||||
|
Uri site = new Uri(siteCollection + "/Commesse/" + projectsYear);
|
||||||
|
|
||||||
using (var authenticationManager = new AuthenticationManager())
|
using (var authMgr = new AuthenticationManager())
|
||||||
using (var ctx = authenticationManager.GetContext(site, user, psw))
|
using (var ctx = authMgr.GetContext(site, user, psw))
|
||||||
{
|
{
|
||||||
if (SharePointCustomOperation.SiteExist(ctx) != false)
|
//SharePointCustomOperation.ProjectsYQuickMenu(ctx);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{projectsYear} - Esiste già.");
|
if (SharePointCustomOperation.SiteExist(ctx) == false)
|
||||||
|
SharePointCustomOperation.ProjectsYSite(year, site, user, psw);
|
||||||
|
|
||||||
|
if (SharePointCustomOperation.SiteExist(ctx) == true && SharePointCustomOperation.ListExist(year, ctx) == false)
|
||||||
|
{
|
||||||
|
SharePointCustomOperation.ProjectsYList(listTitle, ctx);
|
||||||
|
SharePointCustomOperation.ProjectsYListField(listTitle, ctx);
|
||||||
|
SharePointCustomOperation.ProjectsYListView(listTitle, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{projectsYear} - Non esiste, a breve verrà generata.");
|
Console.WriteLine(ex.Message);
|
||||||
SharePointCustomOperation.ProjectsYearGenerator(year, site, user, psw);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,8 +74,24 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectsYearGenerator(string year, Uri site, string user, SecureString psw)
|
public static bool ListExist(string year, ClientContext ctx)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List targetList = ctx.Web.Lists.GetByTitle("Lista Commesse " + year);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectsYSite(string year, Uri site, string user, SecureString psw)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../Commesse{year}'.");
|
||||||
|
|
||||||
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
||||||
|
|
||||||
Uri path = new Uri(siteAdmin);
|
Uri path = new Uri(siteAdmin);
|
||||||
@@ -91,21 +117,154 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
while (!spo.IsComplete)
|
while (!spo.IsComplete)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di creazione.");
|
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di pubblicazione.");
|
||||||
System.Threading.Thread.Sleep(30000);
|
System.Threading.Thread.Sleep(30000);
|
||||||
spo.RefreshLoad();
|
spo.RefreshLoad();
|
||||||
ctx.ExecuteQuery();
|
await ctx.ExecuteQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Il sito è stato creato con successo.\n{site}");
|
Console.WriteLine($"> Il sito è stato creato con successo. ({site})");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Qualcosa è andato storto. (" + ex.Message + ")");
|
Console.WriteLine($"> Qualcosa è andato storto nella creazione della pagina. ( {ex.Message} )");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectsYQuickMenu(ClientContext ctx)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectsYList(string listTitle, ClientContext ctx)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione della lista '{listTitle}'.");
|
||||||
|
|
||||||
|
Web web = ctx.Web;
|
||||||
|
ListCreationInformation creationInfo = new ListCreationInformation();
|
||||||
|
|
||||||
|
creationInfo.Title = listTitle;
|
||||||
|
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
|
||||||
|
List list = web.Lists.Add(creationInfo);
|
||||||
|
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
ctx.Load(list, l => l.Fields);
|
||||||
|
|
||||||
|
var fld = list.Fields.GetByInternalNameOrTitle("Title");
|
||||||
|
if (fld != null)
|
||||||
|
{
|
||||||
|
fld.Required = false;
|
||||||
|
fld.SetShowInDisplayForm(false);
|
||||||
|
fld.SetShowInEditForm(false);
|
||||||
|
fld.SetShowInNewForm(false);
|
||||||
|
|
||||||
|
list.Update();
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"> La lista '{listTitle}' è stato creato con successo.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Qualcosa è andato storto nella creazione della lista. ( {ex.Message} )");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectsYListField(string listTitle, ClientContext ctx)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione dei campi '{listTitle}'.");
|
||||||
|
|
||||||
|
Web web = ctx.Web;
|
||||||
|
List projectsList = web.Lists.GetByTitle(listTitle);
|
||||||
|
List list = web.Lists.GetByTitle(listTitle);
|
||||||
|
|
||||||
|
ctx.Load(list, l => l.Fields);
|
||||||
|
ctx.Load(projectsList, b => b.Id);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
string idProjField = @"<Field Type='URL' Name='PAL_ID_Project' StaticName='ID Progetto' DisplayName='ID Progetto' Required='TRUE' />";
|
||||||
|
Field lookupIdProjField = list.Fields.AddFieldAsXml(idProjField, true, AddFieldOptions.DefaultValue);
|
||||||
|
//lookupIdProjField.Update();
|
||||||
|
//ctx.Load(lookupIdProjField);
|
||||||
|
|
||||||
|
string clientField = @"<Field Type='Text' Name='PAL_Client' StaticName='Cliente' DisplayName='Cliente' Required='TRUE' />";
|
||||||
|
Field lookupClientField = list.Fields.AddFieldAsXml(clientField, true, AddFieldOptions.DefaultValue);
|
||||||
|
//lookupClientField.Update();
|
||||||
|
//ctx.Load(lookupClientField);
|
||||||
|
|
||||||
|
string dlvReasonField = @"<Field Type='Choice' Name='PAL_DlvReason' StaticName='Causale' DisplayName='Causale' Required='TRUE' Format='RadioButtons' >"
|
||||||
|
+ "<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>"
|
||||||
|
+ "</Field>";
|
||||||
|
Field lookupDlvReasonField = list.Fields.AddFieldAsXml(dlvReasonField, true, AddFieldOptions.DefaultValue);
|
||||||
|
//lookupDlvReasonField.Update();
|
||||||
|
//ctx.Load(lookupDlvReasonField);
|
||||||
|
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
|
Console.WriteLine($"> Completata la fase di creazione dei campi '{listTitle}'.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Qualcosa è andato storto nella creazione delle colonne. ( {ex.Message} )");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectsYListView(string listTitle, ClientContext ctx)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
||||||
|
|
||||||
|
List list = ctx.Web.Lists.GetByTitle(listTitle);
|
||||||
|
var views = list.Views;
|
||||||
|
//ctx.Load(list, l => l.Views);
|
||||||
|
|
||||||
|
|
||||||
|
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
||||||
|
|
||||||
|
viewCreation.SetAsDefaultView = true;
|
||||||
|
viewCreation.Title = listTitle;
|
||||||
|
viewCreation.ViewTypeKind = ViewType.None;
|
||||||
|
viewCreation.ColumnWidth = "350";
|
||||||
|
viewCreation.ViewFields = new string[3] { "ID Progetto", "Cliente", "Causale" };
|
||||||
|
|
||||||
|
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($"> MobileView set to true on ListView '{viewCreation.Title}'.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Qualcosa è andato storto nella creazione della ListView. ( {ex.Message} )");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +363,8 @@ namespace SharePointOnlineUtils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Returning token from cache for resource {resourceUri.DnsSafeHost} and user {userPrincipalName}");
|
//Console.WriteLine($"Returning token from cache for resource {resourceUri.DnsSafeHost} and user {userPrincipalName}");
|
||||||
|
Console.WriteLine("OK - Execution Querry");
|
||||||
return accessTokenFromCache;
|
return accessTokenFromCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user