Esempio n. 1
0
        public void UpdateStorage(BiblosDS.Library.Common.Objects.DocumentStorage Storage)
        {
            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.Storage entityStorage = Storage.TryToConvertTo <Model.Storage>(false);

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

                var attachedEntity = db.GetObjectByKey(entityStorage.EntityKey) as Model.Storage;

                if (Storage.StorageType != null)
                {
                    entityStorage.IdStorageType = Storage.StorageType.IdStorageType;
                }

                if (Storage.Server != null && Storage.Server.IdServer != Guid.Empty)
                {
                    entityStorage.IdServer = Storage.Server.IdServer;
                }

                db.ApplyCurrentValues(entityStorage.EntityKey.EntitySetName, entityStorage);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        protected override long SaveDocument(string LocalFilePath, BiblosDS.Library.Common.Objects.DocumentStorage Storage, BiblosDS.Library.Common.Objects.DocumentStorageArea StorageArea, BiblosDS.Library.Common.Objects.Document Document, System.ComponentModel.BindingList <BiblosDS.Library.Common.Objects.DocumentAttributeValue> attributeValue)
        {
            string storage = Path.Combine(Storage.MainPath, StorageArea.Path);

            if (!Directory.Exists(storage))
            {
                Directory.CreateDirectory(storage);
            }
            string fileName = GetFileName(Document);

            if (Path.GetExtension(Document.Name) != string.Empty)
            {
                fileName = GetFileName(Document) + Path.GetExtension(Document.Name);
            }
            string saveFileName = Path.Combine(storage, fileName);

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

            //Write attributes on file system
            WriteAttributes(Document);
            if (!fInfo.Exists)
            {
                throw new Exception("Error on save document");
            }

            return(fInfo.Length);
        }
Esempio n. 3
0
        protected override long SaveDocument(string LocalFilePath, BiblosDS.Library.Common.Objects.DocumentStorage Storage, BiblosDS.Library.Common.Objects.DocumentStorageArea StorageArea, BiblosDS.Library.Common.Objects.Document Document, System.ComponentModel.BindingList <BiblosDS.Library.Common.Objects.DocumentAttributeValue> attributeValue)
        {
            if (string.IsNullOrEmpty(Document.Storage.AuthenticationKey))
            {
                Document.Storage = StorageService.GetStorage(Document.Storage.IdStorage);
            }
            StorageAccountInfo account = StorageAccountInfo.GetAccountInfoFromConfiguration(
                string.Empty,
                Storage.MainPath,
                Document.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())
            {
                BindingList <DocumentAttribute> attribute = AttributeService.GetAttributesFromArchive(Document.Archive.IdArchive);

                NameValueCollection containerMetadata = new NameValueCollection();
                foreach (DocumentAttribute item in attribute)
                {
                    containerMetadata.Add(item.Name, item.Name);
                }
                container.CreateContainer(containerMetadata, ContainerAccessControl.Private);
            }

            //ContainerAccessControl acl = container.GetContainerAccessControl();
            //
            BlobProperties      blobProperty = new BlobProperties(GetFileName(Document));
            NameValueCollection metadata     = new NameValueCollection();

            foreach (DocumentAttributeValue item in Document.AttributeValues)
            {
                metadata.Add(item.Attribute.Name, item.Value.ToString());
            }
            blobProperty.Metadata = metadata;
            container.CreateBlob(
                blobProperty,
                new BlobContents(Document.Content.Blob),
                true
                );


            return(Document.Content.Blob.Length);
        }
Esempio n. 4
0
        /// <summary>
        /// Salvataggio del documento nelle tabelle 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, BiblosDS.Library.Common.Objects.DocumentStorage Storage, BiblosDS.Library.Common.Objects.DocumentStorageArea StorageArea, BiblosDS.Library.Common.Objects.Document Document, System.ComponentModel.BindingList <BiblosDS.Library.Common.Objects.DocumentAttributeValue> attributeValue)
        {
            string connectionString = Storage.MainPath;
            string tableName        = GetTableName(Storage, StorageArea);

            byte[] content = GetFileBytes(LocalFilePath);

            using (SqlConnection cnn = new SqlConnection(connectionString))
            {
                string sqlCreateTable = string.Format(@"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{0}]') AND type in (N'U'))
                                                        BEGIN
                                                           CREATE TABLE {0} (
                                                           DocumentID UNIQUEIDENTIFIER NOT NULL PRIMARY KEY ROWGUIDCOL,
                                                           Document VARBINARY (MAX) FILESTREAM NULL)
                                                        END", tableName);
                cnn.Open();
                using (SqlCommand cmd = new SqlCommand(sqlCreateTable, cnn))
                {
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
                string sqlInsertBlob = string.Format(@"IF NOT EXISTS (SELECT DocumentID FROM {0} WHERE DocumentID = @DocumentID) 
                                                       BEGIN
                                                           INSERT INTO {1}(DocumentID, Document) VALUES (@DocumentID, @Document)  
                                                       END
                                                       ELSE BEGIN 
                                                           UPDATE {2} SET Document = @Document WHERE DocumentID = @DocumentID
                                                       END", tableName, tableName, tableName);
                using (SqlCommand cmd = new SqlCommand(sqlInsertBlob, cnn))
                {
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.Parameters.AddWithValue("@DocumentID", Document.IdDocument);
                    cmd.Parameters.AddWithValue("@Document", content);
                    cmd.ExecuteNonQuery();
                }
            }
            WriteAttributes(Document);
            return(content.Length);
        }
Esempio n. 5
0
        public Guid AddStorage(BiblosDS.Library.Common.Objects.DocumentStorage Storage)
        {
            Storage.IdStorage = Guid.NewGuid();

            using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString))
            {
                Model.Storage entityStorage = Storage.TryToConvertTo <Model.Storage>(db);

                if (Storage.StorageType != null)
                {
                    entityStorage.IdStorageType = Storage.StorageType.IdStorageType;
                }

                if (Storage.Server != null && Storage.Server.IdServer != Guid.Empty)
                {
                    entityStorage.IdServer = Storage.Server.IdServer;
                }

                db.AddToStorage(entityStorage);
                db.SaveChanges();
            }
            return(Storage.IdStorage);
        }
Esempio n. 6
0
 public DocumentArchiveStorage(DocumentArchive archive, DocumentStorage storage)
 {
     this.Archive = archive;
     this.Storage = storage;
 }