public List<Client.Data.Message> GetMessages()
 {
     MessageServiceClient client = new MessageServiceClient();
     var list = from m in client.GetMessages()
                select new Client.Data.Message { Text = m.Text, CreatedAt = m.CreatedAt };
     return list.ToList();
 }
        public void GetReceivedMessagesTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            string senderID = "5cd7c2f9-60f2-4efd-b8fc-ba12dd4c982e";
            string recipientID = "cf841c27-9a75-41d1-9448-8accff537eb7";

            message message = client.CreateMessage(
                senderID,
                new string[] { recipientID, senderID },
                "First message subject",
                "First message body");

            string firstMsgID = client.SendMessage(message);

            message.recipients = new string[] { senderID, recipientID };
            message.subject = "Second message subject";
            message.body = "Second message body";

            string secondMsgID = client.SendMessage(message);

            message[] messagesSent = client.GetReceivedMessages(recipientID);

            Assert.AreEqual<int>(2, messagesSent.Length);

            client.DeleteMessage(firstMsgID);
            client.DeleteMessage(secondMsgID);
        }
 public ActionResult Outbox()
 {
     using (MessageServiceClient messageServiceClient = new MessageServiceClient())
     {
         return View(messageServiceClient.ReadOutbox(User.Identity.Name).Data);
     }
 }
Example #4
0
        static void AccessService1()
        {
            try
            {
                var proxy = new MessageServiceClient();
                proxy.SetUserNameAndPassword("hhoangvan", "hhoangvan");

                var message = new MessageDto()
                {
                    Message = "Hello request/reply"
                };

                proxy.SendMessage(message);
                proxy.LogMessage(message);

                var result = proxy.GetAll();

                Console.WriteLine("Results: " + result.Count());
            }
            catch (Exception ex)
            {
                Console.WriteLine("-----");

                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }

                Console.WriteLine("-----");
            }
        }
 public ActionResult Sender(string id)
 {
     using (MessageServiceClient messageServiceClient = new MessageServiceClient())
     {
         return View("show", messageServiceClient.ReadMessageSender(id, User.Identity.Name).Data);
     }
 }
        public void DeleteMessageTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            message msg = client.CreateMessage(
                "b4a9a5de-0e36-4bdf-b662-589d81a8d07c",
                new string[] { "098a3d69-45fc-4e1b-991e-f7398bafd1c6" },
                "Delete Message Test Subject",
                "Delete Message Test Message Body");

            msg.attachments = new attachment[] {
                new attachment() {
                    name = "Delete Attachment name",
                    content = Encoding.UTF8.GetBytes("Delete attachment"),
                    link = "http://www.babylon.com/attachment",
                    contentSize = 20,
                    contentSizeSpecified = true
                }};

            string msgID = client.SendMessage(msg);

            Assert.IsFalse(string.IsNullOrEmpty(msgID));

            client.DeleteMessage(msgID);

            message msgFromDB = client.GetMessage(msgID);

            Assert.IsNull(msgFromDB);
        }
Example #7
0
        static void SendMessage(string message)
        {
            try
            {
                var proxy = new MessageServiceClient();
                proxy.SetUserNameAndPassword("hhoangvan", "hhoangvan");
                proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

                var messageDto = new MessageDto()
                {
                    Message = message,
                    SentAt = DateTime.Now
                };

                proxy.SendMessage(messageDto);
                proxy.LogMessage(messageDto);
                proxy.GetAll();

                proxy.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("-----");

                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }

                Console.WriteLine("-----");
            }
        }
        /// <summary>
        /// Creates a service through which messages can be sent to server
        /// </summary>
        /// <param name="key">service authentication key</param>
        public MessageService(string key)
        {
            client = new MessageServiceClient();
            if (key == String.Empty) {
                throw new ArgumentException("Service needs valid authentication key");
            }

            authKey = key;
        }
Example #9
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            InstanceContext      instanceContext = new InstanceContext(this);
            MessageServiceClient client          = new MessageServiceClient(instanceContext);
            User user = new User();

            user.UserId   = int.Parse(Sender.Text);
            user.Username = Username.Text;

            client.Connect(user);
        }
