Beispiel #1
0
        public static string UpdateConfig(string slot, XElement docConfig)
        {
            const string _fmtChangeDeployment = "https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}/?comp=config";

            try
            {
                var config = new StringWriter();
                docConfig.Save(config);

                // build xml body to post
                XNamespace ns  = "http://schemas.microsoft.com/windowsazure";
                var        doc = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
                                               new XElement(ns + "ChangeConfiguration",
                                                            new XElement(ns + "Configuration", DataEncoder.ToBase64(config.ToString()))));

                var requestUri = new Uri(string.Format(_fmtChangeDeployment, _devSubscriptionId, _devServiceName, slot));
                var api        = new AzureMgmtApi
                {
                    SubscriptionId = _devSubscriptionId,
                    Certificate    = AzureMgmtApi.GetCertificate(_certThumbprint)
                };

                XDocument responseBody;
                string    reqId = api.InvokeRequest(requestUri, "POST", HttpStatusCode.Accepted, doc, out responseBody);
                if (!string.IsNullOrWhiteSpace(reqId))
                {
                    Console.WriteLine("x-ms-request-id: " + reqId);
                }

                OperationResult result = api.PollGetOperationStatus(reqId, 5, 300);
                api.DisplayOpResult(result, reqId);
                return(reqId);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error encountered: " + e.Message);
                return(null);
            }
        }