Exemplo n.º 1
0
        public Guid AddStorageArea(DocumentStorageArea StorageArea)
        {
            StorageArea.IdStorageArea = Guid.NewGuid();

            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageArea entityAttribute = StorageArea.TryToConvertTo <Model.StorageArea>(false);

                if (StorageArea.Status != null && StorageArea.Status.IdStatus > 0)
                {
                    entityAttribute.IdStorageStatus = StorageArea.Status.IdStatus;
                }

                if (StorageArea.Storage != null)
                {
                    entityAttribute.IdStorage = StorageArea.Storage.IdStorage;
                }

                if (StorageArea.Archive != null)
                {
                    entityAttribute.IdArchive = StorageArea.Archive.IdArchive;
                }

                db.AddToStorageArea(entityAttribute);
                db.SaveChanges();
            }

            return(StorageArea.IdStorageArea);
        }
Exemplo n.º 2
0
        public void UpdateStorageArea(DocumentStorageArea StorageArea)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.StorageArea entityAttribute = StorageArea.TryToConvertTo <Model.StorageArea>(false);

                if (entityAttribute.EntityKey == null)
                {
                    entityAttribute.EntityKey = db.CreateEntityKey(entityAttribute.GetType().Name, entityAttribute);
                }

                var attachedEntity = db.GetObjectByKey(entityAttribute.EntityKey) as Model.StorageArea;

                if (StorageArea.Status != null && StorageArea.Status.IdStatus > 0)
                {
                    entityAttribute.IdStorageStatus = StorageArea.Status.IdStatus;
                }

                if (StorageArea.Storage != null)
                {
                    entityAttribute.IdStorage = StorageArea.Storage.IdStorage;
                }

                if (StorageArea.Archive != null)
                {
                    entityAttribute.IdArchive = StorageArea.Archive.IdArchive;
                }

                db.ApplyCurrentValues(entityAttribute.EntityKey.EntitySetName, entityAttribute);

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private string GetTableName(DocumentStorage Storage, DocumentStorageArea StorageArea)
        {
            string table = Storage.Name;

            if (!string.IsNullOrEmpty(StorageArea.Path))
            {
                table = StorageArea.Path;
            }
            return(table);
        }
Exemplo n.º 4
0
        public static Guid AddStorageArea(DocumentStorageArea StorageArea)
        {
            if (string.IsNullOrEmpty(StorageArea.Name) ||
                StorageArea.Storage == null ||
                StorageArea.Storage.IdStorage == Guid.Empty)
            {
                throw new Exception("Requisiti non sufficienti per l'operazione");
            }

            return(DbAdminProvider.AddStorageArea(StorageArea));
        }
Exemplo n.º 5
0
        public static void UpdateStorageArea(DocumentStorageArea StorageArea)
        {
            if (StorageArea.IdStorageArea == Guid.Empty)
            {
                throw new Exception("Impossibile proseguire. IdStorageArea non valido.");
            }
            if (string.IsNullOrEmpty(StorageArea.Name) ||
                StorageArea.Storage == null ||
                StorageArea.Storage.IdStorage == Guid.Empty)
            {
                throw new Exception("Requisiti non sufficienti per l'operazione");
            }

            DbAdminProvider.UpdateStorageArea(StorageArea);
        }
