update directory name and access visibility
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Online.SharePoint.TenantAdministration;
|
||||
using console_spo_utils.Enums;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
internal class TenantService : ITenantService
|
||||
{
|
||||
private readonly ISharePointAuthenticationManager authMgr;
|
||||
private readonly ISharePointCustomOperation cpt;
|
||||
private readonly IRightsService rightsService;
|
||||
private readonly IOneNoteService oneNoteService;
|
||||
private readonly ILogger<TenantService> logger;
|
||||
private readonly ISiteOptions siteOptions;
|
||||
|
||||
public TenantService(
|
||||
ISharePointAuthenticationManager authMgr,
|
||||
ISharePointCustomOperation cpt,
|
||||
IRightsService rightsService,
|
||||
IOneNoteService oneNoteService,
|
||||
ILogger<TenantService> logger,
|
||||
ISiteOptions siteOptions)
|
||||
{
|
||||
this.authMgr = authMgr;
|
||||
this.cpt = cpt;
|
||||
this.rightsService = rightsService;
|
||||
this.oneNoteService = oneNoteService;
|
||||
this.logger = logger;
|
||||
this.siteOptions = siteOptions;
|
||||
}
|
||||
|
||||
public void CreateForProject()
|
||||
{
|
||||
TenantCreation(
|
||||
siteOptions.GetProjYearTenant(),
|
||||
siteOptions.GetProjectYearSite(),
|
||||
PalFieldType.Project
|
||||
);
|
||||
}
|
||||
|
||||
public void CreateForQuotation()
|
||||
{
|
||||
TenantCreation(
|
||||
siteOptions.GetQuotationTenant(),
|
||||
siteOptions.GetQuotationSite(),
|
||||
PalFieldType.Quotation
|
||||
);
|
||||
}
|
||||
|
||||
public void CreateForNonCompliance()
|
||||
{
|
||||
TenantCreation(
|
||||
siteOptions.GetNonComplianceTenant(),
|
||||
siteOptions.GetNonComplianceSite(),
|
||||
PalFieldType.NonCompliance
|
||||
);
|
||||
}
|
||||
|
||||
public void TenantCreation(string tenantName, Uri site, PalFieldType fieldType)
|
||||
{
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{tenantName.Replace(" ", string.Empty)}'.");
|
||||
|
||||
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
||||
|
||||
Uri path = new Uri(siteAdmin);
|
||||
|
||||
var tenantCtx = authMgr.GetContext(path);
|
||||
var ctx = authMgr.GetContext(site);
|
||||
try
|
||||
{
|
||||
var tenant = new Tenant(tenantCtx);
|
||||
var scp = new SiteCreationProperties
|
||||
{
|
||||
Url = site.ToString(),
|
||||
Title = tenantName,
|
||||
Owner = siteOptions.GetUser(),
|
||||
Template = "SITEPAGEPUBLISHING#0"
|
||||
};
|
||||
|
||||
SpoOperation spo = tenant.CreateSite(scp);
|
||||
|
||||
tenantCtx.Load(tenant);
|
||||
tenantCtx.Load(spo, i => i.IsComplete);
|
||||
tenantCtx.ExecuteQuery();
|
||||
|
||||
while (!spo.IsComplete)
|
||||
{
|
||||
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di pubblicazione.");
|
||||
System.Threading.Thread.Sleep(30000);
|
||||
spo.RefreshLoad();
|
||||
tenantCtx.ExecuteQuery();
|
||||
}
|
||||
|
||||
Console.WriteLine($"> Il sito è stato creato con successo. ({site})");
|
||||
|
||||
rightsService.DomainGroupRights(ctx, tenantName, string.Empty);
|
||||
|
||||
oneNoteService.EnableFeature(ctx);
|
||||
|
||||
cpt.PalCustomField(ctx, fieldType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Tenant Creation");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user