public static void VipSwap() { const string _fmsVipSwap = "https://management.core.windows.net/{0}/services/hostedservices/{1}"; string prod, stage; GetDeploymentNames(out prod, out stage); if (string.IsNullOrWhiteSpace(stage)) { Console.WriteLine("There is nothing in the staging slot"); return; } try { // create the request var requestUri = new Uri(string.Format(_fmsVipSwap, _devSubscriptionId, _devServiceName)); var api = new AzureMgmtApi { SubscriptionId = _devSubscriptionId, Certificate = AzureMgmtApi.GetCertificate(_certThumbprint) }; // 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 + "Swap", new XElement(ns + "Production", prod), new XElement(ns + "SourceDeployment", stage))); doc.Save(@"c:\users\brobichaud.corp\desktop\VipSwap.xml"); XDocument respBody; string reqId = api.InvokeRequest(requestUri, "POST", HttpStatusCode.Accepted, doc, out respBody); Console.WriteLine("x-ms-request-id: " + reqId); OperationResult result = api.PollGetOperationStatus(reqId, 5, 300); api.DisplayOpResult(result, reqId); } catch (Exception e) { Console.WriteLine("Error encountered: " + e.Message); } }
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); } }