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
+71 -65
View File
@@ -1,24 +1,25 @@
using console_spo_utils.Enums;
using console_spo_utils.Interfaces.Repositories;
using console_spo_utils.Interfaces.Services;
using library_spo_utils.Enums;
using library_spo_utils.Interfaces.Repositories;
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 SiteService : ISiteService
{
private readonly ILogger<SiteService> logger;
private readonly ISharePointAuthenticationManager authMgr;
private readonly ISharePointCustomOperation spc;
private readonly ISiteOptions siteOptions;
private readonly ISubSiteService subSiteService;
private readonly IOneNoteService oneNoteService;
private readonly IProjectSettingsRepository projectSettingsRepository;
private readonly IProjectDocLibraryService projectDocLibraryService;
private readonly IProjectQuickMenuService projectQuickMenuService;
private readonly ITenantService tenantService;
private readonly IProjectYearService projectYearService;
private readonly ILogger<SiteService> _logger;
private readonly ISharePointAuthenticationManager _authMgr;
private readonly ISharePointCustomOperation _spc;
private readonly ISiteOptions _siteOptions;
private readonly ISubSiteService _subSiteService;
private readonly IOneNoteService _oneNoteService;
private readonly IProjectRepository _projectRepository;
private readonly IProjectDocLibraryService _projectDocLibraryService;
private readonly IProjectQuickMenuService _projectQuickMenuService;
private readonly ITenantService _tenantService;
private readonly IProjectYearService _projectYearService;
private readonly IFieldEntryDataUpdate _fieldEntryDataUpdate;
public SiteService(
ILogger<SiteService> logger,
@@ -27,43 +28,45 @@ internal class SiteService : ISiteService
ISiteOptions siteOptions,
ISubSiteService subSiteService,
IOneNoteService oneNoteService,
IProjectSettingsRepository projectSettingsRepository,
IProjectRepository projectRepository,
IProjectDocLibraryService projectDocLibraryService,
IProjectQuickMenuService projectQuickMenuService,
ITenantService tenantService,
IProjectYearService projectYearService)
IProjectYearService projectYearService,
IFieldEntryDataUpdate fieldEntryDataUpdate)
{
this.logger = logger;
this.authMgr = authMgr;
this.spc = spc;
this.siteOptions = siteOptions;
this.subSiteService = subSiteService;
this.oneNoteService = oneNoteService;
this.projectSettingsRepository = projectSettingsRepository;
this.projectDocLibraryService = projectDocLibraryService;
this.projectQuickMenuService = projectQuickMenuService;
this.tenantService = tenantService;
this.projectYearService = projectYearService;
_logger = logger;
_authMgr = authMgr;
_spc = spc;
_siteOptions = siteOptions;
_subSiteService = subSiteService;
_oneNoteService = oneNoteService;
_projectRepository = projectRepository;
_projectDocLibraryService = projectDocLibraryService;
_projectQuickMenuService = projectQuickMenuService;
_tenantService = tenantService;
_projectYearService = projectYearService;
_fieldEntryDataUpdate = fieldEntryDataUpdate;
}
public bool CreateProjectSiteIfNotExists()
public bool CreateProjectSiteIfNotExists(string projName)
{
try
{
var site = siteOptions.GetProjectYearSite();
var listTitle = siteOptions.GetProjListTitle();
using var ctx = authMgr.GetContext(site);
if (spc.SiteExist(ctx))
var site = _siteOptions.GetProjectYearSite(projName);
var listTitle = _siteOptions.GetProjListTitle(projName);
using var ctx = _authMgr.GetContext(site);
if (_spc.SiteExist(ctx))
{
return true;
}
tenantService.CreateForProject();
projectYearService.CreateList(listTitle,ctx);
_tenantService.CreateForProject(projName);
_projectYearService.CreateList(projName, listTitle, ctx);
}
catch (Exception e)
{
logger.LogError(e, "Site Service");
_logger.LogError(e, "Site Service");
return false;
}
@@ -73,37 +76,41 @@ internal class SiteService : ISiteService
public bool CreateSubSiteIfNotExists(string projName)
{
var projectSite = siteOptions.GetProjectYearSite();
var subProjSite = siteOptions.GetSubProjSite(projName);
var projectSite = _siteOptions.GetProjectYearSite(projName);
var subProjSite = _siteOptions.GetSubProjSite(projName);
var siteContext = authMgr.GetContext(projectSite);
var subSiteContext = authMgr.GetContext(subProjSite);
var siteContext = _authMgr.GetContext(projectSite);
var subSiteContext = _authMgr.GetContext(subProjSite);
if (!spc.SiteExist(siteContext))
if (!_spc.SiteExist(siteContext))
{
throw new Exception($"Site {siteContext.Url} not exists");
}
if (spc.SiteExist(subSiteContext))
if (_spc.SiteExist(subSiteContext))
{
logger.LogInformation($"The subsite {subSiteContext.Url} already exists");
_logger.LogInformation($"The subsite {subSiteContext.Url} already exists");
_fieldEntryDataUpdate.FieldUpdate(siteContext, _siteOptions.GetProjListTitle(projName), projName, FieldUpdateType.Project);
return true;
}
var existSubSite = subSiteService.Create(projName, siteContext);
var existSubSite = _subSiteService.Create(projName, siteContext);
if (!existSubSite)
{
return true;
}
oneNoteService.CreateFolderInsideProject(projName, siteContext);
_oneNoteService.CreateFolderInsideProject(projName, siteContext);
CreateProjectListEntry(projName, siteContext);
projectDocLibraryService.Create(projName, subSiteContext);
_projectDocLibraryService.Create(projName, subSiteContext);
subSiteService.AddColumnsToListView(projName, subSiteContext);
_subSiteService.AddColumnsToListView(projName, subSiteContext);
projectQuickMenuService.CreateForProject(projName, subSiteContext);
_projectQuickMenuService.CreateForProject(projName, subSiteContext);
return true;
}
@@ -112,17 +119,17 @@ internal class SiteService : ISiteService
{
try
{
var site = siteOptions.GetQuotationSite();
using var ctx = authMgr.GetContext(site);
if (spc.SiteExist(ctx))
var site = _siteOptions.GetQuotationSite();
using var ctx = _authMgr.GetContext(site);
if (_spc.SiteExist(ctx))
{
return true;
}
tenantService.CreateForQuotation();
_tenantService.CreateForQuotation();
}
catch (Exception e)
{
logger.LogError(e, "Site Service");
_logger.LogError(e, "Site Service");
return false;
}
@@ -133,30 +140,29 @@ internal class SiteService : ISiteService
{
try
{
var site = siteOptions.GetNonComplianceSite();
using var ctx = authMgr.GetContext(site);
if (spc.SiteExist(ctx))
var site = _siteOptions.GetNonComplianceSite();
using var ctx = _authMgr.GetContext(site);
if (_spc.SiteExist(ctx))
{
return true;
}
tenantService.CreateForNonCompliance();
_tenantService.CreateForNonCompliance();
}
catch (Exception e)
{
logger.LogError(e, "Site Service");
_logger.LogError(e, "Site Service");
return false;
}
return true;
}
private void CreateProjectListEntry(string projName, ClientContext ctx)
{
try
{
var listTitle = siteOptions.GetProjListTitle();
var tenant = siteOptions.GetProjYearTenant().Replace(" ",string.Empty);
var listTitle = _siteOptions.GetProjListTitle(projName);
var tenant = _siteOptions.GetProjYearTenant(projName).Replace(" ",string.Empty);
var list = ctx.Web.Lists.GetByTitle(listTitle);
var itemCreateInfo = new ListItemCreationInformation();
@@ -169,17 +175,17 @@ internal class SiteService : ISiteService
};
oItem["PAL_ID_Project"] = link;
oItem["PAL_Customer"] = projectSettingsRepository.DefaultCostumer(projName);
oItem["PAL_DlvReason"] = projectSettingsRepository.DefaultDlvReason(projName);
oItem.Update();
ctx.ExecuteQuery();
logger.LogInformation($"> La Commessa {projName} è stata aggiunta alla lista {listTitle} con successo!");
_fieldEntryDataUpdate.FieldUpdate(ctx, listTitle, projName, FieldUpdateType.Project);
_logger.LogInformation($"> La Commessa {projName} è stata aggiunta alla lista {listTitle} con successo!");
}
catch (Exception ex)
{
logger.LogError(ex, "Create List Entry");
_logger.LogError(ex, "Create List Entry");
}
}
}