rabcg /source/v2/samples/Azure HOL Files/End/CSManage/C#/ServiceManagement/Image.cs

Language C# Lines 297
MD5 Hash 4d4be7ff0c78bc75a5b3eee79422ec60 Estimated Cost $4,516 (why?)
Repository https://rabcg.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//---------------------------------------------------------------------------------
// Microsoft (R) Windows Azure SDK
// Software Development Kit
// 
// Copyright (c) Microsoft Corporation. All rights reserved.  
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
//---------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace Microsoft.Samples.WindowsAzure.ServiceManagement
{
    /// <summary>
    /// The desired permission for generating a shared access signature. 
    /// This enum is used in the prepare image upload operation.
    /// </summary>
    [DataContract(Namespace = Constants.ServiceManagementNS)]
    public enum ImageSharedAccessSignaturePermission
    {
        [EnumMember]
        Read,
        [EnumMember]
        ReadWrite
    }

    /// <summary>
    /// The status of an image upload.
    /// </summary>
    [DataContract(Namespace = Constants.ServiceManagementNS)]
    public enum ImageStatus
    {
        [EnumMember]
        Pending,
        [EnumMember]
        Committed
    }

    /// <summary>
    /// Input for the prepare image upload operation.
    /// </summary>
    [DataContract(Name = "PrepareMachineImage", Namespace = Constants.ServiceManagementNS)]
    public class  PrepareImageUploadInput : IExtensibleDataObject
    {
        [DataMember(Order = 1)]
        public string Label { get; set; }

        [DataMember(Order = 2)]
        public string Description { get; set; }

        [DataMember(Order = 3)]
        public string Uuid { get; set; }

        [DataMember(Order = 4)]
        public string Timestamp { get; set; }

        [DataMember(Order = 5)]
        public long CompressedSizeInBytes { get; set; }

        [DataMember(Order = 6)]
        public long MountedSizeInBytes { get; set; }

        [DataMember(Order = 7, EmitDefaultValue = false)]
        public string Location { get; set; }

        [DataMember(Order = 8, EmitDefaultValue = false)]
        public string AffinityGroup { get; set; }

        [DataMember(Order = 9, EmitDefaultValue = false)]
        public string ParentUuid { get; set; }

        [DataMember(Order = 10, EmitDefaultValue = false)]
        public string ParentTimestamp { get; set; }

        public ExtensionDataObject ExtensionData { get; set; }
    }

    /// <summary>
    /// Input for the set image properties operation.
    /// </summary>
    [DataContract(Name="SetMachineImageProperties", Namespace = Constants.ServiceManagementNS)]
    public class SetMachineImagePropertiesInput : IExtensibleDataObject
    {
        [DataMember(Order = 1)]
        public string Label { get; set; }

        [DataMember(Order = 2)]
        public string Description { get; set; }

        public ExtensionDataObject ExtensionData { get; set; }
    }

    /// <summary>
    /// Input for the set parent image operation.
    /// </summary>
    [DataContract(Name="ParentMachineImage", Namespace = Constants.ServiceManagementNS)]
    public class SetParentImageInput : IExtensibleDataObject
    {
        [DataMember(Order = 1)]
        public string ParentImageName { get; set; }

        public ExtensionDataObject ExtensionData { get; set; }
    }


    /// <summary>
    /// Reference to an image that can be used for upload and download.
    /// </summary>
    [DataContract(Namespace = Constants.ServiceManagementNS)]
    public class MachineImageReference : IExtensibleDataObject
    {
        [DataMember(Order = 1)]
        public string SharedAccessSignatureUrl { get; set; }

        public ExtensionDataObject ExtensionData { get; set; }
    }

    /// <summary>
    /// List of images.
    /// </summary>
    [CollectionDataContract(Name="MachineImages",ItemName = "MachineImage",Namespace = Constants.ServiceManagementNS)]
    public class MachineImageList : List<MachineImage>
    {
    }

    /// <summary>
    /// Information associated with an image. 
    /// </summary>
    [DataContract(Namespace = Constants.ServiceManagementNS)]
    public class MachineImage : IExtensibleDataObject
    {
        [DataMember(Order = 1)]
        public string Name { get; set; }

        [DataMember(Order = 2)]
        public string Label { get; set; }

        [DataMember(Order = 3)]
        public string Description { get; set; }

        [DataMember(Order = 4, EmitDefaultValue = false)]
        public string Location { get; set; }

        [DataMember(Order = 5, EmitDefaultValue = false)]
        public string AffinityGroup { get; set; }

        [DataMember(Order = 6)]
        public string Status { get; set; }

        [DataMember(Order = 7)]
        public string ParentImageName { get; set; }

        [DataMember(Order = 8)]
        public string Uuid { get; set; }

        [DataMember(Order = 9)]
        public string Timestamp { get; set; }

        [DataMember(Order = 10)]
        public long MountedSizeInBytes { get; set; }

        [DataMember(Order = 11)]
        public long CompressedSizeInBytes { get; set; }

        [DataMember(Order = 12, EmitDefaultValue = false)]
        public string ParentUuid { get; set; }

        [DataMember(Order = 13, EmitDefaultValue = false)]
        public string ParentTimestamp { get; set; }

        [DataMember(Order = 15)]
        public bool InUse { get; set; }

        public ExtensionDataObject ExtensionData { get; set; }
    }

    /// <summary>
    /// The image-specific part of the service management service.
    /// </summary>
    public partial interface IServiceManagement
    {
        /// <summary>
        /// Prepare an image for upload.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebInvoke(Method = "PUT", UriTemplate = @"{subscriptionID}/machineimages/{imageName}")]
        IAsyncResult BeginPrepareImageUpload(string subscriptionId, string imageName, PrepareImageUploadInput input, AsyncCallback callback, object state);
        void EndPrepareImageUpload(IAsyncResult asyncResult);

        /// <summary>
        /// Get image reference.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebGet(UriTemplate = @"{subscriptionID}/machineimages/{imageName}?comp=reference&expiry={expiry}&permission={permission}")]
        IAsyncResult BeginGetImageReference(string subscriptionID, string imageName, string expiry, string permission, AsyncCallback callback, object state);
        MachineImageReference EndGetImageReference(IAsyncResult asyncResult);

        /// <summary>
        /// Commit the upload of an image.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebInvoke(Method = "POST", UriTemplate = @"{subscriptionID}/machineimages/{imageName}?comp=commitmachineimage")]
        IAsyncResult BeginCommitImageUpload(string subscriptionID, string imageName, AsyncCallback callback, object state);
        void EndCommitImageUpload(IAsyncResult asyncResult);

        /// <summary>
        /// List all images associated with a subscription.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebGet(UriTemplate = @"{subscriptionID}/machineimages")]
        IAsyncResult BeginListImages(string subscriptionID, AsyncCallback callback, object state);
        MachineImageList EndListImages(IAsyncResult asyncResult);

        /// <summary>
        /// Get information about an image.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebGet(UriTemplate = @"{subscriptionID}/machineimages/{imageName}")]
        IAsyncResult BeginGetImageProperties(string subscriptionID, string imageName, AsyncCallback callback, object state);
        MachineImage EndGetImageProperties(IAsyncResult asyncResult);

        /// <summary>
        /// Set image properties.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebInvoke(Method = "POST", UriTemplate = @"{subscriptionID}/machineimages/{imagename}?comp=properties")]
        IAsyncResult BeginSetImageProperties(string subscriptionID, string imageName, SetMachineImagePropertiesInput imageProperties, AsyncCallback callback, object state);
        void EndSetImageProperties(IAsyncResult asyncResult);

        /// <summary>
        /// Set parent image.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebInvoke(Method = "POST", UriTemplate = @"{subscriptionID}/machineimages/{imagename}?comp=setparent")]
        IAsyncResult BeginSetParentImage(string subscriptionID, string imageName, SetParentImageInput parentImageInput, AsyncCallback callback, object state);
        void EndSetParentImage(IAsyncResult asyncResult);

        /// <summary>
        /// Delete an image.
        /// </summary>
        [OperationContract(AsyncPattern = true)]
        [WebInvoke(Method = "DELETE", UriTemplate = @"{subscriptionID}/machineimages/{imageName}")]
        IAsyncResult BeginDeleteImage(string subscriptionID, string imageName, AsyncCallback callback, object state);
        void EndDeleteImage(IAsyncResult asyncResult);
    }

    public static partial class ServiceManagementExtensionMethods
    {
        public static void PrepareImageUpload(this IServiceManagement proxy, string subscriptionID, string imageName, PrepareImageUploadInput input)
        {
            proxy.EndPrepareImageUpload(proxy.BeginPrepareImageUpload(subscriptionID, imageName, input, null, null));
        }

        public static MachineImageReference GetImageReference(this IServiceManagement proxy, string subscriptionId, string imageName, DateTime expiry, ImageSharedAccessSignaturePermission accessModifier)
        {
            return proxy.EndGetImageReference(proxy.BeginGetImageReference(subscriptionId, imageName, expiry.ToString("o"), accessModifier.ToString().ToLower(), null, null));
        }

        public static void CommitImageUpload(this IServiceManagement proxy, string subscriptionId, string imageName)
        {
            proxy.EndCommitImageUpload(proxy.BeginCommitImageUpload(subscriptionId, imageName, null, null));
        }

        public static MachineImageList ListImages(this IServiceManagement proxy, string subscriptionID)
        {
            return proxy.EndListImages(proxy.BeginListImages(subscriptionID, null, null));
        }

        public static MachineImage GetImageProperties(this IServiceManagement proxy, string subscriptionID, string imageName)
        {
            return proxy.EndGetImageProperties(proxy.BeginGetImageProperties(subscriptionID, imageName, null, null));
        }

        public static void SetImageProperties(this IServiceManagement proxy, string subscriptionID, string imageName, SetMachineImagePropertiesInput input)
        {
            proxy.EndSetImageProperties(proxy.BeginSetImageProperties(subscriptionID, imageName, input, null, null));
        }

        public static void SetParentImage(this IServiceManagement proxy, string subscriptionID, string imageName, SetParentImageInput input)
        {
            proxy.EndSetParentImage(proxy.BeginSetParentImage(subscriptionID, imageName, input, null, null));
        }

        public static void DeleteImage(this IServiceManagement proxy, string subscriptionID, string imageName)
        {
            proxy.EndDeleteImage(proxy.BeginDeleteImage(subscriptionID, imageName, null, null));
        }
    }
}
Back to Top