diff --git a/console_spo_utils/Constants/Fields.cs b/console_spo_utils/Constants/Fields.cs index eae59d3..95bd456 100644 --- a/console_spo_utils/Constants/Fields.cs +++ b/console_spo_utils/Constants/Fields.cs @@ -117,7 +117,7 @@ public static class Fields { return new Dictionary() { - { "PAL_Quotation_Reason", new string[] { "Choice", "Causale", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", $"01 VENDITA MACCHINE / IMPIANTI02 VENDITA RICAMBI04 VENDITA SERVIZI FUORI COMMESSA08 VENDITA RIPARAZIONI09 ENGINEERING11 VENDITA E LAVORAZ.CONTO TERZI55 PREVENDITENC NON CONFORMITÁ" } }, + { "PAL_Quotation_Reason", new string[] { "Choice", "Causale", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "01 VENDITA MACCHINE / IMPIANTI02 VENDITA RICAMBI04 VENDITA SERVIZI FUORI COMMESSA08 VENDITA RIPARAZIONI09 ENGINEERING11 VENDITA E LAVORAZ.CONTO TERZI55 PREVENDITENC NON CONFORMITÁ" } }, { "PAL_ID_Quotation", new string[] { "Text", "ID Offerta", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_Quotation_Name", new string[] { "Text", "Fornitore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_Authors", new string[] { "Text", "Autore", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } } @@ -131,13 +131,13 @@ public static class Fields { return new Dictionary() { - { "PAL_NC_Source", new string[] {"Choice", "Sorgente", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "InternoClienteFornitore" } }, + { "PAL_NC_Source", new string[] {"Choice", "Sorgente", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "InternoClienteFornitore" } }, { "PAL_NC_Reference", new string[] { "Text", "Rifermento", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_NC_Nominative", new string[] { "Text", "Nominativo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_NC_DateOfDetection", new string[] { "Text", "Data Rilevazione", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_NC_Project", new string[] { "Text", "Commessa", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, { "PAL_NC_ItemCode", new string[] { "Text", "Parte", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, - { "PAL_NC_Portal", new string[] {"URL", "Portal", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, + { "PAL_NC_PortalUrl", new string[] {"URL", "Portal", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }, }; } } diff --git a/console_spo_utils/Fakes/Repositories/FakeNonComplianceSettingsRepository.cs b/console_spo_utils/Fakes/Repositories/FakeNonComplianceSettingsRepository.cs new file mode 100644 index 0000000..1aa0dbd --- /dev/null +++ b/console_spo_utils/Fakes/Repositories/FakeNonComplianceSettingsRepository.cs @@ -0,0 +1,47 @@ +using console_spo_utils.Interfaces.Repositories; +using Microsoft.SharePoint.Client; +using static System.Net.WebRequestMethods; + +namespace console_spo_utils.Fakes.Repositories; + +public class FakeNonComplianceSettingsRepository : INonComplianceRepository +{ + public string DefaultNonComplianceSource() + { + return "Interno"; + } + + public string DefaultNonComplianceReference() + { + return "Italsort"; + } + + public string DefaultNonComplianceNominative() + { + return "Mario Issor"; + } + + public string DefaultNonComplianceDateOfDetection() + { + return "28-09-2022"; + } + + public string DefaultNonComplianceProject() + { + return "CT0001-001"; + } + + public string DefaultNonComplianceItemCode() + { + return "M24x3"; + } + + public FieldUrlValue DefaultNonCompliancePortalUrl() + { + return new FieldUrlValue + { + Description = "Vai a Portal", + Url = "https://portal.pal.local/" + }; + } +} \ No newline at end of file diff --git a/console_spo_utils/Interfaces/Repositories/INonComplianceRepository.cs b/console_spo_utils/Interfaces/Repositories/INonComplianceRepository.cs new file mode 100644 index 0000000..63ebc13 --- /dev/null +++ b/console_spo_utils/Interfaces/Repositories/INonComplianceRepository.cs @@ -0,0 +1,15 @@ +using Microsoft.SharePoint.Client; + +namespace console_spo_utils.Interfaces.Repositories; + +public interface INonComplianceRepository +{ + public string DefaultNonComplianceSource(); + public string DefaultNonComplianceReference(); + public string DefaultNonComplianceNominative(); + public string DefaultNonComplianceDateOfDetection(); + public string DefaultNonComplianceProject(); + public string DefaultNonComplianceItemCode(); + public FieldUrlValue DefaultNonCompliancePortalUrl(); + +} \ No newline at end of file diff --git a/console_spo_utils/Interfaces/Services/INonComplianceBuildService.cs b/console_spo_utils/Interfaces/Services/INonComplianceBuildService.cs new file mode 100644 index 0000000..9528af2 --- /dev/null +++ b/console_spo_utils/Interfaces/Services/INonComplianceBuildService.cs @@ -0,0 +1,6 @@ +namespace console_spo_utils.Interfaces.Services; + +public interface INonComplianceBuildService +{ + public void CreateIfNotExists(string nonComplianceName); +} \ No newline at end of file diff --git a/console_spo_utils/Interfaces/Services/INonComplianceDocLibraryService.cs b/console_spo_utils/Interfaces/Services/INonComplianceDocLibraryService.cs new file mode 100644 index 0000000..3eb083a --- /dev/null +++ b/console_spo_utils/Interfaces/Services/INonComplianceDocLibraryService.cs @@ -0,0 +1,8 @@ +using Microsoft.SharePoint.Client; + +namespace console_spo_utils.Interfaces.Services; + +public interface INonComplianceDocLibraryService +{ + public void Create(string libName, ClientContext ctx); +} \ No newline at end of file diff --git a/console_spo_utils/Interfaces/Services/INonComplianceDocSetService.cs b/console_spo_utils/Interfaces/Services/INonComplianceDocSetService.cs new file mode 100644 index 0000000..54da872 --- /dev/null +++ b/console_spo_utils/Interfaces/Services/INonComplianceDocSetService.cs @@ -0,0 +1,9 @@ +using Microsoft.SharePoint.Client; + +namespace console_spo_utils.Interfaces.Services; + +public interface INonComplianceDocSetService +{ + public void Create(string nonComplianceName, string docLibraryName, string tenantName, ClientContext ctx); + +} \ No newline at end of file diff --git a/console_spo_utils/Interfaces/Services/IOneNoteService.cs b/console_spo_utils/Interfaces/Services/IOneNoteService.cs index 6b3ea22..f4a09d2 100644 --- a/console_spo_utils/Interfaces/Services/IOneNoteService.cs +++ b/console_spo_utils/Interfaces/Services/IOneNoteService.cs @@ -6,5 +6,6 @@ public interface IOneNoteService { public bool CreateFolderInsideProject(string projName, ClientContext ctx); public bool CreateFolderInsideQuotation(string quotationName, ClientContext ctx); + public bool CreateFolderInsideNonCompliance(string quotationName, ClientContext ctx); public void EnableFeature(ClientContext ctx); } \ No newline at end of file diff --git a/console_spo_utils/Program.cs b/console_spo_utils/Program.cs index 3b8739d..eb2cbce 100644 --- a/console_spo_utils/Program.cs +++ b/console_spo_utils/Program.cs @@ -19,6 +19,7 @@ namespace console_spo_utils services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddHostedService(); }) @@ -45,6 +46,9 @@ namespace console_spo_utils services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/console_spo_utils/Services/NonComplianceBuildService.cs b/console_spo_utils/Services/NonComplianceBuildService.cs new file mode 100644 index 0000000..8d5da57 --- /dev/null +++ b/console_spo_utils/Services/NonComplianceBuildService.cs @@ -0,0 +1,58 @@ +using console_spo_utils.Interfaces.Services; +using Microsoft.Extensions.Logging; + +namespace console_spo_utils.Services; + +public class NonComplianceBuildService : INonComplianceBuildService +{ + private readonly ISiteOptions siteOptions; + private readonly ISharePointAuthenticationManager sharePointAuthenticationManager; + private readonly ISharePointCustomOperation spc; + private readonly ITenantService tenantService; + private readonly INonComplianceDocLibraryService nonComplianceDocLibraryService; + private readonly INonComplianceDocSetService nonComplianceDocSetService; + private readonly ILogger logger; + + public NonComplianceBuildService( + ISiteOptions siteOptions, + ISharePointAuthenticationManager sharePointAuthenticationManager, + ISharePointCustomOperation spc, + ITenantService tenantService, + INonComplianceDocLibraryService nonComplianceDocLibraryService, + INonComplianceDocSetService nonComplianceDocSetService, + ILogger logger) + { + this.siteOptions = siteOptions; + this.sharePointAuthenticationManager = sharePointAuthenticationManager; + this.spc = spc; + this.tenantService = tenantService; + this.nonComplianceDocLibraryService = nonComplianceDocLibraryService; + this.nonComplianceDocSetService = nonComplianceDocSetService; + this.logger = logger; + } + + public void CreateIfNotExists(string nonComplianceName) + { + var site = siteOptions.GetNonComplianceSite(); + var ctx = sharePointAuthenticationManager.GetContext(site); + var list = siteOptions.GetNonComplianceLibrary(); + var tenant = siteOptions.GetNonComplianceTenant(); + + if (!spc.SiteExist(ctx)) + { + tenantService.CreateForNonCompliance(); + } + else if (!spc.ListExist(ctx, list)) + { + nonComplianceDocLibraryService.Create(list, ctx); + } + else if (!spc.FolderExistsInsideList(ctx, list, nonComplianceName)) + { + nonComplianceDocSetService.Create(nonComplianceName, list, tenant, ctx); + } + else + { + logger.LogInformation($"Quotation with {nonComplianceName} already exist"); + } + } +} \ No newline at end of file diff --git a/console_spo_utils/Services/NonComplianceDocLibraryService.cs b/console_spo_utils/Services/NonComplianceDocLibraryService.cs new file mode 100644 index 0000000..4d8c68e --- /dev/null +++ b/console_spo_utils/Services/NonComplianceDocLibraryService.cs @@ -0,0 +1,115 @@ +using console_spo_utils.Interfaces.Services; +using Microsoft.Extensions.Logging; +using Microsoft.SharePoint.Client; + +namespace console_spo_utils.Services; + +public class NonComplianceDocLibraryService : INonComplianceDocLibraryService +{ + private readonly ILogger logger; + + public NonComplianceDocLibraryService(ILogger logger) + { + this.logger = logger; + } + + public void Create(string libName, ClientContext ctx) + { + try + { + #region New DocLib + + Console.WriteLine($"> Inizializzata la fase di creazione '{libName}'."); + + Web web = ctx.Web; + ctx.Load(web, w => w.RootFolder.WelcomePage, w => w.Url); + + ListCreationInformation lci = new ListCreationInformation(); + lci.Title = libName; + lci.TemplateType = (int)ListTemplateType.DocumentLibrary; + web.Lists.Add(lci); + + ctx.ExecuteQuery(); + Console.WriteLine($"> Completata la fase di creazione '{libName}'."); + + #endregion + + #region Field + + Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{libName}'."); + + List list = ctx.Web.Lists.GetByTitle(libName); + var siteField = ctx.Site.RootWeb; + ctx.Load(list, l => l.Fields); + ctx.Load(siteField, s => s.Fields); + + ctx.ExecuteQuery(); + + string[] fieldName = { "Sorgente", "Rifermento", "Nominativo", "Data Rilevazione", "Commessa", "Parte", "Portal" }; + + foreach (var fn in fieldName) + { + var Fields = siteField.Fields.GetByTitle(fn); + list.Fields.Add(Fields); + } + + ctx.ExecuteQuery(); + + Console.WriteLine($"> Completata la fase di importazione dei campi '{libName}'."); + + #endregion + + #region View + + Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{libName}'."); + + var views = list.Views; + + ViewCreationInformation viewCreation = new ViewCreationInformation(); + + viewCreation.SetAsDefaultView = true; + viewCreation.Title = libName; + viewCreation.ViewTypeKind = ViewType.None; + viewCreation.ColumnWidth = "350"; + viewCreation.ViewFields = new string[] { "Type", "Name", "Sorgente", "Rifermento", "Nominativo", "Data Rilevazione", "Commessa", "Parte", "Portal" }; + + 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($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'."); + + #endregion + + #region Shortcut on Quickmenu + + NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch; + NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation(); + + newNavNode.Title = $"{libName}"; + newNavNode.Url = $"{web.Url}/{libName.Replace(" ", "%20").Replace("à", "")}"; + newNavNode.AsLastNode = true; + spNavNodeColl.Add(newNavNode); + + ctx.ExecuteQuery(); + + Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamento a {libName} è ora disponibile."); + + #endregion + } + catch (Exception ex) + { + logger.LogError(ex, "NonComplianceDocLibraryService"); + } + } +} \ No newline at end of file diff --git a/console_spo_utils/Services/NonComplianceDocSetService.cs b/console_spo_utils/Services/NonComplianceDocSetService.cs new file mode 100644 index 0000000..c5ac6fa --- /dev/null +++ b/console_spo_utils/Services/NonComplianceDocSetService.cs @@ -0,0 +1,108 @@ +using console_spo_utils.Constants; +using console_spo_utils.Interfaces.Repositories; +using console_spo_utils.Interfaces.Services; +using Microsoft.Extensions.Logging; +using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client.DocumentSet; + +namespace console_spo_utils.Services; + +public class NonComplianceDocSetService : INonComplianceDocSetService +{ + private readonly ISharePointCustomOperation cpt; + private readonly IOneNoteService oneNoteService; + private readonly INonComplianceRepository nonComplianceRepository; + + public NonComplianceDocSetService( + ISharePointCustomOperation cpt, + IOneNoteService oneNoteService, + INonComplianceRepository nonComplianceRepository) + { + this.cpt = cpt; + this.oneNoteService = oneNoteService; + this.nonComplianceRepository = nonComplianceRepository; + } + + public void Create(string nonComplianceName, string docLibraryName, string tenantName, ClientContext ctx) + { + #region Context + + var web = ctx.Web; + ctx.Load(web, w => w.Url); + List list = web.Lists.GetByTitle(docLibraryName); + ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled); + ctx.ExecuteQuery(); + list.ContentTypesEnabled = true; + list.Update(); + + if (!cpt.ListContentTypeExist(ctx, docLibraryName, "Set di documenti")) + { + var documentCT = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5"); + ctx.Load(documentCT); + ctx.ExecuteQuery(); + + var ctDocSet = new ContentTypeCreationInformation() + { + Name = "Set di documenti", + ParentContentType = documentCT + }; + list.ContentTypes.Add(ctDocSet); + + list.Update(); + ctx.ExecuteQuery(); + } + + var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti"); + var contentType = ctData.FirstOrDefault(); + ctx.Load(contentType); + ctx.ExecuteQuery(); + + #endregion + + + Console.WriteLine($"> Inizializzata la fase di creazione per {nonComplianceName}."); + + #region DocSet Field Entry + + DocumentSet.Create(ctx, list.RootFolder, nonComplianceName, contentType.Id); + ctx.ExecuteQuery(); + + Console.WriteLine($"> DocumentSet {nonComplianceName} creata."); + + var dsItem = list.RootFolder.Folders.GetByUrl(nonComplianceName).ListItemAllFields; + + dsItem["PAL_NC_Source"] = nonComplianceRepository.DefaultNonComplianceSource(); + dsItem["PAL_NC_Reference"] = nonComplianceRepository.DefaultNonComplianceReference(); + dsItem["PAL_NC_Nominative"] = nonComplianceRepository.DefaultNonComplianceNominative(); + dsItem["PAL_NC_DateOfDetection"] = nonComplianceRepository.DefaultNonComplianceDateOfDetection(); + dsItem["PAL_NC_Project"] = nonComplianceRepository.DefaultNonComplianceProject(); + dsItem["PAL_NC_ItemCode"] = nonComplianceRepository.DefaultNonComplianceItemCode(); + dsItem["PAL_NC_PortalUrl"] = nonComplianceRepository.DefaultNonCompliancePortalUrl(); + + dsItem.Update(); + ctx.ExecuteQuery(); + + Console.WriteLine($"> Field value update."); + + #endregion + + #region Quotation Folder + + foreach (var name in Folders.OfferDocSet) + { + Console.WriteLine($"La sotto cartella {name} verrà creata in {nonComplianceName}"); + var rPath = ResourcePath.FromDecodedUrl($"{nonComplianceName}/{name}"); + list.RootFolder.AddSubFolderUsingPath(rPath); + } + + ctx.ExecuteQuery(); + + oneNoteService.CreateFolderInsideNonCompliance(nonComplianceName, ctx); + + Console.WriteLine($"Le sotto cartelle sono state create con successo in {nonComplianceName}"); + + #endregion + + Console.WriteLine($"> {nonComplianceName} creato con successo in Offerte/{docLibraryName}."); + } +} \ No newline at end of file diff --git a/console_spo_utils/Services/OneNoteService.cs b/console_spo_utils/Services/OneNoteService.cs index cf6344d..629b9ab 100644 --- a/console_spo_utils/Services/OneNoteService.cs +++ b/console_spo_utils/Services/OneNoteService.cs @@ -8,16 +8,16 @@ public class OneNoteService : IOneNoteService { private readonly ILogger logger; private readonly ISiteOptions siteOptions; - private readonly ISharePointCustomOperation cpt; + private readonly ISharePointCustomOperation spc; public OneNoteService( ILogger logger, ISiteOptions siteOptions, - ISharePointCustomOperation cpt) + ISharePointCustomOperation spc) { this.logger = logger; this.siteOptions = siteOptions; - this.cpt = cpt; + this.spc = spc; } public bool CreateFolderInsideProject(string projName, ClientContext ctx) @@ -57,6 +57,13 @@ public class OneNoteService : IOneNoteService 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(); @@ -83,7 +90,14 @@ public class OneNoteService : IOneNoteService var list = ctx.Web.Lists.EnsureSiteAssetsLibrary(); ctx.Load(list, l => l.RootFolder); ctx.ExecuteQuery(); - //TODO: verificare se worka + + 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(); @@ -106,7 +120,7 @@ public class OneNoteService : IOneNoteService var featureId = new Guid("f151bb39-7c3b-414f-bb36-6bf18872052f"); #region Feature Activate - if (!cpt.SiteFeaturesExist(ctx, featureName)) + if (!spc.SiteFeaturesExist(ctx, featureName)) { ctx.Web.ActivateFeature(featureId); ctx.ExecuteQuery(); diff --git a/console_spo_utils/Services/QuotationBuildService.cs b/console_spo_utils/Services/QuotationBuildService.cs index 87baed9..0a14f9b 100644 --- a/console_spo_utils/Services/QuotationBuildService.cs +++ b/console_spo_utils/Services/QuotationBuildService.cs @@ -37,6 +37,7 @@ public class QuotationBuildService : IQuotationBuildService var ctx = sharePointAuthenticationManager.GetContext(site); var list = siteOptions.GetQuotationLibrary(); var tenant = siteOptions.GetQuotationTenant(); + if (!spc.SiteExist(ctx)) { tenantService.CreateForQuotation(); diff --git a/console_spo_utils/Services/QuotationDocLibraryService.cs b/console_spo_utils/Services/QuotationDocLibraryService.cs index ced723e..5cf7760 100644 --- a/console_spo_utils/Services/QuotationDocLibraryService.cs +++ b/console_spo_utils/Services/QuotationDocLibraryService.cs @@ -103,13 +103,13 @@ public class QuotationDocLibraryService : IQuotationDocLibraryService ctx.ExecuteQuery(); - Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamemento a {libName} è ora disponibile."); + Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamento a {libName} è ora disponibile."); #endregion } catch (Exception ex) { - logger.LogError(ex, ""); + logger.LogError(ex, "QuotationDocLibraryService"); } } } \ No newline at end of file diff --git a/console_spo_utils/Services/QuotationService.cs b/console_spo_utils/Services/QuotationService.cs deleted file mode 100644 index b3fb437..0000000 --- a/console_spo_utils/Services/QuotationService.cs +++ /dev/null @@ -1,234 +0,0 @@ -//using Microsoft.SharePoint.Client.DocumentSet; -//using Microsoft.SharePoint.Client; -//using System.Security; -//using console_spo_utils.Enums; -//using Microsoft.AddSharePointExtensions.Logging; - -//namespace console_spo_utils.Services -//{ -// internal class OfferService -// { -// private readonly SharePointCustomOperation spc; - -// private readonly ILogger logger; -// private readonly SharePointAuthenticationManager authMgr; - -// public OfferService( -// SharePointCustomOperation spc, -// ILogger logger, -// SharePointAuthenticationManager authMgr) -// { -// this.spc = spc; -// this.logger = logger; -// this.authMgr = authMgr; -// } - -// public void Create(string siteCollection, string user, SecureString psw) -// { -// var year = DateTime.Now.Year.ToString(); -// var tenantName = "Offerte"; -// var docLibName = $"{tenantName} {year}"; -// var quotationName = $"OF0002"; - -// var site = new Uri($"{siteCollection}/sites/Offerte"); - -// var ctx = authMgr.GetContext(site); - -// //spc.AddWebPart(ctx, "/sites/Offerte/SitePages/homepage.aspx"); - -// if (!spc.SiteExist(ctx)) -// { -// spc.TenantCreation(tenantName, PalFieldType.Quotation, site, user, psw); -// } -// else if (spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) == false) -// { -// OfferDocLib(docLibName, ctx); -// } -// else if (spc.SiteExist(ctx) && spc.ListExist(ctx, docLibName) && !spc.FolderExistsInsideList(ctx, docLibName, quotationName)) -// { -// OfferDocSet(quotationName, docLibName, tenantName, ctx); -// } -// } - -// public void OfferDocLib(string docLibName, ClientContext ctx) -// { -// try -// { -// #region New DocLib -// logger.LogInformation($"> Inizializzata la fase di creazione '{docLibName}'."); - -// var web = ctx.Web; -// ctx.Load(web, w => w.RootFolder.WelcomePage, w => w.Url); - -// var lci = new ListCreationInformation -// { -// Title = docLibName, -// TemplateType = (int)ListTemplateType.DocumentLibrary -// }; -// web.Lists.Add(lci); - -// ctx.ExecuteQuery(); -// logger.LogInformation($"> Completata la fase di creazione '{docLibName}'."); -// #endregion - -// #region Field -// logger.LogInformation($"> Inizializzata la fase di importazione dei campi '{docLibName}'."); - -// var list = ctx.Web.Lists.GetByTitle(docLibName); -// var siteField = ctx.Site.RootWeb; -// ctx.Load(list, l => l.Fields); -// ctx.Load(siteField, s => s.Fields); - -// ctx.ExecuteQuery(); - -// string[] fieldName = { "ID Offerta", "Fornitore", "Causale", "Autore" }; - -// foreach (var fn in fieldName) -// { -// var fields = siteField.Fields.GetByTitle(fn); -// list.Fields.Add(fields); -// } - -// ctx.ExecuteQuery(); - -// logger.LogInformation($"> Completata la fase di importazione dei campi '{docLibName}'."); -// #endregion - -// #region View -// logger.LogInformation($"> Inizializzata la fase di creazione della ListView '{docLibName}'."); - -// var views = list.Views; - -// var viewCreation = new ViewCreationInformation -// { -// SetAsDefaultView = true, -// Title = docLibName, -// ViewTypeKind = ViewType.None, -// ColumnWidth = "350", -// ViewFields = new string[] { "Type", "Name", "ID Offerta", "Fornitore", "Causale", "Autore" } -// }; - -// var view = views.Add(viewCreation); - -// ctx.Load(view); -// ctx.ExecuteQuery(); - -// logger.LogInformation($"> 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(); - -// logger.LogInformation($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'."); -// #endregion - -// #region Shortcut on Quickmenu -// var spNavNodeColl = web.Navigation.QuickLaunch; -// var newNavNode = new NavigationNodeCreationInformation -// { -// Title = $"{docLibName}", -// Url = $"{web.Url}/{docLibName.Replace(" ", "%20")}", -// AsLastNode = true -// }; - -// spNavNodeColl.Add(newNavNode); - -// ctx.ExecuteQuery(); - -// logger.LogInformation($"> Il menu rapido è stato aggiornato, il collegamemento a {docLibName} è ora disponibile."); -// #endregion -// } -// catch (Exception ex) -// { -// logger.LogError("Create Doc Lib", ex); -// } -// } - -// public void OfferDocSet(string quotationName, string docLibName, string tenantName, ClientContext ctx) //TODO: add onenote on creation of -// { -// try -// { -// #region Context -// var web = ctx.Web; -// ctx.Load(web, w => w.Url); -// var list = web.Lists.GetByTitle(docLibName); -// ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled); -// ctx.ExecuteQuery(); -// list.ContentTypesEnabled = true; -// list.Update(); - -// if (spc.ListContentTypeExist(ctx, docLibName, "Set di documenti") == false) -// { -// var documentCt = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5"); -// ctx.Load(documentCt); -// ctx.ExecuteQuery(); - -// var ctDocSet = new ContentTypeCreationInformation() -// { -// Name = "Set di documenti", -// ParentContentType = documentCt -// }; -// list.ContentTypes.Add(ctDocSet); - -// list.Update(); -// ctx.ExecuteQuery(); -// } - -// var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti"); -// var contentType = ctData.FirstOrDefault(); -// ctx.Load(contentType); -// ctx.ExecuteQuery(); -// #endregion - - -// logger.LogInformation($"> Inizializzata la fase di creazione per {quotationName}."); - -// #region DocSet Field Entry -// DocumentSet.Create(ctx, list.RootFolder, quotationName, contentType.Id); -// ctx.ExecuteQuery(); - -// logger.LogInformation($"> DocumentSet {quotationName} creata."); - -// var dsItem = list.RootFolder.Folders.GetByUrl(quotationName).ListItemAllFields; - -// dsItem["PAL_ID_Quotation"] = "valueItemCode"; -// dsItem["PAL_Quotation_Name"] = "valueItemDescription"; -// dsItem["PAL_Quotation_Reason"] = "NC NON CONFORMITÁ"; -// dsItem["PAL_Authors"] = "Test"; - -// dsItem.Update(); -// ctx.ExecuteQuery(); - -// logger.LogInformation($"> Field value update."); -// #endregion - -// #region Quotation Folder -// var rev = "Rev. 1"; -// string[] folderName = { rev, $"{rev}/01_Costificazione", $"{rev}/02_Offerta", $"{rev}/03_Meeting", $"{rev}/04_Corrispondenza", $"{rev}/08_Specifiche_Tecniche", $"{rev}/10_Fornitori", $"{rev}/11_Documenti_Tecnici", $"{rev}/14_Foto" }; - -// foreach (var name in folderName) -// { -// logger.LogInformation($"La sotto cartella {name} verrà creata in {quotationName}"); -// var rPath = ResourcePath.FromDecodedUrl($"{quotationName}/{name}"); -// list.RootFolder.AddSubFolderUsingPath(rPath); -// } - -// ctx.ExecuteQuery(); - -// spc.OnenoteSPFeature(ctx, tenantName, quotationName); - -// logger.LogInformation($"Le sotto cartelle sono state create con successo in {quotationName}"); -// #endregion - -// logger.LogInformation($"> {quotationName} creato con successo in Offerte/{docLibName}."); -// } -// catch (Exception ex) -// { -// logger.LogError("Create Doc Set", ex); -// } -// } -// } -//} diff --git a/console_spo_utils/Services/SharePointStructureBuilderService.cs b/console_spo_utils/Services/SharePointStructureBuilderService.cs index 3a32e73..433698f 100644 --- a/console_spo_utils/Services/SharePointStructureBuilderService.cs +++ b/console_spo_utils/Services/SharePointStructureBuilderService.cs @@ -10,6 +10,7 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder private readonly ISubProjectRepository subProjectRepository; private readonly ISubProjectBuilderService subProjectBuilderService; private readonly IQuotationBuildService quotationBuildService; + private readonly INonComplianceBuildService nonComplianceBuildService; private readonly IWebpartService webpartService; public SharePointStructureBuilderService( @@ -17,12 +18,14 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder ISubProjectRepository subProjectRepository, ISubProjectBuilderService subProjectBuilderService, IQuotationBuildService quotationBuildService, + INonComplianceBuildService nonComplianceBuildService, IWebpartService webpartService) { this.siteService = siteService; this.subProjectRepository = subProjectRepository; this.subProjectBuilderService = subProjectBuilderService; this.quotationBuildService = quotationBuildService; + this.nonComplianceBuildService = nonComplianceBuildService; this.webpartService = webpartService; } @@ -72,7 +75,7 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder throw new Exception($"Impossibile to build site"); } - quotationBuildService.CreateIfNotExists(nonComplianceName); + nonComplianceBuildService.CreateIfNotExists(nonComplianceName); return true; } diff --git a/console_spo_utils/Services/TenantService.cs b/console_spo_utils/Services/TenantService.cs index e8a0eab..e933d75 100644 --- a/console_spo_utils/Services/TenantService.cs +++ b/console_spo_utils/Services/TenantService.cs @@ -1,7 +1,6 @@ using console_spo_utils.Interfaces.Services; using Microsoft.Extensions.Logging; using Microsoft.Online.SharePoint.TenantAdministration; -using System.Security; using console_spo_utils.Enums; namespace console_spo_utils.Services; diff --git a/console_spo_utils/Services/WebpartService.cs b/console_spo_utils/Services/WebpartService.cs index 7930e01..b827912 100644 --- a/console_spo_utils/Services/WebpartService.cs +++ b/console_spo_utils/Services/WebpartService.cs @@ -1,11 +1,7 @@ using console_spo_utils.Interfaces.Services; using Microsoft.Extensions.Logging; -using Microsoft.Graph; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.WebParts; -using OfficeDevPnP.Core.Pages; - -//using PnP.Core.Model; namespace console_spo_utils.Services diff --git a/console_spo_utils/Workers/MainWorker.cs b/console_spo_utils/Workers/MainWorker.cs index f32d0b3..163dc4f 100644 --- a/console_spo_utils/Workers/MainWorker.cs +++ b/console_spo_utils/Workers/MainWorker.cs @@ -36,7 +36,7 @@ namespace console_spo_utils.Workers return; } - var buildNonComplianceResult = structureBuilder.BuildNonCompliance("NC0001"); + var buildNonComplianceResult = structureBuilder.BuildNonCompliance("NC0002"); if (!buildNonComplianceResult) {