Dependency Update

This commit is contained in:
Kalarumeth
2022-09-06 08:14:30 +02:00
parent 924cdd3d4b
commit 31efec6eb4
24 changed files with 207 additions and 115 deletions
+40 -9
View File
@@ -2,19 +2,50 @@
public static class Fields public static class Fields
{ {
public static string[] SubProject
{
get
{
return new string[] { "Item", "Codice Articolo", "Descrizione Articolo", "Matricola Macchina" };
}
}
public static string[] SiteFields public static string[] SiteFields
{ {
get get
{ {
return new[] { "ID Progetto", "Cliente", "Causale" }; return new[]
{
"ID Progetto",
"Cliente",
"Causale"
};
}
}
public static string[] SubSiteProject
{
get
{
return new string[]
{
"Item",
"Codice Articolo",
"Descrizione Articolo",
"Matricola Macchina"
};
}
}
public static string[] SubProject
{
get
{
return new string[]
{
"Type",
"Name",
"Description",
"Item",
"Codice Articolo",
"Descrizione Articolo",
"Matricola Macchina",
"Modified",
"Editor",
"Version"
};
} }
} }
+20
View File
@@ -57,4 +57,24 @@ public static class Folders
}; };
} }
} }
public static IEnumerable OfferDocSet
{
get
{
string rev = "Rev. 1"; //TODO: Definire revisione
return new string[]
{
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"
};
}
}
} }
@@ -0,0 +1,25 @@
using console_spo_utils.Interfaces.Repositories;
namespace console_spo_utils.Fakes.Repositories;
public class FakeQuotationSettingRepository:IQuotationRepository
{
public string DefaultIdQuotation(string quotationName)
{
return quotationName;
}
public string DefaultQuotationName(string quotationName)
{
return "Marchiol";
}
public string DefaultQuotationReason(string quotationName)
{
return "02 VENDITA RICAMBI";
}
public string DefaultAuthors(string quotationName)
{
return "User";
}
}
@@ -14,4 +14,29 @@ public class FakeSubProjectRepository:ISubProjectRepository
$"{projName}-004", $"{projName}-004",
}; };
} }
public string DefaultDescription(string projName)
{
return "AutomationTest c.s.";
}
public string DefaultItem(string projName)
{
return "Coclea";
}
public string DefaultItemCode(string projName)
{
return "C84M70";
}
public string DefaultItemDescription(string projName)
{
return "7m con le piastrelle";
}
public string DefaultSerialNumber(string projName)
{
return "S/N 000000988948e";
}
} }
@@ -0,0 +1,11 @@
namespace console_spo_utils.Interfaces.Repositories;
public interface IQuotationRepository
{
public string DefaultIdQuotation(string quotationName);
public string DefaultQuotationName(string quotationName);
public string DefaultQuotationReason(string quotationName);
public string DefaultAuthors(string quotationName);
}
@@ -3,4 +3,9 @@
public interface ISubProjectRepository public interface ISubProjectRepository
{ {
public List<string> GetFromProject(string projName); public List<string> GetFromProject(string projName);
public string DefaultDescription(string projName);
public string DefaultItem(string projName);
public string DefaultItemCode(string projName);
public string DefaultItemDescription(string projName);
public string DefaultSerialNumber(string projName);
} }
@@ -11,5 +11,4 @@ public interface ISharePointCustomOperation
bool SiteFeaturesExist(ClientContext ctx, string featureName); bool SiteFeaturesExist(ClientContext ctx, string featureName);
void PalCustomField(ClientContext ctx, PalFieldType et); void PalCustomField(ClientContext ctx, PalFieldType et);
public bool ListContentTypeExist(ClientContext ctx, string listTitle, string contentTypeName); public bool ListContentTypeExist(ClientContext ctx, string listTitle, string contentTypeName);
} }
@@ -6,15 +6,10 @@ public interface ISiteOptions
{ {
public string TokenEndpoint { get; } public string TokenEndpoint { get; }
public string DefaultAadAppId { get; } public string DefaultAadAppId { get; }
public Uri GetProjectSite(); public Uri GetProjectSite();
public string GetProjTenant(); public string GetProjTenant();
public string GetUser(); public string GetUser();
public SecureString GetPassword(); public SecureString GetPassword();
public string GetProjListTitle(); public string GetProjListTitle();
public Uri GetSubProjSite(string projName); public Uri GetSubProjSite(string projName);
string GetQuotationTenant(); string GetQuotationTenant();
@@ -3,7 +3,6 @@
public interface ISiteService public interface ISiteService
{ {
public bool CreateProjectSiteIfNotExists(); public bool CreateProjectSiteIfNotExists();
public bool CreateSubSiteIfNotExists(string projName); public bool CreateSubSiteIfNotExists(string projName);
public bool CreateQuotationSiteIfNotExists(); public bool CreateQuotationSiteIfNotExists(string quotationName);
} }
+1 -1
View File
@@ -3,7 +3,7 @@
namespace console_spo_utils.Model; namespace console_spo_utils.Model;
[XmlRoot(ElementName = "Field")] [XmlRoot(ElementName = "Field")]
public class XmlFieldsModel public class XmlFieldsModel //TODO ha senso ? se come funziona?
{ {
[XmlAttribute(AttributeName = "Name")] [XmlAttribute(AttributeName = "Name")]
public string Name { get; set; } public string Name { get; set; }
+1 -8
View File
@@ -8,13 +8,6 @@ using Microsoft.Extensions.Hosting;
namespace console_spo_utils namespace console_spo_utils
{ {
#region External Variable
// TODO: Import variable from PP [C:\Sources\VS\web_portal\webapp_italsort\DataItalsortGestionale\ProjTable.cs]
#endregion
public static class Program public static class Program
{ {
public static async Task Main(string[] args) public static async Task Main(string[] args)
@@ -22,10 +15,10 @@ namespace console_spo_utils
var host = Host.CreateDefaultBuilder(args) var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddSharePointExtensions(); services.AddSharePointExtensions();
services.AddTransient<IProjectSettingsRepository, FakeProjectSettingsRepository>(); services.AddTransient<IProjectSettingsRepository, FakeProjectSettingsRepository>();
services.AddTransient<ISubProjectRepository, FakeSubProjectRepository>(); services.AddTransient<ISubProjectRepository, FakeSubProjectRepository>();
services.AddTransient<IQuotationRepository, FakeQuotationSettingRepository>();
services.AddHostedService<MainWorker>(); services.AddHostedService<MainWorker>();
}) })
@@ -1,11 +0,0 @@
using console_spo_utils.Interfaces.Repositories;
namespace console_spo_utils.Repositories;
public class SubProjectRepository:ISubProjectRepository
{
public List<string> GetFromProject(string projName)
{
return new();
}
}
@@ -22,19 +22,14 @@ namespace console_spo_utils.Services
this.siteOptions = siteOptions; this.siteOptions = siteOptions;
} }
private static readonly HttpClient HttpClient = new(); private static readonly HttpClient HttpClient = new();
private static readonly SemaphoreSlim SemaphoreSlimTokens = new(1); private static readonly SemaphoreSlim SemaphoreSlimTokens = new(1);
private AutoResetEvent tokenResetEvent = null; private AutoResetEvent tokenResetEvent = null;
private readonly ConcurrentDictionary<string, string> tokenCache = new(); private readonly ConcurrentDictionary<string, string> tokenCache = new();
private bool disposedValue; private bool disposedValue;
#region CSOM #region CSOM
public ClientContext GetContext(Uri web) public ClientContext GetContext(Uri web)
{ {
var context = new ClientContext(web); var context = new ClientContext(web);
@@ -19,7 +19,7 @@ public class ProjectDocLibraryService : IProjectDocLibraryService
} }
public void Create(string ssProjectTitle, ClientContext ctx) //TODO: Da testare public void Create(string ssProjectTitle, ClientContext ctx)
{ {
try try
{ {
@@ -1,4 +1,5 @@
using console_spo_utils.Interfaces.Services; using console_spo_utils.Constants;
using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client;
@@ -60,9 +61,7 @@ public class ProjectYearService:IProjectYearService
ctx.ExecuteQuery(); ctx.ExecuteQuery();
string[] fieldName = { "ID Progetto", "Cliente", "Causale" }; foreach (var fn in Fields.SiteFields)
foreach (var fn in fieldName)
{ {
var Fields = siteField.Fields.GetByTitle(fn); var Fields = siteField.Fields.GetByTitle(fn);
list.Fields.Add(Fields); list.Fields.Add(Fields);
@@ -87,7 +86,7 @@ public class ProjectYearService:IProjectYearService
viewCreation.Title = listTitle; viewCreation.Title = listTitle;
viewCreation.ViewTypeKind = ViewType.None; viewCreation.ViewTypeKind = ViewType.None;
viewCreation.ColumnWidth = "350"; viewCreation.ColumnWidth = "350";
viewCreation.ViewFields = new string[] { "ID Progetto", "Cliente", "Causale" }; viewCreation.ViewFields = Fields.SiteFields;
var view = views.Add(viewCreation); var view = views.Add(viewCreation);
@@ -1,4 +1,6 @@
using console_spo_utils.Interfaces.Services; using console_spo_utils.Constants;
using console_spo_utils.Interfaces.Repositories;
using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet; using Microsoft.SharePoint.Client.DocumentSet;
@@ -10,14 +12,17 @@ public class QuotationDocSetService : IQuotationDocSetService
private readonly ISharePointCustomOperation cpt; private readonly ISharePointCustomOperation cpt;
private readonly ILogger<QuotationDocSetService> logger; private readonly ILogger<QuotationDocSetService> logger;
private readonly IOneNoteService oneNoteService; private readonly IOneNoteService oneNoteService;
private readonly IQuotationRepository quotationRepository;
public QuotationDocSetService(ISharePointCustomOperation cpt, public QuotationDocSetService(ISharePointCustomOperation cpt,
ILogger<QuotationDocSetService> logger, ILogger<QuotationDocSetService> logger,
IOneNoteService oneNoteService) IOneNoteService oneNoteService,
IQuotationRepository quotationRepository)
{ {
this.cpt = cpt; this.cpt = cpt;
this.logger = logger; this.logger = logger;
this.oneNoteService = oneNoteService; this.oneNoteService = oneNoteService;
this.quotationRepository = quotationRepository;
} }
public void Create(string quotationName, string docLibraryName, string tenantName, ClientContext ctx) public void Create(string quotationName, string docLibraryName, string tenantName, ClientContext ctx)
@@ -70,10 +75,10 @@ public class QuotationDocSetService : IQuotationDocSetService
var dsItem = list.RootFolder.Folders.GetByUrl(quotationName).ListItemAllFields; var dsItem = list.RootFolder.Folders.GetByUrl(quotationName).ListItemAllFields;
dsItem["PAL_ID_Quotation"] = "valueItemCode"; dsItem["PAL_ID_Quotation"] = quotationRepository.DefaultIdQuotation(quotationName);
dsItem["PAL_Quotation_Name"] = "valueItemDescription"; dsItem["PAL_Quotation_Name"] = quotationRepository.DefaultQuotationName(quotationName);
dsItem["PAL_Quotation_Reason"] = "NC NON CONFORMITÁ"; dsItem["PAL_Quotation_Reason"] = quotationRepository.DefaultQuotationReason(quotationName);
dsItem["PAL_Authors"] = "Test"; dsItem["PAL_Authors"] = quotationRepository.DefaultAuthors(quotationName);
dsItem.Update(); dsItem.Update();
ctx.ExecuteQuery(); ctx.ExecuteQuery();
@@ -84,14 +89,7 @@ public class QuotationDocSetService : IQuotationDocSetService
#region Quotation Folder #region Quotation Folder
string rev = "Rev. 1"; foreach (var name in Folders.OfferDocSet)
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 (string name in folderName)
{ {
Console.WriteLine($"La sotto cartella {name} verrà creata in {quotationName}"); Console.WriteLine($"La sotto cartella {name} verrà creata in {quotationName}");
var rPath = ResourcePath.FromDecodedUrl($"{quotationName}/{name}"); var rPath = ResourcePath.FromDecodedUrl($"{quotationName}/{name}");
@@ -39,7 +39,7 @@ namespace console_spo_utils.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError("Site Exists", ex); logger.LogWarning("Site Exists", ex);
return false; return false;
} }
@@ -55,7 +55,7 @@ namespace console_spo_utils.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError("List Exist", ex); logger.LogWarning("List Exist", ex);
return false; return false;
} }
@@ -77,7 +77,7 @@ namespace console_spo_utils.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError("Folder Exists Inside List", ex); logger.LogWarning("Folder Exists Inside List", ex);
return false; return false;
} }
@@ -50,7 +50,7 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder
public bool BuildQuotation(string quotationName) public bool BuildQuotation(string quotationName)
{ {
var siteBuildResult = siteService.CreateQuotationSiteIfNotExists(); var siteBuildResult = siteService.CreateQuotationSiteIfNotExists(quotationName);
if (!siteBuildResult) if (!siteBuildResult)
{ {
throw new Exception($"Impossibile to build site"); throw new Exception($"Impossibile to build site");
+1 -1
View File
@@ -17,7 +17,7 @@ public class SiteOptions : ISiteOptions
private static int GetYear() private static int GetYear()
{ {
return DateTime.Today.Year +1; return DateTime.Today.Year;
} }
public string GetProjTenant() public string GetProjTenant()
+3 -3
View File
@@ -108,7 +108,7 @@ public class SiteService : ISiteService
return true; return true;
} }
public bool CreateQuotationSiteIfNotExists() public bool CreateQuotationSiteIfNotExists(string quotationName)
{ {
try try
{ {
@@ -130,12 +130,12 @@ public class SiteService : ISiteService
} }
private void CreateProjectListEntry(string projName, ClientContext ctx) //TODO: PP var private void CreateProjectListEntry(string projName, ClientContext ctx)
{ {
try try
{ {
var listTitle = siteOptions.GetProjListTitle(); var listTitle = siteOptions.GetProjListTitle();
var tenant = siteOptions.GetProjTenant().Replace(" ",""); var tenant = siteOptions.GetProjTenant().Replace(" ",string.Empty);
var list = ctx.Web.Lists.GetByTitle(listTitle); var list = ctx.Web.Lists.GetByTitle(listTitle);
var itemCreateInfo = new ListItemCreationInformation(); var itemCreateInfo = new ListItemCreationInformation();
@@ -1,4 +1,5 @@
using console_spo_utils.Constants; using console_spo_utils.Constants;
using console_spo_utils.Interfaces.Repositories;
using console_spo_utils.Interfaces.Services; using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client.DocumentSet; using Microsoft.SharePoint.Client.DocumentSet;
@@ -11,16 +12,19 @@ public class SubProjectBuilderService : ISubProjectBuilderService
private readonly ISiteOptions siteOptions; private readonly ISiteOptions siteOptions;
private readonly ISharePointCustomOperation cpt; private readonly ISharePointCustomOperation cpt;
private readonly ISharePointAuthenticationManager authMgr; private readonly ISharePointAuthenticationManager authMgr;
private readonly ISubProjectRepository subProjectRepository;
private readonly ILogger<SubProjectBuilderService> logger; private readonly ILogger<SubProjectBuilderService> logger;
public SubProjectBuilderService(ISiteOptions siteOptions public SubProjectBuilderService(ISiteOptions siteOptions,
, ISharePointCustomOperation cpt ISharePointCustomOperation cpt,
, ISharePointAuthenticationManager authMgr, ISharePointAuthenticationManager authMgr,
ISubProjectRepository subProjectRepository,
ILogger<SubProjectBuilderService> logger) ILogger<SubProjectBuilderService> logger)
{ {
this.siteOptions = siteOptions; this.siteOptions = siteOptions;
this.cpt = cpt; this.cpt = cpt;
this.authMgr = authMgr; this.authMgr = authMgr;
this.subProjectRepository = subProjectRepository;
this.logger = logger; this.logger = logger;
} }
@@ -81,11 +85,11 @@ public class SubProjectBuilderService : ISubProjectBuilderService
var dsItem = list.RootFolder.Folders.GetByUrl(spt).ListItemAllFields; var dsItem = list.RootFolder.Folders.GetByUrl(spt).ListItemAllFields;
dsItem["_ExtendedDescription"] = "valueDescription"; dsItem["_ExtendedDescription"] = subProjectRepository.DefaultDescription(projName);
dsItem["PAL_Item"] = "valueItem"; dsItem["PAL_Item"] = subProjectRepository.DefaultItem(projName);
dsItem["PAL_ItemCode"] = "valueItemCode"; dsItem["PAL_ItemCode"] = subProjectRepository.DefaultItemCode(projName);
dsItem["PAL_ItemDescription"] = "valueItemDescription"; dsItem["PAL_ItemDescription"] = subProjectRepository.DefaultItemDescription(projName);
dsItem["PAL_SerialNumber"] = "valueSerialNumber"; dsItem["PAL_SerialNumber"] = subProjectRepository.DefaultSerialNumber(projName);
dsItem.Update(); dsItem.Update();
ctx.ExecuteQuery(); ctx.ExecuteQuery();
@@ -96,8 +100,6 @@ public class SubProjectBuilderService : ISubProjectBuilderService
#region SubProject Folder #region SubProject Folder
foreach (var name in Folders.SubProjectDocSet) foreach (var name in Folders.SubProjectDocSet)
{ {
Console.WriteLine($"La sotto cartella {name} verrà creata in {spt}"); Console.WriteLine($"La sotto cartella {name} verrà creata in {spt}");
+2 -2
View File
@@ -77,7 +77,7 @@ public class SubSiteService : ISubSiteService
Title = listTitle, Title = listTitle,
ViewTypeKind = ViewType.None, ViewTypeKind = ViewType.None,
ColumnWidth = "350", ColumnWidth = "350",
ViewFields = new string[] { "Type", "Name", "Description", "Item", "Codice Articolo", "Descrizione Articolo", "Matricola Macchina", "Modified", "Editor", "Version", } ViewFields = Fields.SubProject
}; };
var view = views.Add(viewCreation); var view = views.Add(viewCreation);
@@ -104,7 +104,7 @@ public class SubSiteService : ISubSiteService
private static void AddFieldsToSubProj(Web siteField, List list, ClientContext ctx) private static void AddFieldsToSubProj(Web siteField, List list, ClientContext ctx)
{ {
foreach (var fieldName in Fields.SubProject) foreach (var fieldName in Fields.SubSiteProject)
{ {
var fields = siteField.Fields.GetByTitle(fieldName); var fields = siteField.Fields.GetByTitle(fieldName);
list.Fields.Add(fields); list.Fields.Add(fields);
+39 -33
View File
@@ -20,46 +20,52 @@ namespace console_spo_utils.Workers
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
var buildResult = structureBuilder.BuildProject("CT2025"); var buildProjectsResult = structureBuilder.BuildProject("CT0019");
if (!buildResult) if (!buildProjectsResult)
{ {
logger.LogError("Impossible to create structure"); logger.LogError("Impossible to create structure");
return; return;
} }
var buildQuotationResult = structureBuilder.BuildQuotation("OF0003");
if (!buildQuotationResult)
{
//#region SPO Credential logger.LogError("Impossible to create structure");
//var siteCollection = "https://italsortbuttrio.sharepoint.com"; return;
//var svcUser = "svcItsSharePointAdmin@italsort.com"; }
//var svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
//#endregion
//#region General Variable
//var year = DateTime.Now.Year.ToString();
//var tenantName = $"Commesse {year}";
//var projectsYear = tenantName.Replace(" ", string.Empty);
//var listTitle = $"Lista {tenantName}";
//var ssProjectTitle = "CT0018";
//string[] ssSubProjectTitle = { $"{ssProjectTitle}-0001", $"{ssProjectTitle}-0002", $"{ssProjectTitle}-0003" };
//var site = new Uri($"{siteCollection}/sites/{projectsYear}");
//var subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
//#endregion
//#region Create
//projectSiteService.CreateIfNotExists(listTitle, tenantName, svcUser, site, svcUserPsw);
//projectService.Create(siteCollection, svcUser, svcUserPsw, ssProjectTitle);
//subProjectService.Create(siteCollection, svcUser, svcUserPsw,ssProjectTitle, ssSubProjectTitle);
//#endregion
//#region Create
//offerService.Create(siteCollection, svcUser, svcUserPsw);
//#endregion
//return Task.CompletedTask;
} }
} }
} }
//#region SPO Credential
//var siteCollection = "https://italsortbuttrio.sharepoint.com";
//var svcUser = "svcItsSharePointAdmin@italsort.com";
//var svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
//#endregion
//#region General Variable
//var year = DateTime.Now.Year.ToString();
//var tenantName = $"Commesse {year}";
//var projectsYear = tenantName.Replace(" ", string.Empty);
//var listTitle = $"Lista {tenantName}";
//var ssProjectTitle = "CT0018";
//string[] ssSubProjectTitle = { $"{ssProjectTitle}-0001", $"{ssProjectTitle}-0002", $"{ssProjectTitle}-0003" };
//var site = new Uri($"{siteCollection}/sites/{projectsYear}");
//var subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
//#endregion
//#region Create
//projectSiteService.CreateIfNotExists(listTitle, tenantName, svcUser, site, svcUserPsw);
//projectService.Create(siteCollection, svcUser, svcUserPsw, ssProjectTitle);
//subProjectService.Create(siteCollection, svcUser, svcUserPsw,ssProjectTitle, ssSubProjectTitle);
//#endregion
//#region Create
//offerService.Create(siteCollection, svcUser, svcUserPsw);
//#endregion
//return Task.CompletedTask;