public void SetAffinityGroupProcess()
 {
     this.ValidateParameters();
     using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
     {
         try
         {
             UpdateAffinityGroupInput updateAffinityGroupInput = new UpdateAffinityGroupInput();
             updateAffinityGroupInput.Label = ServiceManagementHelper.EncodeToBase64String(this.Label);
             UpdateAffinityGroupInput description = updateAffinityGroupInput;
             if (this.Description != null)
             {
                 description.Description = this.Description;
             }
             CmdletExtensions.WriteVerboseOutputForObject(this, description);
             base.RetryCall((string s) => base.Channel.UpdateAffinityGroup(s, this.Name, description));
             Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
             ManagementOperationContext managementOperationContext = new ManagementOperationContext();
             managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
             managementOperationContext.set_OperationId(operation.OperationTrackingId);
             managementOperationContext.set_OperationStatus(operation.Status);
             ManagementOperationContext managementOperationContext1 = managementOperationContext;
             base.WriteObject(managementOperationContext1, true);
         }
         catch (CommunicationException communicationException1)
         {
             CommunicationException communicationException = communicationException1;
             this.WriteErrorDetails(communicationException);
         }
     }
 }
 public GatewayManagementOperationContext SetVirtualNetworkGatewayCommandProcess()
 {
     using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
     {
         try
         {
             UpdateConnection updateConnection = new UpdateConnection();
             SwitchParameter  connect          = this.Connect;
             if (!connect.IsPresent)
             {
                 updateConnection.Operation = UpdateConnectionOperation.Disconnect;
             }
             else
             {
                 updateConnection.Operation = UpdateConnectionOperation.Connect;
             }
             base.RetryCall <GatewayOperationAsyncResponse>((string s) => base.Channel.UpdateVirtualNetworkGatewayConnection(s, this.VNetName, this.LocalNetworkSiteName, updateConnection));
             Operation operation = base.WaitForGatewayOperation(base.CommandRuntime.ToString());
             ManagementOperationContext managementOperationContext = new ManagementOperationContext();
             managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
             managementOperationContext.set_OperationId(operation.OperationTrackingId);
             managementOperationContext.set_OperationStatus(operation.Status);
             ManagementOperationContext managementOperationContext1 = managementOperationContext;
             base.WriteObject(managementOperationContext1, true);
         }
         catch (CommunicationException communicationException1)
         {
             CommunicationException communicationException = communicationException1;
             this.WriteErrorDetails(communicationException);
         }
     }
     return(null);
 }
        public GatewayManagementOperationContext NewVirtualNetworkGatewayCommandProcess()
        {
            Func <string, GatewayOperationAsyncResponse> func = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    NewAzureVNetGatewayCommand newAzureVNetGatewayCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.NewVirtualNetworkGateway(s, this.VNetName);
                    }
                    ((CmdletBase <IGatewayServiceManagement>)newAzureVNetGatewayCommand).RetryCall <GatewayOperationAsyncResponse>(func);
                    Operation operation = base.WaitForGatewayOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
            return(null);
        }
        public void SetWalkUpgradeDomainProcess()
        {
            Action <string>        action = null;
            WalkUpgradeDomainInput walkUpgradeDomainInput = new WalkUpgradeDomainInput();

            walkUpgradeDomainInput.UpgradeDomain = this.DomainNumber;
            WalkUpgradeDomainInput walkUpgradeDomainInput1 = walkUpgradeDomainInput;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    SetAzureWalkUpgradeDomainCommand setAzureWalkUpgradeDomainCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.WalkUpgradeDomainBySlot(s, this.ServiceName, this.Slot, walkUpgradeDomainInput1);
                    }
                    ((CmdletBase <IServiceManagement>)setAzureWalkUpgradeDomainCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
 public void NewAffinityGroupProcess()
 {
     using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
     {
         try
         {
             CreateAffinityGroupInput createAffinityGroupInput = new CreateAffinityGroupInput();
             createAffinityGroupInput.Description = this.Description;
             createAffinityGroupInput.Label       = ServiceManagementHelper.EncodeToBase64String(this.Label);
             createAffinityGroupInput.Location    = this.Location;
             createAffinityGroupInput.Name        = this.Name;
             CmdletExtensions.WriteVerboseOutputForObject(this, createAffinityGroupInput);
             base.RetryCall((string s) => base.Channel.CreateAffinityGroup(s, createAffinityGroupInput));
             Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
             ManagementOperationContext managementOperationContext = new ManagementOperationContext();
             managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
             managementOperationContext.set_OperationId(operation.OperationTrackingId);
             managementOperationContext.set_OperationStatus(operation.Status);
             ManagementOperationContext managementOperationContext1 = managementOperationContext;
             base.WriteObject(managementOperationContext1, true);
         }
         catch (CommunicationException communicationException1)
         {
             CommunicationException communicationException = communicationException1;
             this.WriteErrorDetails(communicationException);
         }
     }
 }
Beispiel #6
0
        protected void ExecuteClientActionInOCS(object input, string operationDescription, Action <string> action, Func <string, Operation> waitOperation)
        {
            IContextChannel contextChannel = Channel as IContextChannel;

            if (contextChannel != null)
            {
                using (new OperationContextScope(contextChannel))
                {
                    try
                    {
                        RetryCall(action);
                        Operation operation = waitOperation(operationDescription);
                        var       context   = new ManagementOperationContext
                        {
                            OperationDescription = operationDescription,
                            OperationId          = operation.OperationTrackingId,
                            OperationStatus      = operation.Status
                        };

                        WriteObject(context, true);
                    }
                    catch (CommunicationException ex)
                    {
                        WriteErrorDetails(ex);
                    }
                }
            }
            else
            {
                RetryCall(action);
            }
        }
        public void RemoveDeploymentProcess()
        {
            Action <string> action = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    RemoveAzureDeploymentCommand removeAzureDeploymentCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.DeleteDeploymentBySlot(s, this.ServiceName, this.Slot);
                    }
                    ((CmdletBase <IServiceManagement>)removeAzureDeploymentCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
Beispiel #8
0
        public OSImage UpdateVMImageProcess(out string operationId)
        {
            operationId = string.Empty;
            OSImage oSImage = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    OSImage imageName = new OSImage();
                    imageName.Name  = this.ImageName;
                    imageName.Label = this.Label;
                    OSImage oSImage1 = imageName;
                    CmdletExtensions.WriteVerboseOutputForObject(this, oSImage1);
                    oSImage = base.RetryCall <OSImage>((string s) => base.Channel.UpdateOSImage(s, this.ImageName, oSImage1));
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
            return(oSImage);
        }
Beispiel #9
0
        public void SetRoleInstanceCountProcess()
        {
            Func <XElement, bool> func = null;

            this.GetCurrentDeployment();
            if (this.currentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        XNamespace             xNamespace = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration";
                        XDocument              xDocument  = XDocument.Parse(ServiceManagementHelper.DecodeFromBase64String(this.currentDeployment.Configuration));
                        IEnumerable <XElement> xElements  = xDocument.Root.Elements(xNamespace + "Role");
                        if (func == null)
                        {
                            func = (XElement p) => string.Compare(p.Attribute("name").Value, this.RoleName, true) == 0;
                        }
                        XElement xElement = xElements.Where <XElement>(func).SingleOrDefault <XElement>();
                        if (xElement != null)
                        {
                            xElement.Element(xNamespace + "Instances").SetAttributeValue("count", this.Count);
                        }
                        using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                        {
                            ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
                            changeConfigurationInput.Configuration = ServiceManagementHelper.EncodeToBase64String(xDocument.ToString());
                            ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
                            CmdletExtensions.WriteVerboseOutputForObject(this, xDocument);
                            base.RetryCall((string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1));
                            Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                            managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext.set_OperationId(operation.OperationTrackingId);
                            managementOperationContext.set_OperationStatus(operation.Status);
                            ManagementOperationContext managementOperationContext1 = managementOperationContext;
                            base.WriteObject(managementOperationContext1, true);
                        }
                    }
                    catch (EndpointNotFoundException endpointNotFoundException1)
                    {
                        EndpointNotFoundException endpointNotFoundException = endpointNotFoundException1;
                        this.WriteErrorDetails(endpointNotFoundException);
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
        public void RemoveVMImageProcess()
        {
            Func <string, OSImage> func   = null;
            Action <string>        action = null;

            try
            {
                Uri             mediaLink = null;
                SwitchParameter deleteVHD = this.DeleteVHD;
                if (deleteVHD.IsPresent)
                {
                    using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        RemoveAzureVMImageCommand removeAzureVMImageCommand = this;
                        if (func == null)
                        {
                            func = (string s) => base.Channel.GetOSImage(s, this.ImageName);
                        }
                        OSImage oSImage = ((CmdletBase <IServiceManagement>)removeAzureVMImageCommand).RetryCall <OSImage>(func);
                        mediaLink = oSImage.MediaLink;
                    }
                }
                using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    RemoveAzureVMImageCommand removeAzureVMImageCommand1 = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.DeleteOSImage(s, this.ImageName);
                    }
                    ((CmdletBase <IServiceManagement>)removeAzureVMImageCommand1).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                SwitchParameter switchParameter = this.DeleteVHD;
                if (switchParameter.IsPresent)
                {
                    Disks.RemoveVHD(base.Channel, base.get_CurrentSubscription().get_SubscriptionId(), mediaLink);
                }
            }
            catch (CommunicationException communicationException1)
            {
                CommunicationException communicationException = communicationException1;
                this.WriteErrorDetails(communicationException);
            }
        }
Beispiel #11
0
 public void SaveVirtualMachineImageProcess()
 {
     if (base.CurrentDeployment != null)
     {
         using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
         {
             try
             {
                 string str2 = this.Name;
                 base.RetryCall((string s) => {
                     string newImageName;
                     IServiceManagement channel = base.Channel;
                     string str           = s;
                     string serviceName   = this.ServiceName;
                     string name          = this.CurrentDeployment.Name;
                     string str1          = str2;
                     string newImageName1 = this.NewImageName;
                     if (string.IsNullOrEmpty(this.NewImageLabel))
                     {
                         newImageName = this.NewImageName;
                     }
                     else
                     {
                         newImageName = this.NewImageLabel;
                     }
                     channel.CaptureRole(str, serviceName, name, str1, newImageName1, newImageName, (PostCaptureAction)Enum.Parse(typeof(PostCaptureAction), "Delete"), null);
                 }
                                );
                 Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                 ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                 managementOperationContext.OperationDescription = base.CommandRuntime.ToString();
                 managementOperationContext.OperationId          = operation.OperationTrackingId;
                 managementOperationContext.OperationStatus      = operation.Status;
                 ManagementOperationContext managementOperationContext1 = managementOperationContext;
                 base.WriteObject(managementOperationContext1, true);
             }
             catch (CommunicationException communicationException1)
             {
                 CommunicationException communicationException = communicationException1;
                 this.WriteErrorDetails(communicationException);
             }
         }
         return;
     }
     else
     {
         return;
     }
 }
Beispiel #12
0
        public void NewHostedServiceProcess()
        {
            string                   serviceName;
            Action <string>          action = null;
            CreateHostedServiceInput createHostedServiceInput = new CreateHostedServiceInput();

            createHostedServiceInput.ServiceName = this.ServiceName;
            if (string.IsNullOrEmpty(this.Label))
            {
                serviceName = this.ServiceName;
            }
            else
            {
                serviceName = this.Label;
            }
            string str = serviceName;

            createHostedServiceInput.Label         = ServiceManagementHelper.EncodeToBase64String(str);
            createHostedServiceInput.Description   = this.Description;
            createHostedServiceInput.AffinityGroup = this.AffinityGroup;
            createHostedServiceInput.Location      = this.Location;
            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    CmdletExtensions.WriteVerboseOutputForObject(this, createHostedServiceInput);
                    NewAzureServiceCommand newAzureServiceCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.CreateHostedService(s, createHostedServiceInput);
                    }
                    ((CmdletBase <IServiceManagement>)newAzureServiceCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         this.ValidateParameters();
         ManagementOperationContext managementOperationContext = this.ReadRDPFileCommandProcess();
         if (managementOperationContext != null)
         {
             base.WriteObject(managementOperationContext, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
        public void SetVirtualNetworkConfigProcess()
        {
            Action <string> action = null;

            this.ValidateParameters();
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(this.ConfigurationPath, FileMode.Open);
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        SetAzureVNetConfigCommand setAzureVNetConfigCommand = this;
                        if (action == null)
                        {
                            action = (string s) => base.Channel.SetNetworkConfiguration(s, fileStream);
                        }
                        ((CmdletBase <IServiceManagement>)setAzureVNetConfigCommand).RetryCall(action);
                        Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                        managementOperationContext.set_OperationId(operation.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
Beispiel #15
0
        public void StopVirtualMachineProcess()
        {
            StopAzureVMCommand.StopAzureVMCommand variable = null;
            string name;

            if (base.CurrentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        StopAzureVMCommand.StopAzureVMCommand variable1 = variable;
                        if (base.ParameterSetName == "ByName")
                        {
                            name = this.Name;
                        }
                        else
                        {
                            name = this.VM.RoleName;
                        }
                        variable1.roleName = name;
                        base.RetryCall((string s) => base.Channel.ShutdownRole(s, this.ServiceName, this.CurrentDeployment.Name, LambdaVar44));
                        Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                        managementOperationContext.set_OperationId(operation.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
 public void SetStorageAccountProcess()
 {
     if (this.Label == null && this.Description == null)
     {
         base.ThrowTerminatingError(new ErrorRecord(new Exception("You must specify a value for either Label or Description."), string.Empty, ErrorCategory.InvalidData, null));
     }
     using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
     {
         try
         {
             UpdateStorageServiceInput updateStorageServiceInput = new UpdateStorageServiceInput();
             bool?geoReplicationEnabled = this.GeoReplicationEnabled;
             if (geoReplicationEnabled.HasValue)
             {
                 bool?nullable = this.GeoReplicationEnabled;
                 updateStorageServiceInput.GeoReplicationEnabled = new bool?(nullable.Value);
             }
             if (this.Description != null)
             {
                 updateStorageServiceInput.Description = this.Description;
             }
             if (this.Label != null)
             {
                 updateStorageServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.Label);
             }
             CmdletExtensions.WriteVerboseOutputForObject(this, updateStorageServiceInput);
             base.RetryCall((string s) => base.Channel.UpdateStorageService(s, this.StorageAccountName, updateStorageServiceInput));
             Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
             ManagementOperationContext managementOperationContext = new ManagementOperationContext();
             managementOperationContext.OperationDescription = base.CommandRuntime.ToString();
             managementOperationContext.OperationId          = operation.OperationTrackingId;
             managementOperationContext.OperationStatus      = operation.Status;
             ManagementOperationContext managementOperationContext1 = managementOperationContext;
             base.WriteObject(managementOperationContext1, true);
         }
         catch (CommunicationException communicationException1)
         {
             CommunicationException communicationException = communicationException1;
             this.WriteErrorDetails(communicationException);
         }
     }
 }
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         string str = this.RemoveVirtualNetworkConfigProcess();
         if (!string.IsNullOrEmpty(str))
         {
             ManagementOperationContext managementOperationContext = new ManagementOperationContext();
             managementOperationContext.set_OperationId(str);
             ManagementOperationContext managementOperationContext1 = managementOperationContext;
             base.WriteObject(managementOperationContext1, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
        public string RemoveVirtualNetworkConfigProcess()
        {
            Action <string> action = null;

            object[] xAttribute = new object[3];
            xAttribute[0] = new XAttribute("xmlns", RemoveAzureVNetConfigCommand.netconfigNamespace.NamespaceName);
            xAttribute[1] = new XAttribute(XNamespace.Xmlns + "xsi", RemoveAzureVNetConfigCommand.instanceNamespace.NamespaceName);
            xAttribute[2] = new XElement(RemoveAzureVNetConfigCommand.netconfigNamespace + "VirtualNetworkConfiguration");
            XElement     xElement     = new XElement(RemoveAzureVNetConfigCommand.netconfigNamespace + "NetworkConfiguration", xAttribute);
            MemoryStream memoryStream = new MemoryStream();
            XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream);

            xElement.WriteTo(xmlWriter);
            xmlWriter.Flush();
            memoryStream.Seek((long)0, SeekOrigin.Begin);
            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    RemoveAzureVNetConfigCommand removeAzureVNetConfigCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.SetNetworkConfiguration(s, memoryStream);
                    }
                    ((CmdletBase <IServiceManagement>)removeAzureVNetConfigCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
            return(null);
        }
        private void ReimageSingleInstance(string instanceName)
        {
            Action <string> action = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                ResetAzureRoleInstanceCommand resetAzureRoleInstanceCommand = this;
                if (action == null)
                {
                    action = (string s) => base.Channel.ReimageDeploymentRoleInstanceBySlot(s, this.ServiceName, this.Slot, instanceName);
                }
                ((CmdletBase <IServiceManagement>)resetAzureRoleInstanceCommand).RetryCall(action);
                Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                managementOperationContext.set_OperationId(operation.OperationTrackingId);
                managementOperationContext.set_OperationStatus(operation.Status);
                ManagementOperationContext managementOperationContext1 = managementOperationContext;
                base.WriteObject(managementOperationContext1, true);
            }
        }
        internal void AddCertificateProcess()
        {
            Action <string> action = null;

            this.ValidateParameters();
            byte[]          certificateData = this.GetCertificateData();
            CertificateFile certificateFile = new CertificateFile();

            certificateFile.Data              = Convert.ToBase64String(certificateData);
            certificateFile.Password          = this.Password;
            certificateFile.CertificateFormat = "pfx";
            CertificateFile certificateFile1 = certificateFile;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    AddAzureCertificateCommand addAzureCertificateCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.AddCertificates(s, this.ServiceName, certificateFile1);
                    }
                    ((CmdletBase <IServiceManagement>)addAzureCertificateCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
        public void RemoveVirtualMachineProcess()
        {
            int count;
            Func <string, Deployment> func    = null;
            Action <string>           action  = null;
            Action <string>           action1 = null;

            if (base.CurrentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    RemoveAzureVMCommand removeAzureVMCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production");
                    }
                    Deployment deployment = ((CmdletBase <IServiceManagement>)removeAzureVMCommand).RetryCall <Deployment>(func);
                    count = deployment.RoleInstanceList.Count;
                }
                using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        if (count <= 1)
                        {
                            RemoveAzureVMCommand removeAzureVMCommand1 = this;
                            if (action1 == null)
                            {
                                action1 = (string s) => base.Channel.DeleteDeploymentBySlot(s, this.ServiceName, "Production");
                            }
                            ((CmdletBase <IServiceManagement>)removeAzureVMCommand1).RetryCall(action1);
                        }
                        else
                        {
                            RemoveAzureVMCommand removeAzureVMCommand2 = this;
                            if (action == null)
                            {
                                action = (string s) => base.Channel.DeleteRole(s, this.ServiceName, base.CurrentDeployment.Name, this.Name);
                            }
                            ((CmdletBase <IServiceManagement>)removeAzureVMCommand2).RetryCall(action);
                        }
                        Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                        managementOperationContext.set_OperationId(operation.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
Beispiel #22
0
 private void PopulateOperationContext(OperationStatusResponse operationStatus, ManagementOperationContext operationContext)
 {
     operationContext.OperationId          = operationStatus.Id;
     operationContext.OperationStatus      = operationStatus.Status.ToString();
     operationContext.OperationDescription = commandRuntime.ToString();
 }
Beispiel #23
0
        private void PopulateOperationContext(string requestId, ManagementOperationContext operationContext)
        {
            OperationStatusResponse operationStatus = managementClient.GetOperationStatus(requestId);

            PopulateOperationContext(operationStatus, operationContext);
        }
        protected override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (CurrentDeploymentNewSM == null)
            {
                throw new ArgumentException(Resources.NoCloudServicePresent);
            }

            ManagementOperationContext context;
            string rdpFilePath = LocalPath ?? Path.GetTempFileName();

            WriteVerboseWithTimestamp(string.Format(Resources.AzureRemoteDesktopBeginOperation, CommandRuntime));
            var desktopFileResponse = this.ComputeClient.VirtualMachines.GetRemoteDesktopFile(this.ServiceName, CurrentDeploymentNewSM.Name, Name + "_IN_0");

            using (var stream = new MemoryStream(desktopFileResponse.RemoteDesktopFile))
            {
                using (var file = File.Create(rdpFilePath))
                {
                    int    count;
                    byte[] buffer = new byte[1000];

                    while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        file.Write(buffer, 0, count);
                    }
                }

                var operation = GetOperation(desktopFileResponse.RequestId);

                WriteVerboseWithTimestamp(string.Format(Resources.AzureRemoteDesktopCompletedOperation, CommandRuntime));

                context = new ManagementOperationContext
                {
                    OperationDescription = CommandRuntime.ToString(),
                    OperationStatus      = operation.Status.ToString(),
                    OperationId          = operation.Id
                };
            }

            if (Launch.IsPresent)
            {
                var startInfo = new ProcessStartInfo
                {
                    CreateNoWindow = true,
                    WindowStyle    = ProcessWindowStyle.Hidden
                };

                if (LocalPath == null)
                {
                    string scriptGuid = Guid.NewGuid().ToString();

                    string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat";
                    using (var scriptStream = File.OpenWrite(launchRDPScript))
                    {
                        var writer = new StreamWriter(scriptStream);
                        writer.WriteLine("start /wait mstsc.exe " + rdpFilePath);
                        writer.WriteLine("del " + rdpFilePath);
                        writer.WriteLine("del " + launchRDPScript);
                        writer.Flush();
                    }

                    startInfo.FileName = launchRDPScript;
                }
                else
                {
                    startInfo.FileName  = "mstsc.exe";
                    startInfo.Arguments = rdpFilePath;
                }

                Process.Start(startInfo);
            }

            WriteObject(context, true);
        }
Beispiel #25
0
        public void SetDeploymentTmpProcess()
        {
            SetAzureDeploymentCommand.SetAzureDeploymentCommand variable = null;
            string mode;
            string base64String;
            string empty = string.Empty;

            if (!string.IsNullOrEmpty(this.Configuration))
            {
                empty = Utility.GetConfiguration(this.Configuration);
            }
            if (string.Compare(base.ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) != 0)
            {
                if (string.Compare(base.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    Action <string>             action = null;
                    UpdateDeploymentStatusInput updateDeploymentStatusInput = new UpdateDeploymentStatusInput();
                    updateDeploymentStatusInput.Status = this.NewStatus;
                    UpdateDeploymentStatusInput updateDeploymentStatusInput1 = updateDeploymentStatusInput;
                    using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        try
                        {
                            SetAzureDeploymentCommand setAzureDeploymentCommand = this;
                            if (action == null)
                            {
                                action = (string s) => base.Channel.UpdateDeploymentStatusBySlot(s, this.ServiceName, this.Slot, updateDeploymentStatusInput1);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand).RetryCall(action);
                            Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                            managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext.set_OperationId(operation.OperationTrackingId);
                            managementOperationContext.set_OperationStatus(operation.Status);
                            ManagementOperationContext managementOperationContext1 = managementOperationContext;
                            base.WriteObject(managementOperationContext1, true);
                        }
                        catch (CommunicationException communicationException1)
                        {
                            CommunicationException communicationException = communicationException1;
                            this.WriteErrorDetails(communicationException);
                        }
                    }
                }
                else
                {
                    Action <string>          action1 = null;
                    ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
                    changeConfigurationInput.Configuration = empty;
                    ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
                    using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        try
                        {
                            CmdletExtensions.WriteVerboseOutputForObject(this, changeConfigurationInput1);
                            SetAzureDeploymentCommand setAzureDeploymentCommand1 = this;
                            if (action1 == null)
                            {
                                action1 = (string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand1).RetryCall(action1);
                            Operation operation1 = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
                            managementOperationContext2.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext2.set_OperationId(operation1.OperationTrackingId);
                            managementOperationContext2.set_OperationStatus(operation1.Status);
                            ManagementOperationContext managementOperationContext3 = managementOperationContext2;
                            base.WriteObject(managementOperationContext3, true);
                        }
                        catch (CommunicationException communicationException3)
                        {
                            CommunicationException communicationException2 = communicationException3;
                            this.WriteErrorDetails(communicationException2);
                        }
                    }
                }
            }
            else
            {
                Func <string, Uri> func    = null;
                Action <string>    action2 = null;
                Action <string>    action3 = null;
                bool flag = false;
                base.CurrentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);
                string currentStorageAccount = base.CurrentSubscription.CurrentStorageAccount;
                if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
                {
                    Uri uri = new Uri(this.Package);
                }
                else
                {
                    if (!string.IsNullOrEmpty(currentStorageAccount))
                    {
                        ProgressRecord progressRecord = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                        base.WriteProgress(progressRecord);
                        flag = true;
                        SetAzureDeploymentCommand variable1 = variable;
                        SetAzureDeploymentCommand setAzureDeploymentCommand2 = this;
                        if (func == null)
                        {
                            func = (string s) => AzureBlob.UploadPackageToBlob(this.CreateChannel(), currentStorageAccount, s, this.Package);
                        }
                        packageUrl = ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand2).RetryCall <Uri>(func);
                    }
                    else
                    {
                        throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
                    }
                }
                SetAzureDeploymentCommand variable2 = variable;
                UpgradeDeploymentInput    upgradeDeploymentInput  = new UpgradeDeploymentInput();
                UpgradeDeploymentInput    upgradeDeploymentInput1 = upgradeDeploymentInput;
                if (this.Mode == null)
                {
                    mode = "Auto";
                }
                else
                {
                    mode = this.Mode;
                }
                upgradeDeploymentInput1.Mode         = mode;
                upgradeDeploymentInput.Configuration = empty;
                upgradeDeploymentInput.PackageUrl    = uri;
                UpgradeDeploymentInput upgradeDeploymentInput2 = upgradeDeploymentInput;
                if (this.Label != null)
                {
                    base64String = ServiceManagementHelper.EncodeToBase64String(this.Label);
                }
                else
                {
                    base64String = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
                }
                upgradeDeploymentInput2.Label = base64String;
                SwitchParameter force = this.Force;
                upgradeDeploymentInput.Force     = new bool?(force.IsPresent);
                variable2.upgradeDeploymentInput = upgradeDeploymentInput;
                if (!string.IsNullOrEmpty(this.RoleName))
                {
                    UpgradeDeploymentInput roleName = this.RoleName;
                }
                using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        CmdletExtensions.WriteVerboseOutputForObject(this, roleName);
                        SetAzureDeploymentCommand setAzureDeploymentCommand3 = this;
                        if (action2 == null)
                        {
                            action2 = (string s) => this.Channel.UpgradeDeploymentBySlot(s, this.ServiceName, this.Slot, this.upgradeDeploymentInput);
                        }
                        ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand3).RetryCall(action2);
                        Operation operation2 = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
                        managementOperationContext4.OperationDescription = base.CommandRuntime.ToString();
                        managementOperationContext4.OperationId          = operation2.OperationTrackingId;
                        managementOperationContext4.OperationStatus      = operation2.Status;
                        ManagementOperationContext managementOperationContext5 = managementOperationContext4;
                        base.WriteObject(managementOperationContext5, true);
                        if (flag)
                        {
                            SetAzureDeploymentCommand setAzureDeploymentCommand4 = this;
                            if (action3 == null)
                            {
                                action3 = (string s) => AzureBlob.DeletePackageFromBlob(base.Channel, currentStorageAccount, s, uri);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand4).RetryCall(action3);
                        }
                    }
                    catch (CommunicationException communicationException5)
                    {
                        CommunicationException communicationException4 = communicationException5;
                        this.WriteErrorDetails(communicationException4);
                    }
                }
            }
        }
Beispiel #26
0
        public void NewAzureVMProcess()
        {
            NewAzureVMCommand.NewAzureVMCommand variable = null;
            int num;
            List <PersistentVMRole> persistentVMRoles  = new List <PersistentVMRole>();
            NewAzureVMCommand       persistentVMRoles1 = this;
            var persistentVMs = new List <PersistentVMRole>();
            SubscriptionData currentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);

            PersistentVM[] vMs = this.VMs;
            for (int i = 0; i < (int)vMs.Length; i++)
            {
                PersistentVM uri = vMs[i];
                if (uri.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(uri.OSVirtualHardDisk.DiskName))
                {
                    CloudStorageAccount currentStorageAccount = null;
                    try
                    {
                        currentStorageAccount = currentSubscription.GetCurrentStorageAccount(base.Channel);
                    }
                    catch (EndpointNotFoundException endpointNotFoundException)
                    {
                        throw new ArgumentException("CurrentStorageAccount is not accessible. Ensure the current storage account is accessible and in the same location or affinity group as your cloud service.");
                    }
                    if (currentStorageAccount != null)
                    {
                        DateTime now      = DateTime.Now;
                        string   roleName = uri.RoleName;
                        if (uri.OSVirtualHardDisk.DiskLabel != null)
                        {
                            roleName = string.Concat(roleName, "-", uri.OSVirtualHardDisk.DiskLabel);
                        }
                        object[] serviceName = new object[6];
                        serviceName[0] = this.ServiceName;
                        serviceName[1] = roleName;
                        serviceName[2] = now.Year;
                        serviceName[3] = now.Month;
                        serviceName[4] = now.Day;
                        serviceName[5] = now.Millisecond;
                        string str         = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", serviceName);
                        string absoluteUri = currentStorageAccount.BlobEndpoint.AbsoluteUri;
                        if (!absoluteUri.EndsWith("/"))
                        {
                            absoluteUri = string.Concat(absoluteUri, "/");
                        }
                        uri.OSVirtualHardDisk.MediaLink = new Uri(string.Concat(absoluteUri, "vhds/", str));
                    }
                    else
                    {
                        throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storage account to set it.");
                    }
                }
                foreach (DataVirtualHardDisk dataVirtualHardDisk in uri.DataVirtualHardDisks)
                {
                    if (dataVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(dataVirtualHardDisk.DiskName))
                    {
                        CloudStorageAccount cloudStorageAccount = currentSubscription.GetCurrentStorageAccount(base.Channel);
                        if (cloudStorageAccount != null)
                        {
                            DateTime dateTime  = DateTime.Now;
                            string   roleName1 = uri.RoleName;
                            if (dataVirtualHardDisk.DiskLabel != null)
                            {
                                roleName1 = string.Concat(roleName1, "-", dataVirtualHardDisk.DiskLabel);
                            }
                            object[] year = new object[6];
                            year[0] = this.ServiceName;
                            year[1] = roleName1;
                            year[2] = dateTime.Year;
                            year[3] = dateTime.Month;
                            year[4] = dateTime.Day;
                            year[5] = dateTime.Millisecond;
                            string str1         = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", year);
                            string absoluteUri1 = cloudStorageAccount.BlobEndpoint.AbsoluteUri;
                            if (!absoluteUri1.EndsWith("/"))
                            {
                                absoluteUri1 = string.Concat(absoluteUri1, "/");
                            }
                            dataVirtualHardDisk.MediaLink = new Uri(string.Concat(absoluteUri1, "vhds/", str1));
                        }
                        else
                        {
                            throw new ArgumentException("CurrentStorageAccount is not set or not accessible. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
                        }
                    }
                    if (uri.DataVirtualHardDisks.Count <DataVirtualHardDisk>() <= 1)
                    {
                        continue;
                    }
                    Thread.Sleep(1);
                }
                PersistentVMRole persistentVMRole = new PersistentVMRole();
                persistentVMRole.AvailabilitySetName  = uri.AvailabilitySetName;
                persistentVMRole.ConfigurationSets    = uri.ConfigurationSets;
                persistentVMRole.DataVirtualHardDisks = uri.DataVirtualHardDisks;
                persistentVMRole.OSVirtualHardDisk    = uri.OSVirtualHardDisk;
                persistentVMRole.RoleName             = uri.RoleName;
                persistentVMRole.RoleSize             = uri.RoleSize;
                persistentVMRole.RoleType             = uri.RoleType;
                persistentVMRole.Label = uri.Label;
                PersistentVMRole persistentVMRole1 = persistentVMRole;
                persistentVMRoles1.persistentVMs.Add(persistentVMRole1);
            }
            new List <string>();
            Operation operation = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    if (base.ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase))
                    {
                        CreateHostedServiceInput createHostedServiceInput = new CreateHostedServiceInput();
                        createHostedServiceInput.AffinityGroup = this.AffinityGroup;
                        createHostedServiceInput.Location      = this.Location;
                        createHostedServiceInput.ServiceName   = this.ServiceName;
                        if (this.ServiceDescription != null)
                        {
                            createHostedServiceInput.Description = this.ServiceDescription;
                        }
                        else
                        {
                            DateTime now1          = DateTime.Now;
                            DateTime universalTime = now1.ToUniversalTime();
                            string   str2          = string.Format("Implicitly created hosted service{0}", universalTime.ToString("yyyy-MM-dd HH:mm"));
                            createHostedServiceInput.Description = str2;
                        }
                        if (this.ServiceLabel != null)
                        {
                            createHostedServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceLabel);
                        }
                        else
                        {
                            createHostedServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
                        }
                        CmdletExtensions.WriteVerboseOutputForObject(this, createHostedServiceInput);
                        base.RetryCall((string s) => base.Channel.CreateHostedService(s, createHostedServiceInput));
                        Operation operation1 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
                        managementOperationContext.set_OperationId(operation1.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation1.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                    return;
                }
            }
            if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
            {
                if (base.CurrentDeployment != null)
                {
                    if (this.VNetName != null || this.DnsSettings != null || !string.IsNullOrEmpty(this.DeploymentLabel) || !string.IsNullOrEmpty(this.DeploymentName))
                    {
                        base.WriteWarning("VNetName, DnsSettings, DeploymentLabel or DeploymentName Name can only be specified on new deployments.");
                    }
                }
                else
                {
                    using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        try
                        {
                            if (string.IsNullOrEmpty(this.DeploymentName))
                            {
                                this.DeploymentName = this.ServiceName;
                            }
                            if (string.IsNullOrEmpty(this.DeploymentLabel))
                            {
                                this.DeploymentLabel = this.ServiceName;
                            }
                            Deployment deployment = new Deployment();
                            deployment.DeploymentSlot = "Production";
                            deployment.Name           = this.DeploymentName;
                            deployment.Label          = this.DeploymentLabel;
                            List <Role> roles = new List <Role>();
                            roles.Add(persistentVMRoles1.persistentVMs[0]);
                            deployment.RoleList           = new RoleList(roles);
                            deployment.VirtualNetworkName = this.VNetName;
                            Deployment dnsSetting = deployment;
                            if (this.DnsSettings != null)
                            {
                                dnsSetting.Dns            = new DnsSettings();
                                dnsSetting.Dns.DnsServers = new DnsServerList();
                                DnsServer[] dnsSettings = this.DnsSettings;
                                for (int j = 0; j < (int)dnsSettings.Length; j++)
                                {
                                    DnsServer dnsServer = dnsSettings[j];
                                    dnsSetting.Dns.DnsServers.Add(dnsServer);
                                }
                            }
                            CmdletExtensions.WriteVerboseOutputForObject(this, dnsSetting);
                            base.RetryCall((string s) => base.Channel.CreateDeployment(s, this.ServiceName, dnsSetting));
                            Operation operation2 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", persistentVMRoles1.persistentVMs[0].RoleName));
                            ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
                            managementOperationContext2.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", persistentVMRoles1.persistentVMs[0].RoleName));
                            managementOperationContext2.set_OperationId(operation2.OperationTrackingId);
                            managementOperationContext2.set_OperationStatus(operation2.Status);
                            ManagementOperationContext managementOperationContext3 = managementOperationContext2;
                            base.WriteObject(managementOperationContext3, true);
                        }
                        catch (CommunicationException communicationException3)
                        {
                            CommunicationException communicationException2 = communicationException3;
                            if (communicationException2 as EndpointNotFoundException == null)
                            {
                                this.WriteErrorDetails(communicationException2);
                                return;
                            }
                            else
                            {
                                throw new Exception("Cloud Service does not exist. Specify -Location or -AffinityGroup to create one.");
                            }
                        }
                        this.createdDeployment = true;
                    }
                }
                if (!this.createdDeployment && base.CurrentDeployment != null)
                {
                    this.DeploymentName = base.CurrentDeployment.Name;
                }
                if (this.createdDeployment)
                {
                    num = 1;
                }
                else
                {
                    num = 0;
                }
                int             num1   = num;
                Action <string> action = null;
                while (num1 < persistentVMRoles1.persistentVMs.Count)
                {
                    if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
                        {
                            try
                            {
                                CmdletExtensions.WriteVerboseOutputForObject(this, persistentVMRoles1.persistentVMs[num1]);
                                NewAzureVMCommand newAzureVMCommand = this;
                                if (action == null)
                                {
                                    action = (string s) => base.Channel.AddRole(s, this.ServiceName, this.DeploymentName, persistentVMRoles[num1]);
                                }
                                ((CmdletBase <IServiceManagement>)newAzureVMCommand).RetryCall(action);
                                Operation operation3 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", persistentVMRoles1.persistentVMs[num1].RoleName));
                                ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
                                managementOperationContext4.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", persistentVMRoles1.persistentVMs[num1].RoleName));
                                managementOperationContext4.set_OperationId(operation3.OperationTrackingId);
                                managementOperationContext4.set_OperationStatus(operation3.Status);
                                ManagementOperationContext managementOperationContext5 = managementOperationContext4;
                                base.WriteObject(managementOperationContext5, true);
                            }
                            catch (CommunicationException communicationException5)
                            {
                                CommunicationException communicationException4 = communicationException5;
                                this.WriteErrorDetails(communicationException4);
                                return;
                            }
                        }
                        NewAzureVMCommand.NewAzureVMCommand variable1 = variable;
                        variable1.i = variable1.i + 1;
                    }
                    else
                    {
                        return;
                    }
                }
                return;
            }
        }
        public ManagementOperationContext ReadRDPFileCommandProcess()
        {
            Func <string, Stream> func = null;

            if (base.CurrentDeployment != null)
            {
                ManagementOperationContext managementOperationContext = null;
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    string localPath    = this.LocalPath;
                    string tempFileName = localPath;
                    if (localPath == null)
                    {
                        tempFileName = Path.GetTempFileName();
                    }
                    string str = tempFileName;
                    try
                    {
                        GetAzureRemoteDesktopFileCommand getAzureRemoteDesktopFileCommand = this;
                        if (func == null)
                        {
                            func = (string s) => base.Channel.DownloadRDPFile(s, this.ServiceName, base.CurrentDeployment.Name, string.Concat(this.Name, "_IN_0"));
                        }
                        Stream stream = ((CmdletBase <IServiceManagement>)getAzureRemoteDesktopFileCommand).RetryCall <Stream>(func);
                        using (stream)
                        {
                            FileStream fileStream = File.Create(str);
                            using (fileStream)
                            {
                                byte[] numArray = new byte[0x3e8];
                                while (true)
                                {
                                    int num  = stream.Read(numArray, 0, (int)numArray.Length);
                                    int num1 = num;
                                    if (num <= 0)
                                    {
                                        break;
                                    }
                                    fileStream.Write(numArray, 0, num1);
                                }
                            }
                            Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext1 = new ManagementOperationContext();
                            managementOperationContext1.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext1.set_OperationStatus(operation.Status);
                            managementOperationContext1.set_OperationId(operation.OperationTrackingId);
                            managementOperationContext = managementOperationContext1;
                        }
                        SwitchParameter launch = this.Launch;
                        if (launch.IsPresent)
                        {
                            ProcessStartInfo processStartInfo = new ProcessStartInfo();
                            processStartInfo.CreateNoWindow = true;
                            processStartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                            ProcessStartInfo processStartInfo1 = processStartInfo;
                            ProcessStartInfo processStartInfo2 = new ProcessStartInfo();
                            processStartInfo2.CreateNoWindow = true;
                            processStartInfo2.WindowStyle    = ProcessWindowStyle.Hidden;
                            if (this.LocalPath != null)
                            {
                                processStartInfo1.FileName  = "mstsc.exe";
                                processStartInfo1.Arguments = str;
                            }
                            else
                            {
                                Guid       guid        = Guid.NewGuid();
                                string     str1        = guid.ToString();
                                string     str2        = string.Concat(Path.GetTempPath(), str1, ".bat");
                                FileStream fileStream1 = File.OpenWrite(str2);
                                using (fileStream1)
                                {
                                    StreamWriter streamWriter = new StreamWriter(fileStream1);
                                    streamWriter.WriteLine(string.Concat("start /wait mstsc.exe ", str));
                                    streamWriter.WriteLine(string.Concat("del ", str));
                                    streamWriter.WriteLine(string.Concat("del ", str2));
                                    streamWriter.Flush();
                                }
                                processStartInfo1.FileName = str2;
                            }
                            Process.Start(processStartInfo1);
                        }
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
                return(managementOperationContext);
            }
            else
            {
                throw new ArgumentException("Cloud Service is not present or there is no virtual machine deployment.");
            }
        }
        protected override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (CurrentDeploymentNewSM == null)
            {
                throw new ArgumentException(Resources.NoCloudServicePresent);
            }

            ManagementOperationContext context;
            string rdpFilePath = LocalPath ?? Path.GetTempFileName();
            WriteVerboseWithTimestamp(string.Format(Resources.AzureRemoteDesktopBeginOperation, CommandRuntime));
            var desktopFileResponse = this.ComputeClient.VirtualMachines.GetRemoteDesktopFile(this.ServiceName, CurrentDeploymentNewSM.Name, Name + "_IN_0");
            using (var stream = new MemoryStream(desktopFileResponse.RemoteDesktopFile))
            {
                using (var file = File.Create(rdpFilePath))
                {
                    int count;
                    byte[] buffer = new byte[1000];

                    while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        file.Write(buffer, 0, count);
                    }
                }

                var operation = GetOperationNewSM(desktopFileResponse.RequestId);

                WriteVerboseWithTimestamp(string.Format(Resources.AzureRemoteDesktopCompletedOperation, CommandRuntime));

                context = new ManagementOperationContext
                {
                    OperationDescription = CommandRuntime.ToString(),
                    OperationStatus = operation.Status.ToString(),
                    OperationId = operation.Id
                };
            }

            if (Launch.IsPresent)
            {
                var startInfo = new ProcessStartInfo
                {
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                };
                        
                if (LocalPath == null)
                {
                    string scriptGuid = Guid.NewGuid().ToString();

                    string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat";
                    using (var scriptStream = File.OpenWrite(launchRDPScript))
                    {
                        var writer = new StreamWriter(scriptStream);
                        writer.WriteLine("start /wait mstsc.exe " + rdpFilePath);
                        writer.WriteLine("del " + rdpFilePath);
                        writer.WriteLine("del " + launchRDPScript);
                        writer.Flush();
                    }

                    startInfo.FileName = launchRDPScript;
                }
                else
                {
                    startInfo.FileName = "mstsc.exe";
                    startInfo.Arguments = rdpFilePath;
                }

                Process.Start(startInfo);
            }

            WriteObject(context, true);
        }
