PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/AzureTableStorage/src/AzureServicesManagement/ServiceManagement/HostedService.cs

#
C# | 270 lines | 166 code | 46 blank | 58 comment | 0 complexity | 955cc47b23cff7676159d0b646a78a3f MD5 | raw file
  1. //---------------------------------------------------------------------------------
  2. // Microsoft (R) Windows Azure SDK
  3. // Software Development Kit
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  8. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  9. // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  10. //---------------------------------------------------------------------------------
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Runtime.Serialization;
  14. using System.ServiceModel;
  15. using System.ServiceModel.Web;
  16. namespace Microsoft.Samples.WindowsAzure.ServiceManagement
  17. {
  18. /// <summary>
  19. /// A list of hosted services
  20. /// </summary>
  21. [CollectionDataContract(Name = "HostedServices", ItemName = "HostedService", Namespace = Constants.ServiceManagementNS)]
  22. public class HostedServiceList : List<HostedService>
  23. {
  24. public HostedServiceList()
  25. {
  26. }
  27. public HostedServiceList(IEnumerable<HostedService> hostedServices)
  28. : base(hostedServices)
  29. {
  30. }
  31. }
  32. /// <summary>
  33. /// A hosted service
  34. /// </summary>
  35. [DataContract(Namespace = Constants.ServiceManagementNS)]
  36. public class HostedService : IExtensibleDataObject
  37. {
  38. [DataMember(Order = 1)]
  39. public Uri Url { get; set; }
  40. [DataMember(Order = 2, EmitDefaultValue = false)]
  41. public string ServiceName { get; set; }
  42. [DataMember(Order = 3, EmitDefaultValue = false)]
  43. public HostedServiceProperties HostedServiceProperties { get; set; }
  44. [DataMember(Order = 4, EmitDefaultValue = false)]
  45. public DeploymentList Deployments { get; set; }
  46. public ExtensionDataObject ExtensionData { get; set; }
  47. }
  48. /// <summary>
  49. /// A list of deployments contained in the hosted service
  50. /// </summary>
  51. [CollectionDataContract(Name = "Deployments", ItemName = "Deployment", Namespace = Constants.ServiceManagementNS)]
  52. public class DeploymentList : List<Deployment>
  53. {
  54. public DeploymentList()
  55. {
  56. }
  57. public DeploymentList(IEnumerable<Deployment> deployments)
  58. : base(deployments)
  59. {
  60. }
  61. }
  62. /// <summary>
  63. /// A hosted service
  64. /// </summary>
  65. [DataContract(Namespace = Constants.ServiceManagementNS)]
  66. public class HostedServiceProperties : IExtensibleDataObject
  67. {
  68. [DataMember(Order = 1)]
  69. public string Description { get; set; }
  70. [DataMember(Order = 2, EmitDefaultValue = false)]
  71. public string AffinityGroup { get; set; }
  72. [DataMember(Order = 3, EmitDefaultValue = false)]
  73. public string Location { get; set; }
  74. [DataMember(Order = 4)]
  75. public string Label { get; set; }
  76. public ExtensionDataObject ExtensionData { get; set; }
  77. }
  78. /// <summary>
  79. /// List of locations
  80. /// </summary>
  81. [CollectionDataContract(Name = "Locations", ItemName = "Location", Namespace = Constants.ServiceManagementNS)]
  82. public class LocationList : List<Location>
  83. {
  84. public LocationList()
  85. {
  86. }
  87. public LocationList(IEnumerable<Location> locations)
  88. : base(locations)
  89. {
  90. }
  91. }
  92. /// <summary>
  93. /// A location constraint
  94. /// </summary>
  95. [DataContract(Namespace = Constants.ServiceManagementNS)]
  96. public class Location : IExtensibleDataObject
  97. {
  98. [DataMember(Order = 1)]
  99. public string Name { get; set; }
  100. public ExtensionDataObject ExtensionData { get; set; }
  101. }
  102. /// <summary>
  103. /// CreateHostedService contract
  104. /// </summary>
  105. [DataContract(Name = "CreateHostedService", Namespace = Constants.ServiceManagementNS)]
  106. public class CreateHostedServiceInput : IExtensibleDataObject
  107. {
  108. [DataMember(Order = 1)]
  109. public string ServiceName { get; set; }
  110. [DataMember(Order = 2)]
  111. public string Label { get; set; }
  112. [DataMember(Order = 3, EmitDefaultValue = false)]
  113. public string Description { get; set; }
  114. [DataMember(Order = 4, EmitDefaultValue = false)]
  115. public string Location { get; set; }
  116. [DataMember(Order = 5, EmitDefaultValue = false)]
  117. public string AffinityGroup { get; set; }
  118. public ExtensionDataObject ExtensionData { get; set; }
  119. }
  120. /// <summary>
  121. /// UpdateHostedService contract
  122. /// </summary>
  123. [DataContract(Name = "UpdateHostedService", Namespace = Constants.ServiceManagementNS)]
  124. public class UpdateHostedServiceInput : IExtensibleDataObject
  125. {
  126. [DataMember(Order = 1, EmitDefaultValue = false)]
  127. public string Label { get; set; }
  128. [DataMember(Order = 2, EmitDefaultValue = false)]
  129. public string Description { get; set; }
  130. public ExtensionDataObject ExtensionData { get; set; }
  131. }
  132. /// <summary>
  133. /// The hosted services related part of the Service Management API
  134. /// </summary>
  135. public partial interface IServiceManagement
  136. {
  137. #region CreateHostedService
  138. /// <summary>
  139. /// Creates a hosted service
  140. /// </summary>
  141. [OperationContract(AsyncPattern = true)]
  142. [WebInvoke(Method = "POST", UriTemplate = @"{subscriptionId}/services/hostedservices")]
  143. IAsyncResult BeginCreateHostedService(string subscriptionId, CreateHostedServiceInput input, AsyncCallback callback, object state);
  144. void EndCreateHostedService(IAsyncResult asyncResult);
  145. #endregion
  146. #region UpdateHostedService
  147. /// <summary>
  148. /// Updates a hosted service
  149. /// </summary>
  150. [OperationContract(AsyncPattern = true)]
  151. [WebInvoke(Method = "PUT", UriTemplate = @"{subscriptionId}/services/hostedservices/{serviceName}")]
  152. IAsyncResult BeginUpdateHostedService(string subscriptionId, string serviceName,UpdateHostedServiceInput input, AsyncCallback callback, object state);
  153. void EndUpdateHostedService(IAsyncResult asyncResult);
  154. #endregion
  155. #region DeleteHostedService
  156. /// <summary>
  157. /// Deletes a hosted service
  158. /// </summary>
  159. [OperationContract(AsyncPattern = true)]
  160. [WebInvoke(Method = "DELETE", UriTemplate = @"{subscriptionId}/services/hostedservices/{serviceName}")]
  161. IAsyncResult BeginDeleteHostedService(string subscriptionId, string serviceName, AsyncCallback callback, object state);
  162. void EndDeleteHostedService(IAsyncResult asyncResult);
  163. #endregion
  164. /// <summary>
  165. /// Lists the hosted services associated with a given subscription.
  166. /// </summary>
  167. [OperationContract(AsyncPattern = true)]
  168. [WebGet(UriTemplate = @"{subscriptionId}/services/hostedservices")]
  169. IAsyncResult BeginListHostedServices(string subscriptionId, AsyncCallback callback, object state);
  170. HostedServiceList EndListHostedServices(IAsyncResult asyncResult);
  171. /// <summary>
  172. /// Gets the properties for the specified hosted service.
  173. /// </summary>
  174. [OperationContract(AsyncPattern = true)]
  175. [WebGet(UriTemplate = @"{subscriptionId}/services/hostedservices/{serviceName}")]
  176. IAsyncResult BeginGetHostedService(string subscriptionId, string serviceName, AsyncCallback callback, object state);
  177. HostedService EndGetHostedService(IAsyncResult asyncResult);
  178. /// <summary>
  179. /// Gets the detailed properties for the specified hosted service.
  180. /// </summary>
  181. [OperationContract(AsyncPattern = true)]
  182. [WebGet(UriTemplate = @"{subscriptionId}/services/hostedservices/{serviceName}?embed-detail={embedDetail}")]
  183. IAsyncResult BeginGetHostedServiceWithDetails(string subscriptionId, string serviceName, bool embedDetail, AsyncCallback callback, object state);
  184. HostedService EndGetHostedServiceWithDetails(IAsyncResult asyncResult);
  185. /// <summary>
  186. /// List the locations supported by a given subscription.
  187. /// </summary>
  188. [OperationContract(AsyncPattern = true)]
  189. [WebGet(UriTemplate = @"{subscriptionId}/locations")]
  190. IAsyncResult BeginListLocations(string subscriptionId, AsyncCallback callback, object state);
  191. LocationList EndListLocations(IAsyncResult asyncResult);
  192. }
  193. public static partial class ServiceManagementExtensionMethods
  194. {
  195. public static void CreateHostedService(this IServiceManagement proxy, string subscriptionId, CreateHostedServiceInput input)
  196. {
  197. proxy.EndCreateHostedService(proxy.BeginCreateHostedService(subscriptionId, input, null, null));
  198. }
  199. public static void UpdateHostedService(this IServiceManagement proxy, string subscriptionId, string serviceName, UpdateHostedServiceInput input)
  200. {
  201. proxy.EndUpdateHostedService(proxy.BeginUpdateHostedService(subscriptionId, serviceName, input, null, null));
  202. }
  203. public static void DeleteHostedService(this IServiceManagement proxy, string subscriptionId, string serviceName)
  204. {
  205. proxy.EndDeleteHostedService(proxy.BeginDeleteHostedService(subscriptionId, serviceName, null, null));
  206. }
  207. public static HostedServiceList ListHostedServices(this IServiceManagement proxy, string subscriptionId)
  208. {
  209. return proxy.EndListHostedServices(proxy.BeginListHostedServices(subscriptionId, null, null));
  210. }
  211. public static HostedService GetHostedService(this IServiceManagement proxy, string subscriptionId, string serviceName)
  212. {
  213. return proxy.EndGetHostedService(proxy.BeginGetHostedService(subscriptionId, serviceName, null, null));
  214. }
  215. public static HostedService GetHostedServiceWithDetails(this IServiceManagement proxy, string subscriptionId, string serviceName, bool embedDetail)
  216. {
  217. return proxy.EndGetHostedServiceWithDetails(proxy.BeginGetHostedServiceWithDetails(subscriptionId, serviceName, embedDetail, null, null));
  218. }
  219. public static LocationList ListLocations(this IServiceManagement proxy, string subscriptionId)
  220. {
  221. return proxy.EndListLocations(proxy.BeginListLocations(subscriptionId, null, null));
  222. }
  223. }
  224. }