Minor Update

This commit is contained in:
Kalarumeth
2022-07-09 12:02:12 +02:00
parent e95bead144
commit fe2b0a96a5
+6 -28
View File
@@ -23,31 +23,6 @@ namespace SharePointOnlineUtils
SecureString svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword; SecureString svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
ProjectsByYearSite(siteCollection, svcUser, svcUserPsw); ProjectsByYearSite(siteCollection, svcUser, svcUserPsw);
#region test
// Note: The PnP Sites Core AuthenticationManager class also supports this
/*Uri site = new Uri(siteCollection);
using (var authenticationManager = new AuthenticationManager())
using (var ctx = authenticationManager.GetContext(site, svcUser, svcUserPsw))
{
Web web = ctx.Web;
//web.Description = "";
//web.Update();
ctx.Load(web,
w => w.Title,
w => w.Description,
w => w.SiteGroups
);
await ctx.ExecuteQueryAsync();
Console.WriteLine($"Web: {web.Title}");
Console.WriteLine($"Description: {web.Description}");
Console.WriteLine($"Group: {web.SiteGroups}");
}*/
#endregion
} }
public static async Task ProjectsByYearSite(string siteCollection, string user, SecureString psw) public static async Task ProjectsByYearSite(string siteCollection, string user, SecureString psw)
@@ -59,20 +34,20 @@ namespace SharePointOnlineUtils
using (var authenticationManager = new AuthenticationManager()) using (var authenticationManager = new AuthenticationManager())
using (var ctx = authenticationManager.GetContext(site, user, psw)) using (var ctx = authenticationManager.GetContext(site, user, psw))
{ {
if (SPCheck.SiteExist(ctx) != false) if (SharePointCustomOperation.SiteExist(ctx) != false)
{ {
Console.WriteLine($"{projectsYear} - Esiste già."); Console.WriteLine($"{projectsYear} - Esiste già.");
} }
else else
{ {
Console.WriteLine($"{projectsYear} - Non esiste, a breve verrà generata."); Console.WriteLine($"{projectsYear} - Non esiste, a breve verrà generata.");
SPCheck.ProjectsYearGenerator(year, site, user, psw); SharePointCustomOperation.ProjectsYearGenerator(year, site, user, psw);
} }
} }
} }
} }
public class SPCheck public class SharePointCustomOperation
{ {
public static bool SiteExist(ClientContext ctx) public static bool SiteExist(ClientContext ctx)
{ {
@@ -109,6 +84,7 @@ namespace SharePointOnlineUtils
scp.Template = "SITEPAGEPUBLISHING#0"; scp.Template = "SITEPAGEPUBLISHING#0";
SpoOperation spo = tenant.CreateSite(scp); SpoOperation spo = tenant.CreateSite(scp);
ctx.Load(tenant); ctx.Load(tenant);
ctx.Load(spo, i => i.IsComplete); ctx.Load(spo, i => i.IsComplete);
ctx.ExecuteQuery(); ctx.ExecuteQuery();
@@ -129,6 +105,8 @@ namespace SharePointOnlineUtils
} }
} }
} }
} }
public class AuthenticationManager : IDisposable public class AuthenticationManager : IDisposable