private async Task <UDSEntity> UpdateStorageAsync(UDSStorageFacade storage) { UDSEntity entity = null; MetadataEntity metadatas = new MetadataEntity(_logger); try { //verifica esistenza tabella using (SmoContext smo = new SmoContext(ConnectionString, DBSchema)) { if (!smo.TableExist(storage.Builder.UDSTableName)) { _logger.WriteError(new LogMessage(string.Concat(storage.Builder.UDSTableName, " not exist")), LogCategories); throw new Exception(string.Concat(storage.Builder.UDSTableName, " - UDS structures not found")); } } await storage.UpdateStorageAsync(ConnectionString); _logger.WriteInfo(new LogMessage("update storage completed"), LogCategories); entity = metadatas.LoadMetadata(storage); } catch (Exception ex) { _logger.WriteError(ex, LogCategories); throw ex; } return(entity); }
public override async Task ExecuteAsync(ICommandCreateUDS command) { _logger.WriteInfo(new LogMessage(string.Concat(command.CommandName, " is arrived")), LogCategories); try { UDSStorageFacade udsStorageFacade = new UDSStorageFacade(_logger, command.ContentType.ContentTypeValue.XMLContent, CurrentUDSSchemaRepository.SchemaXML, _administrationClient, DBSchema); _logger.WriteInfo(new LogMessage("Starting create storage"), LogCategories); await udsStorageFacade.CreateStorageAsync(ConnectionString, async (smo) => { _logger.WriteInfo(new LogMessage("Create storage completed"), LogCategories); bool res = true; try { res &= smo.TableExist(udsStorageFacade.Builder.UDSTableName); if (res) { _logger.WriteInfo(new LogMessage(string.Concat(udsStorageFacade.Builder.UDSTableName, " has been successfully created")), LogCategories); } res &= smo.TableExist(udsStorageFacade.Builder.UDSDocumentsTableName); if (res) { _logger.WriteInfo(new LogMessage(string.Concat(udsStorageFacade.Builder.UDSDocumentsTableName, " has been successfully created")), LogCategories); } if (!res) { throw new InvalidOperationException("Error in creation table. Detect miss tables."); } MetadataEntity metadatas = new MetadataEntity(_logger); UDSEntity udsEntity = metadatas.LoadMetadata(udsStorageFacade); bool codeGenerated = await GenerateUDSCodeAsync(udsEntity); if (codeGenerated) { _logger.WriteInfo(new LogMessage("UDS libraries has been successfully installed."), LogCategories); } else { _logger.WriteError(new LogMessage("Occour error in UDS libraries building. Process manual UDS Migrations"), LogCategories); } if (udsStorageFacade.UDS.Model.Documents != null) { if (udsStorageFacade.UDS.Model.Documents.Document != null && udsStorageFacade.UDS.Model.Documents.Document.CreateBiblosArchive) { await CreateBiblosDSArchiveAsync(udsEntity, udsStorageFacade, true); udsStorageFacade.UDS.Model.Documents.Document.CreateBiblosArchive = false; _logger.WriteInfo(new LogMessage("Archive created successfully"), LogCategories); } if ((udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null && udsStorageFacade.UDS.Model.Documents.DocumentAttachment.CreateBiblosArchive) || (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null && udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.CreateBiblosArchive) || (udsStorageFacade.UDS.Model.Documents.Document != null && udsStorageFacade.UDS.Model.Documents.Document.DematerialisationEnabled) || (udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null && udsStorageFacade.UDS.Model.Documents.DocumentAttachment.DematerialisationEnabled) || (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null && udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.DematerialisationEnabled)) { await CreateBiblosDSArchiveAsync(udsEntity, udsStorageFacade); if (udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null) { udsStorageFacade.UDS.Model.Documents.DocumentAttachment.CreateBiblosArchive = false; } if (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null) { udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.CreateBiblosArchive = false; } _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories); } command.ContentType.ContentTypeValue.XMLContent = udsStorageFacade.UDS.SerializeToXml(); } if (udsStorageFacade.UDS.Model.Container.CreateContainer) { _logger.WriteInfo(new LogMessage(string.Concat("Creating Container ", udsStorageFacade.UDS.Model.Title, " with admin SecurityUser ", command.Identity.User)), LogCategories); DocSuiteWeb.Entity.Commons.Container container = CreateContainerFromArchive(udsStorageFacade.UDS.Model.Title, command.Identity.User); container = await CreateConteainerAsync(container); udsStorageFacade.UDS.Model.Container.IdContainer = container.EntityShortId.ToString(); udsStorageFacade.UDS.Model.Container.CreateContainer = false; command.ContentType.ContentTypeValue.XMLContent = udsStorageFacade.UDS.SerializeToXml(); _logger.WriteInfo(new LogMessage("DocSuite Container created successfully"), LogCategories); } _logger.WriteInfo(new LogMessage("UDS storage configured successfully"), LogCategories); await SaveUDSRepositoryAsync(command.ContentType.ContentTypeValue, udsStorageFacade.UDS.Model.Container.IdContainer); _logger.WriteInfo(new LogMessage("UDS entity saved successfully"), LogCategories); return(true); } catch (AggregateException aex) { foreach (Exception ex in aex.Flatten().InnerExceptions) { _logger.WriteError(ex, LogCategories); } } catch (Exception ex) { _logger.WriteError(ex, LogCategories); } return(false); }); } catch (Exception ex) { _logger.WriteError(ex, LogCategories); throw ex; } }