Exemplo n.º 1
0
        public void SendMessagesFor(Advert objectWithEventsToBroadcast)
        {
            var client = new MessagingClient(_logger, "172.17.0.1");

            // whitelist of events that have associated MQ messages sent
            var whiteList = new List <string>()
            {
                "AdvertPostedEvent",
                "AdvertPostedToStockEvent",
                "AdvertPublishedEvent"
            };

            var whiteListed = objectWithEventsToBroadcast.GetChanges()
                              .Where(m => whiteList.Contains(m.GetType().Name));

            foreach (var message in whiteListed)
            {
                if (message.GetType().ToString() == "GoFish.Advert.AdvertPostedToStockEvent")
                {
                    var dto = _mapper.Map <Advert, AddAdvertToStockDto>(objectWithEventsToBroadcast);
                    dto.StockQuantity = ((AdvertPostedToStockEvent)message).StockQuantity;
                    client.SendMessage(message.GetType().ToString().Replace("Event", string.Empty), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto)));
                }
                else
                {
                    var dto = _mapper.Map <Advert, AdvertDto>(objectWithEventsToBroadcast);
                    client.SendMessage(message.GetType().ToString().Replace("Event", string.Empty), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto)));
                }
            }
        }
Exemplo n.º 2
0
        static void cdynesvc()
        {
            EventLog appLog = new EventLog();

            appLog.Source = "Application";

            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

            string tophone;

            MessagingClient        client = new MessagingClient("mms2wsHttpBinding");
            OutgoingMessageRequest req    = new OutgoingMessageRequest();

            req.LicenseKey = new Guid(""); //put your CDYNE API Key here
            req.UseMMS     = false;

            service.Credentials           = new WebCredentials("username", "password", "domainname.local");
            service.Url                   = new Uri("https://mail.contoso.com/EWS/Exchange.asmx"); //put the URL to your Exchange EWS server here.
            service.UseDefaultCredentials = false;

            FindItemsResults <Item> findResults = service.FindItems(
                WellKnownFolderName.Inbox,
                new ItemView(1));

            foreach (Item item in findResults.Items)
            {
                if (item.Subject.Contains("Keyword"))
                {
                    tophone = "5555555555"; //cell phone number in the US
                    req.To  = new string[] { tophone };

                    req.Body = item.Subject;
                    OutgoingMessageResponse[] resp = client.SendMessage(req);
                    Console.Write(item.Subject);

                    item.Delete(DeleteMode.HardDelete);

                    appLog.WriteEntry("CDYNE SMS Sent Keyword SMS", EventLogEntryType.Information);
                }
                else
                {
                    tophone = "5555555556";
                    req.To  = new string[] { tophone };

                    req.Body = item.Subject;
                    OutgoingMessageResponse[] resp = client.SendMessage(req);
                    Console.Write(item.Subject);

                    item.Delete(DeleteMode.HardDelete);

                    appLog.WriteEntry("CDYNE SMS Sent Other SMS", EventLogEntryType.Information);
                }
            }
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            using (var client = new MessagingClient())
                client.SendMessage("test message");

            Console.WriteLine("Message sent.  Press <ENTER> to exit.");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends the specified result to the target client
        /// </summary>
        /// <param name="result"></param>
        /// <param name="messageId"></param>
        private void sendresult(Result result, int messageId = -1)
        {
            if (messageId < 0)
            {
                return;
            }

            string message = String.Format("result:{0};message_id:{1};", (int)result, messageId);

            MessagingClient.SendMessage(this.Recipient, message);
        }
        public void CheckTCPConnection()
        {
            PacketFactory packetFactory = new PacketFactory();

            MessagingClient clientObject = new MessagingClient(packetFactory);

            Assert.IsTrue(clientObject.ConnectToServer("user1"));

            Thread.Sleep(2000);
            MessagingClient clientObject2 = new MessagingClient(packetFactory);

            Assert.IsTrue(clientObject2.ConnectToServer("user2"));
            while (true)
            {
            }
            Assert.IsTrue(clientObject.SendMessage(null));
            Assert.IsTrue(clientObject2.SendMessage(null));
        }
Exemplo n.º 6
0
        public void SendMessagesFor(StockItem objectToSend)
        {
            var client = new MessagingClient(_logger, "172.17.0.1");

            var dto = _mapper.Map <StockItem, StockItemDto>(objectToSend);

            // whitelist of events that have associated MQ messages sent
            var whiteList = new List <string>()
            {
                "StockItemCreatedEvent",
                "StockItemSoldEvent"
            };

            var whiteListed = objectToSend.GetChanges()
                              .Where(m => whiteList.Contains(m.GetType().Name));

            foreach (var message in whiteListed)
            {
                client.SendMessage(message.GetType().ToString().Replace("Event", string.Empty), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto)));
            }
        }
        private void SendMessageAsync(object data)
        {
            var mData = data as MessageData;

            try
            {
                if (MessagingClient.IsConnected)
                {
                    if (mData != null)
                    {
                        MessagingClient.SendMessage(FormatMessage(mData.Command, mData.Value));
                    }
                }
                else if (LocalSettings.StartMessagingClient && !Reconnecting)
                {
                    Reconnect();
                }
            }
            catch (Exception)
            {
                //AppServices.MainDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(Reconnect));
            }
        }