Пример #1
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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 /// <summary>
 /// Delete a blob with the given name if the blob has not been modified since it was last obtained.
 /// Use this method for optimistic concurrency to avoid deleting a blob that has been modified since
 /// the last time you retrieved it
 /// </summary>
 /// <param name="blob">A blob object (typically previously obtained from a GetBlob call)</param>
 /// <param name="modified">This out parameter is set to true if the blob was not deleted because
 /// it was modified</param>
 /// <returns>true if the blob exists and was successfully deleted, false if the blob does not exist or was
 /// not deleted because the blob was modified.</returns>
 public abstract bool DeleteBlobIfNotModified(BlobProperties blob, out bool modified);
Пример #4
0
 /// <summary>
 /// Set the metadata of an existing blob if it has not been modified since it was last retrieved.
 /// </summary>
 /// <param name="blobProperties">The blob properties object whose metadata is to be updated.
 /// Typically obtained by a previous call to GetBlob or GetBlobProperties</param>
 /// <returns>true if the blob metadata was updated. false if it was not updated because the blob
 /// has been modified</returns>
 public abstract bool UpdateBlobMetadataIfNotModified(BlobProperties blobProperties);
Пример #5
0
 /// <summary>
 /// Set the metadata of an existing blob.
 /// </summary>
 /// <param name="blobProperties">The blob properties object whose metadata is to be updated</param>
 public abstract void UpdateBlobMetadata(BlobProperties blobProperties);
Пример #6
0
 /// <summary>
 /// Gets the blob contents and properties if the blob has not been modified since the time specified.
 /// Use this method if you have cached the contents of a blob and want to avoid retrieving the blob
 /// if it has not changed since the last time you retrieved it.
 /// </summary>
 /// <param name="blobProperties">The properties of the blob obtained from an earlier call to GetBlob. This
 /// parameter is updated by the call if the blob has been modified</param>
 /// <param name="blobContents">Contains the stream to which the contents of the blob are written if it has been
 /// modified</param>
 /// <param name="transferAsChunks">Should the blob be gotten in pieces. This requires more round-trips, but will retry smaller pieces in case of failure.</param>
 /// <returns>true if the blob has been modified, false otherwise</returns>
 public abstract bool GetBlobIfModified(BlobProperties blobProperties, BlobContents blobContents, bool transferAsChunks);
Пример #7
0
 /// <summary>
 /// Updates an existing blob if it has not been modified since the specified time which is typically
 /// the last modified time of the blob when you retrieved it.
 /// Use this method to implement optimistic concurrency by avoiding clobbering changes to the blob
 /// made by another writer.
 /// </summary>
 /// <param name="blob">The properties of the blob. This object should be one previously
 /// obtained from a call to GetBlob or GetBlobProperties and have its LastModifiedTime property set.</param>
 /// <param name="contents">The contents of the blob. The contents of the blob should be readable</param>
 /// <returns>true if the blob was updated. false if the blob has changed since the last time</returns>
 /// <remarks>The LastModifiedTime property of <paramref name="blob"/> is set as a result of this call.
 /// This method also has an effect on the ETag values that are managed by the service if the update was
 /// successful.</remarks>
 public abstract bool UpdateBlobIfNotModified(BlobProperties blob, BlobContents contents);
Пример #8
0
 /// <summary>
 /// Create a new blob or overwrite an existing blob.
 /// </summary>
 /// <param name="blobProperties">The properties of the blob</param>
 /// <param name="blobContents">The contents of the blob</param>
 /// <param name="overwrite">Should this request overwrite an existing blob ?</param>
 /// <returns>true if the blob was created. false if the blob already exists and <paramref name="overwrite"/>was set to false</returns>
 /// <remarks>The LastModifiedTime property of <paramref name="blobProperties"/> is set as a result of this call.
 /// This method also has an effect on the ETag values that are managed by the service.</remarks>
 public abstract bool CreateBlob(BlobProperties blobProperties, BlobContents blobContents, bool overwrite);