public override void ExecuteCmdlet()
        {
            RemoteAppVm vm = GetVm(CollectionName, UserUpn);
            RestartVmCommandParameter restartDetails = null;
            OperationResultWithTrackingId result = null;

            if (vm == null)
            {
                WriteWarning(string.Format(Commands_RemoteApp.NoVmInCollectionForUser, UserUpn, CollectionName));
                
                return;
            }

            if (vm.LoggedOnUserUpns.Count > 1)
            {
                string otherLoggedInUsers = null;
                string warningCaption = null;
                string warningMessage = null;

                foreach (string user in vm.LoggedOnUserUpns)
                {
                    if (string.Compare(user, UserUpn, true) != 0)
                    {
                        otherLoggedInUsers += "\n" + user;
                    }
                }

                warningMessage = string.Format(Commands_RemoteApp.RestartVmWarningMessage, UserUpn, vm.VirtualMachineName, otherLoggedInUsers);
                warningCaption = string.Format(Commands_RemoteApp.RestartVmWarningCaption, vm.VirtualMachineName);

                WriteWarning(warningMessage);

                if (!ShouldProcess(null, Commands_RemoteApp.GenericAreYouSureQuestion, warningCaption))
                {
                    return;
                }
            }

            restartDetails = new RestartVmCommandParameter(vm.VirtualMachineName);
            restartDetails.LogoffWaitTimeInSeconds = LogoffWaitSeconds <= 0 ? 60 : LogoffWaitSeconds;
            restartDetails.LogoffMessage = string.IsNullOrEmpty(LogoffMessage) ? string.Format(Commands_RemoteApp.DefaultLogoffMessage, restartDetails.LogoffWaitTimeInSeconds) : LogoffMessage;

            result = CallClient(() => Client.Collections.RestartVm(CollectionName, restartDetails), Client.Collections);

            if (result != null)
            {
                TrackingResult trackingId = new TrackingResult(result);
                WriteObject(trackingId);
            }
        }
 /// <summary>
 /// Restarts VM associated with a collection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The RemoteApp collection name containing the VM to be
 /// restarted.
 /// </param>
 /// <param name='details'>
 /// Required. The details of VM to be restarted.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static OperationResultWithTrackingId RestartVm(this ICollectionOperations operations, string collectionName, RestartVmCommandParameter details)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ICollectionOperations)s).RestartVmAsync(collectionName, details);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Restarts VM associated with a collection.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The RemoteApp collection name containing the VM to be
 /// restarted.
 /// </param>
 /// <param name='details'>
 /// Required. The details of VM to be restarted.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static Task<OperationResultWithTrackingId> RestartVmAsync(this ICollectionOperations operations, string collectionName, RestartVmCommandParameter details)
 {
     return operations.RestartVmAsync(collectionName, details, CancellationToken.None);
 }
예제 #4
0
        public void CanRestartVm()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                RemoteAppManagementClient client = GetRemoteAppManagementClient();

                CollectionListResult collectionList = null;
                Assert.DoesNotThrow(() =>
                {
                    collectionList = client.Collections.List();
                });

                Assert.NotNull(collectionList);

                Assert.NotEmpty(collectionList.Collections);

                foreach (Collection collection in collectionList.Collections)
                {
                    CollectionVmsListResult vmsList = null;

                    Assert.DoesNotThrow(() =>
                    {
                        vmsList = client.Collections.ListVms(collection.Name);
                    });

                    Assert.NotNull(vmsList);

                    Assert.NotEmpty(vmsList.Vms);

                    Assert.DoesNotThrow(() =>
                    {
                        RestartVmCommandParameter restartParam = new RestartVmCommandParameter();

                        restartParam.VirtualMachineName = vmsList.Vms[0].VirtualMachineName;
                        restartParam.LogoffMessage = "You will be logged off after 2 minutes";
                        restartParam.LogoffWaitTimeInSeconds = 120;

                        OperationResultWithTrackingId restartResult = client.Collections.RestartVm(collection.Name, restartParam);

                        Assert.True(restartResult.StatusCode == HttpStatusCode.OK);

                        Assert.NotNull(restartResult.TrackingId);
                    });

                    break;
                }
            }
        }