/// <summary>
 ///     失败的微讯消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 public FailMobiSageMessageTransaction(IMessageTransportChannel <BaseMessage> channel)
     : base(channel)
 {
     Identity = new TransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
Пример #2
0
 /// <summary>
 ///     失败的微讯消息事务,提供了相关的基本操作
 /// </summary>
 public FailMobiSageMetadataTransaction(string iep)
 {
     _iep     = iep;
     Identity = new TransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
Пример #3
0
 /// <summary>
 ///     失败的微讯消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="lease">事务生命租期租约</param>
 /// <param name="channel">消息通信信道</param>
 public FailMobiSageMetadataTransaction(ILease lease, IMessageTransportChannel <MetadataContainer> channel)
     : base(lease, channel)
 {
     Identity = new TransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
Пример #4
0
        public Task WaitAsync(TransactionIdentity transactionIdentity, TimeSpan timeout)
        {
            Contract.Requires(transactionIdentity != null);
            Contract.Ensures(Contract.Result <Task>() != null);

            throw new NotImplementedException();
        }
        private async Task CheckChanges()
        {
            var client = new QBitNinjaClient(settings.ApiUrl, Network.Main);

            OnNewCheckCycleStarted?.Invoke(this, EventArgs.Empty);

            foreach (var monitoringElement in monitoringList.ToList())
            {
                var from  = new BlockFeature(SpecialFeature.Last);
                var until = new BlockFeature(monitoringElement.Until.BlockHeight);

                var balance =
                    await client.GetBalanceBetween(new BalanceSelector(monitoringElement.Address), from, until).ConfigureAwait(false);

                if (balance == null)
                {
                    throw new PaymentMonitorException($"Can't get {monitoringElement.Address} balance");
                }


                var monitorUntilTxid   = monitoringElement.Until.TransactionId;
                var oldToNewOperations = balance.Operations.Where(t => t.ReceivedCoins != null).ToList();

                if (oldToNewOperations.Count == 0)
                {
                    continue;
                }

                oldToNewOperations.Reverse();
                if (monitorUntilTxid != uint256.Zero && oldToNewOperations.Exists(x => x.TransactionId == monitorUntilTxid))
                {
                    oldToNewOperations = oldToNewOperations.SkipWhile(x => x.TransactionId != monitorUntilTxid).ToList();
                    oldToNewOperations.RemoveAll(x => x.TransactionId == monitorUntilTxid);
                }

                foreach (var operation in oldToNewOperations)
                {
                    if (operation.Confirmations < settings.MinConfirmations)
                    {
                        continue;
                    }

                    var lku = new TransactionIdentity
                    {
                        BlockHeight   = operation.Height,
                        TransactionId = operation.TransactionId,
                    };


                    var info = new MoneyEventInfo(monitoringElement.Address, lku,
                                                  operation.ReceivedCoins.Cast <Coin>().Select(x => x.Amount).ToList());

                    OnAmountChanged?.Invoke(this, info);
                    UpdateElementIdentity(monitoringElement, lku);
                }
            }
        }
        private void UpdateElementIdentity(MonitoringBlock element, TransactionIdentity identity)
        {
            var u = monitoringList.FirstOrDefault(t => t.Address == element.Address);

            if (u != null)
            {
                u.Until = identity;
            }
        }
Пример #7
0
        /// <summary>
        ///     激活一个事务,并尝试处理该事务的响应消息流程
        /// </summary>
        /// <param name="identity">网络事务唯一标识</param>
        /// <param name="response">应答消息</param>
        public void Active(TransactionIdentity identity, ThriftMessage response)
        {
            ThriftMessageTransaction transaction;

            if (!_transactions.TryRemove(identity, out transaction))
            {
                return;
            }
            transaction.SetResponse(response);
        }
Пример #8
0
        /// <summary>
        ///     激活一个事务,并尝试处理该事务的响应消息流程
        /// </summary>
        /// <param name="identity">事务唯一标示</param>
        /// <param name="response">响应消息</param>
        public void Active(TransactionIdentity identity, TMessage response)
        {
            IMessageTransaction <TMessage> transaction = GetRemove(identity);

            if (transaction == null)
            {
                return;
            }
            transaction.SetResponse(response);
        }
Пример #9
0
        /// <summary>
        ///     为一个管理中的事务进行续约操作
        /// </summary>
        /// <param name="key">事务唯一键值</param>
        /// <param name="timeSpan">续约时间</param>
        /// <returns>
        ///     返回续约后的时间
        ///     <para>* 如果返回值 = MIN(DateTime), 则表示续约失败</para>
        /// </returns>
        public virtual DateTime Renew(TransactionIdentity key, TimeSpan timeSpan)
        {
            IMessageTransaction <TMessage> transaction = GetTransaction(key);

            if (transaction == null)
            {
                return(DateTime.MinValue);
            }
            return(transaction.GetLease().Renew(timeSpan));
        }
Пример #10
0
        public MoneyEventInfo(BitcoinAddress address, TransactionIdentity transactionIdentity, IList <Money> money)
        {
            Address             = address;
            TransactionIdentity = transactionIdentity;
            Money = money;

            if (Money != null)
            {
                TotalSatoshi = Money.Sum(x => x.Satoshi);
            }
        }
Пример #11
0
 /// <summary>
 ///     获取一个正在管理中的事务
 /// </summary>
 /// <param name="key">事务唯一键值</param>
 /// <returns>事务</returns>
 public virtual IMessageTransaction <TMessage> GetTransaction(TransactionIdentity key)
 {
     lock (_lockObj)
     {
         IMessageTransaction <TMessage> transaction;
         if (_transactions.TryGetValue(key, out transaction))
         {
             return(transaction);
         }
         return(default(IMessageTransaction <TMessage>));
     }
 }
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        ///     <para>* 事务超时时间被设置为KJFramework.Message节点的配置。</para>
        ///     <para>* 默认为: 30S</para>
        /// </summary>
        /// <param name="identity">事务唯一标示</param>
        /// <param name="channel">消息通信信道</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public BusinessMessageTransaction Create(TransactionIdentity identity, IMessageTransportChannel <BaseMessage> channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            BusinessMessageTransaction transaction = new BusinessMessageTransaction(new Lease(DateTime.Now.Add(TransactionGlobal.TransactionTimeout)), channel)
            {
                TransactionManager = this, Identity = identity
            };

            return(Add(identity, transaction) ? transaction : null);
        }
Пример #13
0
 /// <summary>
 ///     尝试获取一个具有指定唯一标示的事务,并且在获取该事务后进行移除操作
 /// </summary>
 /// <param name="key">事务唯一键值</param>
 /// <returns>返回获取到的事务</returns>
 public virtual IMessageTransaction <TMessage> GetRemove(TransactionIdentity key)
 {
     lock (_lockObj)
     {
         IMessageTransaction <TMessage> transaction;
         if (!_transactions.TryGetValue(key, out transaction))
         {
             return(null);
         }
         _transactions.Remove(key);
         return(transaction);
     }
 }
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        /// </summary>
        /// <param name="identity">事务唯一标示</param>
        /// <param name="channel">消息通信信道</param>
        /// <param name="timeout">事务超时时间</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public MetadataMessageTransaction Create(TransactionIdentity identity, IMessageTransportChannel <MetadataContainer> channel, TimeSpan timeout)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            MetadataMessageTransaction transaction = new MetadataMessageTransaction(new Lease(DateTime.Now.Add(timeout)), channel)
            {
                TransactionManager = this, Identity = identity
            };

            return(Add(identity, transaction) ? transaction : null);
        }
Пример #15
0
        public void Wait(TransactionIdentity transactionIdentity, TimeSpan timeout)
        {
            var stopwatch = Stopwatch.StartNew();

            while (_projectionDispatcher.Processed(transactionIdentity) == false)
            {
                if (stopwatch.Elapsed > timeout)
                {
                    throw new TimeoutException(ProjectionTimeoutMessage);
                }

                Thread.Sleep(10);
            }
        }
Пример #16
0
        public async Task WaitAsync(TransactionIdentity transactionIdentity, TimeSpan timeout)
        {
            var stopwatch = Stopwatch.StartNew();

            while (_projectionDispatcher.Processed(transactionIdentity) == false)
            {
                if (stopwatch.Elapsed > timeout)
                {
                    throw new TimeoutException(ProjectionTimeoutMessage);
                }

                await Task.Delay(10);
            }
        }
Пример #17
0
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        /// </summary>
        /// <param name="sequenceId">本次新事务的唯一编号</param>
        /// <param name="channel">消息通信信道</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public ThriftMessageTransaction Create(int sequenceId, IMessageTransportChannel <ThriftMessage> channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }
            ThriftMessageTransaction transaction = new ThriftMessageTransaction(new Lease(DateTime.MaxValue), channel)
            {
                TransactionManager = this, SequenceId = sequenceId
            };
            TransactionIdentity identity = IdentityHelper.Create((IPEndPoint)channel.LocalEndPoint, sequenceId, false);

            transaction.Identity = identity;
            return(Add(transaction) ? transaction : null);
        }
