async Task CleanUpOldOutboxQueue(DateTimeOffset olderThan, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var tx = reliableStateManager.CreateTransaction())
            {
                var currentIndex = 0;

                var cleanConditionalValue = await CleanupOld.TryPeekAsync(tx, LockMode.Default, transactionTimeout, cancellationToken).ConfigureAwait(false);

                while (cleanConditionalValue.HasValue && currentIndex <= 100)
                {
                    var cleanupCommand = cleanConditionalValue.Value;

                    if (cleanupCommand.StoredAt <= olderThan)
                    {
                        await Outbox.TryRemoveAsync(tx, cleanupCommand.MessageId, transactionTimeout, cancellationToken).ConfigureAwait(false);

                        await CleanupOld.TryDequeueAsync(tx, transactionTimeout, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        break;
                    }

                    currentIndex++;
                    cleanConditionalValue = await CleanupOld.TryPeekAsync(tx, LockMode.Default, transactionTimeout, cancellationToken).ConfigureAwait(false);
                }

                await tx.CommitAsync().ConfigureAwait(false);
            }
        }
Esempio n. 2
0
            public Fixture()
            {
                this.Message = new TestMessage()
                {
                    Id          = Guid.NewGuid(),
                    Description = "Test Message Text",
                    Name        = "Test Message Name",
                    MessageDate = DateTime.UtcNow,
                };

                this.MessageMetaData = new MessageMetaData(delay: TimeSpan.FromSeconds(10), correlationId: this.Message.Id.ToString(), messageId: this.Message.Id.ToString(), skipTransient: true);
                string messageBody = JsonConvert.SerializeObject(this.Message);

                this.SerializedMessageMetaData = this.MessageMetaData != null?JsonConvert.SerializeObject(this.MessageMetaData) : null;

                this.MessageBytes = Encoding.UTF8.GetBytes(messageBody);

                this.Outbox = new Outbox <ApplicationDbContext>(new OutboxSettings()
                {
                    BatchSize                = 10,
                    MaxConcurrency           = 1,
                    MaxTries                 = 10,
                    SqlConnectionString      = ConnectionString,
                    DisableTransientDispatch = false,
                });

                var handlerFactory = A.Fake <IServiceFactory>();

                this.MessagingService = new MessagingService(this.Outbox, handlerFactory);
            }
        public void SaveOutboxTest()
        {
            var outbox = new Outbox
            {
                DestinationNumber = "+6281381769915",
                UDH         = "",
                TextDecoded = "tesss",
                MultiPart   = "true"
            };

            var result = _repo.SaveOutbox(outbox);

            Assert.IsTrue(result != 0);

            if (outbox.MultiPart == "true")
            {
                var outboxMultipart = new OutboxMultipart
                {
                    Id               = outbox.Id,
                    UDH              = "",
                    TextDecoded      = "tess #2",
                    SequencePosition = 2
                };

                result = _repo.SaveOutboxMultipart(outboxMultipart);
                Assert.IsTrue(result != 0);
            }
        }
