Exemple #1
0
        public static void SaveFileToTransitoAttachLocalPath(DocumentAttach attach, Byte[] content)
        {
            if (attach == null)
            {
                throw new Exceptions.DocumentNotFound_Exception("SaveFileToTransitoAttachLocalPath : document is null");
            }

            if (attach.Document == null)
            {
                throw new Exceptions.DocumentNotFound_Exception("SaveFileToTransitoAttachLocalPath : referrer document is null");
            }

            if (attach.Document.Archive == null || attach.Document.Archive.IdArchive == Guid.Empty)
            {
                throw new Exceptions.Archive_Exception("SaveFileToTransitoAttachLocalPath : document archive is null");
            }

            if (string.IsNullOrWhiteSpace(attach.Document.Archive.PathTransito))
            {
                attach.Document.Archive = ArchiveService.GetArchive(attach.Document.Archive.IdArchive);
                if (attach.Document.Archive == null || string.IsNullOrWhiteSpace(attach.Document.Archive.PathTransito))
                {
                    throw new Exceptions.Archive_Exception("SaveFileToTransitoAttachLocalPath : document archive transit's path is not valid");
                }
            }

            if (!Directory.Exists(attach.Document.Archive.PathTransito))
            {
                Directory.CreateDirectory(attach.Document.Archive.PathTransito);
            }

            File.WriteAllBytes(Path.Combine(attach.Document.Archive.PathTransito, attach.Document.IdDocument + "_" + attach.IdDocumentAttach + Path.GetExtension(attach.Name)), content);
        }