Пример #18
0
        public ProjectionContext(IEventProvider eventProvider, TransactionIdentity transactionIdentity, ICommand command, IReadOnlyCollection <Meta> metadata, EventProviderVersion version, object data)
        {
            Contract.Requires(eventProvider != null);
            Contract.Requires(transactionIdentity != null);
            Contract.Requires(command != null);
            Contract.Requires(metadata != null);
            Contract.Requires(version != null);
            Contract.Requires(data != null);

            EventProvider       = eventProvider;
            TransactionIdentity = transactionIdentity;
            Command             = command;
            Metadata            = metadata;
            Version             = version;
            Data = data;
        }
Пример #19
0
        //new message arrived.
        void ChannelReceivedMessage(object sender, LightSingleArgEventArgs <System.Collections.Generic.List <ThriftMessage> > e)
        {
            IMessageTransportChannel <ThriftMessage> msgChannel = (IMessageTransportChannel <ThriftMessage>)sender;

            foreach (ThriftMessage message in e.Target)
            {
                if (message == null)
                {
                    continue;
                }
                _tracing.Info("L: {0}\r\nR: {1}\r\n{2}", msgChannel.LocalEndPoint, msgChannel.RemoteEndPoint, message.ToString());
                //rebuilds corresponding TransactionIdentity for current RSP message.
                TransactionIdentity identity = IdentityHelper.Create((IPEndPoint)msgChannel.LocalEndPoint, (int)message.Identity.SequenceId, false);
                _transactionManager.Active(identity, message);
            }
        }
Пример #20
0
        /// <summary>
        /// 从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            TransactionIdentity identity = analyseResult.GetValue <TransactionIdentity>(target);

            if (identity == null)
            {
                return;
            }
            if (identity.IdentityType == TransactionIdentityTypes.TCP)
            {
                TCPTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (TCPTransactionIdentity)identity, proxy);
            }
            else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
            {
                NamedPipeTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (NamedPipeTransactionIdentity)identity, proxy);
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
            }
        }
Пример #21
0
        /// <summary>
        ///     管理一个事务
        /// </summary>
        /// <param name="key">事务唯一键值</param>
        /// <param name="transaction">事务</param>
        /// <exception cref="T:System.ArgumentNullException">参数错误</exception>
        /// <returns>
        ///     返回添加操作的状态
        /// </returns>
        public bool Add(TransactionIdentity key, IMessageTransaction <TMessage> transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }
            IMessageTransaction <TMessage> temp;

            if ((temp = GetTransaction(key)) != null)
            {
                _tracing.Error(
                    "#Cannot add MessageTransaction to current TransactionManager, because the target identity has been dup. \r\nDetails below:\r\nIdentity: {0}\r\nCreate Time: {1}\r\nRequest: {2}\r\nResponse: {3}",
                    key,
                    temp.CreateTime,
                    (temp.Request == null ? "" : temp.Request.ToString()),
                    (temp.Response == null ? "" : temp.Response.ToString()));
                return(false);
            }
            lock (_lockObj) _transactions.Add(key, transaction);
            return(true);
        }
