update directory name and access visibility

This commit is contained in:
Kalarumeth
2022-09-29 08:33:32 +02:00
parent 3ab3afe25e
commit f258a284d6
86 changed files with 253 additions and 361 deletions
@@ -0,0 +1,131 @@
using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client;
namespace console_spo_utils.Services;
internal class OneNoteService : IOneNoteService
{
private readonly ILogger<OneNoteService> logger;
private readonly ISiteOptions siteOptions;
private readonly ISharePointCustomOperation spc;
public OneNoteService(
ILogger<OneNoteService> logger,
ISiteOptions siteOptions,
ISharePointCustomOperation spc)
{
this.logger = logger;
this.siteOptions = siteOptions;
this.spc = spc;
}
public bool CreateFolderInsideProject(string projName, ClientContext ctx)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {projName} in OneNote.");
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetProjYearTenant()} Notebook/{projName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
logger.LogInformation($"> Completata la fase di creazione della sezione {projName} in OneNote.");
}
catch (Exception ex)
{
logger.LogError(ex, "OnenoteSPFeature");
return false;
}
return true;
}
public bool CreateFolderInsideQuotation(string quotationName, ClientContext ctx)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {quotationName} in OneNote.");
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
if (!spc.FolderExistsInsideList(ctx, $"{siteOptions.GetQuotationTenant()} Notebook", $"{DateTime.Today.Year}"))
{
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{DateTime.Today.Year}");
list.RootFolder.AddSubFolderUsingPath(rYearPath);
ctx.ExecuteQuery();
}
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{DateTime.Today.Year}/{quotationName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
logger.LogInformation($"> Completata la fase di creazione della sezione {quotationName} in OneNote.");
}
catch (Exception ex)
{
logger.LogError(ex, "OnenoteSPFeature");
return false;
}
return true;
}
public bool CreateFolderInsideNonCompliance(string quotationName, ClientContext ctx)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {quotationName} in OneNote.");
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
if (!spc.FolderExistsInsideList(ctx, $"{siteOptions.GetNonComplianceTenant()} Notebook", $"{DateTime.Today.Year}"))
{
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{DateTime.Today.Year}");
list.RootFolder.AddSubFolderUsingPath(rYearPath);
ctx.ExecuteQuery();
}
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{DateTime.Today.Year}/{quotationName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
logger.LogInformation($"> Completata la fase di creazione della sezione {quotationName} in OneNote.");
}
catch (Exception ex)
{
logger.LogError(ex, "OnenoteSPFeature");
return false;
}
return true;
}
public void EnableFeature(ClientContext ctx)
{
var featureName = "SiteNotebook";
var featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f");
#region Feature Activate
if (!spc.SiteFeaturesExist(ctx, featureName))
{
ctx.Web.ActivateFeature(featureId);
ctx.ExecuteQuery();
logger.LogInformation($"> La Feature {featureName} è ora attiva!");
}
#endregion
}
}