Example #10
0
        public InitializationStateMessageProcessor(ReplicaState replicaState, MessageServiceClient messageServiceClient)
        {
            this.messageServiceClient = messageServiceClient;
            this.replicaState         = replicaState;

            Log.Info("Changed to Initialization State.");

            Task.Factory.StartNew(this.InitProtocol);

            Task.Factory.StartNew(this.StartTimeout);
        }
Example #11
0
 static void Main(string[] args)
 {
     CallBack callback = new CallBack();
     IMessageService messageService = new MessageServiceClient(
        new System.ServiceModel.InstanceContext(callback));
     Console.WriteLine("现在是:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "....");
     Console.WriteLine("20s后接受服务器推送的消息.....(10s推送一次消息)");
     System.Threading.Thread.Sleep(20000);
     messageService.Online();
     Console.ReadKey();
     messageService.Offline();
 }
Example #12
0
        // GET: Home
        public ActionResult Index()
        {
            MessageServiceClient serviceClient = new MessageServiceClient();
            var allMessages = serviceClient.GetAllMessages();

            View(new MessageModel
            {
                Messages = allMessages.ToList()
            });

            return(View());
        }
Example #13
0
        private static MessageServiceClient GetProxy()
        {                       
            EndpointAddress endPoint = new EndpointAddress("http://172.1.0.205:81/CorpSMS.ServiceHost/MessageService.svc");
            //EndpointAddress endPoint = new EndpointAddress("http://localhost:8732/StratCorp.CorpSMS.ServiceLibrary/SMSService/");            
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
            binding.SendTimeout = new TimeSpan(0, 30, 0);

            MessageServiceClient proxy = new MessageServiceClient(binding, endPoint);            

            return proxy;
        }
Example #14
0
        public MainWindow()
        {
            instanceContext     = new InstanceContext(this);
            client              = new MessageServiceClient(instanceContext);
            chatList            = new Dictionary <int, List <MessageViewModel> >();
            currentMessageCount = new Dictionary <int, int>();

            Global.CurrentLoggedInUser.PublicKey = Global.rsaAlgorithm.PublicKey;
            client.Connect(Global.CurrentLoggedInUser);
            InitializeComponent();
            emptyChat();
        }
Example #15
0
        public void Start()
        {
            int lastMessageId = 0;

            while (true)
            {
                if (ClientContext.ChatSession.Any <Message>())
                {
                    lastMessageId = ClientContext.ChatSession.Last().Id;
                }
                try
                {
                    using (var client = new MessageServiceClient(m_ChatServiceNode))
                    {
                        List <Message> newMessages = client.RequestMessages(ClientContext.Token, lastMessageId);

                        if (newMessages == null)
                        {
                            return;
                        }
                        if (newMessages.Any <Message>())
                        {
                            ClientContext.ChatSession.AddRange(newMessages);

                            var buffer = 0;
                            foreach (Message message in newMessages)
                            {
                                var name    = message.Name;
                                var time    = message.Time.ToShortTimeString();
                                var content = message.Content;

                                if (message.Name != ClientContext.Name)
                                {
                                    Console.MoveBufferArea(0, Console.CursorTop, Console.BufferWidth, 1, 0, Console.CursorTop + 1);
                                    buffer = Console.CursorLeft;
                                }

                                Console.CursorLeft = 0;
                                Console.WriteLine("{0}: {1} ({2})", name, content, time);
                            }
                            Console.CursorLeft = buffer;
                        }
                    }
                }
                catch (Exception error)
                {
                    Console.Write("\nServer error: ");
                    Console.WriteLine(error.Message + "\n");
                }
                Thread.Sleep(1000);
            }
        }
        public void CreateMessageTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            message msg = client.CreateMessage(
                "4ab87d67-db83-4364-9ded-d6dd4e616a34",
                new string[] { "0e99b6c2-3633-4154-b628-72e347ac07ad", "5155a63f-485a-487d-81ee-35d8ec5bf2dd" },
                "This is the subject 1",
                "This is the message 1");

            Assert.AreEqual<string>("4ab87d67-db83-4364-9ded-d6dd4e616a34", msg.sender);
            Assert.AreEqual<string>("This is the subject 1", msg.subject);
            Assert.AreEqual<string>("This is the message 1", msg.body);
        }
 public JsonResult ReplyMessage(string id, string title, string content)
 {
     using (MessageServiceClient messageServiceClient = new MessageServiceClient())
     {
         OperationResponse sendResult = messageServiceClient.ReplyMessage(id, title, content.Replace("\n", "<br />"), User.Identity.Name);
         if (sendResult.IsSuccess)
         {
             return Json(new { result = "success", content = sendResult.Message });
         }
         else
         {
             return Json(new { result = "error", content = sendResult.Message });
         }
     }
 }
 public JsonResult ReplyMessage(string id, string title, string content)
 {
     using (MessageServiceClient messageServiceClient = new MessageServiceClient())
     {
         OperationResponse sendResult = messageServiceClient.ReplyMessage(id, title, content.Replace("\n", "<br />"), User.Identity.Name);
         if (sendResult.IsSuccess)
         {
             return(Json(new { result = "success", content = sendResult.Message }));
         }
         else
         {
             return(Json(new { result = "error", content = sendResult.Message }));
         }
     }
 }
 private void Create(object sender, RoutedEventArgs e)
 {
     CreateBulleinImport import = new CreateBulleinImport
     {
         Title = input_Title.Text,
         Context = input_Context.Text,
         BeginTime = GetTime(input_BeginTime.Text),
         EndTime = GetTime(input_EndTime.Text),
         Hide = input_Hide.SelectedIndex == 0,
         Token = DataManager.GetValue<AdministratorExport>(DataKey.IWorld_Backstage_AdministratorInfo).Token
     };
     MessageServiceClient client = new MessageServiceClient();
     client.CreateBulleinCompleted += ShowCreateResult;
     client.CreateBulleinAsync(import);
 }