Beispiel #29
0
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (CurrentDeployment == null)
            {
                throw new ArgumentException("Cloud Service is not present or there is no virtual machine deployment.");
            }

            ManagementOperationContext context = null;

            string rdpFilePath = LocalPath ?? Path.GetTempFileName();

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                WriteVerboseWithTimestamp(string.Format("Begin Operation: {0}", CommandRuntime.ToString()));

                using (var stream = RetryCall(s => Channel.DownloadRDPFile(s, ServiceName, CurrentDeployment.Name, Name + "_IN_0")))
                {
                    using (var file = File.Create(rdpFilePath))
                    {
                        int    count;
                        byte[] buffer = new byte[1000];

                        while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            file.Write(buffer, 0, count);
                        }
                    }

                    Operation operation = GetOperation();

                    WriteVerboseWithTimestamp(string.Format("Completed Operation: {0}", CommandRuntime.ToString()));

                    context = new ManagementOperationContext
                    {
                        OperationDescription = CommandRuntime.ToString(),
                        OperationStatus      = operation.Status,
                        OperationId          = operation.OperationTrackingId
                    };
                }
            }
            if (Launch.IsPresent)
            {
                var startInfo = new ProcessStartInfo()
                {
                    CreateNoWindow = true,
                    WindowStyle    = ProcessWindowStyle.Hidden
                };

                if (LocalPath == null)
                {
                    string scriptGuid = Guid.NewGuid().ToString();

                    string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat";
                    using (var scriptStream = File.OpenWrite(launchRDPScript))
                    {
                        var writer = new StreamWriter(scriptStream);
                        writer.WriteLine("start /wait mstsc.exe " + rdpFilePath);
                        writer.WriteLine("del " + rdpFilePath);
                        writer.WriteLine("del " + launchRDPScript);
                        writer.Flush();
                    }

                    startInfo.FileName = launchRDPScript;
                }
                else
                {
                    startInfo.FileName  = "mstsc.exe";
                    startInfo.Arguments = rdpFilePath;
                }

                Process.Start(startInfo);
            }

            WriteObject(context, true);
        }