Пример #22
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        ///     <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para>
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false)
        {
            TransactionIdentity identity = (TransactionIdentity)target;

            if (identity == null)
            {
                return;
            }
            if (identity.IdentityType == TransactionIdentityTypes.TCP)
            {
                TCPTransactionIdentity.Serialize(0, IdentitySerializationTypes.IntellectObject, (TCPTransactionIdentity)identity, proxy);
            }
            else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
            {
                NamedPipeTransactionIdentity.Serialize(0, IdentitySerializationTypes.IntellectObject, (NamedPipeTransactionIdentity)identity, proxy);
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
            }
        }
Пример #23
0
        static void MetadataNewTransaction(object sender, LightSingleArgEventArgs <IMessageTransaction <MetadataContainer> > e)
        {
            MetadataConnectionAgent agent = (MetadataConnectionAgent)sender;
            IMessageTransaction <MetadataContainer> transaction = e.Target;
            MetadataContainer reqMsg = transaction.Request;
            Tuple <KAENetworkResource, ApplicationLevel> tag = new Tuple <KAENetworkResource, ApplicationLevel>((KAENetworkResource)agent.Tag, (reqMsg.IsAttibuteExsits(0x05) ? (ApplicationLevel)reqMsg.GetAttributeAsType <byte>(0x05) : ApplicationLevel.Stable));
            MessageIdentity     reqMsgIdentity      = reqMsg.GetAttributeAsType <MessageIdentity>(0x00);
            TransactionIdentity transactionIdentity = reqMsg.GetAttributeAsType <TransactionIdentity>(0x01);
            Guid uniqueId = reqMsg.GetAttributeAsType <Guid>(0x03);

            /*
             * We always makes a checking on the Metadata protocol network communication.
             * Because all of ours internal system communications are constructed by this kind of MSG protocol.
             */
            if (reqMsgIdentity.ProtocolId >= 0xFC)
            {
                HandleSystemCommand(transaction);
            }
            //sends it to the appropriate application.
            else
            {
                HandleBusiness(tag, (MetadataMessageTransaction)transaction, reqMsgIdentity, reqMsg, uniqueId, transactionIdentity);
            }
        }
 /// <summary>
 ///     TransactionIdentity类型存储的静态构造器
 /// </summary>
 static TransactionIdentityValueStored()
 {
     _instance        = ValueStoredHelper.BuildMethod <TransactionIdentity>();
     _toBytesDelegate = delegate(IMemorySegmentProxy proxy, BaseValueStored messageIdentityValueStored)
     {
         TransactionIdentity identity = messageIdentityValueStored.GetValue <TransactionIdentity>();
         if (identity.IdentityType == TransactionIdentityTypes.TCP)
         {
             TCPTransactionIdentity.Serialize(0, IdentitySerializationTypes.Metadata, (TCPTransactionIdentity)identity, proxy);
         }
         else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
         {
             NamedPipeTransactionIdentity.Serialize(0, IdentitySerializationTypes.Metadata, (NamedPipeTransactionIdentity)identity, proxy);
         }
         else
         {
             throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
         }
     };
     _toDataDelegate = delegate(ResourceBlock metadataObject, byte id, byte[] byteData, int offsetStart, uint offsetLength)
     {
         TransactionIdentityTypes identityType = (TransactionIdentityTypes)byteData[offsetStart];
         if (identityType == TransactionIdentityTypes.TCP)
         {
             metadataObject.SetAttribute(id, new TransactionIdentityValueStored(TCPTransactionIdentity.Deserialize(byteData, offsetStart, (int)offsetLength)));
         }
         else if (identityType == TransactionIdentityTypes.NamedPipe)
         {
             metadataObject.SetAttribute(id, new TransactionIdentityValueStored(NamedPipeTransactionIdentity.Deserialize(byteData, offsetStart, (int)offsetLength)));
         }
         else
         {
             throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identityType));
         }
     };
 }
 /// <summary>
 ///    移除一个不需要管理的事务
 /// </summary>
 /// <param name="key">事务唯一键值</param>
 public virtual void Remove(TransactionIdentity key)
 {
     ThriftMessageTransaction v;
     _transactions.TryRemove(key, out v);
 }
 /// <summary>
 ///     激活一个事务,并尝试处理该事务的响应消息流程
 /// </summary>
 /// <param name="identity">网络事务唯一标识</param>
 /// <param name="response">应答消息</param>
 public void Active(TransactionIdentity identity, ThriftMessage response)
 {
     ThriftMessageTransaction transaction;
     if (!_transactions.TryRemove(identity, out transaction)) return;
     transaction.SetResponse(response);
 }
