Exemplo n.º 1
0
 public void Create(DalMessage entity)
 {
     var message = new Message()
     {
         Id = entity.Id,
         Content = entity.Content,
         DatePublication = entity.DatePublication,
         SenderId = entity.SenderId,
         ThemeId = entity.ThemeId
     };
     context.Set<Message>().Add(message);
 }
        public void ProcessBatch_Subscriberfails_WithFakeStoreProvider()
        {
            TestUtils.TestHelper.autoEvent = new AutoResetEvent(false);

            var m = new Message();

            var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m)
                .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>), false, false).GetMessage();
            var beforeRetryCount = messagePacket.SubscriberMetadataList[0].RetryCount;

            MessagePacket<Message> outputPostProcessMP = default(MessagePacket<Message>);
            string outputMessageId = string.Empty;

            var MessagePubSubChannel = new PublishSubscribeChannel<Message>();

            var stubStoreProvider = new StubIStoreProvider<Message>
            {
                ProcessStoreAsBatchFuncOfMessagePacketOfT0StringBoolean = funct => MessagePubSubChannel.HandleMessageForBatchProcessing(messagePacket, messagePacket.MessageId.ToString()),
                UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket =>
                {
                    outputPostProcessMP = UpdatedMessagepacket;
                    TestUtils.TestHelper.autoEvent.Set();
                    return;
                },
                SubscriberGroupCompletedForMessageString = messageId =>
                {
                    Assert.IsTrue(messagePacket.MessageId.ToString() == messageId);

                    return true;
                }
            };
            MessagePubSubChannel.StorageProvider = stubStoreProvider;

            MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 0, 1));

            MessagePubSubChannel.ProcessBatch();
            TestUtils.TestHelper.autoEvent.WaitOne(); //new TimeSpan(0, 0, 0, 5, 0)
            Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].RetryCount == messagePacket.SubscriberMetadataList[0].RetryCount + 1);
            Assert.IsTrue(outputPostProcessMP.MessageId == messagePacket.MessageId);
            Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList.Count == 1);
            Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].FailedOrTimedOut == true);
        }
        public void HandleMessageForFirstTime_ExceptionThrownMessageTest_WithFakeStoreProvider()
        {
            TestUtils.TestHelper.Subscriber1Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.Subscriber2Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.Subscriber3Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.UpdateMessageStoreEvent = new AutoResetEvent(false);
            TestUtils.TestHelper.SubscriberGroupCompletedEvent = new AutoResetEvent(false);

            var m = new Message { Name = "MyMessage" };

            var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m)
                .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber<Message>), false, false)
                .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>), false, false).GetMessage();

            List<MessagePacket<Message>> outputPostProcessMP = new List<MessagePacket<Message>>();
            string outputMessageId = string.Empty;
            DateTime timelastupdateCalled = default(DateTime);
            DateTime timeGroupCompletedCalled = default(DateTime);

            var MessagePubSubChannel = new PublishSubscribeChannel<Message>();
            var stubStoreProvider = new StubIStoreProvider<Message>
            {
                UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket =>
                {
                    outputPostProcessMP.Add(UpdatedMessagepacket);
                    timelastupdateCalled = DateTime.Now;
                    TestUtils.TestHelper.UpdateMessageStoreEvent.Set();
                    return;
                },
                SubscriberGroupCompletedForMessageString = messageId =>
                {
                    Assert.IsTrue(messagePacket.MessageId.ToString() == messageId);
                    timeGroupCompletedCalled = DateTime.Now;
                    TestUtils.TestHelper.SubscriberGroupCompletedEvent.Set();
                    return true;
                },
            };

            MessagePubSubChannel.StorageProvider = stubStoreProvider;

            MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1))
                .AddSubscriberType(typeof(TestUtils.SpeedySubscriber<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1));

            MessagePubSubChannel.HandleMessageForFirstTime(messagePacket, messagePacket.MessageId.ToString());

            TestUtils.TestHelper.Subscriber1Ran.WaitOne();
            TestUtils.TestHelper.Subscriber3Ran.WaitOne();
            TestUtils.TestHelper.UpdateMessageStoreEvent.WaitOne();
            TestUtils.TestHelper.SubscriberGroupCompletedEvent.WaitOne();

            foreach (var item in outputPostProcessMP)
            {
                Assert.IsTrue(item.MessageId == messagePacket.MessageId);
                Assert.IsTrue(item.SubscriberMetadataList.Count == 1);
                if (item.SubscriberMetadataList[0].Name.Contains("SpeedySubscriberGuaranteedExceptions"))
                {
                    Assert.IsTrue(item.SubscriberMetadataList[0].FailedOrTimedOut == true);
                }
                else
                {
                    Assert.IsTrue(item.SubscriberMetadataList[0].FailedOrTimedOut == false);
                }
            }
            Trace.WriteLine("timelastupdateCalled: " + timelastupdateCalled.TimeOfDay);
            Trace.WriteLine("timeGroupCompletedCa: " + timeGroupCompletedCalled.TimeOfDay);
            Assert.IsTrue(DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) < 0 || DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) == 0);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new Message object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="messageID">Initial value of the MessageID property.</param>
 /// <param name="subscriptionID">Initial value of the SubscriptionID property.</param>
 /// <param name="guid">Initial value of the Guid property.</param>
 /// <param name="messagePutTime">Initial value of the MessagePutTime property.</param>
 /// <param name="timestamp">Initial value of the Timestamp property.</param>
 /// <param name="batchNumber">Initial value of the BatchNumber property.</param>
 /// <param name="messageReadTime">Initial value of the MessageReadTime property.</param>
 public static Message CreateMessage(global::System.Int32 id, global::System.String name, global::System.String messageID, global::System.String subscriptionID, global::System.Guid guid, global::System.DateTime messagePutTime, global::System.Byte[] timestamp, global::System.Int32 batchNumber, global::System.DateTime messageReadTime)
 {
     Message message = new Message();
     message.ID = id;
     message.Name = name;
     message.MessageID = messageID;
     message.SubscriptionID = subscriptionID;
     message.Guid = guid;
     message.MessagePutTime = messagePutTime;
     message.Timestamp = timestamp;
     message.BatchNumber = batchNumber;
     message.MessageReadTime = messageReadTime;
     return message;
 }
        public void HandleMessageForFirstTime_MessageTest_WithFakeStoreProvider()
        {
            TestUtils.TestHelper.Subscriber1Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.Subscriber2Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.Subscriber3Ran = new AutoResetEvent(false);
            TestUtils.TestHelper.UpdateMessageStoreEvent = new AutoResetEvent(false);
            TestUtils.TestHelper.SubscriberGroupCompletedEvent = new AutoResetEvent(false);

            var m = new Message { Name = "MyMessage"};

            var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m)
                .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber<Message>), false, false)
                .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber2<Message>), false, false).GetMessage();

            MessagePacket<Message> outputPostProcessMP = default(MessagePacket<Message>);
            string outputMessageId = string.Empty;
            DateTime timelastupdateCalled = default(DateTime);
            DateTime timeGroupCompletedCalled = default(DateTime);

            var MessagePubSubChannel = new PublishSubscribeChannel<Message>();
            var stubStoreProvider = new StubIStoreProvider<Message>
            {
                UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket =>
                {
                    outputPostProcessMP = UpdatedMessagepacket;
                    timelastupdateCalled = DateTime.Now;
                    TestUtils.TestHelper.UpdateMessageStoreEvent.Set();
                    return;
                },
                SubscriberGroupCompletedForMessageString = messageId =>
                {
                    Assert.IsTrue(messagePacket.MessageId.ToString() == messageId);
                    timeGroupCompletedCalled = DateTime.Now;
                    TestUtils.TestHelper.SubscriberGroupCompletedEvent.Set();
                    return true;
                }
            };
            MessagePubSubChannel.StorageProvider = stubStoreProvider;

            MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriber2<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1))
                .AddSubscriberType(typeof(TestUtils.SpeedySubscriber<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1));

            MessagePubSubChannel.HandleMessageForFirstTime(messagePacket, messagePacket.MessageId.ToString());

            TestUtils.TestHelper.Subscriber1Ran.WaitOne();
            TestUtils.TestHelper.Subscriber2Ran.WaitOne();
            TestUtils.TestHelper.UpdateMessageStoreEvent.WaitOne();
            TestUtils.TestHelper.SubscriberGroupCompletedEvent.WaitOne();

            Assert.IsTrue(outputPostProcessMP.MessageId == messagePacket.MessageId);
            Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList.Count == 1);
            Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].FailedOrTimedOut == false);
            Assert.IsTrue(DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) < 0 || DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) == 0);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Messages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMessages(Message message)
 {
     base.AddObject("Messages", message);
 }
