コード例 #1
0
ファイル: BDSComStorage.cs プロジェクト: maurbone/DocSuitePA
        protected override void SaveAttributes(BiblosDS.Library.Common.Objects.Document Document)
        {
            //**REMOVE** 20140902 Fix per problema file con estensione xml.
            // se il documento originario è .xml, di fatto il salvataggio degli attributi sovrascrive il documento originario !!
            // per evitare la sovrascrittura comunque antepone il carattere "_" all'estensione del file

            //Write the attribute
            try
            {
                string storage = Path.Combine(Document.Storage.MainPath, Document.StorageArea.Path);

                string fill = "";
                if (Path.GetExtension(Document.Name) == "")
                {
                    fill = "_";
                }

                File.Delete(Path.Combine(storage, GetFileName(Document) + Path.GetExtension(Document.Name) + fill + ".xml"));
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(Document.AttributeValues.GetType());
                using (MemoryStream stream = new MemoryStream())
                {
                    XmlDocument doc = new XmlDocument();
                    x.Serialize(stream, Document.AttributeValues);
                    stream.Position = 0;
                    doc.Load(stream);
                    doc.DocumentElement.Attributes.RemoveAll();
                    doc.Save(Path.Combine(storage, Path.Combine(GetFileName(Document) + Path.GetExtension(Document.Name) + fill + ".xml")));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error on SaveAttributes", ex);
            }
        }
コード例 #2
0
ファイル: SQL2008Storage.cs プロジェクト: maurbone/DocSuitePA
        protected override void RemoveDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            string         connectionString = Document.Storage.MainPath;
            string         tableName        = GetTableName(Document.Storage, Document.StorageArea);
            SqlTransaction transaction      = null;

            using (SqlConnection cnn = new SqlConnection(connectionString))
            {
                string sqlDelFile = string.Format(@"DELETE
                                                     FROM {0}
                                                     WHERE DocumentID = @DocumentID", tableName);

                cnn.Open();
                transaction = cnn.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    using (SqlCommand cmd = new SqlCommand(sqlDelFile, cnn, transaction))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@DocumentID", Document.IdDocument);
                        cmd.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch (Exception)
                {
                    try
                    {
                        transaction.Rollback();
                    }
                    catch { }
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: AzureStorage.cs プロジェクト: maurbone/DocSuitePA
        protected override void RemoveDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            if (string.IsNullOrEmpty(Document.Storage.AuthenticationKey))
            {
                Document.Storage = StorageService.GetStorage(Document.Storage.IdStorage);
            }

            StorageAccountInfo account = StorageAccountInfo.GetAccountInfoFromConfiguration(
                string.Empty,
                Document.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(Document.StorageArea.Path))
            {
                container = blobStorage.GetBlobContainer(Document.Storage.Name.ToLower() + Document.StorageArea.Path.ToLower());
            }
            else
            {
                container = blobStorage.GetBlobContainer(Document.Storage.Name.ToLower());
            }

            container.DeleteBlob(GetFileName(Document));
        }
コード例 #4
0
ファイル: AzureStorage.cs プロジェクト: maurbone/DocSuitePA
        protected override byte[] LoadDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            if (string.IsNullOrEmpty(Document.Storage.AuthenticationKey))
            {
                Document.Storage = StorageService.GetStorage(Document.Storage.IdStorage);
            }


            StorageAccountInfo account = StorageAccountInfo.GetAccountInfoFromConfiguration(
                string.Empty,
                Document.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(Document.StorageArea.Path))
            {
                container = blobStorage.GetBlobContainer(Document.Storage.Name.ToLower() + Document.StorageArea.Path.ToLower());
            }
            else
            {
                container = blobStorage.GetBlobContainer(Document.Storage.Name.ToLower());
            }

            BlobContents   contents = new BlobContents(new MemoryStream());
            BlobProperties blob     = container.GetBlob(GetFileName(Document), contents, false);

            return(contents.AsBytes());
        }
コード例 #5
0
ファイル: BDSComStorage.cs プロジェクト: maurbone/DocSuitePA
        protected override void RemoveDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            string storageDir           = Path.Combine(Document.Storage.MainPath, Document.StorageArea.Path);
            string saveFileName         = Path.Combine(storageDir, string.Concat(GetFileName(Document), Path.GetExtension(Document.Name)));
            string saveFileNameMetadata = Path.Combine(storageDir, string.Concat(GetFileName(Document), Path.GetExtension(Document.Name), ".xml"));

            File.Delete(saveFileName);
            File.Delete(saveFileNameMetadata);
        }
コード例 #6
0
ファイル: SQL2008Storage.cs プロジェクト: maurbone/DocSuitePA
        protected override byte[] LoadDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            SqlFileStream stream           = null;
            string        connectionString = Document.Storage.MainPath;
            string        tableName        = GetTableName(Document.Storage, Document.StorageArea);

            SqlTransaction transaction = null;

            using (SqlConnection cnn = new SqlConnection(connectionString))
            {
                string sqlPathFile = string.Format(@"SELECT Document.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() 
                                                     FROM {0}
                                                     WHERE DocumentID = @DocumentID", tableName);

                cnn.Open();
                transaction = cnn.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    using (SqlCommand cmd = new SqlCommand(sqlPathFile, cnn, transaction))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@DocumentID", Document.IdDocument);
                        string path = string.Empty;
                        using (SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                        {
                            if (reader.Read())
                            {
                                path   = reader[0].ToString();
                                stream = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Write, FileOptions.SequentialScan, 0);
                            }
                            else
                            {
                                throw new Exception("Document Id: " + Document.IdDocument + " not found.");
                            }
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception)
                {
                    try
                    {
                        transaction.Rollback();
                    }
                    catch { }
                    throw;
                }
            }
            byte[] contents = new byte[stream.Length];
            stream.Read(contents, 0, contents.Length);
            return(contents);
        }
コード例 #7
0
ファイル: BDSComStorage.cs プロジェクト: maurbone/DocSuitePA
        protected override byte[] LoadDocument(BiblosDS.Library.Common.Objects.Document Document)
        {
            string storage = Path.Combine(Document.Storage.MainPath, Document.StorageArea.Path);

            if (Path.GetExtension(Document.Name) != string.Empty)
            {
                var fileName = GetFileName(Document) + Path.GetExtension(Document.Name);
                if (File.Exists(Path.Combine(storage, fileName)))
                {
                    return(File.ReadAllBytes(Path.Combine(storage, fileName)));
                }
            }
            //Se la ricerca con estensione non va a buon fine si prova a cercare il nome del file
            var files = Directory.GetFiles(storage, GetFileName(Document) + ".*");

            if (files.Length <= 0)
            {
                throw new Exception("File non found.");
            }
            //FIX
            Document.Name = Path.GetFileName(files.Where(x => Path.GetExtension(x) != ".CRC" && Path.GetExtension(x) != ".xml").First());
            return(File.ReadAllBytes(files.Where(x => Path.GetExtension(x) != ".CRC" && Path.GetExtension(x) != ".xml").First()));
        }
コード例 #8
0
ファイル: BDSComStorage.cs プロジェクト: maurbone/DocSuitePA
        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);
        }
コード例 #9
0
ファイル: BDSComStorage.cs プロジェクト: maurbone/DocSuitePA
 protected override System.ComponentModel.BindingList <BiblosDS.Library.Common.Objects.DocumentAttributeValue> LoadAttributes(BiblosDS.Library.Common.Objects.Document Document)
 {
     return(new System.ComponentModel.BindingList <Common.Objects.DocumentAttributeValue>());
 }
コード例 #10
0
ファイル: SQL2008Storage.cs プロジェクト: maurbone/DocSuitePA
        /// <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);
        }
コード例 #11
0
ファイル: AzureStorage.cs プロジェクト: maurbone/DocSuitePA
        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);
        }