/// <summary>
        /// The List Resource Extensions operation lists the resource
        /// extensions that are available to add to a Virtual Machine. In
        /// Windows Azure, a process can run as a resource extension of a
        /// Virtual Machine. For example, Remote Desktop Access or the Windows
        /// Azure Diagnostics Agent can run as resource extensions to the
        /// Virtual Machine.  (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn495441.aspx
        /// for more information)
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The List Resource Extensions operation response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineExtensionListResponse> ListAsync(CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                Tracing.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/resourceextensions";

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2013-11-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    VirtualMachineExtensionListResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new VirtualMachineExtensionListResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement resourceExtensionsSequenceElement = responseDoc.Element(XName.Get("ResourceExtensions", "http://schemas.microsoft.com/windowsazure"));
                    if (resourceExtensionsSequenceElement != null)
                    {
                        foreach (XElement resourceExtensionsElement in resourceExtensionsSequenceElement.Elements(XName.Get("ResourceExtension", "http://schemas.microsoft.com/windowsazure")))
                        {
                            VirtualMachineExtensionListResponse.ResourceExtension resourceExtensionInstance = new VirtualMachineExtensionListResponse.ResourceExtension();
                            result.ResourceExtensions.Add(resourceExtensionInstance);

                            XElement publisherElement = resourceExtensionsElement.Element(XName.Get("Publisher", "http://schemas.microsoft.com/windowsazure"));
                            if (publisherElement != null)
                            {
                                string publisherInstance = publisherElement.Value;
                                resourceExtensionInstance.Publisher = publisherInstance;
                            }

                            XElement nameElement = resourceExtensionsElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                            if (nameElement != null)
                            {
                                string nameInstance = nameElement.Value;
                                resourceExtensionInstance.Name = nameInstance;
                            }

                            XElement versionElement = resourceExtensionsElement.Element(XName.Get("Version", "http://schemas.microsoft.com/windowsazure"));
                            if (versionElement != null)
                            {
                                string versionInstance = versionElement.Value;
                                resourceExtensionInstance.Version = versionInstance;
                            }

                            XElement labelElement = resourceExtensionsElement.Element(XName.Get("Label", "http://schemas.microsoft.com/windowsazure"));
                            if (labelElement != null)
                            {
                                string labelInstance = labelElement.Value;
                                resourceExtensionInstance.Label = labelInstance;
                            }

                            XElement descriptionElement = resourceExtensionsElement.Element(XName.Get("Description", "http://schemas.microsoft.com/windowsazure"));
                            if (descriptionElement != null)
                            {
                                string descriptionInstance = descriptionElement.Value;
                                resourceExtensionInstance.Description = descriptionInstance;
                            }

                            XElement publicConfigurationSchemaElement = resourceExtensionsElement.Element(XName.Get("PublicConfigurationSchema", "http://schemas.microsoft.com/windowsazure"));
                            if (publicConfigurationSchemaElement != null)
                            {
                                string publicConfigurationSchemaInstance = TypeConversion.FromBase64String(publicConfigurationSchemaElement.Value);
                                resourceExtensionInstance.PublicConfigurationSchema = publicConfigurationSchemaInstance;
                            }

                            XElement privateConfigurationSchemaElement = resourceExtensionsElement.Element(XName.Get("PrivateConfigurationSchema", "http://schemas.microsoft.com/windowsazure"));
                            if (privateConfigurationSchemaElement != null)
                            {
                                string privateConfigurationSchemaInstance = TypeConversion.FromBase64String(privateConfigurationSchemaElement.Value);
                                resourceExtensionInstance.PrivateConfigurationSchema = privateConfigurationSchemaInstance;
                            }

                            XElement sampleConfigElement = resourceExtensionsElement.Element(XName.Get("SampleConfig", "http://schemas.microsoft.com/windowsazure"));
                            if (sampleConfigElement != null)
                            {
                                string sampleConfigInstance = TypeConversion.FromBase64String(sampleConfigElement.Value);
                                resourceExtensionInstance.SampleConfig = sampleConfigInstance;
                            }
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
        /// <summary>
        /// The List Resource Extensions operation lists the resource
        /// extensions that are available to add to a Virtual Machine. In
        /// Azure, a process can run as a resource extension of a Virtual
        /// Machine. For example, Remote Desktop Access or the Azure
        /// Diagnostics Agent can run as resource extensions to the Virtual
        /// Machine.  (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn495441.aspx
        /// for more information)
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The List Resource Extensions operation response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineExtensionListResponse> ListAsync(CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                Tracing.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url     = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/resourceextensions";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2014-06-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    VirtualMachineExtensionListResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new VirtualMachineExtensionListResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement resourceExtensionsSequenceElement = responseDoc.Element(XName.Get("ResourceExtensions", "http://schemas.microsoft.com/windowsazure"));
                    if (resourceExtensionsSequenceElement != null)
                    {
                        foreach (XElement resourceExtensionsElement in resourceExtensionsSequenceElement.Elements(XName.Get("ResourceExtension", "http://schemas.microsoft.com/windowsazure")))
                        {
                            VirtualMachineExtensionListResponse.ResourceExtension resourceExtensionInstance = new VirtualMachineExtensionListResponse.ResourceExtension();
                            result.ResourceExtensions.Add(resourceExtensionInstance);

                            XElement publisherElement = resourceExtensionsElement.Element(XName.Get("Publisher", "http://schemas.microsoft.com/windowsazure"));
                            if (publisherElement != null)
                            {
                                string publisherInstance = publisherElement.Value;
                                resourceExtensionInstance.Publisher = publisherInstance;
                            }

                            XElement nameElement = resourceExtensionsElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                            if (nameElement != null)
                            {
                                string nameInstance = nameElement.Value;
                                resourceExtensionInstance.Name = nameInstance;
                            }

                            XElement versionElement = resourceExtensionsElement.Element(XName.Get("Version", "http://schemas.microsoft.com/windowsazure"));
                            if (versionElement != null)
                            {
                                string versionInstance = versionElement.Value;
                                resourceExtensionInstance.Version = versionInstance;
                            }

                            XElement labelElement = resourceExtensionsElement.Element(XName.Get("Label", "http://schemas.microsoft.com/windowsazure"));
                            if (labelElement != null)
                            {
                                string labelInstance = labelElement.Value;
                                resourceExtensionInstance.Label = labelInstance;
                            }

                            XElement descriptionElement = resourceExtensionsElement.Element(XName.Get("Description", "http://schemas.microsoft.com/windowsazure"));
                            if (descriptionElement != null)
                            {
                                string descriptionInstance = descriptionElement.Value;
                                resourceExtensionInstance.Description = descriptionInstance;
                            }

                            XElement publicConfigurationSchemaElement = resourceExtensionsElement.Element(XName.Get("PublicConfigurationSchema", "http://schemas.microsoft.com/windowsazure"));
                            if (publicConfigurationSchemaElement != null)
                            {
                                string publicConfigurationSchemaInstance = TypeConversion.FromBase64String(publicConfigurationSchemaElement.Value);
                                resourceExtensionInstance.PublicConfigurationSchema = publicConfigurationSchemaInstance;
                            }

                            XElement privateConfigurationSchemaElement = resourceExtensionsElement.Element(XName.Get("PrivateConfigurationSchema", "http://schemas.microsoft.com/windowsazure"));
                            if (privateConfigurationSchemaElement != null)
                            {
                                string privateConfigurationSchemaInstance = TypeConversion.FromBase64String(privateConfigurationSchemaElement.Value);
                                resourceExtensionInstance.PrivateConfigurationSchema = privateConfigurationSchemaInstance;
                            }

                            XElement sampleConfigElement = resourceExtensionsElement.Element(XName.Get("SampleConfig", "http://schemas.microsoft.com/windowsazure"));
                            if (sampleConfigElement != null)
                            {
                                string sampleConfigInstance = TypeConversion.FromBase64String(sampleConfigElement.Value);
                                resourceExtensionInstance.SampleConfig = sampleConfigInstance;
                            }

                            XElement replicationCompletedElement = resourceExtensionsElement.Element(XName.Get("ReplicationCompleted", "http://schemas.microsoft.com/windowsazure"));
                            if (replicationCompletedElement != null && string.IsNullOrEmpty(replicationCompletedElement.Value) == false)
                            {
                                bool replicationCompletedInstance = bool.Parse(replicationCompletedElement.Value);
                                resourceExtensionInstance.ReplicationCompleted = replicationCompletedInstance;
                            }

                            XElement eulaElement = resourceExtensionsElement.Element(XName.Get("Eula", "http://schemas.microsoft.com/windowsazure"));
                            if (eulaElement != null)
                            {
                                Uri eulaInstance = TypeConversion.TryParseUri(eulaElement.Value);
                                resourceExtensionInstance.Eula = eulaInstance;
                            }

                            XElement privacyUriElement = resourceExtensionsElement.Element(XName.Get("PrivacyUri", "http://schemas.microsoft.com/windowsazure"));
                            if (privacyUriElement != null)
                            {
                                Uri privacyUriInstance = TypeConversion.TryParseUri(privacyUriElement.Value);
                                resourceExtensionInstance.PrivacyUri = privacyUriInstance;
                            }

                            XElement homepageUriElement = resourceExtensionsElement.Element(XName.Get("HomepageUri", "http://schemas.microsoft.com/windowsazure"));
                            if (homepageUriElement != null)
                            {
                                Uri homepageUriInstance = TypeConversion.TryParseUri(homepageUriElement.Value);
                                resourceExtensionInstance.HomepageUri = homepageUriInstance;
                            }

                            XElement isJsonExtensionElement = resourceExtensionsElement.Element(XName.Get("IsJsonExtension", "http://schemas.microsoft.com/windowsazure"));
                            if (isJsonExtensionElement != null && string.IsNullOrEmpty(isJsonExtensionElement.Value) == false)
                            {
                                bool isJsonExtensionInstance = bool.Parse(isJsonExtensionElement.Value);
                                resourceExtensionInstance.IsJsonExtension = isJsonExtensionInstance;
                            }

                            XElement isInternalExtensionElement = resourceExtensionsElement.Element(XName.Get("IsInternalExtension", "http://schemas.microsoft.com/windowsazure"));
                            if (isInternalExtensionElement != null && string.IsNullOrEmpty(isInternalExtensionElement.Value) == false)
                            {
                                bool isInternalExtensionInstance = bool.Parse(isInternalExtensionElement.Value);
                                resourceExtensionInstance.IsInternalExtension = isInternalExtensionInstance;
                            }

                            XElement disallowMajorVersionUpgradeElement = resourceExtensionsElement.Element(XName.Get("DisallowMajorVersionUpgrade", "http://schemas.microsoft.com/windowsazure"));
                            if (disallowMajorVersionUpgradeElement != null && string.IsNullOrEmpty(disallowMajorVersionUpgradeElement.Value) == false)
                            {
                                bool disallowMajorVersionUpgradeInstance = bool.Parse(disallowMajorVersionUpgradeElement.Value);
                                resourceExtensionInstance.DisallowMajorVersionUpgrade = disallowMajorVersionUpgradeInstance;
                            }

                            XElement supportedOSElement = resourceExtensionsElement.Element(XName.Get("SupportedOS", "http://schemas.microsoft.com/windowsazure"));
                            if (supportedOSElement != null)
                            {
                                string supportedOSInstance = supportedOSElement.Value;
                                resourceExtensionInstance.SupportedOS = supportedOSInstance;
                            }

                            XElement companyNameElement = resourceExtensionsElement.Element(XName.Get("CompanyName", "http://schemas.microsoft.com/windowsazure"));
                            if (companyNameElement != null)
                            {
                                string companyNameInstance = companyNameElement.Value;
                                resourceExtensionInstance.CompanyName = companyNameInstance;
                            }

                            XElement publishedDateElement = resourceExtensionsElement.Element(XName.Get("PublishedDate", "http://schemas.microsoft.com/windowsazure"));
                            if (publishedDateElement != null && string.IsNullOrEmpty(publishedDateElement.Value) == false)
                            {
                                DateTime publishedDateInstance = DateTime.Parse(publishedDateElement.Value, CultureInfo.InvariantCulture);
                                resourceExtensionInstance.PublishedDate = publishedDateInstance;
                            }
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
예제 #3
0
        public void CanRegisterUpdateAndUnregisterExtensionImage()
        {
            TestLogTracingInterceptor.Current.Start();
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt    = fixture.GetManagementClient();
                var compute = fixture.GetComputeManagementClient();
                var storage = fixture.GetStorageManagementClient();

                string versionStr = "74.59.0.0";
                string verUpdtStr = "74.60.0.0";

                const string publicSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>"
                                               + @"<xs:schema attributeFormDefault=""unqualified"""
                                               + @"  elementFormDefault=""qualified"""
                                               + @"  xmlns:xs=""http://www.w3.org/2001/XMLSchema"">"
                                               + @"  <xs:element name=""PublicConfig"">"
                                               + @"    <xs:complexType>"
                                               + @"      <xs:sequence>"
                                               + @"        <xs:element name=""UserName"" type=""xs:string"" />"
                                               + @"      </xs:sequence>"
                                               + @"    </xs:complexType>"
                                               + @"  </xs:element>"
                                               + @"</xs:schema>";

                const string privateSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>"
                                                + @"<xs:schema attributeFormDefault=""unqualified"""
                                                + @"  elementFormDefault=""qualified"""
                                                + @"  xmlns:xs=""http://www.w3.org/2001/XMLSchema"">"
                                                + @"  <xs:element name=""PrivateConfig"">"
                                                + @"    <xs:complexType>"
                                                + @"      <xs:sequence>"
                                                + @"        <xs:element name=""Password"" type=""xs:string"" />"
                                                + @"      </xs:sequence>"
                                                + @"    </xs:complexType>"
                                                + @"  </xs:element>"
                                                + @"</xs:schema>";

                const string sampleConfigStr = "TestSampleConfig";

                try
                {
                    string storageName   = TestUtilities.GenerateName("teststorage");
                    string providerName  = TestUtilities.GenerateName("testprovider");
                    string extensionName = TestUtilities.GenerateName("testextension");
                    string location      = mgmt.GetDefaultLocation("Storage", "Compute");

                    const string usWestLocStr = "West US";
                    if (mgmt.Locations.List().Any(
                            c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase)))
                    {
                        location = usWestLocStr;
                    }

                    // create a storage account
                    var storageAccountResult = storage.StorageAccounts.Create(
                        new StorageAccountCreateParameters
                    {
                        Location    = location,
                        Name        = storageName,
                        AccountType = "Standard_LRS"
                    });

                    // get the storage account
                    var keyResult = storage.StorageAccounts.GetKeys(storageName);

                    // build the connection string
                    const string containerStr = "ext";
                    Uri          blobUri      = StorageTestUtilities.UploadFileToBlobStorage(storageName, containerStr, @".\RemoteAccessPlugin.zip");
                    bool         isPublisher  = false;
                    const string errorCodeStr = "ForbiddenError";

                    try
                    {
                        var parameters = new ExtensionImageRegisterParameters
                        {
                            ProviderNameSpace = providerName,
                            Type                 = extensionName,
                            Version              = versionStr,
                            HostingResources     = "VmRole",
                            MediaLink            = blobUri,
                            Label                = providerName,
                            Description          = providerName,
                            BlockRoleUponFailure = false,
                            Certificate          = new ExtensionCertificateConfiguration
                            {
                                StoreLocation       = "LocalMachine",
                                StoreName           = "My",
                                ThumbprintAlgorithm = "sha1",
                                ThumbprintRequired  = true
                            },
                            LocalResources = new List <ExtensionLocalResourceConfiguration>
                            {
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test1",
                                    SizeInMB = 100
                                },
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test2",
                                    SizeInMB = 200
                                }
                            },
                            DisallowMajorVersionUpgrade = true,
                            SampleConfig               = sampleConfigStr,
                            PublishedDate              = DateTime.Now,
                            Eula                       = new Uri("http://test.com"),
                            PrivacyUri                 = new Uri("http://test.com"),
                            HomepageUri                = new Uri("http://test.com"),
                            IsInternalExtension        = true,
                            PrivateConfigurationSchema = privateSchemaStr,
                            PublicConfigurationSchema  = publicSchemaStr,
                            ExtensionEndpoints         = new ExtensionEndpointConfiguration
                            {
                                InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test1",
                                        Port      = 1111,
                                        LocalPort = "*",
                                        Protocol  = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test2",
                                        Port      = 2222,
                                        LocalPort = "22222",
                                        Protocol  = "tcp"
                                    }
                                },
                                InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test1",
                                        Port     = 1111,
                                        Protocol = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test2",
                                        Port     = 2222,
                                        Protocol = "tcp"
                                    },
                                },
                                InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test1",
                                        Protocol     = "tcp",
                                        LocalPort    = "111",
                                        FixedPortMin = 100,
                                        FixedPortMax = 1000
                                    },
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test2",
                                        Protocol     = "tcp",
                                        LocalPort    = "22",
                                        FixedPortMin = 2000,
                                        FixedPortMax = 10000
                                    }
                                }
                            },
                            IsJsonExtension = false,
                            CompanyName     = providerName,
                            SupportedOS     = ExtensionImageSupportedOperatingSystemType.Windows,
                            Regions         = usWestLocStr,
                        };

                        compute.ExtensionImages.Register(parameters);

                        isPublisher = true;

                        bool      found         = false;
                        const int maxRetryTimes = 60;
                        int       retryTime     = 0;
                        VirtualMachineExtensionListResponse.ResourceExtension ext = null;
                        while (!found && retryTime < maxRetryTimes)
                        {
                            Thread.Sleep(TimeSpan.FromMinutes(1.0));

                            ext = compute.VirtualMachineExtensions
                                  .ListVersions(providerName, extensionName)
                                  .FirstOrDefault(e => string.Equals(e.Version, versionStr));

                            if (ext != null)
                            {
                                found = true;
                            }

                            retryTime++;
                        }

                        if (found)
                        {
                            Assert.True(ext != null);

                            Assert.Equal <string>(ext.Name, parameters.Type);
                            Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace);
                            Assert.Equal <string>(ext.Description, parameters.Description);
                            Assert.Equal <string>(ext.SampleConfig, parameters.SampleConfig);
                            Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema);
                            Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema);
                            Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString());
                            Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString());
                            Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString());
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade);
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <string>(ext.CompanyName, parameters.CompanyName);
                            Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS);

                            Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value &&
                                        (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value));
                        }
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    try
                    {
                        var parameters = new ExtensionImageUpdateParameters
                        {
                            ProviderNameSpace = providerName,
                            Type                 = extensionName,
                            Version              = verUpdtStr,
                            HostingResources     = "VmRole",
                            MediaLink            = blobUri,
                            Label                = providerName,
                            Description          = providerName,
                            BlockRoleUponFailure = false,
                            Certificate          = new ExtensionCertificateConfiguration
                            {
                                StoreLocation       = "LocalMachine",
                                StoreName           = "My",
                                ThumbprintAlgorithm = "sha1",
                                ThumbprintRequired  = true
                            },
                            LocalResources = new List <ExtensionLocalResourceConfiguration>
                            {
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test1",
                                    SizeInMB = 100
                                },
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test2",
                                    SizeInMB = 200
                                }
                            },
                            DisallowMajorVersionUpgrade = true,
                            SampleConfig               = sampleConfigStr,
                            PublishedDate              = DateTime.Now,
                            Eula                       = new Uri("http://test.com"),
                            PrivacyUri                 = new Uri("http://test.com"),
                            HomepageUri                = new Uri("http://test.com"),
                            IsInternalExtension        = true,
                            PrivateConfigurationSchema = privateSchemaStr,
                            PublicConfigurationSchema  = publicSchemaStr,
                            ExtensionEndpoints         = new ExtensionEndpointConfiguration
                            {
                                InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test1",
                                        Port      = 1111,
                                        LocalPort = "11111",
                                        Protocol  = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test2",
                                        Port      = 2222,
                                        LocalPort = "*",
                                        Protocol  = "tcp"
                                    }
                                },
                                InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test1",
                                        Port     = 1111,
                                        Protocol = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test2",
                                        Port     = 2222,
                                        Protocol = "tcp"
                                    }
                                },
                                InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test1",
                                        Protocol     = "tcp",
                                        LocalPort    = "11",
                                        FixedPortMin = 100,
                                        FixedPortMax = 1000
                                    },
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test2",
                                        Protocol     = "tcp",
                                        LocalPort    = "22",
                                        FixedPortMin = 2000,
                                        FixedPortMax = 10000
                                    }
                                }
                            },
                            IsJsonExtension = false,
                            CompanyName     = providerName,
                            SupportedOS     = ExtensionImageSupportedOperatingSystemType.Windows,
                            Regions         = usWestLocStr,
                        };

                        compute.ExtensionImages.Update(parameters);

                        bool      found         = false;
                        const int maxRetryTimes = 60;
                        int       retryTime     = 0;
                        VirtualMachineExtensionListResponse.ResourceExtension ext = null;
                        while (!found && retryTime < maxRetryTimes)
                        {
                            Thread.Sleep(TimeSpan.FromMinutes(1.0));

                            ext = compute.VirtualMachineExtensions
                                  .ListVersions(providerName, extensionName)
                                  .FirstOrDefault(e => string.Equals(e.Version, verUpdtStr));

                            if (ext != null)
                            {
                                found = true;
                            }

                            retryTime++;
                        }

                        if (found)
                        {
                            Assert.True(ext != null);

                            Assert.Equal <string>(ext.Name, parameters.Type);
                            Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace);
                            Assert.Equal <string>(ext.Description, parameters.Description);
                            Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema);
                            Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema);
                            Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString());
                            Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString());
                            Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString());
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade);
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <string>(ext.CompanyName, parameters.CompanyName);
                            Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS);

                            Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value &&
                                        (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value));
                        }
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    try
                    {
                        compute.ExtensionImages.Unregister(
                            providerName,
                            extensionName,
                            versionStr);

                        compute.ExtensionImages.Unregister(
                            providerName,
                            extensionName,
                            verUpdtStr);
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    // List Publisher Extensions
                    try
                    {
                        compute.HostedServices.ListPublisherExtensions();
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    compute.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }