public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { AssociateAddressResponse response = new AssociateAddressResponse(); int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth = 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("associationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.AssociationId = unmarshaller.Unmarshall(context); continue; } } } return(response); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { AssociateAddressResponse response = new AssociateAddressResponse(); int targetDepth = 2; while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("associationId", targetDepth)) { response.AssociationId = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } } } return(response); }
private void btnServerStart_Click(object sender, EventArgs e) { this.btnRefreshStatus.Enabled = false; this.btnServerStart.Enabled = false; this.btnServerStopAll.Enabled = false; //Stop any other ones running first... this.btnServerStopAll_Click(null, null); try { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string AMI = configuration.AppSettings.Settings["AMI"].Value; string IP = configuration.AppSettings.Settings["IPAddress"].Value; string type = configuration.AppSettings.Settings["InstanceType"].Value; string securityGroup = configuration.AppSettings.Settings["SecurityGroup"].Value; string urlToStartupPackage = "WZA_startupPackageURL=" + configuration.AppSettings.Settings["URLToStartupPackage"].Value; bool shouldUseStartupPackage = bool.Parse(configuration.AppSettings.Settings["ShouldUseStartupPackage"].Value); this.statusStripLbl.Text = "Starting a Wowza server - " + DateTime.Now.ToShortTimeString(); RunInstancesRequest req = new RunInstancesRequest(); req.EbsOptimized = false; req.ImageId = AMI; req.InstanceType = InstanceType.FindValue(type); req.MaxCount = 1; req.MinCount = 1; if (shouldUseStartupPackage) { byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(urlToStartupPackage); req.UserData = Convert.ToBase64String(encbuff); } req.SecurityGroupIds = new List <string> { securityGroup }; RunInstancesResponse response = this.EC2.RunInstances(req); //wait AssociateAddressRequest addressReq = new AssociateAddressRequest(); Instance latestInstance = response.Reservation.Instances.OrderBy(o => o.LaunchTime).FirstOrDefault(); int giveUpCount = 0; while (giveUpCount < 20) { var statusRequest = new DescribeInstanceStatusRequest { InstanceIds = { latestInstance.InstanceId } }; var result = this.EC2.DescribeInstanceStatus(statusRequest); if (result.InstanceStatuses.Count > 0 && result.InstanceStatuses[0].InstanceState.Code == 16) { break; } this.GetStatus(false); giveUpCount++; int timeout = 0; while (timeout < 1000) { this.statusStripLbl.Text = "Waiting for the Wowza server to start- " + DateTime.Now.ToShortTimeString(); Application.DoEvents(); System.Threading.Thread.Sleep(100); timeout++; } } this.statusStripLbl.Text = "Associated the IP address " + IP + " to the new server - " + DateTime.Now.ToShortTimeString(); addressReq.InstanceId = latestInstance.InstanceId; addressReq.PublicIp = IP; AssociateAddressResponse addressResponse = this.EC2.AssociateAddress(addressReq); this.GetStatus(false); } catch (Exception ex) { this.statusStripLbl.Text = "Caught Exception: " + ex.Message; } this.btnRefreshStatus.Enabled = true; this.btnServerStart.Enabled = true; this.btnServerStopAll.Enabled = true; }