Exemple #1
0
        private async void RefreshMessageCollection()
        {
            IsRefreshing = true;
            await Task.Run(() =>
            {
                var Result = _dataRepository.GetAllMessages();
                if (null != Result)
                {
                    foreach (Message m in Result)
                    {
                        if (!Messages.Contains(m))
                        {
                            Messages.Add(m);
                        }
                    }
                }
                else
                {
                    var CommandResult = new OperationResultArgs
                    {
                        IsError    = true,
                        ResultText = string.Format("Failed to get messages from server.{0}Error : {1}", Environment.NewLine, Result.ToString())
                    };
                    RaiseNotification(this, CommandResult);
                }
            });

            IsRefreshing = false;
        }
 /// <summary>
 ///
 /// </summary>
 protected void RaiseNotification(Object Sender, OperationResultArgs EventArgument)
 {
     if (Notification != null)
     {
         Notification(Sender, EventArgument);
     }
 }
        /// <summary>
        /// This is a top level command function.
        /// </summary>
        private async void SendMessage()
        {
            IsSending = true;
            OperationResultArgs CommandResult;
            bool   isError    = true;
            string statusText = string.Empty;

            if (Message.Validate())
            {
                var Result = await WebCommunicator.Post(Message);

                statusText = Message.Status.Text;
                if (Result == HttpStatusCode.OK)
                {
                    isError = false;
                    ClearMessage();
                }
            }
            else
            {
                statusText = "Invalid Message.";
            }

            CommandResult = new OperationResultArgs
            {
                IsError    = isError,
                ResultText = statusText
            };

            _dataRepository.AddMessage(Message);

            RaiseNotification(this, CommandResult);
            IsSending = false;
        }