Exemplo n.º 7
0
        private void UpdateDisplayPanel(Entities.Message msg)
        {
            if (msg.Type == MessageType.TextMessage)
            {
                if (msg.User.IPAddress != Me.IPAddress)
                {
                    try
                    {
                        frmChatWindow frm = chatWindows.Where(f => f.SI.IpAddress == msg.User.IPAddress).FirstOrDefault();
                        if (frm == null)
                        {
                            frm              = new frmChatWindow(new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress));
                            frm.FormClosing += Frm_FormClosing;
                            Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress());

                            frm.ClientIPAddress = msg.User.IPAddress;
                            frm.Me = Me;

                            if (chatWindows.Count(x => x.SI.IpAddress == msg.User.IPAddress) == 0)
                            {
                                chatWindows.Add(frm);
                            }
                            //frm.DisplayChat(msg);
                            if (Me.Status == UserStatus.Available)
                            {
                                frm.Show();
                            }
                            else //This is for testing purpose
                            {
                                foreach (StatusIndicator s in flContainer.Controls)
                                {
                                    if (msg.User.IPAddress == s.IpAddress)
                                    {
                                        s.NumberOfUnreadMessages++;
                                        break;
                                    }
                                }
                            }
                            frm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - (Width + frm.Width), Screen.PrimaryScreen.WorkingArea.Height - frm.Height);
                        }
                        else //This is for testing purpose
                        {
                            foreach (StatusIndicator s in flContainer.Controls)
                            {
                                if (msg.User.IPAddress == s.IpAddress)
                                {
                                    s.NumberOfUnreadMessages++;
                                    break;
                                }
                            }
                        }
                        frm.DisplayChat(msg);
                    }
                    catch
                    {
                    }
                }
            }
            else if (msg.Type == MessageType.StatusMessage)
            {
                if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0)
                {
                    usersList.Add(msg.User);
                    StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress);
                    si.Click += Si_Click;
                    si.Width  = flContainer.Width - 2;
                    flContainer.Controls.Add(si);
                }
                else
                {
                    int index = usersList.IndexOf(usersList.Where(x => x.IPAddress == msg.User.IPAddress).First());
                    ((StatusIndicator)flContainer.Controls[index]).Status      = msg.User.Status;
                    ((StatusIndicator)flContainer.Controls[index]).DisplayName = msg.User.DisplayName;
                }
            }
        }