Пример #27
0
 /*
  *  处理外部请求的总入口
  *
  *  [RSP MESSAGE]
  *  ===========================================
  *      0x00 - Message Identity
  *      0x01 - Transaction Identity
  *      0x02 - Requested Targeting APP Level (REQUIRED)
  *      ...
  *      Other Business Fields
  */
 private static void HandleBusiness(Tuple <KAENetworkResource, ApplicationLevel> tag, MetadataMessageTransaction transaction, MessageIdentity reqMsgIdentity, object reqMsg, Guid kppUniqueId, TransactionIdentity transactionIdentity)
 {
     _rspRemainningCounter.Increment();
     Application.HandleBusiness(tag, transaction, reqMsgIdentity, reqMsg, transactionIdentity);
 }
Пример #28
0
 /// <summary>
 ///     移除一个不需要管理的事务
 /// </summary>
 /// <param name="key">事务唯一键值</param>
 public virtual void Remove(TransactionIdentity key)
 {
     lock (_lockObj) _transactions.Remove(key);
 }
        public bool Processed(TransactionIdentity transactionIdentity)
        {
            Contract.Requires(transactionIdentity != null);

            throw new NotImplementedException();
        }
 public bool Processed(TransactionIdentity transactionIdentity)
 {
     return(_processedTransactions.Contains(transactionIdentity));
 }
 public bool Processed(TransactionIdentity transactionIdentity)
 {
     return(_projectionDispatcher.Processed(transactionIdentity));
 }
Пример #32
0
        internal void HandleBusiness(Tuple <KAENetworkResource, ApplicationLevel> tag, MetadataMessageTransaction transaction, MessageIdentity reqMsgIdentity, object reqMsg, TransactionIdentity transactionIdentity)
        {
            MetadataKAEProcessor processor;

            //Targeted MessageIdentity CANNOT be support.
            if (!_processors.TryGetValue(reqMsgIdentity, out processor))
            {
                _handleErrorSituation(transaction, KAEErrorCodes.NotSupportedMessageIdentity, "#We'd not supported current business protocol yet!");
                return;
            }
            MetadataContainer rsp = processor.Process(transaction.Request);

            if (!transaction.NeedResponse)
            {
                return;
            }
            if (rsp == null)
            {
                _handleErrorSituation(transaction, KAEErrorCodes.UnhandledExceptionOccured, string.Empty);
            }
            else
            {
                _handleSucceedSituation(transaction, rsp);
            }
        }