public DocumentStorageAreaRule(DocumentStorageArea storageArea, DocumentAttribute attribute, short ruleOrder, string ruleFilter, string ruleFormat, DocumentRuleOperator ruleOperator) { this.StorageArea = storageArea; this.Attribute = attribute; this.RuleOrder = ruleOrder; this.RuleFilter = ruleFilter; this.RuleFormat = ruleFormat; this.RuleOperator = ruleOperator; }
public Document(Guid IdDocument, int IdBiblos, Guid?IdParentBiblos, DocumentStorageArea StorageArea, DocumentStorage Storage, DocumentArchive Archive, int ChainOrder, decimal Version, Guid?IdDocumentLink, Guid?IdCertificate, string SignHeader, string FullSign, string DocumentHash, bool?IsLinked, bool IsVisible, short?IsConservated, DateTime?DateExpire, string FileName, long?Size, DocumentNodeType NodeType, short?IsConfirmed, Status Status, short IsCheckOut) { this.IdDocument = IdDocument; this.IdBiblos = IdBiblos; if (IdParentBiblos != null) { this.DocumentParent = new Document((Guid)IdParentBiblos); } this.StorageArea = StorageArea; this.Archive = Archive; this.Storage = Storage; this.ChainOrder = ChainOrder; this.Version = Version; if (IdDocumentLink != null) { this.DocumentLink = new Document((Guid)IdDocumentLink); } if (IdCertificate != null) { this.Certificate = new DocumentCertificate((Guid)IdCertificate); } this.SignHeader = SignHeader; this.FullSign = FullSign; this.DocumentHash = DocumentHash; this.IsLinked = IsLinked; this.IsVisible = IsVisible; this.IsConservated = IsConservated.Equals(1); this.DateExpire = DateExpire; this.Name = FileName; this.Size = Size; this.NodeType = NodeType; this.IsConfirmed = IsConfirmed.Equals(1); this.Status = Status; this.IsCheckOut = IsCheckOut.Equals(1); this.IsRemoved = (IsDetached.HasValue && IsDetached.Value) || (Status != null && Status.IdStatus == (int)DocumentStatus.RemovedFromStorage); }
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); }
/// <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); }
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); }