Exemplo n.º 6
0
        private string GetStorageDir(DocumentStorage Storage, DocumentStorageArea StorageArea)
        {
            string dir = Path.Combine(Storage.MainPath, Storage.Name);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            if (!string.IsNullOrEmpty(StorageArea.Path))
            {
                dir = Path.Combine(dir, StorageArea.Path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            return(dir);
        }
Exemplo n.º 7
0
 protected abstract long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content);
Exemplo n.º 8
0
 /// <summary>
 /// Add a document to an archive
 /// </summary>
 /// <param name="document"></param>
 /// <returns>
 /// The size of the docuemnt Blob
 /// </returns>
 protected abstract long SaveDocument(string localFilePath, DocumentStorage storage, DocumentStorageArea storageArea, Document document, BindingList <DocumentAttributeValue> attributeValue);
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
        protected override long SaveDocument(string localFilePath, DocumentStorage storage, DocumentStorageArea storageArea, Document document, BindingList <DocumentAttributeValue> attributeValue)
        {
            byte[] content  = File.ReadAllBytes(localFilePath);
            string fileName = GetFileName(document);

            //Save document
            DocumentService.AddDocumentToSQL(document, fileName, content, DocumentType.Default);

            //Save searchable document
            string searchableFileName;

            byte[] extractedContent = base.GetDocumentSignedContent(document, document.Content.Blob, out searchableFileName);
            searchableFileName = string.Concat(document.IdDocument, Path.GetExtension(searchableFileName));
            DocumentService.AddDocumentToSQL(document, searchableFileName, extractedContent, DocumentType.Searchable);

            //Write attributes on file system
            WriteAttributes(document);

            return(content.Length);
        }
Exemplo n.º 11
0
 public void AddStorageArea(DocumentStorageArea StorageArea)
 {
     StorageService.AddStorageArea(StorageArea);
 }
Exemplo n.º 12
0
 protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
 {
     try
     {
         byte[] data         = null;
         File   fileUploaded = null;
         //Pick up the file in binary stream
         data = Document.Content.Blob;
         //
         ClientContext context = new ClientContext(Storage.MainPath);
         context.Credentials = new NetworkCredential(Storage.AuthenticationKey, Storage.AuthenticationPassword);
         Web  web  = context.Web;
         List docs = web.Lists.GetByTitle(Storage.Name);
         context.ExecuteQuery();
         //
         Folder foolder = docs.RootFolder;
         if (!string.IsNullOrEmpty(StorageArea.Path))
         {
             try
             {
                 if ((foolder = docs.RootFolder.Folders.Where(x => x.Name == StorageArea.Path).FirstOrDefault()) == null)
                 {
                     docs.RootFolder.Folders.Add(StorageArea.Path);
                 }
             }
             catch (Exception)
             {
                 docs.RootFolder.Folders.Add(StorageArea.Path);
             }
         }
         context.ExecuteQuery();
         string fileName = GetIdDocuemnt(Document) + System.IO.Path.GetExtension(Document.Name);
         FileCreationInformation newFile = new FileCreationInformation();
         newFile.Content = data;
         newFile.Url     = fileName;
         try
         {
             IEnumerable <File> resultFiles = context.LoadQuery(foolder.Files.Where(x => x.Name == fileName).Include(x => x.ListItemAllFields));
             context.ExecuteQuery();
             fileUploaded = resultFiles.FirstOrDefault();
         }
         catch { }
         if (fileUploaded != null)
         {
             fileUploaded.CheckOut();
             context.ExecuteQuery();
             FileSaveBinaryInformation newFileInfo = new FileSaveBinaryInformation();
             newFileInfo.Content = data;
             fileUploaded.SaveBinary(newFileInfo);
             fileUploaded.CheckIn("BiblosDS", CheckinType.MajorCheckIn);
             context.ExecuteQuery();
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         else
         {
             fileUploaded = foolder.Files.Add(newFile);
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         //Set the file version
         context.ExecuteQuery();
         context.Load(fileUploaded, w => w.MajorVersion);
         context.ExecuteQuery();
         Document.StorageVersion = fileUploaded.MajorVersion;
         return(data.Length);
     }
     catch (Exception ex)
     {
         Logging.WriteLogEvent(LoggingSource.BiblosDS_WCF_Storage, "SaveDocument", ex.ToString(), LoggingOperationType.BiblosDS_InsertDocument, LoggingLevel.BiblosDS_Errors);
         throw;
     }
 }
Exemplo n.º 13
0
        protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
        {
            SPSite site = null;
            SPWeb  web  = null;

            byte[]            data            = null;
            SPFile            fileUploaded    = null;
            string            RootLibraryName = String.Empty;
            SPDocumentLibrary doclib          = null;

            //Pick up the file in binary stream
            data = Document.Content.Blob;

            using (site = new SPSite(Storage.MainPath))
            {
                using (web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;

                    //SPFolder Folder = web.GetFolder(StorageArea.Path);
                    doclib = web.Lists[Storage.Name] as SPDocumentLibrary;
                    if (doclib == null)
                    {
                        web.Lists.Add(Storage.Name, string.Empty, SPListTemplateType.DocumentLibrary);
                    }

                    /// **REMOVE**: 20090818
                    /// viene impostato l'override, altrimenti il documento resterebbe nel transito
                    /// TODO : da sistemare con la gestione delle versioni in sharepoint
                    try
                    {
                        SPFolder foolder = null;
                        if (data != null)
                        {
                            if (!string.IsNullOrEmpty(StorageArea.Path))
                            {
                                try
                                {
                                    if (doclib.RootFolder.SubFolders[StorageArea.Path] == null)
                                    {
                                        doclib.RootFolder.SubFolders.Add(StorageArea.Path);
                                    }
                                }
                                catch (Exception)
                                {
                                    doclib.RootFolder.SubFolders.Add(StorageArea.Path);
                                }
                                foolder = doclib.RootFolder.SubFolders[StorageArea.Path];
                            }
                            else
                            {
                                foolder = doclib.RootFolder;
                            }

                            string fileName = GetIdDocuemnt(Document) + Path.GetExtension(Document.Name);
                            try
                            {
                                fileUploaded = foolder.Files[fileName];
                            }
                            catch { }
                            if (fileUploaded != null)
                            {
                                fileUploaded.CheckOut();
                                fileUploaded.SaveBinary(data);
                                fileUploaded.CheckIn("BiblosDS", SPCheckinType.MajorCheckIn);
                            }
                            else
                            {
                                fileUploaded = foolder.Files.Add(fileName, data, true);
                            }
                            //Set the file version
                            Document.StorageVersion = fileUploaded.MajorVersion;


                            if (ConfigurationManager.AppSettings["ForceSharePointSecurity"] != null && ConfigurationManager.AppSettings["ForceSharePointSecurity"].ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase))
                            {
                                fileUploaded.Item.BreakRoleInheritance(false);
                                try
                                {
                                    for (int i = 0; i < fileUploaded.Item.RoleAssignments.Count; i++)
                                    {
                                        try
                                        {
                                            fileUploaded.Item.RoleAssignments.Remove((SPPrincipal)fileUploaded.Item.RoleAssignments[i].Member);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                        //
                                    }
                                    string SiteGroupsName = ConfigurationManager.AppSettings["SiteGroupsName"] == null ? string.Empty : ConfigurationManager.AppSettings["SiteGroupsName"].ToString();
                                    //foreach (var item in Document.Permissions)
                                    //{
                                    SPRoleDefinitionCollection webroledefinition = web.RoleDefinitions;

                                    SPGroup group = null;
                                    try
                                    {
                                        group = web.SiteGroups[SiteGroupsName];
                                    }
                                    catch (Exception)
                                    {
                                        web.SiteGroups.Add(SiteGroupsName, web.AssociatedOwnerGroup, null, "");
                                        group = web.SiteGroups[SiteGroupsName];
                                    }

                                    //Add user to the group of viewer
                                    //try
                                    //{
                                    //    group.AddUser()
                                    //}
                                    //catch (Exception)
                                    //{

                                    //    throw;
                                    //}
                                    SPRoleAssignment assignment = new SPRoleAssignment(group);
                                    assignment.RoleDefinitionBindings.Add(webroledefinition.GetByType(SPRoleType.Reader));
                                    fileUploaded.Item.RoleAssignments.Add(assignment);
                                    //}
                                }
                                catch (Exception)
                                {
                                }
                                finally
                                {
                                    fileUploaded.Item.BreakRoleInheritance(true);
                                }
                            }

                            //In questo caso forse conviene salvare gli attributi al momento dell'upload del file.
                            //SPListItem MyListItem = fileUploaded.Item;
                            foreach (var item in Document.AttributeValues)
                            {
                                try
                                {
                                    fileUploaded.Item[item.Attribute.Name] = item.Value;
                                }
                                catch (Exception)
                                {
                                    doclib.Fields.Add(item.Attribute.Name, ParseSPFieldType(item.Attribute.AttributeType), item.Attribute.IsRequired);
                                    doclib.Update();
                                }
                            }
                            fileUploaded.Item.SystemUpdate();
                        }
                    }
                    catch (Exception ex)
                    {
                        //Write the log
                        Logging.WriteLogEvent(BiblosDS.Library.Common.Enums.LoggingSource.BiblosDS_Sharepoint,
                                              "SaveDocument",
                                              ex.ToString(),
                                              BiblosDS.Library.Common.Enums.LoggingOperationType.BiblosDS_General,
                                              BiblosDS.Library.Common.Enums.LoggingLevel.BiblosDS_Errors);
                        throw new FileNotUploaded_Exception("File not uploaded" + Environment.NewLine + ex.ToString());
                    }
                    web.AllowUnsafeUpdates = false;
                }
            }
            return(data.Length);
        }
Exemplo n.º 14
0
        /// <summary>
        /// salvataggio del documento nella directory del definitivo
        /// </summary>
        /// <param name="LocalFilePath"></param>
        /// <param name="Storage"></param>
        /// <param name="StorageArea"></param>
        /// <param name="Document"></param>
        /// <param name="attributeValue"></param>
        /// <returns></returns>
        /// <remarks>piuttosto di trovarsi in situazioni, che non dovrebbero succedere, di documenti
        /// nel transito aventi lo stesso nome di documenti nel definitivo e l'impossibilità di sovrascriverli,
        /// viene permesso la sovrascrittura
        /// </remarks>
        protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, System.ComponentModel.BindingList <DocumentAttributeValue> attributeValue)
        {
            string saveFileName = Path.Combine(GetStorageDir(Document.Storage, Document.StorageArea), GetFileName(Document));

            File.Copy(LocalFilePath, saveFileName, true);
            FileInfo     fInfo = new FileInfo(saveFileName);
            FileSecurity fSec  = null;

            if (Document.Permissions != null)
            {
                fSec = fInfo.GetAccessControl();
                AuthorizationRuleCollection fileRoles = fSec.GetAccessRules(true, true, typeof(NTAccount));
                foreach (AuthorizationRule item in fileRoles)
                {
                    fSec.RemoveAuditRuleAll(new FileSystemAuditRule(item.IdentityReference.ToString(), FileSystemRights.FullControl, AuditFlags.Success));
                }
                //
                foreach (var item in Document.Permissions)
                {
                    fSec.AddAccessRule(new FileSystemAccessRule(item.Name, FileSystemRights.Read, AccessControlType.Allow));
                }
                fInfo.SetAccessControl(fSec);
            }
            //Write attributes on file system
            WriteAttributes(Document);
            if (!fInfo.Exists)
            {
                throw new Exception();
            }

            return(fInfo.Length);
        }
Exemplo n.º 15
0
 protected override long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
        protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
        {
            try
            {
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                binding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;

                BiblosSvcClient client = new BiblosSvcClient(binding, new EndpointAddress(Storage.MainPath));
                client.ClientCredentials.Windows.ClientCredential          = new NetworkCredential(Storage.AuthenticationKey, Storage.AuthenticationPassword);
                client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
                string fileName = GetIdDocuemnt(Document) + Path.GetExtension(Document.Name);
                if (!client.ExistsDocumentSet(Storage.Name, StorageArea.Path, Document.DocumentParent.IdDocument.ToString()))
                {
                    var chainAttributes  = new Dictionary <object, object>();
                    var chainContentType = attributeValue.Where(x => (x.Attribute.IsChainAttribute.HasValue && x.Attribute.IsChainAttribute.Value) && x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                    //attributeValue.Where(x => (!x.Attribute.IsChainAttribute.HasValue || x.Attribute.IsChainAttribute.Value) && !x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).ToList().ForEach(x => chainAttributes.Add(x.Attribute.Name, x.Value));
                    attributeValue.Where(x => !x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).ToList().ForEach(x => chainAttributes.Add(x.Attribute.Name, x.Value));
                    client.CreateDocumentSet(Storage.Name, StorageArea.Path, chainContentType != null ? chainContentType.Attribute.KeyFilter.ToString() : string.Empty, Document.DocumentParent.IdDocument.ToString(), chainAttributes);
                }
                var attributes  = new Dictionary <string, object>();
                var contentType = attributeValue.Where(x => (!x.Attribute.IsChainAttribute.HasValue || !x.Attribute.IsChainAttribute.Value) && x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                //attributeValue.Where(x => (!x.Attribute.IsChainAttribute.HasValue || !x.Attribute.IsChainAttribute.Value) && !x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).ToList().ForEach(x => attributes.Add(x.Attribute.Name, x.Value));
                attributeValue.Where(x => !x.Attribute.Name.Equals("contentType", StringComparison.InvariantCultureIgnoreCase)).ToList().ForEach(x => attributes.Add(x.Attribute.Name, x.Value));
                return((long)client.AddToDocumentSet(Storage.Name, StorageArea.Path, Document.DocumentParent.IdDocument.ToString(), contentType != null ? contentType.Attribute.KeyFilter : string.Empty, fileName, Document.Content.Blob, attributes));
            }
            catch (Exception ex)
            {
                //Write the log
                Logging.WriteLogEvent(BiblosDS.Library.Common.Enums.LoggingSource.BiblosDS_Sharepoint,
                                      "SaveDocument",
                                      ex.ToString(),
                                      BiblosDS.Library.Common.Enums.LoggingOperationType.BiblosDS_General,
                                      BiblosDS.Library.Common.Enums.LoggingLevel.BiblosDS_Errors);
                throw new FileNotUploaded_Exception("File not uploaded" + Environment.NewLine + ex.ToString());
            }
        }
Exemplo n.º 17
0
 public void UpdateStorageArea(DocumentStorageArea StorageArea)
 {
     StorageService.UpdateStorageArea(StorageArea);
 }
Exemplo n.º 18
0
 protected override long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content)
 {
     DocumentService.AddDocumentToSQL(document, saveFileName, content.Blob, DocumentType.Attachment);
     return(content.Blob.Length);
 }
Exemplo n.º 19
0
        /// <summary>
        /// salvataggio del documento nella directory del definitivo
        /// </summary>
        /// <param name="LocalFilePath"></param>
        /// <param name="Storage"></param>
        /// <param name="StorageArea"></param>
        /// <param name="Document"></param>
        /// <param name="attributeValue"></param>
        /// <returns></returns>
        /// <remarks>piuttosto di trovarsi in situazioni, che non dovrebbero succedere, di documenti
        /// nel transito aventi lo stesso nome di documenti nel definitivo e l'impossibilità di sovrascriverli,
        /// viene permesso la sovrascrittura
        /// </remarks>
        protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, System.ComponentModel.BindingList <DocumentAttributeValue> attributeValue)
        {
            //string saveFileName = GetStorageDir(Document.Storage, Document.StorageArea) + GetFileName(Document);
            string[] pathAndPort = Storage.MainPath.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
            string   path        = pathAndPort.FirstOrDefault();
            string   port        = pathAndPort.LastOrDefault();
            long     bytes       = -1;

            if (!string.IsNullOrEmpty(port) && !string.IsNullOrEmpty(path))
            {
                logger.Debug(path + " (port" + port + ")");
                logger.Debug("filepath: " + LocalFilePath + " , StorageAreaPath: " + StorageArea.Path);

                FTPFactory fact = new FTPFactory();
                fact.setRemoteUser(Storage.AuthenticationKey);
                fact.setRemotePass(Storage.AuthenticationPassword);
                fact.setRemoteHost(path);
                fact.setRemotePath(StorageArea.Path);
                fact.setRemotePort(int.Parse(port));

                fact.login();
                fact.upload(LocalFilePath);

                //long bytes = FtpWrite(LocalFilePath, saveFileName, Storage.AuthenticationKey, Storage.AuthenticationPassword);
                bytes = new FileInfo(LocalFilePath).Length;
                logger.Debug(bytes + " writed...");
            }
            return(bytes);
        }
Exemplo n.º 20
0
        protected override long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content)
        {
            if (string.IsNullOrEmpty(storage.AuthenticationKey))
            {
                storage = StorageService.GetStorage(storage.IdStorage);
            }
            StorageAccountInfo account = StorageAccountInfo.GetAccountInfoFromConfiguration(
                string.Empty,
                storage.MainPath,
                storage.AuthenticationKey,
                true);

            BlobStorage blobStorage = BlobStorage.Create(account);

            blobStorage.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));

            //Check if exist storage area
            //If exist put the storage in the configured path
            if (!string.IsNullOrEmpty(storageArea.Path))
            {
                container = blobStorage.GetBlobContainer(storage.Name.ToLower() + storageArea.Path.ToLower());
            }
            else
            {
                container = blobStorage.GetBlobContainer(storage.Name.ToLower());
            }
            //Create the container if it does not exist.
            if (!container.DoesContainerExist())
            {
                container.CreateContainer();
                //throw new Exception("Attenzione, container non esistente. Procedere alla creazione utilizzando il metodo SaveDocument");
            }

            BlobProperties      blobProperty = new BlobProperties(saveFileName);
            NameValueCollection metadata     = new NameValueCollection();

            container.CreateBlob(
                blobProperty,
                new BlobContents(content.Blob),
                true
                );

            return(content.Blob.Length);
        }
Exemplo n.º 21
0
        protected override long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content)
        {
            string saveFilePathName = Path.Combine(GetStorageDir(storage, storageArea), saveFileName);

            File.WriteAllBytes(saveFilePathName, content.Blob);
            return(content.Blob.Length);
        }