internal async Task CreateAsync(Subscription subscription) { Contract.Requires(Subscription == null); Contract.Requires(subscription != null); Contract.Requires(!string.IsNullOrWhiteSpace(Name)); Contract.Requires(!string.IsNullOrWhiteSpace(Label)); Contract.Requires(Location == null || Location.Trim().Length > 0); Contract.Requires(AffinityGroup == null || AffinityGroup.Trim().Length > 0); Contract.Requires((Location == null) != (AffinityGroup == null)); var ns = XmlNamespaces.WindowsAzure; var content = new XElement(ns + "CreateHostedService", new XElement(ns + "ServiceName", Name), new XElement(ns + "Label", Label.ToBase64String()), string.IsNullOrWhiteSpace(Description) ? null : new XElement(ns + "Description", Description), string.IsNullOrWhiteSpace(Location) ? null : new XElement(ns + "Location", Location), string.IsNullOrWhiteSpace(AffinityGroup) ? null : new XElement(ns + "AffinityGroup", AffinityGroup), ExtendedProperties == null || ExtendedProperties.Count == 0 ? null : new XElement(ns + "ExtendedProperties", ExtendedProperties.Select(kv => new XElement(ns + "ExtendedProperty", new XElement(ns + "Name", kv.Key), new XElement(ns + "Value", kv.Value)))) ); var hc = subscription.GetCoreRestClient20140601("services/hostedservices"); await hc.PostAsync(content); Subscription = subscription; }
internal async Task CreateAsync(Subscription subscription) { Contract.Requires(Subscription == null); Contract.Requires(subscription != null); Contract.Requires(!string.IsNullOrWhiteSpace(ServiceName)); Contract.Requires(!string.IsNullOrWhiteSpace(Label)); Contract.Requires(Location == null || Location.Trim().Length > 0); Contract.Requires(AffinityGroup == null || AffinityGroup.Trim().Length > 0); Contract.Requires((Location == null) != (AffinityGroup == null)); var azureNamespace = XmlNamespaces.WindowsAzure; var content = new XElement(azureNamespace + "CreateStorageServiceInput", new XElement(azureNamespace + "ServiceName", ServiceName), string.IsNullOrWhiteSpace(Description) ? null : new XElement(azureNamespace + "Description", Description), new XElement(azureNamespace + "Label", Label.ToBase64String()), string.IsNullOrWhiteSpace(Location) ? null : new XElement(azureNamespace + "Location", Location), string.IsNullOrWhiteSpace(AffinityGroup) ? null : new XElement(azureNamespace + "AffinityGroup", AffinityGroup), new XElement(azureNamespace + "GeoReplicationEnabled", GeoReplicationEnabled ? "true" : "false"), ExtendedProperties == null || ExtendedProperties.Count == 0 ? new XElement(azureNamespace + "ExtendedProperties") : new XElement(azureNamespace + "ExtendedProperties", ExtendedProperties.Select(kv => new XElement(azureNamespace + "ExtendedProperty", new XElement(azureNamespace + "Name", kv.Key), new XElement(azureNamespace + "Value", kv.Value)))), new XElement(azureNamespace + "SecondaryReadEnabled", SecondaryReadEnabled ? "true" : "false")); var hc = subscription.GetCoreRestClient20131101("services/storageservices"); await hc.PostAsync(content); Subscription = subscription; }