Beispiel #1
0
        protected void ExecuteClientActionInOCS(object input, string operationDescription, Action <string> action)
        {
            IContextChannel contextChannel = null;

            try
            {
                contextChannel = Channel.ToContextChannel();
            }
            catch (Exception)
            {
                // Do nothing, proceed.
            }

            if (contextChannel != null)
            {
                object context = null;

                using (new OperationContextScope(contextChannel))
                {
                    Operation operation = null;

                    WriteVerboseWithTimestamp(string.Format("Begin Operation: {0}", operationDescription));

                    try
                    {
                        RetryCall(action);
                        operation = GetOperation();
                    }
                    catch (ServiceManagementClientException ex)
                    {
                        WriteErrorDetails(ex);
                    }

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

                    if (operation != null)
                    {
                        context = new ManagementOperationContext
                        {
                            OperationDescription = operationDescription,
                            OperationId          = operation.OperationTrackingId,
                            OperationStatus      = operation.Status
                        };
                    }
                }

                if (context != null)
                {
                    WriteObject(context, true);
                }
            }
            else
            {
                RetryCall(action);
            }
        }
Beispiel #2
0
        protected void ExecuteClientAction(object input, string operationDescription, Action <string> action)
        {
            Operation operation = null;

            WriteVerboseWithTimestamp(string.Format("Begin Operation: {0}", operationDescription));

            RetryCall(action);
            operation = GetOperation();

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

            if (operation != null)
            {
                var context = new ManagementOperationContext
                {
                    OperationDescription = operationDescription,
                    OperationId          = operation.OperationTrackingId,
                    OperationStatus      = operation.Status
                };

                WriteObject(context, true);
            }
        }
        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);
        }