Exemple #2
0
 public static void SaveFileToTransitoLocalPath(Document Document, Byte[] content)
 {
     if (string.IsNullOrEmpty(Document.Archive.PathTransito))
     {
         Document.Archive = ArchiveService.GetArchive(Document.Archive.IdArchive);
     }
     if (!Directory.Exists(Document.Archive.PathTransito))
     {
         Directory.CreateDirectory(Document.Archive.PathTransito);
     }
     File.WriteAllBytes(Path.Combine(Document.Archive.PathTransito, Document.IdDocument + Path.GetExtension(Document.Name)), content);
 }
        public static Guid CloneArchive(string templateName, string archiveName)
        {
            DocumentArchive            archiveToClone = null, existingArchive;
            List <DocumentAttribute>   attributesAdded   = new List <DocumentAttribute>();
            List <DocumentStorageArea> storageAreasAdded = new List <DocumentStorageArea>();
            List <DocumentStorage>     storagesAdded     = new List <DocumentStorage>();

            try
            {
                if (string.IsNullOrWhiteSpace(archiveName))
                {
                    throw new BiblosDS.Library.Common.Exceptions.Archive_Exception(string.Format("Destination archive name is null or empty for source archive {0}.", templateName));
                }

                archiveToClone = ArchiveService.GetArchiveByName(templateName);
                if (archiveToClone == null)
                {
                    throw new BiblosDS.Library.Common.Exceptions.Archive_Exception(string.Format("Archive with name {0} not found.", templateName));
                }
                //Il nome può essere lungo al massimo 63 caratteri.
                if (archiveName.Length > 63)
                {
                    archiveName = archiveName.Remove(63);
                }
                //Controlla se per caso l'archivio che si desidera clonare è già presente in banca dati.
                existingArchive = ArchiveService.GetArchiveByName(archiveName);

                if (existingArchive != null)
                {
                    return(existingArchive.IdArchive);
                }

                Guid idArchiveToClone = archiveToClone.IdArchive;
                archiveToClone.IdArchive = Guid.NewGuid();
                archiveToClone.Name      = Regex.Replace(archiveName, @"[^a-zA-Z0-9]", "-");
                if (!string.IsNullOrEmpty(archiveToClone.PathTransito) && archiveToClone.PathTransito.LastIndexOf('\\') > 0)
                {
                    archiveToClone.PathTransito = Path.Combine(archiveToClone.PathTransito.Substring(0, archiveToClone.PathTransito.LastIndexOf('\\')), archiveToClone.Name);
                }

                if (!string.IsNullOrEmpty(archiveToClone.PathPreservation) && archiveToClone.PathPreservation.LastIndexOf('\\') > 0)
                {
                    archiveToClone.PathPreservation = Path.Combine(archiveToClone.PathPreservation.Substring(0, archiveToClone.PathPreservation.LastIndexOf('\\')), archiveToClone.Name);
                }

                DbAdminProvider.AddArchive(archiveToClone);
                //Clone attributes
                var attributes = AttributeService.GetAttributesFromArchive(idArchiveToClone);
                foreach (var attributeItem in attributes)
                {
                    var attribute = new DocumentAttribute {
                        IdAttribute = Guid.NewGuid(), Archive = archiveToClone, AttributeType = attributeItem.AttributeType, ConservationPosition = attributeItem.ConservationPosition, DefaultValue = attributeItem.DefaultValue, Description = attributeItem.Description, Disabled = attributeItem.Disabled, Format = attributeItem.Format, IsAutoInc = attributeItem.IsAutoInc, IsChainAttribute = attributeItem.IsChainAttribute, IsEnumerator = attributeItem.IsEnumerator, IsMainDate = attributeItem.IsMainDate, IsRequired = attributeItem.IsRequired, IsRequiredForPreservation = attributeItem.IsRequiredForPreservation, IsSectional = attributeItem.IsSectional, IsUnique = attributeItem.IsUnique, IsVisible = attributeItem.IsVisible, IsVisibleForUser = attributeItem.IsVisibleForUser, KeyFilter = attributeItem.KeyFilter, KeyFormat = attributeItem.KeyFormat, KeyOrder = attributeItem.KeyOrder, MaxLenght = attributeItem.MaxLenght, Mode = attributeItem.Mode, Name = attributeItem.Name, Validation = attributeItem.Validation
                    };
                    DbAdminProvider.AddAttribute(attribute);
                    attributesAdded.Add(attribute);
                }
                //Retrive storage
                var storage = DbProvider.GetStoragesActiveFromArchive(idArchiveToClone);
                foreach (var storageItem in storage)
                {
                    var storageArea = DbProvider.GetStorageAreaActiveFromStorage(storageItem.IdStorage);
                    if (storageArea.Any(x => x.Archive != null && x.Archive.IdArchive == idArchiveToClone))
                    {
                        storageArea = new BindingList <DocumentStorageArea>(storageArea.Where(x => x.Archive != null && x.Archive.IdArchive == idArchiveToClone).ToList());
                    }

                    foreach (var storageAreaItem in storageArea)
                    {
                        var newStorageArea = new DocumentStorageArea {
                            IdStorageArea = Guid.NewGuid(), Archive = archiveToClone, Storage = storageItem, Enable = true, MaxFileNumber = storageAreaItem.MaxFileNumber, MaxSize = storageAreaItem.MaxSize, Name = archiveToClone.Name, Path = archiveToClone.Name, Priority = storageAreaItem.Priority, Status = storageAreaItem.Status
                        };
                        DbAdminProvider.AddStorageArea(newStorageArea);
                        storageAreasAdded.Add(newStorageArea);
                    }
                    DbAdminProvider.AddArchiveStorage(new DocumentArchiveStorage {
                        Storage = storageItem, Archive = archiveToClone, Active = true
                    });
                    storagesAdded.Add(storageItem);
                }
                return(archiveToClone.IdArchive);
            }
            catch (Exception)
            {
                try
                {
                    if (archiveToClone != null)
                    {
                        foreach (var item in storagesAdded)
                        {
                            DbAdminProvider.DeleteArchiveStorage(new DocumentArchiveStorage {
                                Archive = archiveToClone, Storage = item
                            });;
                        }
                        foreach (var item in storageAreasAdded)
                        {
                            DbAdminProvider.DeleteStorageArea(item.IdStorageArea);
                        }
                        foreach (var item in attributesAdded)
                        {
                            DbAdminProvider.DeleteAttribute(item.IdAttribute, false);
                        }
                        DbAdminProvider.DeleteArchive(archiveToClone);
                    }
                }
                catch (Exception ex)
                {
                    logger.Warn(ex);
                    throw;
                }
                throw;
            }
        }