From 49d0288be3d78337f8d9b36efb4b856154d73846 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Tue, 21 Feb 2012 10:14:52 -0800 Subject: [PATCH 01/11] Initial checkin for WinMD API --- microsoft-azure-servicelayer/.gitignore | 3 + .../.gitignore | 4 + .../AzureServiceException.cs | 27 +++ .../HttpErrorHandler.cs | 67 ++++++ .../HttpQuery.cs | 55 +++++ ...Microsoft.WindowsAzure.ServiceLayer.csproj | 139 ++++++++++++ .../Properties/AssemblyInfo.cs | 29 +++ .../SerializationHelper.cs | 117 +++++++++++ .../ServiceBus/IServiceBusService.cs | 64 ++++++ .../ServiceBus/QueueInfo.cs | 88 ++++++++ .../ServiceBus/QueueSettings.cs | 61 ++++++ .../ServiceBus/ServiceBusRestProxy.cs | 197 ++++++++++++++++++ .../ServiceBus/ServiceBusService.cs | 49 +++++ .../ServiceBus/ServiceConfiguration.cs | 82 ++++++++ .../ServiceBus/WrapAuthenticationHandler.cs | 117 +++++++++++ .../ServiceBus/WrapToken.cs | 77 +++++++ .../ServiceBusServiceOptions.cs | 42 ++++ .../microsoft-azure-servicelayer.sln | 38 ++++ 18 files changed, 1256 insertions(+) create mode 100644 microsoft-azure-servicelayer/.gitignore create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/.gitignore create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBusServiceOptions.cs create mode 100644 microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln diff --git a/microsoft-azure-servicelayer/.gitignore b/microsoft-azure-servicelayer/.gitignore new file mode 100644 index 0000000000000..07738ecbbc33f --- /dev/null +++ b/microsoft-azure-servicelayer/.gitignore @@ -0,0 +1,3 @@ +*.suo +TestApp/ +microsoft-azure-servicelayer-pr.sln diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/.gitignore b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/.gitignore new file mode 100644 index 0000000000000..0efa2abfb6aea --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/.gitignore @@ -0,0 +1,4 @@ +*.suo +bin/ +obj/ + diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs new file mode 100644 index 0000000000000..384df45443aee --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs @@ -0,0 +1,27 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + class AzureServiceException: Exception + { + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs new file mode 100644 index 0000000000000..13c044c8a90bd --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -0,0 +1,67 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + class HttpErrorHandler: MessageProcessingHandler + { + /// + /// Constructor. + /// + internal HttpErrorHandler() + : base() + { + } + + /// + /// Constructor. + /// + /// Inner HTTP handler + internal HttpErrorHandler(HttpMessageHandler innerHandler) + : base(innerHandler) + { + } + + /// + /// Processes outhoing HTTP requests. + /// + /// Request + /// Cancellation token + /// Processed HTTP request + protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + // We're not interested in outgoing requests; do nothing. + return request; + } + + /// + /// Processes incoming HTTP responses. + /// + /// HTTP response + /// Cancellation token + /// Processed HTTP response + protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, System.Threading.CancellationToken cancellationToken) + { + if (!response.IsSuccessStatusCode) + throw new AzureServiceException(); + return response; + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs new file mode 100644 index 0000000000000..64a0dbef3c82f --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs @@ -0,0 +1,55 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + /// + /// Helper class for processing HTTP query strings. + /// + class HttpQuery + { + Dictionary _values = new Dictionary(StringComparer.OrdinalIgnoreCase); + + /// + /// Constructor. + /// + /// Query string + internal HttpQuery(string queryString) + { + string[] pairs = queryString.Split('&'); + + foreach (string pair in pairs) + { + int pos = pair.IndexOf('='); + string name = pair.Substring(0, pos); + string value = pair.Substring(pos + 1); + _values.Add(name, value); + } + } + + /// + /// Gets parameter by name. + /// + /// Parameter name + /// Parameter value + internal string this[string parameterName] { get { return _values[parameterName]; } } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj new file mode 100644 index 0000000000000..6c1a5bc58429b --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj @@ -0,0 +1,139 @@ + + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {53C097E2-7384-446B-836B-A7910993091E} + winmdobj + Properties + Microsoft.WindowsAzure.ServiceLayer + Microsoft.WindowsAzure.ServiceLayer + en-US + 512 + {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE + prompt + 4 + + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + ARM + false + prompt + ExpressRules.ruleset + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + ARM + false + prompt + ExpressRules.ruleset + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x64 + false + prompt + ExpressRules.ruleset + true + + + bin\x64\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x64 + false + prompt + ExpressRules.ruleset + true + + + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x86 + false + prompt + ExpressRules.ruleset + true + + + bin\x86\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x86 + false + prompt + ExpressRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + 11.0 + + + + + + + \ No newline at end of file diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000..96d35f890c36a --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.WindowsAzure.ServiceLayer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Microsoft.WindowsAzure.ServiceLayer")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs new file mode 100644 index 0000000000000..91e6d7d2cbffb --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -0,0 +1,117 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Runtime.Serialization; +using System.Xml; + +using Windows.Data.Xml.Dom; +using Windows.Web.Syndication; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + /// + /// Serialization/deserialization helper. + /// + static class SerializationHelper + { + /// + /// Deserializes the feed into a collection of items of the same type. + /// + /// Type of result items in the collection + /// Atom feed with serialized items + /// Additional action to perform on each item + /// Collection of deserialized items + static internal IEnumerable DeserializeCollection(SyndicationFeed feed, Action itemAction) + { + DataContractSerializer serializer = new DataContractSerializer(typeof(T)); + + foreach (SyndicationItem item in feed.Items) + { + yield return DeserializeItem(serializer, item, itemAction); + } + } + + /// + /// Deserializes an atom item. + /// + /// Target object type + /// Atom item to deserialize + /// Action to perform after deserialization + /// Deserialized object + static internal T DeserializeItem(SyndicationItem item, Action itemAction) + { + return DeserializeItem(new DataContractSerializer(typeof(T)), item, itemAction); + } + + /// + /// Deserializes an atom item using given serializer. + /// + /// Target object type + /// Serializer + /// Atom item + /// Action to perform after deserialization + /// Deserialized object + static T DeserializeItem(DataContractSerializer serializer, SyndicationItem item, Action itemAction) + { + string serializedString = item.Content.Xml.GetXml(); + + using (StringReader stringReader = new StringReader(serializedString)) + using (XmlReader xmlReader = XmlReader.Create(stringReader)) + { + T deserializedObject = (T)serializer.ReadObject(xmlReader); + itemAction(item, deserializedObject); + return deserializedObject; + } + } + + /// + /// Serializes given object. + /// + /// Object to serialize + /// Serialized representation + static internal string Serialize(object item) + { + // Serialize the content + string itemXml; + + using (MemoryStream stream = new MemoryStream()) + { + DataContractSerializer serializer = new DataContractSerializer(item.GetType()); + serializer.WriteObject(stream, item); + + stream.Flush(); + stream.Seek(0, SeekOrigin.Begin); + using (StreamReader reader = new StreamReader(stream)) + { + itemXml = reader.ReadToEnd(); + } + } + + SyndicationContent content = new SyndicationContent(); + content.Type = "application/xml"; + content.Xml = new XmlDocument(); + content.Xml.LoadXml(itemXml); + + SyndicationItem entry = new SyndicationItem(); + entry.Content = content; + + return entry.GetXmlDocument(SyndicationFormat.Atom10).GetXml(); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs new file mode 100644 index 0000000000000..490d0e1e950e5 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs @@ -0,0 +1,64 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +using Windows.Foundation; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// Service bus service + /// + public interface IServiceBusService + { + /// + /// Lists all available queues in the namespace. + /// + /// Collection of queues + IAsyncOperation> ListQueuesAsync(); + + /// + /// Gets a queue with the given name. + /// + /// Name of the queue + /// Queue data + IAsyncOperation GetQueueAsync(string queueName); + + /// + /// Deletes a queue with the given name. + /// + /// Queue name + /// Asynchronous operation + IAsyncAction DeleteQueueAsync(string queueName); + + /// + /// Creates a queue with the given name and default settings. + /// + /// Queue name + /// Created queue + IAsyncOperation CreateQueueAsync(string queueName); + + /// + /// Creates a queue with the given parameters. + /// + /// Queue name + /// Queue parameters + /// Created queue + IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queueSettings); + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs new file mode 100644 index 0000000000000..e16cd9a16affd --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs @@ -0,0 +1,88 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +using Windows.Data.Xml.Dom; +using Windows.Web.Syndication; + + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// Service bus queue info + /// + [DataContract(Namespace="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", Name="QueueDescription")] + public sealed class QueueInfo + { + [DataMember(Order=0)] + public TimeSpan LockDuration { get; internal set; } + + [DataMember(Order=1)] + public int MaxSizeInMegabytes { get; internal set; } + + [DataMember(Order=2)] + public bool RequiresDuplicateDetection { get; internal set; } + + [DataMember(Order=3)] + public bool RequiresSession { get; internal set; } + + [DataMember(Order=4)] + public TimeSpan DefaultMessageTimeToLive { get; internal set; } + + [DataMember(Order=5, Name="DeadLetteringOnMessageExpiration")] + public bool EnableDeadLetteringOnMessageExpiration { get; internal set; } + + [DataMember(Order=6)] + public TimeSpan DuplicateDetectionHistoryTimeWindow { get; internal set; } + + [DataMember(Order=7)] + public int MaxDeliveryCount { get; internal set; } + + [DataMember(Order=8)] + public bool EnableBatchedOperations { get; internal set; } + + [DataMember(Order=9)] + public int SizeInBytes { get; internal set; } + + [DataMember(Order=10)] + public int MessageCount { get; internal set; } + + [IgnoreDataMember] + public string Name { get; private set; } + + [IgnoreDataMember] + public Uri Uri { get; private set; } + + /// + /// Constructor for serialization purposes. + /// + internal QueueInfo() + { + } + + /// + /// Initializes the object after deserialization. + /// + /// Atom item + internal void Initialize(SyndicationItem item) + { + Name = item.Title.Text; + Uri = new Uri(item.Id); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs new file mode 100644 index 0000000000000..a2affba9a3dc4 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs @@ -0,0 +1,61 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// Queue creation options + /// + [DataContract(Namespace="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", Name="QueueDescription")] + public sealed class QueueSettings + { + [DataMember(Order = 0)] + public TimeSpan? LockDuration { get; internal set; } + + [DataMember(Order = 1)] + public int? MaxSizeInMegabytes { get; internal set; } + + [DataMember(Order = 2)] + public bool? RequiresDuplicateDetection { get; internal set; } + + [DataMember(Order = 3)] + public bool? RequiresSession { get; internal set; } + + [DataMember(Order = 4)] + public TimeSpan? DefaultMessageTimeToLive { get; internal set; } + + [DataMember(Order = 5, Name = "DeadLetteringOnMessageExpiration")] + public bool? EnableDeadLetteringOnMessageExpiration { get; internal set; } + + [DataMember(Order = 6)] + public TimeSpan? DuplicateDetectionHistoryTimeWindow { get; internal set; } + + [DataMember(Order = 7)] + public int? MaxDeliveryCount { get; internal set; } + + [DataMember(Order = 8)] + public bool? EnableBatchedOperations { get; internal set; } + + [DataMember(Order = 9)] + public int? SizeInBytes { get; internal set; } + + [DataMember(Order = 10)] + public int? MessageCount { get; internal set; } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs new file mode 100644 index 0000000000000..a9a339e757ace --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -0,0 +1,197 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +using Windows.Data.Xml.Dom; +using Windows.Foundation; +using Windows.Web.Syndication; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// REST proxy for the service bus interface. + /// + class ServiceBusRestProxy: IServiceBusService + { + /// + /// Gets the service options. + /// + internal ServiceConfiguration ServiceConfig { get; private set; } + + /// + /// Gets HTTP client used for communicating with the service. + /// + HttpClient Channel { get; set; } + + + /// + /// Constructor. + /// + /// Service options + internal ServiceBusRestProxy(ServiceConfiguration serviceOptions) + { + Debug.Assert(serviceOptions != null); + + ServiceConfig = serviceOptions; + HttpMessageHandler chain = new HttpErrorHandler( + new WrapAuthenticationHandler(serviceOptions)); + Channel = new HttpClient(chain); + } + + /// + /// Gets all available queues in the namespace. + /// + /// All queues in the namespace + IAsyncOperation> IServiceBusService.ListQueuesAsync() + { + Uri uri = new Uri(ServiceConfig.ServiceBusUri, "$Resources/Queues"); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); + + return Channel.SendAsync(request) + .ContinueWith>(r => { return GetQueues(r.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) + .AsAsyncOperation>(); + } + + /// + /// Gets the queue with the given name. + /// + /// Name of the queue + /// Queue data + IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) + { + if (queueName == null) + throw new ArgumentNullException("queueName"); + + Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); + + return Channel.SendAsync(request) + .ContinueWith(r => { return GetQueue(r.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) + .AsAsyncOperation(); + } + + /// + /// Deletes a queue with the given name. + /// + /// Queue name + /// Asycnrhonous action + IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) + { + if (queueName == null) + throw new ArgumentNullException("queueName"); + + Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, uri); + + return Channel.SendAsync(request) + .AsAsyncAction(); + } + + /// + /// Creates a queue with the given name and default settings. + /// + /// Name of the queue + /// Queue data + IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName) + { + if (queueName == null) + throw new ArgumentNullException("queueName"); + + return CreateQueueAsync(queueName, new QueueSettings()); + } + + /// + /// Creates a queue with the given parameters. + /// + /// Name of the queue + /// Parameters of the queue + /// Created queue + IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName, QueueSettings queueSettings) + { + if (queueName == null) + throw new ArgumentNullException("queueName"); + if (queueSettings == null) + throw new ArgumentNullException("queueSettings"); + + return CreateQueueAsync(queueName, queueSettings); + } + + /// + /// Extracts queues from the given HTTP response. + /// + /// HTTP response + /// Collection of queues + IEnumerable GetQueues(HttpResponseMessage response) + { + Debug.Assert(response.IsSuccessStatusCode); + SyndicationFeed feed = new SyndicationFeed(); + feed.Load(response.Content.ReadAsStringAsync().Result); + + return SerializationHelper.DeserializeCollection(feed, (item, queue) => queue.Initialize(item)); + } + + /// + /// Extracts a single queue from the given response. + /// + /// HTTP response + /// Queue + QueueInfo GetQueue(HttpResponseMessage response) + { + XmlDocument doc = new XmlDocument(); + doc.LoadXml(response.Content.ReadAsStringAsync().Result); + + SyndicationItem feedItem = new SyndicationItem(); + feedItem.LoadFromXml(doc); + return SerializationHelper.DeserializeItem(feedItem, (item, queue) => queue.Initialize(item)); + } + + /// + /// Creates a queue with the given parameters. + /// + /// Name of the queue + /// Parameters of the queue + /// Created queue + IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queueSettings) + { + Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, uri); + + return Task.Factory.StartNew(() => SetBody(request, queueSettings)) + .ContinueWith(tr => { return Channel.SendAsync(request).Result; }, TaskContinuationOptions.OnlyOnRanToCompletion) + .ContinueWith(tr => { return GetQueue(tr.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) + .AsAsyncOperation(); + + } + + /// + /// Serializes given object and sets the request's body. + /// + /// Target request + /// Object to serialize + void SetBody(HttpRequestMessage request, object bodyObject) + { + string content = SerializationHelper.Serialize(bodyObject); + request.Content = new StringContent(content, Encoding.UTF8, "application/atom+xml"); + request.Content.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", "entry")); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs new file mode 100644 index 0000000000000..42123ff4c775a --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs @@ -0,0 +1,49 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// Factory for creating service bus services + /// + public static class ServiceBusService + { + /// + /// Creates a service bus servive using given settings. + /// + /// Service namespace + /// User name + /// Password + /// A service bus service with the given parameters + public static IServiceBusService Create(string serviceNamespace, string userName, string password) + { + if (serviceNamespace == null) + throw new ArgumentNullException("serviceNamespace"); + if (userName == null) + throw new ArgumentNullException("userName"); + if (password == null) + throw new ArgumentNullException("password"); + + ServiceConfiguration serviceOptions = new ServiceConfiguration(serviceNamespace, userName, password); + return new ServiceBusRestProxy(serviceOptions); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs new file mode 100644 index 0000000000000..812fb3707ecc3 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs @@ -0,0 +1,82 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// Options of the service bus service. + /// + public class ServiceConfiguration + { + /// + /// Gets the service namespace. + /// + public string ServiceNamespace { get; private set; } + + /// + /// Gets the user name used for authentication. + /// + public string UserName { get; private set; } + + /// + /// Gets the password used for authentication. + /// + public string Password { get; private set; } + + /// + /// Gets the service bus URI. + /// + internal Uri ServiceBusUri { get; private set; } + + /// + /// Gets URI of the authentication service. + /// + internal Uri AuthenticationUri { get; private set; } + + /// + /// Gets the host URI for authenticating requests. + /// + internal Uri ScopeHostUri { get; private set; } + + /// + /// Constructor with explicitly specified options. + /// + /// Service namespace + /// User name for authentication + /// Password for authentication + internal ServiceConfiguration(string serviceNamespace, string userName, string password) + { + ServiceNamespace = serviceNamespace; + UserName = userName; + Password = password; + + string stringUri = string.Format(CultureInfo.InvariantCulture, "https://{0}.servicebus.windows.net/", ServiceNamespace); + ServiceBusUri = new Uri(stringUri, UriKind.Absolute); + + stringUri = string.Format(CultureInfo.InvariantCulture, "https://{0}-sb.accesscontrol.windows.net/wrapv0.9/", ServiceNamespace); + AuthenticationUri = new Uri(stringUri, UriKind.Absolute); + + stringUri = string.Format(CultureInfo.InvariantCulture, "http://{0}.servicebus.windows.net/", ServiceNamespace); + ScopeHostUri = new Uri(stringUri); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs new file mode 100644 index 0000000000000..4eaa37e532eab --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -0,0 +1,117 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Http; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// HTTP handler for WRAP authentication of outgoing requests. + /// + class WrapAuthenticationHandler: HttpClientHandler + { + ServiceConfiguration ServiceConfig { get; set; } // Configuration parameters + HttpClient Channel { get; set; } // HTTP channel for processing requests + Dictionary Tokens { get; set; } // Cached tokens + Object SyncObject { get; set; } // Synchronization object for accessing cached tokens + + /// + /// Constructor. + /// + /// Configuration + internal WrapAuthenticationHandler(ServiceConfiguration serviceConfig) + { + ServiceConfig = serviceConfig; + Tokens = new Dictionary(StringComparer.OrdinalIgnoreCase); + SyncObject = new object(); + + HttpMessageHandler handlers = new HttpErrorHandler( + new HttpClientHandler()); + Channel = new HttpClient(handlers); + } + + /// + /// Sends the request. + /// + /// HTTP request to send + /// Cancellation token + /// HTTP response + protected override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + return Task.Factory.StartNew(() => { return GetToken(request.RequestUri.AbsolutePath); }) + .ContinueWith((tr) => { return tr.Result.Authorize(request); }, TaskContinuationOptions.OnlyOnRanToCompletion) + .ContinueWith((tr) => { return base.SendAsync(tr.Result, cancellationToken).Result; }, TaskContinuationOptions.OnlyOnRanToCompletion); + } + + /// + /// Gets authentication token for a resource with the given path. + /// + /// Resource path + /// Authentication token + WrapToken GetToken(string resourcePath) + { + WrapToken token; + + lock (SyncObject) + { + Tokens.TryGetValue(resourcePath, out token); + if (token != null && token.IsExpired) + Tokens.Remove(resourcePath); + } + + if (token == null) + { + // Issue new authentication request. + Uri scopeUri = new Uri(ServiceConfig.ScopeHostUri, resourcePath); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, ServiceConfig.AuthenticationUri); + Dictionary settings = new Dictionary() + { + {"wrap_name", ServiceConfig.UserName}, + {"wrap_password", ServiceConfig.Password}, + {"wrap_scope", scopeUri.ToString()}, + }; + + request.Headers.Accept.ParseAdd("application/x-www-form-urlencoded"); //TODO: is there a constant for this type? + request.Content = new FormUrlEncodedContent(settings); + + HttpResponseMessage response = Channel.SendAsync(request).Result; + Debug.Assert(response.IsSuccessStatusCode); // Errors should've been handled by the error handler + token = new WrapToken(resourcePath, response); + + lock (SyncObject) + { + WrapToken existingToken; + + if (Tokens.TryGetValue(resourcePath, out existingToken) && !existingToken.IsExpired) + { + // Ignore new results; use existing token + token = existingToken; + } + else + { + // Cache the token + Tokens[resourcePath] = token; + } + } + } + + return token; + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs new file mode 100644 index 0000000000000..9c6b53a3b1355 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -0,0 +1,77 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus +{ + /// + /// WRAP token; used for authenticating outgoing web requests. + /// + class WrapToken + { + DateTime _expirationDate; + + /// + /// Specifies the scope of the token. + /// + internal string Scope { get; private set; } + + /// + /// Specifies the + /// + internal string Token { get; private set; } + + /// + /// Gets the value saying whether the token is expired. + /// + internal bool IsExpired { get { return DateTime.Now > _expirationDate; } } + + /// + /// Constructor. + /// + /// Path of the authenticated resource + /// HTTP response with the token + internal WrapToken(string resourcePath, HttpResponseMessage response) + { + Debug.Assert(response.IsSuccessStatusCode); + Scope = resourcePath; + string content = response.Content.ReadAsStringAsync().Result; + + HttpQuery query = new HttpQuery(content); + Token = string.Format(CultureInfo.InvariantCulture, "WRAP access_token=\"{0}\"", WebUtility.UrlDecode(query["wrap_access_token"])); + _expirationDate = DateTime.Now + TimeSpan.FromSeconds(int.Parse(query["wrap_access_token_expires_in"]) / 2); + } + + /// + /// Authorizes the request. + /// + /// Source request + /// Authorized request + internal HttpRequestMessage Authorize(HttpRequestMessage request) + { + request.Headers.Add("Authorization", Token); + return request; + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBusServiceOptions.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBusServiceOptions.cs new file mode 100644 index 0000000000000..387bcfff3a76b --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBusServiceOptions.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + /// + /// Options of the service bus service. + /// + public class ServiceBusServiceOptions + { + /// + /// Gets the service namespace. + /// + public string ServiceNamespace { get; private set; } + + /// + /// Gets the user name used for authentication. + /// + public string UserName { get; private set; } + + /// + /// Gets the password used for authentication. + /// + public string Password { get; private set; } + + /// + /// Constructor with explicitly specified options. + /// + /// Service namespace + /// User name for authentication + /// Password for authentication + internal ServiceBusServiceOptions(string serviceNamespace, string userName, string password) + { + ServiceNamespace = serviceNamespace; + UserName = userName; + Password = password; + } + } +} diff --git a/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln b/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln new file mode 100644 index 0000000000000..84c0b1bafc02b --- /dev/null +++ b/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 11 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.WindowsAzure.ServiceLayer", "Microsoft.WindowsAzure.ServiceLayer\Microsoft.WindowsAzure.ServiceLayer.csproj", "{53C097E2-7384-446B-836B-A7910993091E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {53C097E2-7384-446B-836B-A7910993091E}.Debug|ARM.ActiveCfg = Debug|ARM + {53C097E2-7384-446B-836B-A7910993091E}.Debug|ARM.Build.0 = Debug|ARM + {53C097E2-7384-446B-836B-A7910993091E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {53C097E2-7384-446B-836B-A7910993091E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {53C097E2-7384-446B-836B-A7910993091E}.Debug|x64.ActiveCfg = Debug|x64 + {53C097E2-7384-446B-836B-A7910993091E}.Debug|x64.Build.0 = Debug|x64 + {53C097E2-7384-446B-836B-A7910993091E}.Debug|x86.ActiveCfg = Debug|x86 + {53C097E2-7384-446B-836B-A7910993091E}.Debug|x86.Build.0 = Debug|x86 + {53C097E2-7384-446B-836B-A7910993091E}.Release|ARM.ActiveCfg = Release|ARM + {53C097E2-7384-446B-836B-A7910993091E}.Release|ARM.Build.0 = Release|ARM + {53C097E2-7384-446B-836B-A7910993091E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {53C097E2-7384-446B-836B-A7910993091E}.Release|Any CPU.Build.0 = Release|Any CPU + {53C097E2-7384-446B-836B-A7910993091E}.Release|x64.ActiveCfg = Release|x64 + {53C097E2-7384-446B-836B-A7910993091E}.Release|x64.Build.0 = Release|x64 + {53C097E2-7384-446B-836B-A7910993091E}.Release|x86.ActiveCfg = Release|x86 + {53C097E2-7384-446B-836B-A7910993091E}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From e13a0e125d91ac74f5136061ea7bc52f4d69a22b Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Tue, 21 Feb 2012 17:16:38 -0800 Subject: [PATCH 02/11] Unit tests for queue management --- .../.gitignore | 4 + .../Configuration.cs | 17 ++ ...WindowsAzure.ServiceLayer.UnitTests.csproj | 138 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 29 ++++ .../ServiceBusManagementTests.cs | 149 ++++++++++++++++++ ...Microsoft.WindowsAzure.ServiceLayer.csproj | 2 +- .../ServiceBus/QueueSettings.cs | 24 ++- .../microsoft-azure-servicelayer.sln | 18 +++ 8 files changed, 365 insertions(+), 16 deletions(-) create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/.gitignore create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Microsoft.WindowsAzure.ServiceLayer.UnitTests.csproj create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Properties/AssemblyInfo.cs create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/ServiceBusManagementTests.cs diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/.gitignore b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/.gitignore new file mode 100644 index 0000000000000..0efa2abfb6aea --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/.gitignore @@ -0,0 +1,4 @@ +*.suo +bin/ +obj/ + diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs new file mode 100644 index 0000000000000..de9d9497d63d9 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests +{ + static class Configuration + { + public static string ServiceNamespace { get { return "aliakb-test"; } } + + public static string UserName { get { return "owner"; } } + + public static string Password { get { return "0Myg+PyST7O5Bj+j9+Byjlljr4lomN1Y1QJR7D9JgZg="; } } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Microsoft.WindowsAzure.ServiceLayer.UnitTests.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Microsoft.WindowsAzure.ServiceLayer.UnitTests.csproj new file mode 100644 index 0000000000000..c6fb4fc4fe469 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Microsoft.WindowsAzure.ServiceLayer.UnitTests.csproj @@ -0,0 +1,138 @@ + + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C} + Library + Properties + Microsoft.WindowsAzure.ServiceLayer.UnitTests + Microsoft.WindowsAzure.ServiceLayer.UnitTests + en-US + 512 + {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE + prompt + 4 + + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + ARM + false + prompt + ExpressRules.ruleset + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + ARM + false + prompt + ExpressRules.ruleset + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x64 + false + prompt + ExpressRules.ruleset + true + + + bin\x64\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x64 + false + prompt + ExpressRules.ruleset + true + + + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x86 + false + prompt + ExpressRules.ruleset + true + + + bin\x86\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x86 + false + prompt + ExpressRules.ruleset + true + + + + + {53c097e2-7384-446b-836b-a7910993091e} + Microsoft.WindowsAzure.ServiceLayer + + + + + + + + + + ..\..\..\..\Tools\XUnit 1.9\xunit.dll + + + + 11.0 + + + + + + + \ No newline at end of file diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Properties/AssemblyInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000..5145af51540b1 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.WindowsAzure.ServiceLayer.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Microsoft.WindowsAzure.ServiceLayer.UnitTests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/ServiceBusManagementTests.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/ServiceBusManagementTests.cs new file mode 100644 index 0000000000000..b22ff7beba0f2 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/ServiceBusManagementTests.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.WindowsAzure.ServiceLayer.ServiceBus; + +using Xunit; + +namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests +{ + /// + /// Tests for the service bus management. + /// + public class ServiceBusManagementTests + { + class InternalQueueInfoComparer : IEqualityComparer + { + bool IEqualityComparer.Equals(QueueInfo x, QueueInfo y) + { + return x.DefaultMessageTimeToLive == y.DefaultMessageTimeToLive + && x.DuplicateDetectionHistoryTimeWindow == y.DuplicateDetectionHistoryTimeWindow + && x.EnableBatchedOperations == y.EnableBatchedOperations + && x.EnableDeadLetteringOnMessageExpiration == y.EnableDeadLetteringOnMessageExpiration + && x.LockDuration == y.LockDuration + && x.MaxDeliveryCount == y.MaxDeliveryCount + && x.MaxSizeInMegabytes == y.MaxSizeInMegabytes + && x.MessageCount == y.MessageCount + && string.Equals(x.Name, y.Name, StringComparison.OrdinalIgnoreCase) + && x.RequiresDuplicateDetection == y.RequiresDuplicateDetection + && x.RequiresSession == y.RequiresSession + && x.SizeInBytes == y.SizeInBytes + && string.Equals(x.Uri.ToString(), y.Uri.ToString(), StringComparison.OrdinalIgnoreCase); + } + + int IEqualityComparer.GetHashCode(QueueInfo obj) + { + return obj.GetHashCode(); + } + } + + IServiceBusService Service { get; set; } + IEqualityComparer QueueInfoComparer { get; set; } + + public ServiceBusManagementTests() + { + Service = ServiceBusService.Create(Configuration.ServiceNamespace, Configuration.UserName, Configuration.Password); + QueueInfoComparer = new InternalQueueInfoComparer(); + } + + + string GetUniqueEntityName() + { + return string.Format("UnitTests.{0}", Guid.NewGuid().ToString()); + } + + Dictionary GetQueues() + { + Dictionary queues = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (QueueInfo queue in Service.ListQueuesAsync().AsTask>().Result) + { + queues.Add(queue.Name, queue); + } + return queues; + } + + [Fact] + public void NullArgsInQueues() + { + Assert.Throws(() => Service.CreateQueueAsync(null)); + Assert.Throws(() => Service.CreateQueueAsync(null, new QueueSettings())); + Assert.Throws(() => Service.CreateQueueAsync("foo", null)); + Assert.Throws(() => Service.GetQueueAsync(null)); + Assert.Throws(() => Service.DeleteQueueAsync(null)); + } + + /// + /// Tests full lifecycle of a queue. + /// + [Fact] + public void QueueLifecycle() + { + // Create a queue. + string queueName = GetUniqueEntityName(); + QueueInfo newQueue = Service.CreateQueueAsync(queueName).AsTask().Result; + + // Confirm that the queue can be obtained from the server + QueueInfo storedQueue = Service.GetQueueAsync(queueName).AsTask().Result; + Assert.Equal(storedQueue, newQueue, QueueInfoComparer); + + // Confirm that the queue can be obtained in the list + Dictionary queues = GetQueues(); + + Assert.True(queues.ContainsKey(queueName)); + Assert.Equal(newQueue, queues[queueName], QueueInfoComparer); + + // Delete the queue + Service.DeleteQueueAsync(queueName).AsTask().Wait(); + queues = GetQueues(); + Assert.False(queues.ContainsKey(queueName)); + } + + /// + /// Verifies that using an existing name for a new queue result in an exception. + /// + [Fact] + public void CreateQueueDuplicateName() + { + // Create a queue + string queueName = GetUniqueEntityName(); + QueueInfo newQueue = Service.CreateQueueAsync(queueName).AsTask().Result; + + Task t = Service.CreateQueueAsync(queueName).AsTask(); + Assert.Throws(() => t.Wait()); + } + + /// + /// Verifies creation of the queue with all non-default parameters + /// + [Fact] + public void CreateQueueWithNonDefaultParams() + { + string queueName = GetUniqueEntityName(); + QueueSettings settings = new QueueSettings(); + + settings.DefaultMessageTimeToLive = TimeSpan.FromHours(24); + settings.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromDays(2); + settings.EnableBatchedOperations = false; + settings.EnableDeadLetteringOnMessageExpiration = true; + settings.LockDuration = TimeSpan.FromMinutes(3); + settings.MaxDeliveryCount = 5; + settings.MaxSizeInMegabytes = 2048; + settings.RequiresDuplicateDetection = true; + settings.RequiresSession = true; + + QueueInfo queueInfo = Service.CreateQueueAsync(queueName, settings).AsTask().Result; + Assert.Equal(queueInfo.DefaultMessageTimeToLive, settings.DefaultMessageTimeToLive.Value); + Assert.Equal(queueInfo.DuplicateDetectionHistoryTimeWindow, settings.DuplicateDetectionHistoryTimeWindow.Value); + Assert.Equal(queueInfo.EnableBatchedOperations, settings.EnableBatchedOperations.Value); + Assert.Equal(queueInfo.EnableDeadLetteringOnMessageExpiration, settings.EnableDeadLetteringOnMessageExpiration.Value); + Assert.Equal(queueInfo.LockDuration, settings.LockDuration.Value); + Assert.Equal(queueInfo.MaxDeliveryCount, settings.MaxDeliveryCount.Value); + Assert.Equal(queueInfo.MaxSizeInMegabytes, settings.MaxSizeInMegabytes.Value); + Assert.Equal(queueInfo.RequiresDuplicateDetection, settings.RequiresDuplicateDetection.Value); + Assert.Equal(queueInfo.RequiresSession, settings.RequiresSession.Value); + } + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj index 6c1a5bc58429b..73863a93ecc4b 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj @@ -7,7 +7,7 @@ 8.0.30703 2.0 {53C097E2-7384-446B-836B-A7910993091E} - winmdobj + Library Properties Microsoft.WindowsAzure.ServiceLayer Microsoft.WindowsAzure.ServiceLayer diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs index a2affba9a3dc4..3a31f5e062b70 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs @@ -26,36 +26,30 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus public sealed class QueueSettings { [DataMember(Order = 0)] - public TimeSpan? LockDuration { get; internal set; } + public TimeSpan? LockDuration { get; set; } [DataMember(Order = 1)] - public int? MaxSizeInMegabytes { get; internal set; } + public int? MaxSizeInMegabytes { get; set; } [DataMember(Order = 2)] - public bool? RequiresDuplicateDetection { get; internal set; } + public bool? RequiresDuplicateDetection { get; set; } [DataMember(Order = 3)] - public bool? RequiresSession { get; internal set; } + public bool? RequiresSession { get; set; } [DataMember(Order = 4)] - public TimeSpan? DefaultMessageTimeToLive { get; internal set; } + public TimeSpan? DefaultMessageTimeToLive { get; set; } [DataMember(Order = 5, Name = "DeadLetteringOnMessageExpiration")] - public bool? EnableDeadLetteringOnMessageExpiration { get; internal set; } + public bool? EnableDeadLetteringOnMessageExpiration { get; set; } [DataMember(Order = 6)] - public TimeSpan? DuplicateDetectionHistoryTimeWindow { get; internal set; } + public TimeSpan? DuplicateDetectionHistoryTimeWindow { get; set; } [DataMember(Order = 7)] - public int? MaxDeliveryCount { get; internal set; } + public int? MaxDeliveryCount { get; set; } [DataMember(Order = 8)] - public bool? EnableBatchedOperations { get; internal set; } - - [DataMember(Order = 9)] - public int? SizeInBytes { get; internal set; } - - [DataMember(Order = 10)] - public int? MessageCount { get; internal set; } + public bool? EnableBatchedOperations { get; set; } } } diff --git a/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln b/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln index 84c0b1bafc02b..52c44ec8b5d0a 100644 --- a/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln +++ b/microsoft-azure-servicelayer/microsoft-azure-servicelayer.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 11 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.WindowsAzure.ServiceLayer", "Microsoft.WindowsAzure.ServiceLayer\Microsoft.WindowsAzure.ServiceLayer.csproj", "{53C097E2-7384-446B-836B-A7910993091E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.WindowsAzure.ServiceLayer.UnitTests", "Microsoft.WindowsAzure.ServiceLayer.UnitTests\Microsoft.WindowsAzure.ServiceLayer.UnitTests.csproj", "{DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -31,6 +33,22 @@ Global {53C097E2-7384-446B-836B-A7910993091E}.Release|x64.Build.0 = Release|x64 {53C097E2-7384-446B-836B-A7910993091E}.Release|x86.ActiveCfg = Release|x86 {53C097E2-7384-446B-836B-A7910993091E}.Release|x86.Build.0 = Release|x86 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|ARM.ActiveCfg = Debug|ARM + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|ARM.Build.0 = Debug|ARM + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|x64.ActiveCfg = Debug|x64 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|x64.Build.0 = Debug|x64 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|x86.ActiveCfg = Debug|x86 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Debug|x86.Build.0 = Debug|x86 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|ARM.ActiveCfg = Release|ARM + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|ARM.Build.0 = Release|ARM + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|Any CPU.Build.0 = Release|Any CPU + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|x64.ActiveCfg = Release|x64 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|x64.Build.0 = Release|x64 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|x86.ActiveCfg = Release|x86 + {DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 6ca763a966bdc24717245d7ed36c6f14db9b3340 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 09:35:00 -0800 Subject: [PATCH 03/11] Updated file headers --- .../AzureServiceException.cs | 28 +++++++-------- .../HttpErrorHandler.cs | 28 +++++++-------- .../HttpQuery.cs | 28 +++++++-------- .../Properties/AssemblyInfo.cs | 17 +++++++++- .../SerializationHelper.cs | 28 +++++++-------- .../ServiceBus/IServiceBusService.cs | 28 +++++++-------- .../ServiceBus/QueueInfo.cs | 28 +++++++-------- .../ServiceBus/QueueSettings.cs | 34 ++++++++----------- .../ServiceBus/ServiceBusRestProxy.cs | 28 +++++++-------- .../ServiceBus/ServiceBusService.cs | 28 +++++++-------- .../ServiceBus/ServiceConfiguration.cs | 28 +++++++-------- .../ServiceBus/WrapAuthenticationHandler.cs | 28 +++++++-------- .../ServiceBus/WrapToken.cs | 28 +++++++-------- 13 files changed, 184 insertions(+), 175 deletions(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs index 384df45443aee..c0ad5ff5397c6 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs index 13c044c8a90bd..50a2b602fca2f 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs index 64a0dbef3c82f..9c965fe1f6992 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs index 96d35f890c36a..6405ee648d8e1 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs @@ -1,4 +1,19 @@ -using System.Reflection; +// +// 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. +// + +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index 91e6d7d2cbffb..ca46e2499b903 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs index 490d0e1e950e5..8bddda01d0687 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs index e16cd9a16affd..af3ffaa291173 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs index a2affba9a3dc4..53a9ae5aab782 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; @@ -51,11 +51,5 @@ public sealed class QueueSettings [DataMember(Order = 8)] public bool? EnableBatchedOperations { get; internal set; } - - [DataMember(Order = 9)] - public int? SizeInBytes { get; internal set; } - - [DataMember(Order = 10)] - public int? MessageCount { get; internal set; } } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index a9a339e757ace..aa5c633bd28e7 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs index 42123ff4c775a..255aff53ce8a0 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs index 812fb3707ecc3..360d2f625c3cf 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index 4eaa37e532eab..a4f05d02f6e33 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index 9c6b53a3b1355..e69e9878191fe 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -1,17 +1,17 @@ -/* - * 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 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. +// using System; using System.Collections.Generic; From 112e273e7c5a59919d6bb9165d95d755526f4f1e Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 09:43:30 -0800 Subject: [PATCH 04/11] Explicit visibility on classes and their members --- .../AzureServiceException.cs | 5 ++++- .../HttpErrorHandler.cs | 2 +- .../HttpQuery.cs | 4 ++-- .../SerializationHelper.cs | 2 +- .../ServiceBus/QueueSettings.cs | 18 +++++++++--------- .../ServiceBus/ServiceBusRestProxy.cs | 12 ++++++------ .../ServiceBus/WrapAuthenticationHandler.cs | 12 ++++++------ .../ServiceBus/WrapToken.cs | 2 +- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs index c0ad5ff5397c6..730fbf9e33eb4 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs @@ -21,7 +21,10 @@ namespace Microsoft.WindowsAzure.ServiceLayer { - class AzureServiceException: Exception + /// + /// Exception that occurs as a result of calls to Windows Azure service. + /// + internal class AzureServiceException: Exception { } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs index 50a2b602fca2f..51c424bb07dd6 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -20,7 +20,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer { - class HttpErrorHandler: MessageProcessingHandler + internal class HttpErrorHandler: MessageProcessingHandler { /// /// Constructor. diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs index 9c965fe1f6992..15fa8919d8cae 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs @@ -24,9 +24,9 @@ namespace Microsoft.WindowsAzure.ServiceLayer /// /// Helper class for processing HTTP query strings. /// - class HttpQuery + internal class HttpQuery { - Dictionary _values = new Dictionary(StringComparer.OrdinalIgnoreCase); + private Dictionary _values = new Dictionary(StringComparer.OrdinalIgnoreCase); /// /// Constructor. diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index ca46e2499b903..afba76fc90572 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -28,7 +28,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer /// /// Serialization/deserialization helper. /// - static class SerializationHelper + static internal class SerializationHelper { /// /// Deserializes the feed into a collection of items of the same type. diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs index 53a9ae5aab782..0fb0f6d5ad254 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs @@ -26,30 +26,30 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus public sealed class QueueSettings { [DataMember(Order = 0)] - public TimeSpan? LockDuration { get; internal set; } + public TimeSpan? LockDuration { get; set; } [DataMember(Order = 1)] - public int? MaxSizeInMegabytes { get; internal set; } + public int? MaxSizeInMegabytes { get; set; } [DataMember(Order = 2)] - public bool? RequiresDuplicateDetection { get; internal set; } + public bool? RequiresDuplicateDetection { get; set; } [DataMember(Order = 3)] - public bool? RequiresSession { get; internal set; } + public bool? RequiresSession { get; set; } [DataMember(Order = 4)] - public TimeSpan? DefaultMessageTimeToLive { get; internal set; } + public TimeSpan? DefaultMessageTimeToLive { get; set; } [DataMember(Order = 5, Name = "DeadLetteringOnMessageExpiration")] - public bool? EnableDeadLetteringOnMessageExpiration { get; internal set; } + public bool? EnableDeadLetteringOnMessageExpiration { get; set; } [DataMember(Order = 6)] - public TimeSpan? DuplicateDetectionHistoryTimeWindow { get; internal set; } + public TimeSpan? DuplicateDetectionHistoryTimeWindow { get; set; } [DataMember(Order = 7)] - public int? MaxDeliveryCount { get; internal set; } + public int? MaxDeliveryCount { get; set; } [DataMember(Order = 8)] - public bool? EnableBatchedOperations { get; internal set; } + public bool? EnableBatchedOperations { get; set; } } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index aa5c633bd28e7..94ea23a13a0d7 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -30,17 +30,17 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// /// REST proxy for the service bus interface. /// - class ServiceBusRestProxy: IServiceBusService + internal class ServiceBusRestProxy: IServiceBusService { /// /// Gets the service options. /// - internal ServiceConfiguration ServiceConfig { get; private set; } + private ServiceConfiguration ServiceConfig { get; set; } /// /// Gets HTTP client used for communicating with the service. /// - HttpClient Channel { get; set; } + private HttpClient Channel { get; set; } /// @@ -140,7 +140,7 @@ IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName, /// /// HTTP response /// Collection of queues - IEnumerable GetQueues(HttpResponseMessage response) + private IEnumerable GetQueues(HttpResponseMessage response) { Debug.Assert(response.IsSuccessStatusCode); SyndicationFeed feed = new SyndicationFeed(); @@ -154,7 +154,7 @@ IEnumerable GetQueues(HttpResponseMessage response) /// /// HTTP response /// Queue - QueueInfo GetQueue(HttpResponseMessage response) + private QueueInfo GetQueue(HttpResponseMessage response) { XmlDocument doc = new XmlDocument(); doc.LoadXml(response.Content.ReadAsStringAsync().Result); @@ -187,7 +187,7 @@ IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queu /// /// Target request /// Object to serialize - void SetBody(HttpRequestMessage request, object bodyObject) + private void SetBody(HttpRequestMessage request, object bodyObject) { string content = SerializationHelper.Serialize(bodyObject); request.Content = new StringContent(content, Encoding.UTF8, "application/atom+xml"); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index a4f05d02f6e33..b25faa09a13a6 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -24,12 +24,12 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// /// HTTP handler for WRAP authentication of outgoing requests. /// - class WrapAuthenticationHandler: HttpClientHandler + internal class WrapAuthenticationHandler: HttpClientHandler { - ServiceConfiguration ServiceConfig { get; set; } // Configuration parameters - HttpClient Channel { get; set; } // HTTP channel for processing requests - Dictionary Tokens { get; set; } // Cached tokens - Object SyncObject { get; set; } // Synchronization object for accessing cached tokens + private ServiceConfiguration ServiceConfig { get; set; } // Configuration parameters + private HttpClient Channel { get; set; } // HTTP channel for processing requests + private Dictionary Tokens { get; set; } // Cached tokens + private Object SyncObject { get; set; } // Synchronization object for accessing cached tokens /// /// Constructor. @@ -64,7 +64,7 @@ protected override Task SendAsync(HttpRequestMessage reques /// /// Resource path /// Authentication token - WrapToken GetToken(string resourcePath) + private WrapToken GetToken(string resourcePath) { WrapToken token; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index e69e9878191fe..c528c6ca46231 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -30,7 +30,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// class WrapToken { - DateTime _expirationDate; + private DateTime _expirationDate; /// /// Specifies the scope of the token. From 044fd810c1602ded2aa1a85dd8c7ddf04d2d1dc8 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 09:59:57 -0800 Subject: [PATCH 05/11] Enclosing single-line statements into curlies --- .../HttpErrorHandler.cs | 2 ++ .../ServiceBus/ServiceBusRestProxy.cs | 10 ++++++++++ .../ServiceBus/ServiceBusService.cs | 6 ++++++ .../ServiceBus/WrapAuthenticationHandler.cs | 2 ++ .../ServiceBus/WrapToken.cs | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs index 51c424bb07dd6..9daff7de2574c 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -60,7 +60,9 @@ protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, System.Threading.CancellationToken cancellationToken) { if (!response.IsSuccessStatusCode) + { throw new AzureServiceException(); + } return response; } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index 94ea23a13a0d7..563e383d50a54 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -79,7 +79,9 @@ IAsyncOperation> IServiceBusService.ListQueuesAsync() IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) { if (queueName == null) + { throw new ArgumentNullException("queueName"); + } Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); @@ -97,7 +99,9 @@ IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) { if (queueName == null) + { throw new ArgumentNullException("queueName"); + } Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, uri); @@ -114,7 +118,9 @@ IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName) { if (queueName == null) + { throw new ArgumentNullException("queueName"); + } return CreateQueueAsync(queueName, new QueueSettings()); } @@ -128,9 +134,13 @@ IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName) IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName, QueueSettings queueSettings) { if (queueName == null) + { throw new ArgumentNullException("queueName"); + } if (queueSettings == null) + { throw new ArgumentNullException("queueSettings"); + } return CreateQueueAsync(queueName, queueSettings); } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs index 255aff53ce8a0..7234f54138bb1 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs @@ -36,11 +36,17 @@ public static class ServiceBusService public static IServiceBusService Create(string serviceNamespace, string userName, string password) { if (serviceNamespace == null) + { throw new ArgumentNullException("serviceNamespace"); + } if (userName == null) + { throw new ArgumentNullException("userName"); + } if (password == null) + { throw new ArgumentNullException("password"); + } ServiceConfiguration serviceOptions = new ServiceConfiguration(serviceNamespace, userName, password); return new ServiceBusRestProxy(serviceOptions); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index b25faa09a13a6..b25165ff22071 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -72,7 +72,9 @@ private WrapToken GetToken(string resourcePath) { Tokens.TryGetValue(resourcePath, out token); if (token != null && token.IsExpired) + { Tokens.Remove(resourcePath); + } } if (token == null) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index c528c6ca46231..3ea79245005aa 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -30,7 +30,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// class WrapToken { - private DateTime _expirationDate; + private DateTime _expirationDate; // Token's expiration date. /// /// Specifies the scope of the token. From a53701460ce25108bfdd27124564cc9f54a622a8 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 10:21:44 -0800 Subject: [PATCH 06/11] Punctuation in comments --- .../HttpErrorHandler.cs | 17 ++++---- .../HttpQuery.cs | 6 +-- .../SerializationHelper.cs | 30 +++++++------- .../ServiceBus/IServiceBusService.cs | 22 +++++----- .../ServiceBus/QueueInfo.cs | 4 +- .../ServiceBus/QueueSettings.cs | 2 +- .../ServiceBus/ServiceBusRestProxy.cs | 40 +++++++++---------- .../ServiceBus/ServiceBusService.cs | 2 +- .../ServiceBus/ServiceConfiguration.cs | 6 +-- .../ServiceBus/WrapAuthenticationHandler.cs | 20 +++++----- .../ServiceBus/WrapToken.cs | 10 ++--- 11 files changed, 81 insertions(+), 78 deletions(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs index 9daff7de2574c..89179192a8d7b 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -20,6 +20,9 @@ namespace Microsoft.WindowsAzure.ServiceLayer { + /// + /// Handler for processing HTTP errors and translating them into exceptions. + /// internal class HttpErrorHandler: MessageProcessingHandler { /// @@ -33,7 +36,7 @@ internal HttpErrorHandler() /// /// Constructor. /// - /// Inner HTTP handler + /// Inner HTTP handler. internal HttpErrorHandler(HttpMessageHandler innerHandler) : base(innerHandler) { @@ -42,9 +45,9 @@ internal HttpErrorHandler(HttpMessageHandler innerHandler) /// /// Processes outhoing HTTP requests. /// - /// Request - /// Cancellation token - /// Processed HTTP request + /// Request. + /// Cancellation token. + /// Processed HTTP request. protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { // We're not interested in outgoing requests; do nothing. @@ -54,9 +57,9 @@ protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, /// /// Processes incoming HTTP responses. /// - /// HTTP response - /// Cancellation token - /// Processed HTTP response + /// HTTP response. + /// Cancellation token. + /// Processed HTTP response. protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, System.Threading.CancellationToken cancellationToken) { if (!response.IsSuccessStatusCode) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs index 15fa8919d8cae..c03dc764450f2 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs @@ -31,7 +31,7 @@ internal class HttpQuery /// /// Constructor. /// - /// Query string + /// Query string. internal HttpQuery(string queryString) { string[] pairs = queryString.Split('&'); @@ -48,8 +48,8 @@ internal HttpQuery(string queryString) /// /// Gets parameter by name. /// - /// Parameter name - /// Parameter value + /// Parameter name. + /// Parameter value. internal string this[string parameterName] { get { return _values[parameterName]; } } } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index afba76fc90572..97b6f396d101f 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -33,10 +33,10 @@ static internal class SerializationHelper /// /// Deserializes the feed into a collection of items of the same type. /// - /// Type of result items in the collection - /// Atom feed with serialized items - /// Additional action to perform on each item - /// Collection of deserialized items + /// Type of result items in the collection. + /// Atom feed with serialized items. + /// Additional action to perform on each item. + /// Collection of deserialized items. static internal IEnumerable DeserializeCollection(SyndicationFeed feed, Action itemAction) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); @@ -50,10 +50,10 @@ static internal IEnumerable DeserializeCollection(SyndicationFeed feed, Ac /// /// Deserializes an atom item. /// - /// Target object type - /// Atom item to deserialize - /// Action to perform after deserialization - /// Deserialized object + /// Target object type. + /// Atom item to deserialize. + /// Action to perform after deserialization. + /// Deserialized object. static internal T DeserializeItem(SyndicationItem item, Action itemAction) { return DeserializeItem(new DataContractSerializer(typeof(T)), item, itemAction); @@ -62,11 +62,11 @@ static internal T DeserializeItem(SyndicationItem item, Action /// Deserializes an atom item using given serializer. /// - /// Target object type - /// Serializer - /// Atom item - /// Action to perform after deserialization - /// Deserialized object + /// Target object type. + /// Serializer. + /// Atom item. + /// Action to perform after deserialization. + /// Deserialized object. static T DeserializeItem(DataContractSerializer serializer, SyndicationItem item, Action itemAction) { string serializedString = item.Content.Xml.GetXml(); @@ -83,8 +83,8 @@ static T DeserializeItem(DataContractSerializer serializer, SyndicationItem i /// /// Serializes given object. /// - /// Object to serialize - /// Serialized representation + /// Object to serialize. + /// Serialized representation. static internal string Serialize(object item) { // Serialize the content diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs index 8bddda01d0687..5e3a138bbeb53 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/IServiceBusService.cs @@ -22,43 +22,43 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus { /// - /// Service bus service + /// Service bus service. /// public interface IServiceBusService { /// /// Lists all available queues in the namespace. /// - /// Collection of queues + /// Collection of queues. IAsyncOperation> ListQueuesAsync(); /// /// Gets a queue with the given name. /// - /// Name of the queue - /// Queue data + /// Name of the queue. + /// Queue data. IAsyncOperation GetQueueAsync(string queueName); /// /// Deletes a queue with the given name. /// - /// Queue name - /// Asynchronous operation + /// Queue name. + /// Asynchronous operation. IAsyncAction DeleteQueueAsync(string queueName); /// /// Creates a queue with the given name and default settings. /// - /// Queue name - /// Created queue + /// Queue name. + /// Created queue. IAsyncOperation CreateQueueAsync(string queueName); /// /// Creates a queue with the given parameters. /// - /// Queue name - /// Queue parameters - /// Created queue + /// Queue name. + /// Queue parameters. + /// Created queue. IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queueSettings); } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs index af3ffaa291173..d60eb397d8781 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueInfo.cs @@ -24,7 +24,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus { /// - /// Service bus queue info + /// Service bus queue info. /// [DataContract(Namespace="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", Name="QueueDescription")] public sealed class QueueInfo @@ -78,7 +78,7 @@ internal QueueInfo() /// /// Initializes the object after deserialization. /// - /// Atom item + /// Atom item. internal void Initialize(SyndicationItem item) { Name = item.Title.Text; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs index 0fb0f6d5ad254..7213a0d0ee975 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/QueueSettings.cs @@ -20,7 +20,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus { /// - /// Queue creation options + /// Queue creation options. /// [DataContract(Namespace="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", Name="QueueDescription")] public sealed class QueueSettings diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index 563e383d50a54..ca316929952e6 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -46,7 +46,7 @@ internal class ServiceBusRestProxy: IServiceBusService /// /// Constructor. /// - /// Service options + /// Configuration parameters. internal ServiceBusRestProxy(ServiceConfiguration serviceOptions) { Debug.Assert(serviceOptions != null); @@ -60,7 +60,7 @@ internal ServiceBusRestProxy(ServiceConfiguration serviceOptions) /// /// Gets all available queues in the namespace. /// - /// All queues in the namespace + /// All queues in the namespace. IAsyncOperation> IServiceBusService.ListQueuesAsync() { Uri uri = new Uri(ServiceConfig.ServiceBusUri, "$Resources/Queues"); @@ -74,8 +74,8 @@ IAsyncOperation> IServiceBusService.ListQueuesAsync() /// /// Gets the queue with the given name. /// - /// Name of the queue - /// Queue data + /// Name of the queue. + /// Queue data. IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) { if (queueName == null) @@ -94,8 +94,8 @@ IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) /// /// Deletes a queue with the given name. /// - /// Queue name - /// Asycnrhonous action + /// Queue name. + /// Asycnrhonous action. IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) { if (queueName == null) @@ -113,8 +113,8 @@ IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) /// /// Creates a queue with the given name and default settings. /// - /// Name of the queue - /// Queue data + /// Name of the queue. + /// Queue data. IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName) { if (queueName == null) @@ -128,9 +128,9 @@ IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName) /// /// Creates a queue with the given parameters. /// - /// Name of the queue - /// Parameters of the queue - /// Created queue + /// Name of the queue. + /// Parameters of the queue. + /// Created queue. IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName, QueueSettings queueSettings) { if (queueName == null) @@ -148,8 +148,8 @@ IAsyncOperation IServiceBusService.CreateQueueAsync(string queueName, /// /// Extracts queues from the given HTTP response. /// - /// HTTP response - /// Collection of queues + /// HTTP response. + /// Collection of queues. private IEnumerable GetQueues(HttpResponseMessage response) { Debug.Assert(response.IsSuccessStatusCode); @@ -162,8 +162,8 @@ private IEnumerable GetQueues(HttpResponseMessage response) /// /// Extracts a single queue from the given response. /// - /// HTTP response - /// Queue + /// HTTP response. + /// Queue data. private QueueInfo GetQueue(HttpResponseMessage response) { XmlDocument doc = new XmlDocument(); @@ -177,9 +177,9 @@ private QueueInfo GetQueue(HttpResponseMessage response) /// /// Creates a queue with the given parameters. /// - /// Name of the queue - /// Parameters of the queue - /// Created queue + /// Name of the queue. + /// Parameters of the queue. + /// Created queue. IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queueSettings) { Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); @@ -195,8 +195,8 @@ IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queu /// /// Serializes given object and sets the request's body. /// - /// Target request - /// Object to serialize + /// Target request. + /// Object to serialize. private void SetBody(HttpRequestMessage request, object bodyObject) { string content = SerializationHelper.Serialize(bodyObject); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs index 7234f54138bb1..4ebbd2d377e9d 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusService.cs @@ -22,7 +22,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus { /// - /// Factory for creating service bus services + /// Factory for creating service bus services. /// public static class ServiceBusService { diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs index 360d2f625c3cf..829c51c673924 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs @@ -60,9 +60,9 @@ public class ServiceConfiguration /// /// Constructor with explicitly specified options. /// - /// Service namespace - /// User name for authentication - /// Password for authentication + /// Service namespace. + /// User name for authentication. + /// Password for authentication. internal ServiceConfiguration(string serviceNamespace, string userName, string password) { ServiceNamespace = serviceNamespace; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index b25165ff22071..4d4345226caed 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -26,15 +26,15 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// internal class WrapAuthenticationHandler: HttpClientHandler { - private ServiceConfiguration ServiceConfig { get; set; } // Configuration parameters - private HttpClient Channel { get; set; } // HTTP channel for processing requests - private Dictionary Tokens { get; set; } // Cached tokens - private Object SyncObject { get; set; } // Synchronization object for accessing cached tokens + private ServiceConfiguration ServiceConfig { get; set; } // Configuration parameters. + private HttpClient Channel { get; set; } // HTTP channel for processing requests. + private Dictionary Tokens { get; set; } // Cached tokens. + private Object SyncObject { get; set; } // Synchronization object for accessing cached tokens. /// /// Constructor. /// - /// Configuration + /// Configuration of the service. internal WrapAuthenticationHandler(ServiceConfiguration serviceConfig) { ServiceConfig = serviceConfig; @@ -49,9 +49,9 @@ internal WrapAuthenticationHandler(ServiceConfiguration serviceConfig) /// /// Sends the request. /// - /// HTTP request to send - /// Cancellation token - /// HTTP response + /// HTTP request to send. + /// Cancellation token. + /// HTTP response. protected override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { return Task.Factory.StartNew(() => { return GetToken(request.RequestUri.AbsolutePath); }) @@ -62,8 +62,8 @@ protected override Task SendAsync(HttpRequestMessage reques /// /// Gets authentication token for a resource with the given path. /// - /// Resource path - /// Authentication token + /// Resource path. + /// Authentication token. private WrapToken GetToken(string resourcePath) { WrapToken token; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index 3ea79245005aa..278ea04fe02c7 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -38,7 +38,7 @@ class WrapToken internal string Scope { get; private set; } /// - /// Specifies the + /// Gets the token string. /// internal string Token { get; private set; } @@ -50,8 +50,8 @@ class WrapToken /// /// Constructor. /// - /// Path of the authenticated resource - /// HTTP response with the token + /// Path of the authenticated resource. + /// HTTP response with the token. internal WrapToken(string resourcePath, HttpResponseMessage response) { Debug.Assert(response.IsSuccessStatusCode); @@ -66,8 +66,8 @@ internal WrapToken(string resourcePath, HttpResponseMessage response) /// /// Authorizes the request. /// - /// Source request - /// Authorized request + /// Source request. + /// Authorized request. internal HttpRequestMessage Authorize(HttpRequestMessage request) { request.Headers.Add("Authorization", Token); From aa20ab205fca9e34ee3e5f8949f4c2f85c02b4d1 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 10:57:15 -0800 Subject: [PATCH 07/11] Some shared constants --- .../Constants.cs | 39 +++++++++++++++++++ .../SerializationHelper.cs | 2 +- .../ServiceBus/ServiceBusRestProxy.cs | 2 +- .../ServiceBus/ServiceConfiguration.cs | 6 +-- .../ServiceBus/WrapAuthenticationHandler.cs | 2 +- .../ServiceBus/WrapToken.cs | 2 +- 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs new file mode 100644 index 0000000000000..5f131c0381d77 --- /dev/null +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs @@ -0,0 +1,39 @@ +// +// 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. +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.ServiceLayer +{ + /// + /// Shared constants. + /// + internal static class Constants + { + internal const string ServiceBusServiceUri = "https://{0}.servicebus.windows.net/"; + internal const string ServiceBusAuthenticationUri = "https://{0}-sb.accesscontrol.windows.net/wrapv0.9/"; + internal const string ServiceBusScopeUri = "http://{0}.servicebus.windows.net/"; + + internal const string WrapTokenAuthenticationString = "WRAP access_token=\"{0}\""; + + internal const string SerializationContentType = "application/xml"; + internal const string BodyContentType = "application/atom+xml"; + internal const string WrapAuthenticationContentType = "application/x-www-form-urlencoded"; + } +} diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index 97b6f396d101f..4ab9d4bd115ba 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -104,7 +104,7 @@ static internal string Serialize(object item) } SyndicationContent content = new SyndicationContent(); - content.Type = "application/xml"; + content.Type = Constants.SerializationContentType; content.Xml = new XmlDocument(); content.Xml.LoadXml(itemXml); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index ca316929952e6..ad891abb0cc55 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -200,7 +200,7 @@ IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queu private void SetBody(HttpRequestMessage request, object bodyObject) { string content = SerializationHelper.Serialize(bodyObject); - request.Content = new StringContent(content, Encoding.UTF8, "application/atom+xml"); + request.Content = new StringContent(content, Encoding.UTF8, Constants.BodyContentType); request.Content.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", "entry")); } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs index 829c51c673924..b86221e7e1e47 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceConfiguration.cs @@ -69,13 +69,13 @@ internal ServiceConfiguration(string serviceNamespace, string userName, string p UserName = userName; Password = password; - string stringUri = string.Format(CultureInfo.InvariantCulture, "https://{0}.servicebus.windows.net/", ServiceNamespace); + string stringUri = string.Format(CultureInfo.InvariantCulture, Constants.ServiceBusServiceUri, ServiceNamespace); ServiceBusUri = new Uri(stringUri, UriKind.Absolute); - stringUri = string.Format(CultureInfo.InvariantCulture, "https://{0}-sb.accesscontrol.windows.net/wrapv0.9/", ServiceNamespace); + stringUri = string.Format(CultureInfo.InvariantCulture, Constants.ServiceBusAuthenticationUri, ServiceNamespace); AuthenticationUri = new Uri(stringUri, UriKind.Absolute); - stringUri = string.Format(CultureInfo.InvariantCulture, "http://{0}.servicebus.windows.net/", ServiceNamespace); + stringUri = string.Format(CultureInfo.InvariantCulture, Constants.ServiceBusScopeUri, ServiceNamespace); ScopeHostUri = new Uri(stringUri); } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index 4d4345226caed..e32bc96886c0a 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -89,7 +89,7 @@ private WrapToken GetToken(string resourcePath) {"wrap_scope", scopeUri.ToString()}, }; - request.Headers.Accept.ParseAdd("application/x-www-form-urlencoded"); //TODO: is there a constant for this type? + request.Headers.Accept.ParseAdd(Constants.WrapAuthenticationContentType); request.Content = new FormUrlEncodedContent(settings); HttpResponseMessage response = Channel.SendAsync(request).Result; diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index 278ea04fe02c7..695509d7072a7 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -59,7 +59,7 @@ internal WrapToken(string resourcePath, HttpResponseMessage response) string content = response.Content.ReadAsStringAsync().Result; HttpQuery query = new HttpQuery(content); - Token = string.Format(CultureInfo.InvariantCulture, "WRAP access_token=\"{0}\"", WebUtility.UrlDecode(query["wrap_access_token"])); + Token = string.Format(CultureInfo.InvariantCulture, Constants.WrapTokenAuthenticationString, WebUtility.UrlDecode(query["wrap_access_token"])); _expirationDate = DateTime.Now + TimeSpan.FromSeconds(int.Parse(query["wrap_access_token_expires_in"]) / 2); } From bd5da9d74865453d6d0b4f9c089a50b727f73e13 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 11:06:20 -0800 Subject: [PATCH 08/11] Updated project file --- .../Microsoft.WindowsAzure.ServiceLayer.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj index 6c1a5bc58429b..9449c0fd6fba5 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj @@ -109,6 +109,7 @@ + From 4bb37694ac3fcd2b28af571014100be96e65c3ed Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 12:15:42 -0800 Subject: [PATCH 09/11] Addressing code review issues --- .../HttpErrorHandler.cs | 9 +++++---- .../{HttpQuery.cs => HttpQueryStringParser.cs} | 4 ++-- .../Microsoft.WindowsAzure.ServiceLayer.csproj | 4 ++-- .../Properties/AssemblyInfo.cs | 4 ++-- .../SerializationHelper.cs | 8 +++----- .../ServiceBus/ServiceBusRestProxy.cs | 12 ++++++++---- .../ServiceBus/WrapAuthenticationHandler.cs | 6 ++++-- .../ServiceBus/WrapToken.cs | 2 +- ...eException.cs => WindowsAzureServiceException.cs} | 2 +- 9 files changed, 28 insertions(+), 23 deletions(-) rename microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/{HttpQuery.cs => HttpQueryStringParser.cs} (94%) rename microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/{AzureServiceException.cs => WindowsAzureServiceException.cs} (93%) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs index 89179192a8d7b..ff4eeeedbe2da 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpErrorHandler.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.WindowsAzure.ServiceLayer @@ -43,12 +44,12 @@ internal HttpErrorHandler(HttpMessageHandler innerHandler) } /// - /// Processes outhoing HTTP requests. + /// Processes outgoing HTTP requests. /// /// Request. /// Cancellation token. /// Processed HTTP request. - protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken) { // We're not interested in outgoing requests; do nothing. return request; @@ -60,11 +61,11 @@ protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, /// HTTP response. /// Cancellation token. /// Processed HTTP response. - protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, System.Threading.CancellationToken cancellationToken) + protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken) { if (!response.IsSuccessStatusCode) { - throw new AzureServiceException(); + throw new WindowsAzureServiceException(); } return response; } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs similarity index 94% rename from microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs rename to microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs index c03dc764450f2..b7904477845ca 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQuery.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs @@ -24,7 +24,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer /// /// Helper class for processing HTTP query strings. /// - internal class HttpQuery + internal class HttpQueryStringParser { private Dictionary _values = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -32,7 +32,7 @@ internal class HttpQuery /// Constructor. /// /// Query string. - internal HttpQuery(string queryString) + internal HttpQueryStringParser(string queryString) { string[] pairs = queryString.Split('&'); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj index 176f32fb7cc58..96eefd2f569c0 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj @@ -108,10 +108,10 @@ - + - + diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs index 6405ee648d8e1..355714b07842b 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Properties/AssemblyInfo.cs @@ -23,9 +23,9 @@ [assembly: AssemblyTitle("Microsoft.WindowsAzure.ServiceLayer")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyProduct("Microsoft.WindowsAzure.ServiceLayer")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index 4ab9d4bd115ba..3a695e9561e72 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Runtime.Serialization; using System.Xml; @@ -40,11 +41,7 @@ static internal class SerializationHelper static internal IEnumerable DeserializeCollection(SyndicationFeed feed, Action itemAction) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); - - foreach (SyndicationItem item in feed.Items) - { - yield return DeserializeItem(serializer, item, itemAction); - } + return feed.Items.Select(item => DeserializeItem(item, itemAction)); } /// @@ -103,6 +100,7 @@ static internal string Serialize(object item) } } + // Turn serialized content into an atom entry. SyndicationContent content = new SyndicationContent(); content.Type = Constants.SerializationContentType; content.Xml = new XmlDocument(); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs index ad891abb0cc55..2cbb2065586cd 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/ServiceBusRestProxy.cs @@ -66,7 +66,8 @@ IAsyncOperation> IServiceBusService.ListQueuesAsync() Uri uri = new Uri(ServiceConfig.ServiceBusUri, "$Resources/Queues"); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); - return Channel.SendAsync(request) + return Channel + .SendAsync(request) .ContinueWith>(r => { return GetQueues(r.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) .AsAsyncOperation>(); } @@ -86,7 +87,8 @@ IAsyncOperation IServiceBusService.GetQueueAsync(string queueName) Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); - return Channel.SendAsync(request) + return Channel + .SendAsync(request) .ContinueWith(r => { return GetQueue(r.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) .AsAsyncOperation(); } @@ -106,7 +108,8 @@ IAsyncAction IServiceBusService.DeleteQueueAsync(string queueName) Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, uri); - return Channel.SendAsync(request) + return Channel + .SendAsync(request) .AsAsyncAction(); } @@ -185,7 +188,8 @@ IAsyncOperation CreateQueueAsync(string queueName, QueueSettings queu Uri uri = new Uri(ServiceConfig.ServiceBusUri, queueName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, uri); - return Task.Factory.StartNew(() => SetBody(request, queueSettings)) + return Task.Factory + .StartNew(() => SetBody(request, queueSettings)) .ContinueWith(tr => { return Channel.SendAsync(request).Result; }, TaskContinuationOptions.OnlyOnRanToCompletion) .ContinueWith(tr => { return GetQueue(tr.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion) .AsAsyncOperation(); diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs index e32bc96886c0a..817070c3f857d 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapAuthenticationHandler.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus @@ -52,9 +53,10 @@ internal WrapAuthenticationHandler(ServiceConfiguration serviceConfig) /// HTTP request to send. /// Cancellation token. /// HTTP response. - protected override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - return Task.Factory.StartNew(() => { return GetToken(request.RequestUri.AbsolutePath); }) + return Task.Factory + .StartNew(() => { return GetToken(request.RequestUri.AbsolutePath); }) .ContinueWith((tr) => { return tr.Result.Authorize(request); }, TaskContinuationOptions.OnlyOnRanToCompletion) .ContinueWith((tr) => { return base.SendAsync(tr.Result, cancellationToken).Result; }, TaskContinuationOptions.OnlyOnRanToCompletion); } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index 695509d7072a7..bf4a5c7a54d58 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -57,8 +57,8 @@ internal WrapToken(string resourcePath, HttpResponseMessage response) Debug.Assert(response.IsSuccessStatusCode); Scope = resourcePath; string content = response.Content.ReadAsStringAsync().Result; + HttpQueryStringParser query = new HttpQueryStringParser(content); - HttpQuery query = new HttpQuery(content); Token = string.Format(CultureInfo.InvariantCulture, Constants.WrapTokenAuthenticationString, WebUtility.UrlDecode(query["wrap_access_token"])); _expirationDate = DateTime.Now + TimeSpan.FromSeconds(int.Parse(query["wrap_access_token_expires_in"]) / 2); } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/WindowsAzureServiceException.cs similarity index 93% rename from microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs rename to microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/WindowsAzureServiceException.cs index 730fbf9e33eb4..9b5d88cca2e37 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/AzureServiceException.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/WindowsAzureServiceException.cs @@ -24,7 +24,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer /// /// Exception that occurs as a result of calls to Windows Azure service. /// - internal class AzureServiceException: Exception + internal class WindowsAzureServiceException: Exception { } } From 73cf42da92952982d7b5e446f7df8c02f917038a Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 12:21:01 -0800 Subject: [PATCH 10/11] Removing sensitive data --- .../Configuration.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs index de9d9497d63d9..dc0ec32f6fe30 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer.UnitTests/Configuration.cs @@ -8,10 +8,10 @@ namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests { static class Configuration { - public static string ServiceNamespace { get { return "aliakb-test"; } } + public static string ServiceNamespace { get { throw new NotImplementedException(); } } - public static string UserName { get { return "owner"; } } + public static string UserName { get { throw new NotImplementedException(); } } - public static string Password { get { return "0Myg+PyST7O5Bj+j9+Byjlljr4lomN1Y1QJR7D9JgZg="; } } + public static string Password { get { throw new NotImplementedException(); } } } } From 8de0cc602b73846532c793d949bc96086561ec92 Mon Sep 17 00:00:00 2001 From: Aliaksei Baturytski Date: Wed, 22 Feb 2012 15:07:00 -0800 Subject: [PATCH 11/11] Fixes for code analysis issues --- .../HttpQueryStringParser.cs | 8 +++++++- .../Microsoft.WindowsAzure.ServiceLayer.csproj | 2 +- .../SerializationHelper.cs | 9 ++++----- .../ServiceBus/WrapToken.cs | 10 ++++++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs index b7904477845ca..171972405f3c9 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/HttpQueryStringParser.cs @@ -50,6 +50,12 @@ internal HttpQueryStringParser(string queryString) /// /// Parameter name. /// Parameter value. - internal string this[string parameterName] { get { return _values[parameterName]; } } + internal string this[string parameterName] + { + get + { + return _values[parameterName]; + } + } } } diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj index 96eefd2f569c0..8032022e3ef99 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Microsoft.WindowsAzure.ServiceLayer.csproj @@ -7,7 +7,7 @@ 8.0.30703 2.0 {53C097E2-7384-446B-836B-A7910993091E} - Library + winmdobj Properties Microsoft.WindowsAzure.ServiceLayer Microsoft.WindowsAzure.ServiceLayer diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs index 3a695e9561e72..2f8b36cea3c21 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/SerializationHelper.cs @@ -69,10 +69,11 @@ static T DeserializeItem(DataContractSerializer serializer, SyndicationItem i string serializedString = item.Content.Xml.GetXml(); using (StringReader stringReader = new StringReader(serializedString)) - using (XmlReader xmlReader = XmlReader.Create(stringReader)) { + XmlReader xmlReader = XmlReader.Create(stringReader); T deserializedObject = (T)serializer.ReadObject(xmlReader); itemAction(item, deserializedObject); + return deserializedObject; } } @@ -94,10 +95,8 @@ static internal string Serialize(object item) stream.Flush(); stream.Seek(0, SeekOrigin.Begin); - using (StreamReader reader = new StreamReader(stream)) - { - itemXml = reader.ReadToEnd(); - } + StreamReader reader = new StreamReader(stream); + itemXml = reader.ReadToEnd(); } // Turn serialized content into an atom entry. diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs index bf4a5c7a54d58..293d70400ad0e 100644 --- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs +++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/WrapToken.cs @@ -28,7 +28,7 @@ namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus /// /// WRAP token; used for authenticating outgoing web requests. /// - class WrapToken + internal class WrapToken { private DateTime _expirationDate; // Token's expiration date. @@ -45,7 +45,13 @@ class WrapToken /// /// Gets the value saying whether the token is expired. /// - internal bool IsExpired { get { return DateTime.Now > _expirationDate; } } + internal bool IsExpired + { + get + { + return DateTime.Now > _expirationDate; + } + } /// /// Constructor.