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); }
protected override void SaveAttributes(Document Document) { if (container == null) { 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()); } } BlobProperties blobProperty = container.GetBlobProperties(GetFileName(Document)); foreach (DocumentAttributeValue item in Document.AttributeValues) { try { blobProperty.Metadata[item.Attribute.Name] = item.Value.ToString(); } catch (Exception) { blobProperty.Metadata.Add(item.Attribute.Name, item.Value.ToString()); } } container.UpdateBlobMetadata(blobProperty); }