/// <summary> /// Internal constructor which accept broker as connection /// </summary> internal AsyncAzureOperation(AzureManagementBroker broker, string operationId, bool completed) { this.completed = completed; // We really only need the client from broker this.client = new AzureManagementClient(broker.certificate, broker.subscriptionId); this.status = AzureOperationStatus.InProgress; this.errorCode = null; this.errorMessage = null; this.operationId = operationId; }
/// <summary> /// Refreshes the current cached state of the operation /// </summary> private void Refresh() { // Query Azure for an update AzureManagementResponse response = client.SubmitRequest(RequestType.GET, "2009-10-01", "operations/{0}", this.operationId); // Read the status from XML response and update state accordingly XmlNode statusNode = response.GetXmlNode("Status"); switch (statusNode.InnerText) { case "InProgress": this.status = AzureOperationStatus.InProgress; break; case "Succeeded": this.status = AzureOperationStatus.Succeeded; break; case "Failed": this.status = AzureOperationStatus.Failed; break; default: throw new InvalidOperationException("Failure to query"); } // Mark the operation as completed if necessary if (this.status != AzureOperationStatus.InProgress) { this.completed = true; } // Populate failure information if necessary if (this.status == AzureOperationStatus.Failed) { XmlNode errorNode = response.GetXmlNode("Error"); this.errorCode = response.GetXmlValue(errorNode, "Code"); this.errorMessage = response.GetXmlValue(errorNode, "Message"); } }