internal static DataContracts.BlobContents GetBlobContents(Storage.StorageAccountInfo accountInfo, string containerName, string blobName) { Storage.BlobStorage storage = Storage.BlobStorage.Create(accountInfo); Storage.BlobContainer container = storage.GetBlobContainer(containerName); if (!container.DoesContainerExist()) return null; if (!container.DoesBlobExist(blobName)) return null; System.IO.MemoryStream ms = new System.IO.MemoryStream(); Storage.BlobContents contents = new Microsoft.Samples.ServiceHosting.StorageClient.BlobContents(ms); container.GetBlob(blobName, contents, true); DataContracts.BlobContents result = new global::StorageClientService.DataContracts.BlobContents(); result.Contents = contents.AsBytes(); return result; }
public override byte[] Read(string key) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); BlobContents contents = new BlobContents(ms); try { BlobProperties properties = (BlobProperties)blobContainer.GetBlob(key, contents, false); if (properties == null) { return null; } } catch (StorageServerException ex) { return null; } return contents.AsBytes(); }
public override bool Write(string key, byte[] data, bool overwrite) { BlobProperties properties = new BlobProperties(key); BlobContents contents = new BlobContents(data); return blobContainer.CreateBlob(properties, contents, overwrite); }
/// <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);
/// <summary> /// Get the blob contents and properties if the blob exists /// </summary> /// <param name="name">The name of the blob</param> /// <param name="blobContents">Object in which the contents are returned. /// This object should contain a writable stream or should be a default constructed object.</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>The properties of the blob if the blob exists.</returns> public abstract BlobProperties GetBlob(string name, BlobContents blobContents, bool transferAsChunks);
/// <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);
/// <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);
/// <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</remarks> public override bool CreateBlob(BlobProperties blobProperties, BlobContents blobContents, bool overwrite) { return PutBlobImpl(blobProperties, blobContents.AsStream, overwrite, null); }
/// <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="blobProperties">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="properties"/> is set as a result of this call</remarks> public override bool UpdateBlobIfNotModified(BlobProperties blobProperties, BlobContents contents) { return PutBlobImpl(blobProperties, contents.AsStream, true, blobProperties.ETag); }
/// <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 piecs in case of failure.</param> /// <returns>true if the blob has been modified, false otherwise</returns> public override bool GetBlobIfModified(BlobProperties blobProperties, BlobContents blobContents, bool transferAsChunks) { bool modified = true; BlobProperties newProperties = GetBlobImpl(blobProperties.Name, blobContents.AsStream, blobProperties.ETag, transferAsChunks, out modified); if (modified) blobProperties.Assign(newProperties); return modified; }
/// <summary> /// Get the blob contents and properties if the blob exisits /// </summary> /// <param name="name">The name of the blob</param> /// <param name="blobContents">Object in which the contents are returned. /// This object should contain a writable stream or should be a default constructed object.</param> /// <param name="transferAsChunks">Should the blob be gotten in pieces. This requires more round-trips, but will retry smaller piecs in case of failure.</param> /// <returns>The properties of the blob if the blob exists.</returns> public override BlobProperties GetBlob(string name, BlobContents blobContents, bool transferAsChunks) { bool notModified = false; return GetBlobImpl(name, blobContents.AsStream, null, transferAsChunks, out notModified); }