Esempio n. 1
0
        public void OnOrder(Order order)
        {
            // invoke event specific for the transaction
            var correlationId = _typeConverter.ToString(order.TransID);

            #region Totally untested code or handling manual transactions

            if (!_persistentStorage.Contains(correlationId))
            {
                correlationId = "manual:" + order.OrderNum + ":" + correlationId;
                var fakeTrans = new Transaction()
                {
                    Comment  = correlationId,
                    IsManual = true
                               // TODO map order properties back to transaction
                               // ideally, make C# property names consistent (Lua names are set as JSON.NET properties via an attribute)
                };
                _persistentStorage.Set(correlationId, fakeTrans);
            }

            #endregion Totally untested code or handling manual transactions

            var tr = _persistentStorage.Get <Transaction>(correlationId);
            if (tr != null)
            {
                lock (tr)
                {
                    tr.OnOrder(order);
                }
            }

            Trace.Assert(tr != null, "Transaction must exist in persistent storage until it is completed and all order messages are recieved");
        }
Esempio n. 2
0
        private async Task SendItemsToCollector()
        {
            IEnumerable <SessionCollection> repo = null;

            var ls = await _persistentStorage.GetLastSyncDateTime();

            if (ls.HasValue && (ls.Value > DateTime.UtcNow.AddMinutes(-this._queueRetentionMinutes)))
            {
                repo = await _persistentStorage.Get();

                if (repo.Sum(g => g.Collection.Payloads.Count) < this._queueSize)
                {
                    return;
                }
            }

            if (repo == null)
            {
                repo = await _persistentStorage.Get();
            }

            bool wasSuccessPublish = false;

            // TODO paralell run
            foreach (var eventCollection in repo)
            {
                var isSuccess = await this._eventPublisher.Send(eventCollection, this._sharedSecretKey);

                if (isSuccess)
                {
                    await _persistentStorage.Delete(eventCollection);

                    wasSuccessPublish = true;
                }
            }

            if (wasSuccessPublish)
            {
                await _persistentStorage.SetLastSyncDateTime(DateTime.UtcNow);
            }
        }