Skip to content

Commit

Permalink
Merge pull request #219 from WindowsAzure/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Abdelrahman Elogeel authored and Abdelrahman Elogeel committed Jul 2, 2013
2 parents b8e2247 + 7b94801 commit 9f0c13d
Show file tree
Hide file tree
Showing 112 changed files with 2,683 additions and 920 deletions.
Expand Up @@ -185,7 +185,7 @@ public void UpdateKey(string keyValue, string keyName)
throw new InvalidOperationException(errorMessage);
}

if (string.IsNullOrEmpty(keyValue))
if (keyValue == null)
{
throw new ArgumentNullException("keyValue");
}
Expand Down
@@ -0,0 +1,35 @@
// -----------------------------------------------------------------------------------------
// <copyright file="AuthenticationScheme.cs" company="Microsoft">
// Copyright 2012 Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// -----------------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Storage
{
/// <summary>
/// Specifies the authentication scheme used to sign HTTP requests.
/// </summary>
public enum AuthenticationScheme
{
/// <summary>
/// Signs HTTP requests using the Shared Key Lite authentication scheme.
/// </summary>
SharedKeyLite,

/// <summary>
/// Signs HTTP requests using the Shared Key authentication scheme.
/// </summary>
SharedKey
}
}
Expand Up @@ -50,9 +50,10 @@ internal abstract class BlobWriteStreamBase : Stream
/// <summary>
/// Initializes a new instance of the BlobWriteStreamBase class.
/// </summary>
/// <param name="serviceClient">The service client.</param>
/// <param name="accessCondition">An object that represents the access conditions for the blob. If null, no condition is used.</param>
/// <param name="options">An object that specifies any additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
/// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param>
private BlobWriteStreamBase(CloudBlobClient serviceClient, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
: base()
{
Expand Down Expand Up @@ -80,7 +81,7 @@ protected BlobWriteStreamBase(CloudBlockBlob blockBlob, AccessCondition accessCo
{
this.blockBlob = blockBlob;
this.blockList = new List<string>();
this.blockIdPrefix = new Random().Next().ToString("X8") + "-";
this.blockIdPrefix = Guid.NewGuid().ToString("N") + "-";
this.buffer = new MemoryStream(this.Blob.StreamWriteSizeInBytes);
}

Expand Down
Expand Up @@ -17,13 +17,14 @@

namespace Microsoft.WindowsAzure.Storage.Blob
{
using System;
using System.Globalization;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Core;
using Microsoft.WindowsAzure.Storage.Core.Auth;
using Microsoft.WindowsAzure.Storage.Core.Util;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
using System;
using System.Globalization;

/// <summary>
/// Provides a client-side logical representation of the Windows Azure Blob Service. This client is used to configure and execute requests against the Blob Service.
Expand Down Expand Up @@ -61,6 +62,8 @@ public sealed partial class CloudBlobClient
/// </summary>
private TimeSpan? maximumExecutionTime;

private AuthenticationScheme authenticationScheme;

/// <summary>
/// Initializes a new instance of the <see cref="CloudBlobClient"/> class using the specified Blob service endpoint
/// and anonymous credentials.
Expand Down Expand Up @@ -113,6 +116,7 @@ internal CloudBlobClient(bool? usePathStyleUris, Uri baseUri, StorageCredentials
this.RetryPolicy = new ExponentialRetry();
this.ServerTimeout = Constants.DefaultServerSideTimeout;
this.DefaultDelimiter = NavigationHelper.Slash;
this.AuthenticationScheme = AuthenticationScheme.SharedKey;

if (usePathStyleUris.HasValue)
{
Expand Down Expand Up @@ -269,6 +273,16 @@ public CloudBlobContainer GetContainerReference(string containerName)
return new CloudBlobContainer(containerName, this);
}

private ICanonicalizer GetCanonicalizer()
{
if (this.AuthenticationScheme == AuthenticationScheme.SharedKeyLite)
{
return SharedKeyLiteCanonicalizer.Instance;
}

return SharedKeyCanonicalizer.Instance;
}

/// <summary>
/// Parses the user prefix.
/// </summary>
Expand Down
Expand Up @@ -28,7 +28,6 @@ namespace Microsoft.WindowsAzure.Storage.Blob
/// <summary>
/// Represents a container in the Windows Azure Blob service.
/// </summary>
/// <remarks>Containers hold directories, which are encapsulated as <see cref="CloudBlobDirectory"/> objects, and directories hold block blobs and page blobs. Directories can also contain sub-directories.</remarks>
public sealed partial class CloudBlobContainer
{
/// <summary>
Expand Down Expand Up @@ -63,8 +62,10 @@ internal CloudBlobContainer(string containerName, CloudBlobClient serviceClient)
}

/// <summary>
/// Initializes a new instance of the <see cref="CloudBlobContainer"/> class.
/// Initializes a new instance of the <see cref="CloudBlobContainer" /> class.
/// </summary>
/// <param name="properties">The properties.</param>
/// <param name="metadata">The metadata.</param>
/// <param name="containerName">The container name.</param>
/// <param name="serviceClient">The client to be used.</param>
internal CloudBlobContainer(BlobContainerProperties properties, IDictionary<string, string> metadata, string containerName, CloudBlobClient serviceClient)
Expand Down
Expand Up @@ -379,7 +379,9 @@ private string GetCanonicalName(bool ignoreSnapshotTime)
{
string accountName = this.ServiceClient.Credentials.AccountName;
string containerName = this.Container.Name;
string blobName = this.Name;

// Replace \ with / for uri compatibility when running under .net 4.5.
string blobName = this.Name.Replace('\\', '/');

string canonicalName = string.Format("/{0}/{1}/{2}", accountName, containerName, blobName);

Expand Down
Expand Up @@ -379,7 +379,9 @@ private string GetCanonicalName(bool ignoreSnapshotTime)
{
string accountName = this.ServiceClient.Credentials.AccountName;
string containerName = this.Container.Name;
string blobName = this.Name;

// Replace \ with / for uri compatibility when running under .net 4.5.
string blobName = this.Name.Replace('\\', '/');

string canonicalName = string.Format("/{0}/{1}/{2}", accountName, containerName, blobName);

Expand Down
Expand Up @@ -26,6 +26,9 @@ namespace Microsoft.WindowsAzure.Storage.Blob.Protocol
using Microsoft.WindowsAzure.Storage.Core.Auth;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;

/// <summary>
/// Provides a set of helper methods for constructing a request against the Blob service.
/// </summary>
#if RTMD
internal
#else
Expand Down
Expand Up @@ -17,6 +17,9 @@

namespace Microsoft.WindowsAzure.Storage.Blob.Protocol
{
/// <summary>
/// Represents an item that may be returned by a blob listing operation.
/// </summary>
#if RTMD
internal
#else
Expand Down
Expand Up @@ -280,7 +280,7 @@ public static CloudStorageAccount Parse(string connectionString)
throw new ArgumentNullException("connectionString");
}

if (TryParse(connectionString, out ret, err => { throw new FormatException(err); }))
if (ParseImpl(connectionString, out ret, err => { throw new FormatException(err); }))
{
return ret;
}
Expand All @@ -300,11 +300,18 @@ public static bool TryParse(string connectionString, out CloudStorageAccount acc
if (string.IsNullOrEmpty(connectionString))
{
account = null;

return false;
}

return TryParse(connectionString, out account, err => { });
try
{
return ParseImpl(connectionString, out account, err => { });
}
catch (Exception)
{
account = null;
return false;
}
}

/// <summary>
Expand Down Expand Up @@ -466,7 +473,7 @@ internal static CloudStorageAccount GetDevelopmentStorageAccount(Uri proxyUri)
/// <param name="accountInformation">The <see cref="CloudStorageAccount"/> to return.</param>
/// <param name="error">A callback for reporting errors.</param>
/// <returns>If true, the parse was successful. Otherwise, false.</returns>
internal static bool TryParse(string s, out CloudStorageAccount accountInformation, Action<string> error)
internal static bool ParseImpl(string s, out CloudStorageAccount accountInformation, Action<string> error)
{
IDictionary<string, string> settings = ParseStringIntoSettings(s, error);

Expand Down

This file was deleted.

Expand Up @@ -24,44 +24,50 @@ namespace Microsoft.WindowsAzure.Storage.Core
/// </summary>
internal class CanonicalizedString
{
private const int DefaultCapacity = 300;
private const char ElementDelimiter = '\n';

/// <summary>
/// Stores the internal <see cref="StringBuilder"/> that holds the canonicalized string.
/// </summary>
private StringBuilder canonicalizedString;
private readonly StringBuilder canonicalizedString;

/// <summary>
/// Initializes a new instance of the <see cref="CanonicalizedString"/> class.
/// </summary>
/// <param name="initialElement">The first canonicalized element to start the string with.</param>
internal CanonicalizedString(string initialElement)
public CanonicalizedString(string initialElement)
: this(initialElement, CanonicalizedString.DefaultCapacity)
{
this.canonicalizedString = new StringBuilder(initialElement);
}

/// <summary>
/// Gets the canonicalized string.
/// Initializes a new instance of the <see cref="CanonicalizedString"/> class.
/// </summary>
internal string Value
/// <param name="initialElement">The first canonicalized element to start the string with.</param>
/// <param name="capacity">The starting size of the string.</param>
public CanonicalizedString(string initialElement, int capacity)
{
get
{
return this.canonicalizedString.ToString();
}
this.canonicalizedString = new StringBuilder(initialElement, capacity);
}

/// <summary>
/// Append additional canonicalized element to the string.
/// </summary>
/// <param name="element">An additional canonicalized element to append to the string.</param>
internal void AppendCanonicalizedElement(string element)
public void AppendCanonicalizedElement(string element)
{
this.canonicalizedString.Append("\n");
this.canonicalizedString.Append(CanonicalizedString.ElementDelimiter);
this.canonicalizedString.Append(element);
}

/// <summary>
/// Converts the value of this instance to a string.
/// </summary>
/// <returns>A string whose value is the same as this instance.</returns>
public override string ToString()
{
return this.Value;
return this.canonicalizedString.ToString();
}
}
}

0 comments on commit 9f0c13d

Please sign in to comment.