Esempio n. 4
0
        protected override void Listen()
        {
            while (bNetworkAlive)
            {
                try
                {
                    var endPoint = new IPEndPoint(IPAddress.Any, port);
                    var data     = this.UdpClient.Receive(ref endPoint);

                    byte sender = CompareClients(endPoint);
                    if (sender != 0)
                    {
                        Inbox.Enqueue(new NetworkMessage(sender, data));
                    }
                    else
                    {
                        byte clientId = GetAvaliableClientId();
                        Clients.Add(clientId, endPoint);
                        Outbox.Enqueue(new NetworkMessage(clientId, CreateIdMessage(clientId)));

                        Console.WriteLine("Got new client at Id: " + clientId.ToString() + " with address " + endPoint.ToString());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                }
            }
        }
        public async Task RunProcessingAsyncProcessMessagesCorrectlyAsync()
        {
            // Arrange
            var fetcher       = new Mock <IOutboxFetcher>();
            var scopedFactory = new Mock <IServiceScopeFactory>();
            var ilogger       = new Mock <ILogger <Outbox> >();
            var outBox        = new Outbox(fetcher.Object, scopedFactory.Object, ilogger.Object);
            var tokenSource   = new CancellationTokenSource();

            var msg = new TestMessage();

            fetcher.Setup(x => x.ReadOutboxMessagesAsync(tokenSource.Token)).ReturnsAsync(new[] { msg });
            var scope = new Mock <IServiceScope>();

            scopedFactory.Setup(x => x.CreateScope()).Returns(scope.Object);
            var provider = new Mock <IServiceProvider>();

            scope.Setup(x => x.ServiceProvider).Returns(provider.Object);
            var processor = new Mock <IOutboxMessageProcessor>();

            provider.Setup(x => x.GetService(typeof(IOutboxMessageProcessor))).Returns(processor.Object);

            // Act
            var exception = await Record.ExceptionAsync(async() => await outBox.RunProcessingAsync(tokenSource.Token));

            // Assert
            exception.Should().BeNull();
            fetcher.Verify(x => x.ReadOutboxMessagesAsync(tokenSource.Token), Times.Once);
            scopedFactory.Verify(x => x.CreateScope(), Times.Once);
            scope.Verify(x => x.ServiceProvider, Times.Once);
            provider.Verify(x => x.GetService(typeof(IOutboxMessageProcessor)), Times.Once);
            processor.Verify(x => x.TryProcessAsync(msg, tokenSource.Token), Times.Once);
            scope.Verify(x => x.Dispose(), Times.Once);
        }
Esempio n. 6
0
    public override bool Use(Item target)
    {
        if (!base.Use(target))
        {
            return(false);
        }

        // Send letter
        Outbox outbox = target.GetComponent <Outbox>();

        if (outbox != null)
        {
            if (outbox.TrySendOutput(this))
            {
                // hide the letter
                in_outbox = true;
                gameObject.SetActive(false);
                hand.DropHeldItem();

                return(true);
            }
        }

        return(false);
    }
Esempio n. 7
0
        protected async Task <(Func <int, DateTime, bool>, Producer <T>)> CreateWindow(int index, int count, DateTime now, CancellationToken cancellationToken)
        {
            var windowProducer = new WindowProducer <T>(index, WindowDuration, WindowSize);
            await Outbox.WriteAsync(windowProducer, cancellationToken);

            return(NewWindow(count, now, WindowSize, WindowDuration), windowProducer);
        }
Esempio n. 8
0
            public Fixture()
            {
                this.Message = new TestMessage()
                {
                    Id          = Guid.NewGuid(),
                    Description = "Test Message Text",
                    Name        = "Test Message Name",
                    MessageDate = DateTime.UtcNow,
                };

                string messageBody = JsonConvert.SerializeObject(this.Message);

                this.MessageBytes = Encoding.UTF8.GetBytes(messageBody);

                this.Outbox = new Outbox <ApplicationDbContext>(new OutboxSettings()
                {
                    BatchSize                = 5,
                    MaxConcurrency           = 1,
                    MaxTries                 = 3,
                    SqlConnectionString      = ConnectionString,
                    DisableTransientDispatch = true,
                    RetryStrategy            = new ConstantRetryStrategy(0.5)
                });

                var handlerFactory = A.Fake <IServiceFactory>();

                this.MessagingService = new MessagingService(this.Outbox, handlerFactory);
            }
Esempio n. 9
0
        protected override void Send()
        {
            while (bNetworkAlive)
            {
                while (Outbox.Count > 0)
                {
                    NetworkMessage msg;
                    bool           bMsg = Outbox.TryDequeue(out msg);

                    IPEndPoint destination;
                    bool       bDest = Clients.TryGetValue(msg.NetworkDestination, out destination);

                    if (bMsg && bDest)
                    {
                        try
                        {
                            UdpClient.Send(msg.NetworkData, msg.NetworkData.Length, destination);
                        }
                        catch
                        {
                            System.Environment.Exit(0);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        internal async Task CleanupMessagesOlderThan(DateTimeOffset date, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var tx = reliableStateManager.CreateTransaction())
            {
                var iterator = await Cleanup.CreateEnumerableAsync(tx).ConfigureAwait(false);

                var enumerator = iterator.GetAsyncEnumerator();

                var currentIndex      = 0;
                var somethingToCommit = false;
                while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false) && currentIndex <= 100)
                {
                    var cleanupCommand = enumerator.Current;
                    if (cleanupCommand.StoredAt <= date)
                    {
                        await Outbox.TryRemoveAsync(tx, cleanupCommand.MessageId, defaultOperationTimeout, cancellationToken).ConfigureAwait(false);

                        somethingToCommit = true;
                    }
                    currentIndex++;
                }

                if (somethingToCommit)
                {
                    await tx.CommitAsync().ConfigureAwait(false);
                }
            }
        }
Esempio n. 11
0
        public async Task <OutboxMessage> Get(string messageId, ContextBag context)
        {
            StoredOutboxMessage storedOutboxMessage;

            using (var tx = reliableStateManager.CreateTransaction())
            {
                var conditionalValue = await Outbox.TryGetValueAsync(tx, messageId).ConfigureAwait(false);

                if (!conditionalValue.HasValue)
                {
                    return(null);
                }

                storedOutboxMessage = conditionalValue.Value;
            }

            var transportOperations = new TransportOperation[storedOutboxMessage.TransportOperations.Length];

            for (var i = 0; i < storedOutboxMessage.TransportOperations.Length; i++)
            {
                var o = storedOutboxMessage.TransportOperations[i];
                transportOperations[i] = new TransportOperation(o.MessageId, o.Options, o.Body, o.Headers);
            }
            return(new OutboxMessage(messageId, transportOperations));
        }
 protected override async Task UpdateOutbox(Outbox outbox)
 {
     await _graphClient.Cypher.Merge($"(o:{nameof(Outbox)} {{ Id: {{id}} }})")
     .WithParam("id", outbox.Id)
     .Set("o = {outbox}").WithParam("outbox", outbox)
     .ExecuteWithoutResultsAsync();
 }
Esempio n. 13
0
        public async Task Add(Outbox outbox)
        {
            var entity = MapToEntity(outbox);

            _dbContext.Outbox.Add(entity);

            await _dbContext.SaveChangesAsync();
        }
Esempio n. 14
0
        public IActionResult RemoveBySender(int MessageId)
        {
            Outbox Ob = dbContext.Outbox.FirstOrDefault(x => x.MessageId == MessageId);

            Ob.IsDeleted = 1;
            dbContext.SaveChanges();
            return(Redirect("/Message/Sent"));
        }
Esempio n. 15
0
 private void UpdateOutboxValues(Outbox ob)
 {
     ob.OutboxDate   = OutboxDate;
     ob.Subject      = Subject;
     ob.GoingTo      = GoingTo;
     ob.AttachmentNo = Attachements;
     ob.Notes        = Notes;
 }
        public override async Task <Outbox> Save(Outbox outbox)
        {
            await _graphClient.Cypher
            .Create($"(outbox:{nameof(Outbox)})")
            .Set("outbox = {outbox}").WithParam("outbox", outbox)
            .ExecuteWithoutResultsAsync();

            return(outbox);
        }
Esempio n. 17
0
        /// <summary>
        /// Broadcast this vote
        /// </summary>
        public void SendToAll()
        {
            var msg = new Message(MessageType.Vote, IPAddress.Broadcast)
            {
                DataAsString = VotingNumber.ToString()
            };

            Outbox.SendMessage(msg);
        }
Esempio n. 18
0
        public void ViewOutbox()
        {
            panel_body.Controls.Clear();
            Outbox ucClass = new Outbox();

            panel_body.Controls.Add(ucClass);
            InactiveAllnav();
            label_Outbox.ForeColor = System.Drawing.Color.DeepSkyBlue;
        }
        public async Task <TUnitOfWork> Create(Outbox outbox)
        {
            var dbContext  = _dbContextFactory.Invoke();
            var unitOfWork = _unitOfWorkFactory.Invoke();

            await unitOfWork.Init(_defaultOutboxDispatcher, dbContext, outbox);

            return(unitOfWork);
        }
 public EntityFrameworkTopicRepository(
     IKafkaDbContextFactory kafkaDbContextFactory,
     ICapabilityServiceDbContextFactory capabilityServiceDbContextFactory,
     Outbox outbox)
 {
     _capabilityServiceDbContextFactory = capabilityServiceDbContextFactory;
     _kafkaDbContextFactory             = kafkaDbContextFactory;
     _outbox = outbox;
 }
Esempio n. 21
0
        public async Task Update(Outbox outbox)
        {
            var entity = MapToEntity(outbox);

            _dbContext.Outbox.Local.Clear();
            _dbContext.Outbox.Update(entity);

            await _dbContext.SaveChangesAsync();
        }
Esempio n. 22
0
    protected virtual async Task PublishOutgoingMessagesInBatchAsync(List <OutgoingEventInfo> waitingEvents)
    {
        await DistributedEventBus
        .AsSupportsEventBoxes()
        .PublishManyFromOutboxAsync(waitingEvents, OutboxConfig);

        await Outbox.DeleteManyAsync(waitingEvents.Select(x => x.Id).ToArray());

        Logger.LogInformation($"Sent {waitingEvents.Count} events to message broker");
    }
Esempio n. 23
0
 public IEnumerable <string> Create(IEnumerable <ISendable <ITransmittable> > sendables)
 {
     foreach (var sendable in sendables)
     {
         Console.WriteLine(sendable);
         Outbox.Add(sendable);
         _action?.Invoke(sendable.ToString());
         yield return(sendable.ToString());
     }
 }
Esempio n. 24
0
        public OutboxTestsFixture()
        {
            Now               = DateTime.UtcNow;
            Connection        = new Mock <DbConnection>();
            UnitOfWorkContext = new Mock <IUnitOfWorkContext>();
            Settings          = new Mock <ReadOnlySettings>();
            Transaction       = new Mock <DbTransaction> {
                CallBase = true
            };
            Command           = new Mock <DbCommand>();
            Parameters        = new Mock <DbParameterCollection>();
            OutboxTransaction = new OutboxTransaction(Transaction.Object);
            EndpointName      = "SFA.DAS.NServiceBus";

            Events = new List <Event>
            {
                new FooEvent {
                    Created = Now.AddDays(-1)
                },
                new BarEvent {
                    Created = Now
                }
            };

            EventsData = JsonConvert.SerializeObject(Events, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });
            OutboxMessage  = new OutboxMessage(GuidComb.NewGuidComb(), EndpointName, Events);
            OutboxMessages = new List <IOutboxMessageAwaitingDispatch>();

            Parameters.Setup(p => p.Add(It.IsAny <DbParameter>()));
            Command.SetupSet(c => c.CommandText = It.IsAny <string>());
            Command.SetupSet(c => c.Transaction = It.IsAny <DbTransaction>());

            Command.Protected().Setup <DbParameter>("CreateDbParameter").Returns(() =>
            {
                var parameter = new Mock <DbParameter> {
                    CallBase = true
                };

                parameter.SetupProperty(p => p.ParameterName);
                parameter.SetupProperty(p => p.Value);

                return(parameter.Object);
            });

            Command.Protected().Setup <DbParameterCollection>("DbParameterCollection").Returns(Parameters.Object);
            Connection.Protected().Setup <DbTransaction>("BeginDbTransaction", IsolationLevel.Unspecified).Returns(Transaction.Object);
            Connection.Protected().Setup <DbCommand>("CreateDbCommand").Returns(Command.Object);
            UnitOfWorkContext.Setup(c => c.Get <DbConnection>()).Returns(Connection.Object);
            UnitOfWorkContext.Setup(c => c.Get <DbTransaction>()).Returns(Transaction.Object);
            Settings.Setup(s => s.Get <string>("NServiceBus.Routing.EndpointName")).Returns(EndpointName);

            Outbox = new Outbox(Connection.Object, UnitOfWorkContext.Object);
        }
Esempio n. 25
0
 public void Show(Outbox outbox)
 {
     OutboxNo     = outbox.OutboxNo;
     OutboxDate   = outbox.OutboxDate;
     Subject      = outbox.Subject;
     GoingTo      = outbox.GoingTo;
     Attachements = outbox.AttachmentNo;
     Notes        = outbox.Notes;
     IsDeleted    = outbox.Deleted;
     ControlState(ControllerStates.Loaded);
 }
Esempio n. 26
0
        public void SendMessage(SMSMessage message)
        {
            var item = new Outbox
            {
                DestenationNumber = message.DestinationNumber,
                MessageText       = message.MessageText,
                SendingDateTime   = DateTime.Now
            };

            this.SendMessageToSIM(item);
        }
Esempio n. 27
0
        public static SendBox ConverOutboxToSendbox(Outbox obj)
        {
            SendBox send = new SendBox();

            send.DestenationNumber = obj.DestenationNumber;
            send.MessageText       = obj.MessageText;
            send.SendBoxID         = 0;
            send.SendingDateTime   = obj.SendingDateTime;
            send.UpdatedInDb       = obj.UpdatedInDb;
            return(send);
        }
Esempio n. 28
0
 protected override void Send()
 {
     while (bNetworkAlive)
     {
         NetworkMessage msg;
         while (Outbox.TryDequeue(out msg))
         {
             UdpClient.Send(msg.NetworkData, msg.NetworkData.Length);
         }
     }
 }
        public async Task StartOutboxHostedService()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            services.AddHostedService <OutboxHostedService <EntityContext> >();

            var options = new DbContextOptionsBuilder <EntityContext>()
                          .UseInMemoryDatabase($"OutboxHostedService-{Guid.NewGuid()}")
                          .Options;
            var context = new EntityContext(options);
            var outbox  = new Outbox()
            {
                EventType = "foo", Topic = "bar", RoutingKey = "baz", Body = "{}", CorrelationId = Guid.NewGuid().ToString(), MessageId = Guid.NewGuid().ToString(), LockId = Guid.NewGuid().ToString()
            };

            context.Set <Outbox>().Add(outbox);
            await context.SaveChangesAsync().ConfigureAwait(false);

            services.AddSingleton(context);
            var publisher = new Mock <IDomainEventPublisher>();

            publisher.Setup(x => x.PublishAsync(outbox.Body, It.IsAny <EventProperties>()));
            services.AddSingleton <IDomainEventPublisher>(publisher.Object);
            services.AddSingleton(new ReceiverHostedServiceSettings()
            {
                Enabled = true, MessageTypes = new Dictionary <string, Type>()
            });
            services.AddSingleton(new OutboxHostedServiceConfiguration()
            {
                Enabled = true, Interval = 5
            });

            var serviceProvider = services.BuildServiceProvider();

            var service = serviceProvider.GetService <IHostedService>() as OutboxHostedService <EntityContext>;

            CancellationTokenSource source = new CancellationTokenSource();
            await service.StartAsync(source.Token).ConfigureAwait(false);

            await Task.Delay(1000).ConfigureAwait(false);

            var messages = await context.Set <Outbox>().ToListAsync().ConfigureAwait(false);

            Assert.Single(messages);
            Assert.Null(messages[0].LockId);
            Assert.Equal(OutboxStatus.Published, messages[0].Status);
            Assert.NotNull(messages[0].PublishedDate);
            publisher.VerifyAll();

            source.Cancel();
            await service.StopAsync(source.Token).ConfigureAwait(false);
        }
Esempio n. 30
0
 private bool ProcessResponseFromTsp(HttpWebResponse webResponse, string TransactionId)
 {
     try
     {
         Console.Clear();
         if (webResponse.StatusCode == HttpStatusCode.OK)
         {
             Console.WriteLine("\r\nResponse Status Code is OK and StatusDescription is: {0}", webResponse.StatusDescription);
         }
         else
         {
             throw new Exception("web response is null and GISB is not received.");
         }
         StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
         string       fullResponse   = responseReader.ReadToEnd();
         if (string.IsNullOrEmpty(fullResponse))
         {
             AppLogManager(new StringBuilder("Send Nomination File Task Manager Task Manager Send " + TransactionId), "Error", new StringBuilder("In ProcessResponse response is empty."));
             return(false);
         }
         else
         {
             Outbox newFile = _serviceOutbox.GetByTransactionId(Guid.Parse(TransactionId));
             if (newFile != null)
             {
                 newFile.GISB = fullResponse;
                 if (newFile.GISB.Contains("request-status=ok"))
                 {
                     newFile.StatusID = (int)NomStatus.Submitted;
                 }
                 else
                 {
                     newFile.StatusID = (int)NomStatus.GISBError;
                 }
                 _serviceOutbox.Update(newFile);
                 _serviceOutbox.Save();
             }
             TransactionLog Log = _serviceTransactionLog.GetByTransactionId(TransactionId);
             if (Log != null)
             {
                 Log.EndDate = DateTime.Now;
                 _serviceTransactionLog.Update(Log);
                 _serviceTransactionLog.Save();
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         AppLogManager(new StringBuilder("SendNominationFile Task Manager Task Manager Send " + TransactionId), "Error", new StringBuilder("In processResponse " + ex.Message));
         return(false);
     }
 }