Beispiel #30
0
        public void MoveDeploymentProcess()
        {
            Func <string, Deployment> func   = null;
            Action <string>           action = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    new List <PersistentVMRoleContext>();
                    MoveAzureDeploymentCommand moveAzureDeploymentCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production");
                    }
                    Deployment deployment = ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand).RetryCall <Deployment>(func);
                    if (deployment.RoleList != null && string.Compare(deployment.RoleList[0].RoleType, "PersistentVMRole", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new ArgumentException("Cannot Move Deployments with Virtual Machines Present");
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                }
            }
            string deploymentName = this.GetDeploymentName("Production");
            string str            = this.GetDeploymentName("Staging");

            if (str != null)
            {
                SwapDeploymentInput swapDeploymentInput = new SwapDeploymentInput();
                swapDeploymentInput.SourceDeployment = str;
                swapDeploymentInput.Production       = deploymentName;
                using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        CmdletExtensions.WriteVerboseOutputForObject(this, swapDeploymentInput);
                        MoveAzureDeploymentCommand moveAzureDeploymentCommand1 = this;
                        if (action == null)
                        {
                            action = (string s) => base.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput);
                        }
                        ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand1).RetryCall(action);
                        Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                        managementOperationContext.set_OperationId(operation.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                    catch (CommunicationException communicationException3)
                    {
                        CommunicationException communicationException2 = communicationException3;
                        this.WriteErrorDetails(communicationException2);
                    }
                }
                return;
            }
            else
            {
                throw new ArgumentException("The Staging deployment slot is empty.");
            }
        }
        public void NewPaaSDeploymentProcess()
        {
            NewAzureDeploymentCommand.NewAzureDeploymentCommand variable = null;
            Func <string, Deployment> func    = null;
            Func <string, Uri>        func1   = null;
            Action <string>           action  = null;
            Action <string>           action1 = null;
            bool flag = false;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    new List <PersistentVMRoleContext>();
                    NewAzureDeploymentCommand newAzureDeploymentCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production");
                    }
                    Deployment deployment = ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand).RetryCall <Deployment>(func);
                    if (deployment.RoleList != null && string.Compare(deployment.RoleList[0].RoleType, "PersistentVMRole", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new ArgumentException("Cannot Create New Deployment with Virtual Machines Present");
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null && !base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                }
            }
            string currentStorageAccount = base.get_CurrentSubscription().get_CurrentStorageAccount();

            if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                Uri uri = new Uri(this.Package);
            }
            else
            {
                ProgressRecord progressRecord = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                base.WriteProgress(progressRecord);
                flag = true;
                NewAzureDeploymentCommand.NewAzureDeploymentCommand variable1 = variable;
                NewAzureDeploymentCommand newAzureDeploymentCommand1          = this;
                if (func1 == null)
                {
                    func1 = (string s) => AzureBlob.UploadPackageToBlob(base.Channel, currentStorageAccount, s, this.Package);
                }
                variable1.packageUrl = ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand1).RetryCall <Uri>(func1);
            }
            CreateDeploymentInput createDeploymentInput = new CreateDeploymentInput();

            createDeploymentInput.PackageUrl    = uri;
            createDeploymentInput.Configuration = Utility.GetConfiguration(this.Configuration);
            createDeploymentInput.Label         = ServiceManagementHelper.EncodeToBase64String(this.Label);
            createDeploymentInput.Name          = this.Name;
            SwitchParameter doNotStart = this.DoNotStart;

            createDeploymentInput.StartDeployment = new bool?(!doNotStart.IsPresent);
            SwitchParameter treatWarningsAsError = this.TreatWarningsAsError;

            createDeploymentInput.TreatWarningsAsError = new bool?(treatWarningsAsError.IsPresent);
            CreateDeploymentInput createDeploymentInput1 = createDeploymentInput;

            using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    ProgressRecord progressRecord1 = new ProgressRecord(0, "Please wait...", "Creating the new deployment");
                    base.WriteProgress(progressRecord1);
                    CmdletExtensions.WriteVerboseOutputForObject(this, createDeploymentInput1);
                    NewAzureDeploymentCommand newAzureDeploymentCommand2 = this;
                    if (action == null)
                    {
                        action = (string s) => this.Channel.CreateOrUpdateDeployment(s, this.ServiceName, this.Slot, this.deploymentInput);
                    }

                    ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand2).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.OperationDescription = base.CommandRuntime.ToString();
                    managementOperationContext.OperationId          = operation.OperationTrackingId;
                    managementOperationContext.OperationStatus      = operation.Status;
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                    if (flag)
                    {
                        NewAzureDeploymentCommand newAzureDeploymentCommand3 = this;
                        if (action1 == null)
                        {
                            action1 = (string s) => AzureBlob.DeletePackageFromBlob(base.Channel, currentStorageAccount, s, uri);
                        }
                        ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand3).RetryCall(action1);
                    }
                }
                catch (CommunicationException communicationException3)
                {
                    CommunicationException communicationException2 = communicationException3;
                    this.WriteErrorDetails(communicationException2);
                }
            }
        }
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (CurrentDeployment == null)
            {
                throw new ArgumentException("Cloud Service is not present or there is no virtual machine deployment.");
            }

            ManagementOperationContext context = null;

            string rdpFilePath = LocalPath ?? Path.GetTempFileName();
            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                using (var stream = RetryCall(s => Channel.DownloadRDPFile(s, ServiceName, CurrentDeployment.Name, Name + "_IN_0")))
                {
                    using (var file = File.Create(rdpFilePath))
                    {
                        int count;
                        byte[] buffer = new byte[1000];

                        while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            file.Write(buffer, 0, count);
                        }
                    }

                    Operation operation = WaitForOperation(CommandRuntime.ToString());

                    context = new ManagementOperationContext
                                  {
                                      OperationDescription = CommandRuntime.ToString(),
                                      OperationStatus = operation.Status,
                                      OperationId = operation.OperationTrackingId
                                  };
                }
            }
            if (Launch.IsPresent)
            {
                var startInfo = new ProcessStartInfo()
                {
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                };

                if (LocalPath == null)
                {
                    string scriptGuid = Guid.NewGuid().ToString();

                    string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat";
                    using (var scriptStream = File.OpenWrite(launchRDPScript))
                    {
                        var writer = new StreamWriter(scriptStream);
                        writer.WriteLine("start /wait mstsc.exe " + rdpFilePath);
                        writer.WriteLine("del " + rdpFilePath);
                        writer.WriteLine("del " + launchRDPScript);
                        writer.Flush();
                    }

                    startInfo.FileName = launchRDPScript;
                }
                else
                {
                    startInfo.FileName = "mstsc.exe";
                    startInfo.Arguments = rdpFilePath;
                }

                Process.Start(startInfo);
            }

            WriteObject(context, true);
        }