Exemplo n.º 8
0
        private void InitMessages()
        {
            var random = new Random();
            var users = _context.Users.ToList();
            foreach (var user in users)
            {
                var otherUsers = users.Where(x => x.Id != user.Id).ToList();

                foreach (var otherUser in otherUsers)
                {
                    for (var i = 0; i < 50; i++)
                    {
                        var isRead = random.Next()%2 == 0;
                        var isRecipientDeketed = random.Next()%2 == 0;
                        var isSenderDeleted = random.Next()%2 == 0;

                        var message = new Message
                                          {
                                              Recipient = otherUser,
                                              Sender = user,
                                              Title = $"Private message {i}",
                                              Body = $"Private message body {i}",
                                              IsRead = isRead,
                                              IsRecipientDeleted = isRecipientDeketed,
                                              IsSenderDeleted = isSenderDeleted
                                          };
                        _context.Messages.Add(message);
                    }
                }
            }
        }
Exemplo n.º 9
0
        void InvocarServicio()
        {
            TransDepotProxy           proxy   = new TransDepotProxy();
            RequestEquipmentOperation request = new RequestEquipmentOperation();

            request.OceanCarrier = OceanCarrier;

            if (OperationType != null)
            {
                if (OperationType.Equals("E"))
                {
                    request.ReferenceType = ConfigurationManager.AppSettings["ReferenceTypeBK"].ToString();
                }
                else
                {
                    request.ReferenceType = ConfigurationManager.AppSettings["ReferenceTypeBL"].ToString();
                }
            }

            request.ReferenceNumber           = ReferenceNumber;
            request.YardCode                  = ConfigurationManager.AppSettings["DepSanAgustin"].ToString();
            request.ActionType                = ActionType;
            request.ActivityCode              = ActivityCode;
            request.OperationTypeMovementCode = "";
            request.OperationType             = OperationType;
            request.VehiclePlate              = VehiclePlate;
            request.ExecutionDate             = ExecutionDate;
            request.direction                 = Direction;
            request.Status      = Status;
            request.truckerCode = "";
            request.driverCode  = "";

            request.Equipments.Add(new YardOperationEquipment()
            {
                EquipmentNumber          = EquipmentNumber,
                EquipmentTypeSizeISOCode = EquipmentTypeSizeISOCode,
                IsEmpty        = (IsEmpty.Equals("S")) ? true : false,
                IsHazardous    = (IsHazardous.Equals("S")) ? true : false,
                RequiresReview = false
            });

            ResponseEquipmentOperation resp = new ResponseEquipmentOperation();

            try
            {
                resp = proxy.EquipmentOperation(request);
            }catch (Exception ex)
            {
                resp.isValid = false;
                Message msg = new Message();
                msg.message = ex.Message.ToString();
                resp.messages.Add(msg);
                MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

            if (!resp.isValid)
            {
                List <string> listaDestinatarios = new List <string>();
                List <string> listaCopia         = new List <string>();
                List <string> listaCopiaOculta   = new List <string>();

                string destinatarios = ConfigurationManager.AppSettings["Destinatarios"].ToString();
                if (destinatarios != "" && destinatarios.Contains(";"))
                {
                    var correosDestino = destinatarios.Split(';');
                    foreach (string item in correosDestino)
                    {
                        listaDestinatarios.Add(item);
                    }
                }
                else
                {
                    listaDestinatarios.Add(destinatarios);
                }

                string copia = ConfigurationManager.AppSettings["ConCopia"].ToString();
                if (copia != "" && copia.Contains(";"))
                {
                    var correosCopia = copia.Split(';');
                    foreach (string item in correosCopia)
                    {
                        listaCopia.Add(item);
                    }
                }
                else
                {
                    listaCopia.Add(copia);
                }

                string copiaOculta = ConfigurationManager.AppSettings["CopiaOculta"].ToString();
                if (copiaOculta != "" && copiaOculta.Contains(";"))
                {
                    var correosCopiaOculta = copiaOculta.Split(';');
                    foreach (string item in correosCopiaOculta)
                    {
                        listaCopiaOculta.Add(item);
                    }
                }
                else
                {
                    listaCopiaOculta.Add(copiaOculta);
                }

                new ManejadorCorreos().EnviarCorreo(ConfigurationManager.AppSettings["AsuntoCorreoError"].ToString(), resp.messages[0].message, listaDestinatarios, listaCopia, listaCopiaOculta);
            }
            else
            {
                MessageBox.Show("Se procesó correctamente", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 10
0
        public void PublishMessage(string userName, string text)
        {
            text = text?.Trim();
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException(nameof(text));
            }

            var user = this.GetUserByUserName(userName);

            if (null == user)
            {
                return;
            }

            var message = new Message { Text = text, TimeStampUtc = this._dateTimeService.UtcNow };
            if (null == user.Messages)
            {
                //// TODO [FS]: locking???
                user.Messages = new List<Message> { message };
            }
            else
            {
                user.Messages.Add(new Message { Text = text, TimeStampUtc = this._dateTimeService.UtcNow });
            }

            this._userStorage.Save(user);
        }
Exemplo n.º 11
-1
 public void SaveMessageTest()
 {
     MessageService target = new MessageService(); // TODO: Initialize to an appropriate value
     Message input = new Message();
     input.MessageID = "MessageID1";
     input.MessagePutTime = DateTime.Now;
     input.MessageReadTime = DateTime.Now;
     input.Guid = Guid.NewGuid();
     input.Name = "Johnny";
     input.SubscriptionID =  "SubscriptionID1";
     int expected = 1; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.SaveMessage(input);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 12
-1
        public void GetMessageTest()
        {
            MessageService target = new MessageService(); // TODO: Initialize to an appropriate value

            Message input = new Message();
            input.MessageID = "MessageID1";
            input.MessagePutTime = DateTime.Now;
            input.MessageReadTime = DateTime.Now;
            input.Guid = Guid.NewGuid();
            input.Name = "Johnny";
            input.SubscriptionID = "SubscriptionID1";

            var result = target.SaveMessage(input);
            Message actual;
            actual = target.GetMessage(result);
            Assert.AreEqual(1, actual.ID);

            target.DeleteMessage(input);
            actual = target.GetMessage(input.ID);
            Assert.AreEqual(null, actual);
        }