Exemplo n.º 1
0
        public override async Task ExecuteAsync(ICommandUpdateUDS command)
        {
            _logger.WriteInfo(new LogMessage(string.Concat(command.CommandName, " is arrived")), LogCategories);
            _logger.WriteInfo(new LogMessage("starting update storage"), LogCategories);
            UDSStorageFacade storage = new UDSStorageFacade(_logger, command.ContentType.ContentTypeValue.XMLContent, CurrentUDSSchemaRepository.SchemaXML, _administrationClient, DBSchema);
            UDSEntity        uds     = await UpdateStorageAsync(storage);

            _logger.WriteInfo(new LogMessage(string.Concat(command.ContentType.Id, " model evaluating ... ")), LogCategories);
            await UpdateTableAndCodeAsync(uds);

            _logger.WriteInfo(new LogMessage("Tables and codes aligned"), LogCategories);

            await UpdateArchiveAsync(uds, storage);

            _logger.WriteInfo(new LogMessage("Archive updated"), LogCategories);

            command.ContentType.ContentTypeValue.XMLContent = storage.UDS.SerializeToXml();
            if (storage.UDS.Model.RequiredRevisionUDSRepository)
            {
                await UpdateUDSRepositoryAsync(command.ContentType.ContentTypeValue);

                _logger.WriteInfo(new LogMessage("Repository updated"), LogCategories);
            }
            else
            {
                await UpdateUDSRepositoryAsync(command.ContentType.ContentTypeValue, false);

                _logger.WriteInfo(new LogMessage("Confirmed repository updated and draft repository deleted"), LogCategories);
            }
            _logger.WriteInfo(new LogMessage("message completed."), LogCategories);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private async Task CreateBiblosDSArchiveAsync(UDSEntity uds, UDSStorageFacade udsStorageFacade, bool isMainDocument = false)
        {
            try
            {
                await udsStorageFacade.GenerateStorageAsync(async (udsArchive, attributeGroups, attributeModes) =>
                {
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ReadOnly          = attributeModes.Single(f => f.IdMode == 0);
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ModifyAlways      = attributeModes.Single(f => f.IdMode == 3);
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ModifyNotArchived = attributeModes.Single(f => f.IdMode == 2);

                    BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_chain   = attributeGroups.SingleOrDefault(a => a.GroupType.Equals(BiblosDS.BiblosDSManagement.AttributeGroupType.Chain));
                    BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_default = attributeGroups.SingleOrDefault(a => a.GroupType.Equals(BiblosDS.BiblosDSManagement.AttributeGroupType.Undefined));

                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ReadOnly, AttributeHelper.AttributeName_Signature, "System.String", true);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ReadOnly, AttributeHelper.AttributeName_Filename, "System.String", true);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ModifyAlways, AttributeHelper.AttributeName_PrivacyLevel, "System.Int64", false);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ModifyAlways, AttributeHelper.AttributeName_SignModels, "System.String", false);

                    if (isMainDocument)
                    {
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ModifyNotArchived, "Subject", "System.String", false);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Year", "System.Int64", true);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Number", "System.Int64", true);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Date", "System.DateTime", true, isMainDate: true);

                        foreach (Metadata metadata in uds.MetaData)
                        {
                            await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain,
                                                                             metadata.Required ? attributeMode_ReadOnly : attributeMode_ModifyNotArchived,
                                                                             metadata.PropertyName, metadata.BiblosPropertyType.FullName, metadata.Required);
                        }
                    }
                }, BiblosDS_Storage_MainPath, BiblosDS_Storage_StorageType, isMainDocument);
            }
            catch (Exception ex)
            {
                _logger.WriteError(ex, LogCategories);
                throw ex;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Carica le informazioni sui metadati inseriti nell'entità principale
        /// </summary>
        /// <param name="storage"></param>
        /// <returns></returns>
        public UDSEntity LoadMetadata(UDSStorageFacade storage)
        {
            UDSEntity entity = new UDSEntity
            {
                TableName = storage.Builder.UDSTableName,
                Namespace = storage.Builder.UDSTableNameWithoutPrefix
            };
            Type metadataBiblosType;
            Type metadataPropertyType;

            foreach (Section sezione in storage.UDS.Model.Metadata.Where(f => f.Items != null).ToList())
            {
                foreach (FieldBaseType element in sezione.Items)
                {
                    metadataPropertyType = GetMetadataPropertyType(element);
                    metadataBiblosType   = GetMetadataBiblosType(element);
                    _log.WriteInfo(new LogMessage($"Nuovo metadato individuato in {entity.TableName} di tipo {metadataPropertyType.Name} e colonna {element.ColumnName}"), LogCategories);
                    if (metadataPropertyType != null && metadataBiblosType != null)
                    {
                        entity.MetaData.Add(new Metadata()
                        {
                            PropertyType       = metadataPropertyType,
                            Nullable           = metadataPropertyType != typeof(string),
                            BiblosPropertyType = metadataBiblosType,
                            PropertyName       = element.ColumnName,
                            Required           = element.Required,
                        });
                    }
                    else
                    {
                        _log.WriteWarning(new LogMessage($"Metadato {element.ColumnName} scartato per la tabella {entity.TableName} in quanto non valido : {element.GetType().Name}"), LogCategories);
                    }
                }
            }
            return(entity);
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
        private async Task UpdateArchiveAsync(UDSEntity uds, UDSStorageFacade udsStorageFacade, bool isMainDocument = false)
        {
            _logger.WriteInfo(new LogMessage("starting update archive"), LogCategories);

            if (udsStorageFacade.UDS.Model.Documents != null)
            {
                IList <BiblosDS.BiblosDSManagement.Archive> archives = _administrationClient.GetArchives().ToList();
                string miscellaneousArchiveName = string.Concat("Archive_UDS_Miscellaneous_", udsStorageFacade.UDS.Model.Title);
                BiblosDS.BiblosDSManagement.Archive miscellaneousArchive = new BiblosDS.BiblosDSManagement.Archive
                {
                    Name = miscellaneousArchiveName
                };

                if (udsStorageFacade.UDS.Model.Documents.Document != null)
                {
                    BiblosDS.BiblosDSManagement.Archive udsArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.Document.BiblosArchive));
                    if (udsArchive == null)
                    {
                        if (udsStorageFacade.UDS.Model.Documents.Document.CreateBiblosArchive)
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade, true);

                            _logger.WriteInfo(new LogMessage("Archive created successfully"), LogCategories);
                        }
                        else
                        {
                            _logger.WriteError(new LogMessage(string.Format("Archive {0} to update not found", udsStorageFacade.UDS.Model.Documents.Document.BiblosArchive)), LogCategories);
                        }
                    }
                    else
                    {
                        BiblosDS.BiblosDSManagement.Attribute[]            attributes                      = _administrationClient.GetAttributesFromArchive(udsArchive.IdArchive);
                        Task <BiblosDS.BiblosDSManagement.AttributeMode[]> task_attributeModes             = _administrationClient.GetAttributeModesAsync();
                        BiblosDS.BiblosDSManagement.AttributeMode[]        attributeModes                  = await task_attributeModes;
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ReadOnly          = attributeModes.Single(f => f.IdMode == 0);
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ModifyAlways      = attributeModes.Single(f => f.IdMode == 3);
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ModifyNotArchived = attributeModes.Single(f => f.IdMode == 2);

                        Metadata[] addedMetadata = uds.MetaData.Where(m => !attributes.Any(a => a.Name.Equals(m.PropertyName))).ToArray();

                        string[] requiredAttributes = { AttributeHelper.AttributeName_Signature, AttributeHelper.AttributeName_Filename,  AttributeHelper.AttributeName_UDSSubject,
                                                        AttributeHelper.AttributeName_UDSYear,   AttributeHelper.AttributeName_UDSNumber, AttributeHelper.AttributeName_Date, AttributeHelper.AttributeName_SignModels };
                        BiblosDS.BiblosDSManagement.Attribute[] dynamicAttributes   = attributes.Where(a => !requiredAttributes.Any(r => r.Equals(a.Name))).ToArray();
                        BiblosDS.BiblosDSManagement.Attribute[] deprecatedAttribute = dynamicAttributes.Where(a => !uds.MetaData.Any(m => m.PropertyName.Equals(a.Name))).ToArray();

                        //creo i nuovi attributi aggiunti all'archivio
                        foreach (Metadata metadata in addedMetadata)
                        {
                            BiblosDS.BiblosDSManagement.Attribute      attribute            = attributes.FirstOrDefault(a => a.AttributeGroup.GroupType == BiblosDS.BiblosDSManagement.AttributeGroupType.Chain);
                            BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_chain = attribute.AttributeGroup;
                            await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ModifyAlways,
                                                                             metadata.PropertyName, metadata.BiblosPropertyType.FullName, metadata.Required);
                        }
                        //disabilito gli attributi tolti dall'archivio
                        foreach (BiblosDS.BiblosDSManagement.Attribute item in deprecatedAttribute)
                        {
                            item.IsRequired       = false;
                            item.IsVisible        = false;
                            item.IsVisibleForUser = false;
                            item.Mode             = attributeMode_ReadOnly;
                            _logger.WriteInfo(new LogMessage(string.Concat("Updating biblosds attribute ", item.Name)), LogCategories);
                            await _administrationClient.UpdateAttributeAsync(item);
                        }
                    }
                }

                if (udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null && udsStorageFacade.UDS.Model.Documents.DocumentAttachment.CreateBiblosArchive)
                {
                    BiblosDS.BiblosDSManagement.Archive udsAttachmentArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.DocumentAttachment.BiblosArchive));

                    if (udsAttachmentArchive == null)
                    {
                        udsStorageFacade.UDS.Model.Documents.DocumentAttachment.BiblosArchive = miscellaneousArchiveName;
                        if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                            archives.Add(miscellaneousArchive);
                            _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                        }
                    }
                }

                if (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null && udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.CreateBiblosArchive)
                {
                    BiblosDS.BiblosDSManagement.Archive udsAnnexedArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.BiblosArchive));

                    if (udsAnnexedArchive == null)
                    {
                        udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.BiblosArchive = miscellaneousArchiveName;
                        if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                            archives.Add(miscellaneousArchive);
                            _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                        }
                    }
                }

                if ((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))
                {
                    if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                    {
                        await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                        archives.Add(miscellaneousArchive);
                        _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                    }

                    if (udsStorageFacade.UDS.Model.Documents.DocumentDematerialisation == null || !udsStorageFacade.UDS.Model.Documents.DocumentDematerialisation.Instances.Any())
                    {
                        udsStorageFacade.AddDocumentDematerialisation(udsStorageFacade.UDS.Model.Documents, miscellaneousArchiveName);
                    }
                }
            }
        }