Example #20
0
        private MessageServiceClient InitializeClient()
        {
            var binding = new BasicHttpBinding()
            {
                SendTimeout = TimeSpan.FromMinutes(1)
                ,
                Security =
                {
                    Mode = BasicHttpSecurityMode.Transport
                           //Mode = BasicHttpSecurityMode.TransportWithMessageCredential,
                           //Message = { ClientCredentialType = BasicHttpMessageCredentialType.UserName }
                }
            };

            var endpointAddress = new EndpointAddress(_url);

            MessageServiceClient client = new MessageServiceClient(binding, endpointAddress);

            return(client);
        }
Example #21
0
        public MessageForm(int chatId, int profileId)
        {
            #region initialize
            InitializeComponent();
            client = new MessageServiceClient(new InstanceContext(this));

            cm = new ContextMenu();
            cm.MenuItems.Add(new MenuItem("Remove", MenuItemNew_Click));

            this.chatId    = chatId;
            this.profileId = profileId;

            if (userListBox.Items.Count == 2)
            {
                rps_btn.Visible = true;
            }
            #endregion

            client.JoinChat(chatId, profileId, "");
        }
Example #22
0
        static void Main(string[] args)
        {
            String text;
            MessageServiceClient serviceClient = new MessageServiceClient();

            Console.WriteLine("Avsluta programmet genom att skriva \"exit\" eller ett tomt meddelande.\n");

            while (true)
            {
                try
                {
                    Console.Write("Skriv ett meddelande: ");
                    text = Console.ReadLine();

                    if (String.Equals(text, "") || String.Equals(text, "exit"))
                    {
                        Environment.Exit(0);
                    }
                    else if (text.Length < 4000)    // SQL nvarchar(MAX)
                    {
                        if (serviceClient.AddNewMessage(text) == true)
                        {
                            Console.WriteLine("Meddelandet \"" + text + "\" har nu sparats i databasen.\n");
                        }
                        else
                        {
                            throw new Exception("Något gick fel och meddelandet kunde inte sparas i databasen.");
                        }
                    }
                    else
                    {
                        throw new Exception("Meddelandet får inte vara mer än 4000 tecken långt.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: " + e.Message + "\n");
                }
            }
        }
Example #23
0
        static void Main(string[] args)
        {
            var client = new MessageServiceClient();

            SimplifiedMessage message;

            try
            {
                message = client.GetMessage(4);
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }

            message.Number = DateTime.Now.Millisecond.ToString();

            Console.Out.WriteLine("Retrieved current message.  Hit enter to update...");
            Console.In.ReadLine();

            try
            {
                client.UpdateMessage(message);
                client.Close();

                Console.Out.WriteLine("Successed!");
            }
            catch (FaultException <ConcurrencyFault> )
            {
                client.Abort();
                Console.Out.WriteLine("Update failed due to a concurrency conflict.");
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
Example #24
0
        static void Main(string[] args)
        {
            var client = new MessageServiceClient();

            SimplifiedMessage message;

            try
            {
                message = client.GetMessage(4);
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }

            message.Number = DateTime.Now.Millisecond.ToString();

            Console.Out.WriteLine("Retrieved current message.  Hit enter to update...");
            Console.In.ReadLine();

            try
            {
                client.UpdateMessage(message);
                client.Close();

                Console.Out.WriteLine("Successed!");
            }
            catch (FaultException<ConcurrencyFault>)
            {
                client.Abort();
                Console.Out.WriteLine("Update failed due to a concurrency conflict.");
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
Example #25
0
        private void UpdateServiceClient()
        {
            if (this._MessageServiceClient != null)
            {
                return;
            }

            var binding = new BasicHttpBinding()
            {
                Name = "basicHttpBinding",
                MaxReceivedMessageSize = 67108864,
            };

            var timeout = new TimeSpan(0, 1, 0);

            binding.SendTimeout        = timeout;
            binding.OpenTimeout        = timeout;
            binding.ReceiveTimeout     = timeout;
            this._MessageServiceClient = new MessageServiceClient(
                binding,
                new EndpointAddress($"http://{this.IpAddress}:8080/Xamarin.Wcf/MessageService"));
        }
Example #26
0
        static void AccessService0()
        {
            try
            {
                var proxy = new MessageServiceClient();
                proxy.SetUserNameAndPassword("hhoangvan1", "hhoangvan1");

                var token = proxy.AuthorizeClient();
                Console.WriteLine("Token " + token);
            }
            catch (Exception ex)
            {
                Console.WriteLine("-----");

                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }

                Console.WriteLine("-----");
            }
        }
Example #27
0
        public GenericActionResult <string> SendEmail(string emailAddress, string subject, string body)
        {
            try
            {
                var messagingService = new MessageServiceClient();

                var receipents = new List <RecipientData>();
                receipents.Add(new RecipientData {
                    EmailAddress = emailAddress, Name = "Pay and Go Team"
                });

                var emailData = new EmailData()
                {
                    IsHtml     = true,
                    Body       = body,
                    Subject    = subject,
                    Recipients = receipents.ToArray()
                };

                messagingService.SendEmail(emailData);

                return(new GenericActionResult <string>()
                {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                _logger.Error(ex);

                return(new GenericActionResult <string>()
                {
                    IsSuccess = false,
                });
            }
        }
Example #28
0
 public MessageServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(MessageServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #29
0
 public MessageServiceClient(EndpointConfiguration endpointConfiguration) :
     base(MessageServiceClient.GetBindingForEndpoint(endpointConfiguration), MessageServiceClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #30
0
 public MessageServiceClient() :
     base(MessageServiceClient.GetDefaultBinding(), MessageServiceClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IMessageService.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #31
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(MessageServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IMessageService));
 }
Example #32
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(MessageServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IMessageService));
 }
        public void SendMessageTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            message msg = client.CreateMessage(
                "54b9da49-bef3-4e2e-a0e5-6dc7539dead2",
                new string[] { "b4a9a5de-0e36-4bdf-b662-589d81a8d07c", "098a3d69-45fc-4e1b-991e-f7398bafd1c6" },
                "Send Message Test Subject",
                "Send Message Test Message Body");

            msg.attachments = new attachment[] {
                new attachment() {
                    name = "Attachment name",
                    content = Encoding.UTF8.GetBytes("hola mundo"),
                    link = "http://www.babylon.com/attachment",
                    contentSize = 20,
                    contentSizeSpecified = true
                }};

            string msgID = client.SendMessage(msg);

            Assert.IsFalse(string.IsNullOrEmpty(msgID));

            message msgFromDB = client.GetMessage(msgID);

            Assert.AreEqual<string>("54b9da49-bef3-4e2e-a0e5-6dc7539dead2", msgFromDB.sender);
            Assert.AreEqual<int>(2, msgFromDB.recipients.Length);
            Assert.AreEqual<string>("Send Message Test Subject", msgFromDB.subject);
            Assert.AreEqual<string>("Send Message Test Message Body", msgFromDB.body);
            Assert.AreEqual<int>(1, msgFromDB.attachments.Length);

            client.DeleteMessage(msgID);
        }
Example #34
0
        public ReplicaState(MessageServiceClient messageServiceClient, Uri url, string serverId)
        {
            this.MessageServiceClient = messageServiceClient;
            this.ServerId             = serverId;
            this.MyUrl = url;

            this.Configuration = new SortedDictionary <string, Uri> {
                { this.ServerId, url }
            };
            this.ReplicasUrl      = new List <Uri>();
            this.Logger           = new List <ClientRequest>();
            this.ClientTable      = new Dictionary <string, Tuple <int, ClientResponse> >();
            this.State            = new InitializationStateMessageProcessor(this, this.MessageServiceClient);
            this.ViewNumber       = 0;
            this.opNumber         = 0;
            this.commitNumber     = 0;
            this.ExecutionQueue   = new OrderedQueue(this);
            this.TupleSpace       = new TupleSpace.TupleSpace();
            this.requestsExecutor = new RequestsExecutor(this, this.MessageServiceClient);
            this.HeartBeats       = new SortedDictionary <string, DateTime>();


            // Handlers
            this.HandlerStateChanged = new EventWaitHandle(false, EventResetMode.ManualReset);
            this.HandlersCommits     = new EventWaitHandle(false, EventResetMode.ManualReset);
            this.HandlersPrepare     = new EventWaitHandle(false, EventResetMode.ManualReset);
            this.HandlersClient      = new ConcurrentDictionary <string, EventWaitHandle>();

            // Task that executes the requests.
            Task.Factory.StartNew(() => {
                while (true)
                {
                    if (this.ExecutionQueue.TryTake(out Executor requestToExecute, Timeout.TIMEOUT_RECOVERY))
                    {
                        requestToExecute.Execute(this.requestsExecutor);
                    }
                    else
                    {
                        this.ChangeToRecoveryState();
                    }
                }
            });

            // Task that checks HeartBeats
            Task.Factory.StartNew(() => {
                while (true)
                {
                    Thread.Sleep(Timeout.TIMEOUT_VIEW_CHANGE);
                    foreach (KeyValuePair <string, DateTime> entry in this.HeartBeats)
                    {
                        if (entry.Value < DateTime.Now.AddMilliseconds(-Timeout.TIMEOUT_HEART_BEAT * 1.1))
                        {
                            int newViewNumber = this.ViewNumber + 1;
                            SortedDictionary <string, Uri> newConfiguration = new SortedDictionary <string, Uri>(
                                this.Configuration
                                .Where(kvp => !kvp.Key.Equals(entry.Key))
                                .ToDictionary(kvp => kvp.Key, kvp => kvp.Value));

                            Log.Debug($"Server {entry.Key} is presumably dead as the HeartBeat timeout expired.");
                            this.ChangeToViewChange(newViewNumber, newConfiguration);
                            break;
                        }
                    }
                }
            });

            // Task that sends the HeartBeats
            Task.Factory.StartNew(() => {
                while (true)
                {
                    Thread.Sleep(Timeout.TIMEOUT_HEART_BEAT);
                    if (!(this.State is NormalStateMessageProcessor))
                    {
                        continue;
                    }
                    Task.Factory.StartNew(() => this.MessageServiceClient.RequestMulticast(
                                              new HeartBeat(this.ServerId),
                                              this.ReplicasUrl.ToArray(),
                                              this.ReplicasUrl.Count,
                                              -1,
                                              false));
                }
            });
        }
 public ChatController(IAuthProvider authProvider)
 {
     _userService = new UserServiceClient();
     _authProvider = authProvider;
     _messageService = new MessageServiceClient();
 }
Example #36
0
        public void Send(string chatId, string profileId, string text)//send message method
        {
            MessageServiceClient client = new MessageServiceClient(new InstanceContext(this));

            client.CreateMessage(Int32.Parse(profileId), text, Int32.Parse(chatId));
        }
Example #37
0
        public void JoinRoom(string chatId, string profileId, string clientId)//joins chat
        {
            MessageServiceClient client = new MessageServiceClient(new InstanceContext(this));

            client.JoinChat(Int32.Parse(chatId), Int32.Parse(profileId), clientId);
        }
Example #38
0
        public void AddMessage(string text)
        {
            MessageServiceClient client = new MessageServiceClient();

            client.AddMessage(text);
        }
Example #39
0
File: Program.cs Project: jazzmz/ps
        static void Main(string[] args)
        {
            MessageServiceClient client = null;

            try
            {
                // Создание клиента сервиса
                client = new MessageServiceClient();

                // Настройки безопасности
                client.ClientCredentials.HttpDigest.ClientCredential.UserName = Properties.Settings.Default.Login;
                client.ClientCredentials.HttpDigest.ClientCredential.Password = Properties.Settings.Default.Password;
                client.ClientCredentials.HttpDigest.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

                // Получение идентификаторов сообщении за указанный период
                DateTime dateFrom = new DateTime(2015, 11, 15);
                DateTime dateTo   = new DateTime(2015, 12, 01);
                #region Output
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(String.Format("Получение идентификаторов сообщении за период с {0} по {1}:{2}", dateFrom.ToString("dd-MM-yyyy"), dateTo.ToString("dd-MM-yyyy"), Environment.NewLine));
                Console.ResetColor();
                #endregion
                int[] messageIds = client.GetMessageIds(dateFrom, dateTo);
                #region Output
                if (messageIds != null && messageIds.Length > 0)
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    foreach (int messageId in messageIds)
                    {
                        Console.WriteLine(messageId);
                    }
                    Console.ResetColor();

                    Console.WriteLine();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Сообщений не найдено");
                    Console.ResetColor();
                }
                #endregion

                if (messageIds != null && messageIds.Length > 0)
                {
                    // Получение контента сообщения по его идентификатору
                    #region Output
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(String.Format("Получение контента сообщения с идентификатором {0}:{1}", messageIds[0], Environment.NewLine));
                    Console.ResetColor();
                    #endregion
                    string messageContent = client.GetMessageContent(messageIds[0]);
                    #region Output
                    if (messageContent != null)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        Console.WriteLine(messageContent);
                        Console.ResetColor();

                        Console.WriteLine();
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                #region Output
                Console.WriteLine(String.Format("ERROR: {0}", ex.Message));
                #endregion
            }
            finally
            {
                if (client != null)
                {
                    // Закрытие соединения
                    client.Close();
                }

                Console.ReadKey();
            }
        }
Example #40
0
 public XLExecuter(MessageServiceClient messageServiceClient, Client client)
 {
     this.messageServiceClient = messageServiceClient;
     this.client = client;
 }
        public void ModifyMessageTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            message msg = client.CreateMessage(
                "098a3d69-45fc-4e1b-991e-f7398bafd1c6",
                new string[] { "b4a9a5de-0e36-4bdf-b662-589d81a8d07c" },
                "Modify Message Test Subject",
                "Modify Message Test Message Body");

            msg.attachments = new attachment[] {
                new attachment() {
                    name = "Modify Attachment name",
                    content = Encoding.UTF8.GetBytes("Modify attachment"),
                    link = "http://www.babylon.com/attachment",
                    contentSize = 20,
                    contentSizeSpecified = true
                }};

            string msgID = client.SendMessage(msg);

            message msgFromDB = client.GetMessage(msgID);

            msgFromDB.subject = "Modified subject";
            msgFromDB.body = "Modified body";
            msgFromDB.attachments = null;

            client.ModifyMessage(msgFromDB);

            message modifiedMsg = client.GetMessage(msgID);

            Assert.IsNotNull(modifiedMsg);
            Assert.AreEqual<string>("Modified subject", modifiedMsg.subject);
            Assert.AreEqual<string>("Modified body", modifiedMsg.body);
            Assert.IsNull(modifiedMsg.attachments);

            client.DeleteMessage(msgID);
        }
Example #42
0
 public void AddMessage(string text)
 {
     MessageServiceClient client = new MessageServiceClient();
     client.AddMessage(text);
 }
        public void GetSentMessagesTest()
        {
            MessageServiceClient client = new MessageServiceClient();

            string senderID = "deec4a6d-cead-4116-a193-a978a5df34bd";
            string recipientID = "aec5db99-8fc2-4a27-8fe5-556d810083e6";

            message message = client.CreateMessage(
                senderID,
                new string[] { recipientID, senderID },
                "First message subject",
                "First message body");

            string firstMsgID = client.SendMessage(message);

            message.recipients = new string[] { senderID, recipientID };
            message.subject = "Second message subject";
            message.body = "Second message body";

            string secondMsgID = client.SendMessage(message);

            message[] messagesSent = client.GetSentMessages(senderID);

            Assert.AreEqual<int>(2, messagesSent.Length);

            client.DeleteMessage(firstMsgID);
            client.DeleteMessage(secondMsgID);
        }
Example #44
0
 public void Init(MessageServiceClient messageServiceClient, Uri url, string serverId)
 {
     this.ReplicaState = new ReplicaState(messageServiceClient, url, serverId);
 }
Example #45
0
 public RequestsExecutor(ReplicaState replicaState, MessageServiceClient messageServiceClient)
 {
     this.replicaState         = replicaState;
     this.messageServiceClient = messageServiceClient;
 }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var cache = HttpRuntime.Cache;

            if (!string.IsNullOrWhiteSpace(ViewDataKey))
            {
                filterContext.Controller.ViewData[ViewDataKey] = cache[CacheKey] ?? new ServiceMessage[0];
            }

            if (cache[CacheKey] != null) return;

            if (string.IsNullOrWhiteSpace(ServiceUrl))
                throw new InvalidOperationException(
                    "Service Url is not valid:  Please set either MessageServiceAppSettingsKey or MessageServiceAppSettingsKey");

            cache[CacheKey] = new ServiceMessage[0];

            var binding = new BasicHttpBinding();

            if (ServiceUrl.StartsWith("https://")) binding.Security.Mode = BasicHttpSecurityMode.Transport;

            var client = new MessageServiceClient(binding, new EndpointAddress(ServiceUrl));

            client.BeginGetMessages(_appName, OnMessagesRecieved, client);
        }
        //处理获取中奖排行的结果
        void ShowGetTopBonusResult(object sender, GetTopBonusCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                Dictionary<string, List<TopBonus>> tD = new Dictionary<string, List<TopBonus>>();
                tD.Add("_all", e.Result.Info);
                DataManager.SetValue(DataKey.IWorld_Client_TopBouns, tD);

                GetBulletinsImport import = new GetBulletinsImport
                {
                    Token = DataManager.GetValue<string>(DataKey.IWorld_Client_Token)
                };
                MessageServiceClient client = new MessageServiceClient();
                client.GetBulletinsCompleted += ShowGetBulletinsResult;
                this.LoadingMessage = "加载系统公告(6/7)...";
                client.GetBulletinsAsync(import);
            }
            else
            {
                ShowLoginError(e.Result.Error);
            }
        }
Example #48
0
 public ChatController(IAuthProvider authProvider)
 {
     _userService    = new UserServiceClient();
     _authProvider   = authProvider;
     _messageService = new MessageServiceClient();
 }
Example #49
0
 public MainWindow()
 {
     instanceContext = new InstanceContext(this);
     client          = new MessageServiceClient(instanceContext);
     InitializeComponent();
 }
        void Remove_do(object sender, EventArgs e)
        {
            NormalPrompt np = (NormalPrompt)sender;
            if (np.DialogResult != true) { return; }
            AdministratorExport aInfo = DataManager.GetValue<AdministratorExport>(DataKey.IWorld_Backstage_AdministratorInfo);

            RemoveBulleinImport import = new RemoveBulleinImport
            {
                Id = this.State.Id,
                Token = aInfo.Token
            };
            MessageServiceClient client = new MessageServiceClient();
            client.RemoveBulleinCompleted += ShowRemoveResult;
            client.RemoveBulleinAsync(import);
        }