public override void ExecuteCmdlet()
        {
            SessionSendMessageCommandParameter parameter = new SessionSendMessageCommandParameter
            {
                UserUpn = UserUpn,
                Message = Message
            };

            var response = CallClient(() => Client.Collections.SendMessageToSession(CollectionName, parameter), Client.Collections);

            WriteTrackingId(response);
        }
 /// <summary>
 /// Sends message to the session associated with the user UPN
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The RemoteApp collection name where the session exists.
 /// </param>
 /// <param name='sessionMessageParameter'>
 /// Required. The session command parameter to send message to a
 /// session.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static Task<OperationResultWithTrackingId> SendMessageToSessionAsync(this ICollectionOperations operations, string collectionName, SessionSendMessageCommandParameter sessionMessageParameter)
 {
     return operations.SendMessageToSessionAsync(collectionName, sessionMessageParameter, CancellationToken.None);
 }
 /// <summary>
 /// Sends message to the session associated with the user UPN
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The RemoteApp collection name where the session exists.
 /// </param>
 /// <param name='sessionMessageParameter'>
 /// Required. The session command parameter to send message to a
 /// session.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static OperationResultWithTrackingId SendMessageToSession(this ICollectionOperations operations, string collectionName, SessionSendMessageCommandParameter sessionMessageParameter)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ICollectionOperations)s).SendMessageToSessionAsync(collectionName, sessionMessageParameter);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void CanSendMessageToASessionInACollection()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                RemoteAppManagementClient client = GetRemoteAppManagementClient();

                SessionSendMessageCommandParameter parameter = new SessionSendMessageCommandParameter
                {
                    UserUpn = "*****@*****.**",
                    Message = "Hello there!"
                };

                // testing the web fault
                OperationResultWithTrackingId response = null;

                response = client.Collections.SendMessageToSession("simple", parameter);


                Assert.NotNull(response);
                Assert.NotNull(response.TrackingId);
                Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

                AssertLongrunningOperation(client, RemoteAppOperationStatus.Success, response.TrackingId);

                CollectionSessionListResult sessionList = client.Collections.ListSessions("simple");

                Assert.NotNull(sessionList);
                Assert.NotNull(sessionList.Sessions);
                Assert.True(sessionList.StatusCode == HttpStatusCode.OK);
                Assert.NotEmpty(sessionList.Sessions);

                RemoteAppSession session = null;

                foreach (var s in sessionList.Sessions)
                {
                    if (s.UserUpn == parameter.UserUpn)
                    {
                        session = s;
                        break;
                    }
                }

                Assert.NotNull(session);
                Assert.True(session.State == SessionState.Connected);
            }
        }
        public void CanNotSendCommandToASessionOnNonExistingCollection()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                RemoteAppManagementClient client = GetRemoteAppManagementClient();

                SessionCommandParameter parameter = new SessionCommandParameter
                {
                    UserUpn = "*****@*****.**"
                };

                // testing the web fault
                OperationResultWithTrackingId response = null;

                Assert.Throws<CloudException>(() => response = client.Collections.LogoffSession("mycoll", parameter));

                Assert.Throws<CloudException>(() => response = client.Collections.DisconnectSession("mycoll", parameter));

                SessionSendMessageCommandParameter messageParameter = new SessionSendMessageCommandParameter()
                {
                    Message = "Hey there!",
                    UserUpn = "*****@*****.**"
                };

                Assert.Throws<CloudException>(() => response = client.Collections.SendMessageToSession("mycoll", messageParameter));
            }
        }