Service update, import changes from web_portal

This commit is contained in:
Claudio Boggian
2023-06-21 10:38:57 +02:00
parent 39fa4dedf3
commit bb99cef33c
101 changed files with 4266 additions and 3044 deletions
+76 -12
View File
@@ -1,8 +1,11 @@
using console_spo_utils.Interfaces.Services;
using System.Net;
using library_spo_utils.Constants;
using library_spo_utils.Enums;
using library_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client;
namespace console_spo_utils.Services;
namespace library_spo_utils.Services;
internal class OneNoteService : IOneNoteService
{
@@ -31,7 +34,7 @@ internal class OneNoteService : IOneNoteService
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetProjYearTenant()} Notebook/{projName}");
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetProjYearTenant(projName)} Notebook/{projName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
@@ -46,6 +49,7 @@ internal class OneNoteService : IOneNoteService
return true;
}
public bool CreateFolderInsideQuotation(string quotationName, ClientContext ctx)
{
try
@@ -53,18 +57,20 @@ internal class OneNoteService : IOneNoteService
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {quotationName} in OneNote.");
var year = siteOptions.GetYear(quotationName);
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
if (!spc.FolderExistsInsideList(ctx, $"{siteOptions.GetQuotationTenant()} Notebook", $"{DateTime.Today.Year}"))
if (!spc.FolderExist(ctx, $"SiteAssets/{siteOptions.GetQuotationTenant()} Notebook/{year}"))
{
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{DateTime.Today.Year}");
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{year}");
list.RootFolder.AddSubFolderUsingPath(rYearPath);
ctx.ExecuteQuery();
}
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{DateTime.Today.Year}/{quotationName}");
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetQuotationTenant()} Notebook/{year}/{quotationName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
@@ -80,29 +86,31 @@ internal class OneNoteService : IOneNoteService
return true;
}
public bool CreateFolderInsideNonCompliance(string quotationName, ClientContext ctx)
public bool CreateFolderInsideNonCompliance(string nonComplianceName, ClientContext ctx)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {quotationName} in OneNote.");
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {nonComplianceName} in OneNote.");
var year = siteOptions.GetYear(nonComplianceName);
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
if (!spc.FolderExistsInsideList(ctx, $"{siteOptions.GetNonComplianceTenant()} Notebook", $"{DateTime.Today.Year}"))
if (!spc.FolderExist(ctx, $"SiteAssets/{siteOptions.GetNonComplianceTenant()} Notebook/{year}"))
{
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{DateTime.Today.Year}");
var rYearPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{year}");
list.RootFolder.AddSubFolderUsingPath(rYearPath);
ctx.ExecuteQuery();
}
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{DateTime.Today.Year}/{quotationName}");
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{year}/{nonComplianceName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
logger.LogInformation($"> Completata la fase di creazione della sezione {quotationName} in OneNote.");
logger.LogInformation($"> Completata la fase di creazione della sezione {nonComplianceName} in OneNote.");
}
catch (Exception ex)
@@ -114,6 +122,62 @@ internal class OneNoteService : IOneNoteService
return true;
}
public bool CreateFolderInsidePurchasing(string purchasingName, ClientContext ctx, PurchType type)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {purchasingName} in OneNote.");
var purchasingOneNote = "Acquisti Notebook";
var year = siteOptions.GetYear(purchasingName);
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
if (!spc.FolderExist(ctx, $"SiteAssets/{purchasingOneNote}/{year}"))
{
foreach (var dir in Folders.PurchasingOneNoteDir(year))
{
var rDirPath = ResourcePath.FromDecodedUrl($"{purchasingOneNote}/{dir}");
list.RootFolder.AddSubFolderUsingPath(rDirPath);
ctx.ExecuteQuery();
}
}
switch (type)
{
case PurchType.Order:
var oPath = ResourcePath.FromDecodedUrl($"{purchasingOneNote}/{year}/Ordini di Acquisto/{purchasingName}");
list.RootFolder.AddSubFolderUsingPath(oPath);
ctx.ExecuteQuery();
break;
case PurchType.PackingSlip:
var psPath = ResourcePath.FromDecodedUrl($"{purchasingOneNote}/{year}/DDT di Acquisto/{purchasingName}");
list.RootFolder.AddSubFolderUsingPath(psPath);
ctx.ExecuteQuery();
break;
case PurchType.Request:
var rPath = ResourcePath.FromDecodedUrl($"{purchasingOneNote}/{year}/Richieste di Acquisto/{purchasingName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
break;
}
logger.LogInformation($"> Completata la fase di creazione della sezione {purchasingName} in OneNote.");
}
catch (Exception ex)
{
logger.LogError(ex, "OnenoteSPFeature");
return false;
}
return true;
}
public void EnableFeature(ClientContext ctx)
{
var featureName = "SiteNotebook";