/// <summary> /// Initializes a new instance of the <see cref="CloudBlockBlob"/> class using the specified blob name and /// the parent container reference. /// If snapshotTime is not null, the blob instance represents a Snapshot. /// </summary> /// <param name="blobName">Name of the blob.</param> /// <param name="snapshotTime">Snapshot time in case the blob is a snapshot.</param> /// <param name="container">The reference to the parent container.</param> internal CloudBlockBlob(string blobName, DateTimeOffset?snapshotTime, CloudBlobContainer container) { CommonUtils.AssertNotNullOrEmpty("blobName", blobName); CommonUtils.AssertNotNull("container", container); this.attributes = new BlobAttributes(); this.Uri = NavigationHelper.AppendPathToUri(container.Uri, blobName); this.ServiceClient = container.ServiceClient; this.container = container; this.SnapshotTime = snapshotTime; this.Properties.BlobType = BlobType.BlockBlob; }
/// <summary> /// Gets a reference to a virtual blob directory beneath this container. /// </summary> /// <param name="relativeAddress">A string containing the name of the virtual blob directory.</param> /// <returns>A <see cref="CloudBlobDirectory"/> object.</returns> public virtual CloudBlobDirectory GetDirectoryReference(string relativeAddress) { CommonUtility.AssertNotNull("relativeAddress", relativeAddress); if (!string.IsNullOrEmpty(relativeAddress) && !relativeAddress.EndsWith(this.ServiceClient.DefaultDelimiter, StringComparison.Ordinal)) { relativeAddress = relativeAddress + this.ServiceClient.DefaultDelimiter; } StorageUri blobDirectoryUri = NavigationHelper.AppendPathToUri(this.StorageUri, relativeAddress); return(new CloudBlobDirectory(blobDirectoryUri, relativeAddress, this)); }
/// <summary> /// Returns a virtual subdirectory within this virtual directory. /// </summary> /// <param name="itemName">The name of the virtual subdirectory.</param> /// <returns>A <see cref="CloudBlobDirectory"/> object representing the virtual subdirectory.</returns> public CloudBlobDirectory GetDirectoryReference(string itemName) { CommonUtility.AssertNotNullOrEmpty("itemName", itemName); if (!itemName.EndsWith(this.ServiceClient.DefaultDelimiter, StringComparison.Ordinal)) { itemName = itemName + this.ServiceClient.DefaultDelimiter; } StorageUri subdirectoryUri = NavigationHelper.AppendPathToUri(this.StorageUri, itemName, this.ServiceClient.DefaultDelimiter); return(new CloudBlobDirectory(subdirectoryUri, this.Prefix + itemName, this.Container)); }
public TableResultSegment EndListTablesSegmented(IAsyncResult asyncResult) { TableQuerySegment <DynamicTableEntity> res = Executor.EndExecuteAsync <TableQuerySegment <DynamicTableEntity> >(asyncResult); List <CloudTable> tables = res.Results.Select(tbl => new CloudTable( NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return(retSeg); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlockBlob"/> class using the specified blob name and /// the parent container reference. /// If snapshotTime is not null, the blob instance represents a Snapshot. /// </summary> /// <param name="blobName">Name of the blob.</param> /// <param name="snapshotTime">Snapshot time in case the blob is a snapshot.</param> /// <param name="container">The reference to the parent container.</param> internal CloudBlockBlob(string blobName, DateTimeOffset?snapshotTime, CloudBlobContainer container) { CommonUtility.AssertNotNullOrEmpty("blobName", blobName); CommonUtility.AssertNotNull("container", container); this.attributes = new BlobAttributes(); this.attributes.StorageUri = NavigationHelper.AppendPathToUri(container.StorageUri, blobName); this.ServiceClient = container.ServiceClient; // Set the relativized name from the URI. this.Name = NavigationHelper.GetBlobName(this.attributes.Uri, this.ServiceClient.UsePathStyleUris); this.container = container; this.SnapshotTime = snapshotTime; this.Properties.BlobType = BlobType.BlockBlob; }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobDirectory"/> class given an address and a client. /// </summary> /// <param name="absolutePath">The blob directory's address.</param> /// <param name="container">The container for the virtual directory.</param> internal CloudBlobDirectory(string absolutePath, CloudBlobContainer container) { CommonUtility.AssertNotNullOrEmpty("absolutePath", absolutePath); CommonUtility.AssertNotNull("container", container); this.ServiceClient = container.ServiceClient; this.Container = container; string delimiter = Uri.EscapeUriString(this.ServiceClient.DefaultDelimiter); if (!absolutePath.EndsWith(delimiter, StringComparison.Ordinal)) { absolutePath = absolutePath + delimiter; } this.Uri = NavigationHelper.AppendPathToUri(this.ServiceClient.BaseUri, absolutePath); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobDirectory"/> class given an address and a client. /// </summary> /// <param name="absolutePath">The blob directory's address.</param> /// <param name="service">The client to use.</param> internal CloudBlobDirectory(string absolutePath, CloudBlobClient service) { CommonUtils.AssertNotNullOrEmpty("absolutePath", absolutePath); CommonUtils.AssertNotNull("service", service); this.ServiceClient = service; string delimiter = Uri.EscapeUriString(this.ServiceClient.DefaultDelimiter); if (!absolutePath.EndsWith(delimiter)) { absolutePath = absolutePath + delimiter; } this.Uri = NavigationHelper.AppendPathToUri(service.BaseUri, absolutePath); }
private static RESTCommand <TableQuerySegment <RESULT_TYPE> > QueryImpl <RESULT_TYPE>(TableQuery query, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver <RESULT_TYPE> resolver, TableRequestOptions requestOptions) { UriQueryBuilder builder = query.GenerateQueryBuilder(requestOptions.ProjectSystemProperties); if (token != null) { token.ApplyToUriQueryBuilder(builder); } StorageUri tempUri = NavigationHelper.AppendPathToUri(client.StorageUri, table.Name); RESTCommand <TableQuerySegment <RESULT_TYPE> > queryCmd = new RESTCommand <TableQuerySegment <RESULT_TYPE> >(client.Credentials, tempUri); requestOptions.ApplyToStorageCommand(queryCmd); queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token); queryCmd.RetrieveResponseStream = true; queryCmd.SignRequest = client.AuthenticationHandler.SignRequest; queryCmd.Builder = builder; queryCmd.ParseError = ODataErrorHelper.ReadFromStreamUsingODataLib; queryCmd.BuildRequestDelegate = (uri, queryBuilder, timeout, useVersionHeader, ctx) => TableOperationHttpWebRequestFactory.BuildRequestForTableQuery(uri, queryBuilder, timeout, useVersionHeader, ctx, requestOptions.PayloadFormat.Value); queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp != null ? resp.StatusCode : HttpStatusCode.Unused, null /* retVal */, cmd, ex); queryCmd.PostProcessResponse = (cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = TableOperationHttpResponseParsers.TableQueryPostProcessGeneric <RESULT_TYPE, DynamicTableEntity>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; queryCmd.PostProcessResponseAsync = async(cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = await TableOperationHttpResponseParsers.TableQueryPostProcessGenericAsync <RESULT_TYPE, DynamicTableEntity>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; return(queryCmd); }
private static RESTCommand <TableQuerySegment <RESULT_TYPE> > QueryImpl <T, RESULT_TYPE>(TableQuery <T> query, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver <RESULT_TYPE> resolver, TableRequestOptions requestOptions) { requestOptions.AssertPolicyIfRequired(); // If encryption policy is set, then add the encryption metadata column to Select columns in order to be able to decrypt properties. if (requestOptions.EncryptionPolicy != null && query.SelectColumns != null && query.SelectColumns.Count() > 0) { query.SelectColumns.Add(Constants.EncryptionConstants.TableEncryptionKeyDetails); query.SelectColumns.Add(Constants.EncryptionConstants.TableEncryptionPropertyDetails); } UriQueryBuilder builder = query.GenerateQueryBuilder(requestOptions.ProjectSystemProperties); if (token != null) { token.ApplyToUriQueryBuilder(builder); } StorageUri tempUri = NavigationHelper.AppendPathToUri(client.StorageUri, table.Name); RESTCommand <TableQuerySegment <RESULT_TYPE> > queryCmd = new RESTCommand <TableQuerySegment <RESULT_TYPE> >(client.Credentials, tempUri); requestOptions.ApplyToStorageCommand(queryCmd); queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token); queryCmd.RetrieveResponseStream = true; queryCmd.SignRequest = client.AuthenticationHandler.SignRequest; queryCmd.Builder = builder; queryCmd.ParseError = ODataErrorHelper.ReadFromStreamUsingODataLib; queryCmd.BuildRequestDelegate = (uri, queryBuilder, timeout, useVersionHeader, ctx) => TableOperationHttpWebRequestFactory.BuildRequestForTableQuery(uri, queryBuilder, timeout, useVersionHeader, ctx, requestOptions.PayloadFormat.Value); queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp != null ? resp.StatusCode : HttpStatusCode.Unused, null /* retVal */, cmd, ex); queryCmd.PostProcessResponse = (cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = TableOperationHttpResponseParsers.TableQueryPostProcessGeneric <RESULT_TYPE, T>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx, client.AccountName); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; return(queryCmd); }
/// <summary> /// Selects the protocol response. /// </summary> /// <param name="protocolItem">The protocol item.</param> /// <returns>The parsed <see cref="IListFileItem"/>.</returns> private IListFileItem SelectListFileItem(IListFileEntry protocolItem) { ListFileEntry file = protocolItem as ListFileEntry; if (file != null) { CloudFileAttributes attributes = file.Attributes; attributes.StorageUri = NavigationHelper.AppendPathToUri(this.StorageUri, file.Name); return(new CloudFile(attributes, this.ServiceClient)); } ListFileDirectoryEntry fileDirectory = protocolItem as ListFileDirectoryEntry; if (fileDirectory != null) { CloudFileDirectory directory = this.GetDirectoryReference(fileDirectory.Name); directory.Properties = fileDirectory.Properties; return(directory); } throw new InvalidOperationException(SR.InvalidFileListItem); }
public TableResultSegment ListTablesSegmented( string prefix, int?maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); TableQuerySegment <DynamicTableEntity> res = this.GenerateListTablesQuery(prefix, maxResults).ExecuteQuerySegmented(currentToken, this, TableConstants.TableServiceTablesName, requestOptions, operationContext); List <CloudTable> tables = res.Results.Select(tbl => new CloudTable( NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return(retSeg); }
private RESTCommand <TableQuerySegment <RESULT_TYPE> > QueryImpl <RESULT_TYPE>(TableContinuationToken token, CloudTableClient client, string tableName, EntityResolver <RESULT_TYPE> resolver, TableRequestOptions requestOptions) { UriQueryBuilder builder = this.GenerateQueryBuilder(); if (token != null) { token.ApplyToUriQueryBuilder(builder); } StorageUri tempUri = NavigationHelper.AppendPathToUri(client.StorageUri, tableName); RESTCommand <TableQuerySegment <RESULT_TYPE> > queryCmd = new RESTCommand <TableQuerySegment <RESULT_TYPE> >(client.Credentials, tempUri); requestOptions.ApplyToStorageCommand(queryCmd); queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token); queryCmd.RetrieveResponseStream = true; queryCmd.Handler = client.AuthenticationHandler; queryCmd.BuildClient = HttpClientFactory.BuildHttpClient; queryCmd.ParseError = StorageExtendedErrorInformation.ReadFromStreamUsingODataLib; queryCmd.Builder = builder; queryCmd.BuildRequest = (cmd, uri, queryBuilder, cnt, serverTimeout, ctx) => TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(uri, builder, serverTimeout, cnt, ctx, requestOptions.PayloadFormat.Value); queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp.StatusCode, null /* retVal */, cmd, ex); queryCmd.PostProcessResponse = async(cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = await TableOperationHttpResponseParsers.TableQueryPostProcessGeneric <RESULT_TYPE>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx, client.AccountName); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; return(queryCmd); }
/// <summary> /// Returns a virtual subdirectory within this virtual directory. /// </summary> /// <param name="itemName">The name of the virtual subdirectory.</param> /// <returns>A <see cref="CloudBlobDirectory"/> object representing the virtual subdirectory.</returns> public CloudBlobDirectory GetSubdirectoryReference(string itemName) { CommonUtility.AssertNotNull("itemName", itemName); Uri subdirectoryUri = NavigationHelper.AppendPathToUri(this.Uri, itemName, this.ServiceClient.DefaultDelimiter); return new CloudBlobDirectory(subdirectoryUri.AbsoluteUri, this.Container); }
/// <summary> /// Gets the individual message address. /// </summary> /// <param name="messageId">A string specifying the message ID.</param> /// <returns>The URI of the message.</returns> internal StorageUri GetIndividualMessageAddress(string messageId) { return(NavigationHelper.AppendPathToUri(this.GetMessageRequestAddress(), messageId)); }
/// <summary> /// Gets the individual message address. /// </summary> /// <param name="messageId">The message id.</param> /// <returns>The URI of the message.</returns> internal Uri GetIndividualMessageAddress(string messageId) { Uri individualMessageUri = NavigationHelper.AppendPathToUri(this.GetMessageRequestAddress(), messageId); return(individualMessageUri); }
/// <summary> /// Returns a result segment containing a collection of tables beginning with the specified prefix. /// </summary> /// <param name="prefix">The table name prefix.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is <c>null</c> the maximum possible number of results will be returned, up to 5000.</param> /// <param name="currentToken">A <see cref="TableContinuationToken"/> token returned by a previous listing operation.</param> /// <param name="requestOptions">A <see cref="TableRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that provides information on how the operation executed.</param> /// <returns>The result segment containing the collection of tables.</returns> public IAsyncOperation <TableResultSegment> ListTablesSegmentedAsync( string prefix, int?maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions, OperationContext operationContext) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); TableQuery query = this.GenerateListTablesQuery(prefix, maxResults); return(AsyncInfo.Run(async(cancellationToken) => { TableQuerySegment seg = await this.ExecuteQuerySegmentedAsync(TableConstants.TableServiceTablesName, query, currentToken, requestOptions, operationContext).AsTask(cancellationToken); TableResultSegment retSegment = new TableResultSegment(seg.Results.Select(tbl => new CloudTable(NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList()); retSegment.ContinuationToken = seg.ContinuationToken as TableContinuationToken; return retSegment; })); }
internal static HttpRequestMessage BuildRequestForTableBatchOperation(Uri uri, int?timeout, Uri baseUri, string tableName, TableBatchOperation batch, OperationContext ctx) { HttpRequestMessage msg = BuildRequestCore(NavigationHelper.AppendPathToUri(uri, "$batch"), HttpMethod.Post, timeout, ctx); // create the writer, indent for readability of the examples. ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings() { CheckCharacters = false, // sets this flag on the XmlWriter for ATOM Version = ODataVersion.V2 // set the Odata version to use when writing the entry }; HttpRequestAdapterMessage adapterMsg = new HttpRequestAdapterMessage(msg); // Start Batch ODataMessageWriter odataWriter = new ODataMessageWriter(adapterMsg, writerSettings); ODataBatchWriter batchWriter = odataWriter.CreateODataBatchWriter(); batchWriter.WriteStartBatch(); bool isQuery = batch.Count == 1 && batch[0].OperationType == TableOperationType.Retrieve; // Query operations should not be inside changeset in payload if (!isQuery) { // Start Operation batchWriter.WriteStartChangeset(); batchWriter.Flush(); } foreach (TableOperation operation in batch) { string httpMethod = operation.OperationType == TableOperationType.Merge || operation.OperationType == TableOperationType.InsertOrMerge ? "MERGE" : operation.HttpMethod.Method; ODataBatchOperationRequestMessage mimePartMsg = batchWriter.CreateOperationRequestMessage(httpMethod, operation.GenerateRequestURI(baseUri, tableName)); // etag if (operation.OperationType == TableOperationType.Delete || operation.OperationType == TableOperationType.Replace || operation.OperationType == TableOperationType.Merge) { mimePartMsg.SetHeader("If-Match", operation.Entity.ETag); } if (operation.OperationType != TableOperationType.Delete && operation.OperationType != TableOperationType.Retrieve) { using (ODataMessageWriter batchEntryWriter = new ODataMessageWriter(mimePartMsg, writerSettings)) { // Write entity ODataWriter entryWriter = batchEntryWriter.CreateODataEntryWriter(); WriteOdataEntity(operation.Entity, operation.OperationType, ctx, entryWriter); } } } if (!isQuery) { // End Operation batchWriter.WriteEndChangeset(); } // End Batch batchWriter.WriteEndBatch(); batchWriter.Flush(); return(adapterMsg.GetPopulatedMessage()); }