Пример #1
0
 /// <summary>
 ///     检查当前业务字段是否合法
 /// </summary>
 /// <param name="reqMsg">请求消息</param>
 /// <param name="errorMsg">返回错误信息</param>
 /// <returns>返回是否合法</returns>
 protected override bool CheckDataFields(MetadataContainer reqMsg, out string errorMsg)
 {
     errorMsg = null;
     if (!reqMsg.IsAttibuteExsits(0x0F))
     {
         errorMsg = "#CoinTypeId不存在";
     }
     else if (!reqMsg.IsAttibuteExsits(0x10))
     {
         errorMsg = "#PlatformId不存在";
     }
     return(errorMsg == null);
 }
        /// <summary>
        ///     根据指定编号异步获取Ticker对象的操作
        /// </summary>
        /// <param name="coinType">币种编号</param>
        /// <param name="platformType">平台编号</param>
        /// <returns>返回执行结果</returns>
        public async Task <IExecuteResult> GetTickerAsync(CoinTypes coinType, PlatformTypes platformType)
        {
            MetadataMessageTransaction transaction = SystemWorker.Instance.CreateMetadataTransaction("CoinAPI");
            MetadataContainer          reqMsg      = new MetadataContainer();

            reqMsg.SetAttribute(0x00, new MessageIdentityValueStored(new MessageIdentity
            {
                ProtocolId = 1,
                ServiceId  = 0,
                DetailsId  = 0
            }));
            reqMsg.SetAttribute(0x0F, new ByteValueStored((byte)coinType));
            reqMsg.SetAttribute(0x10, new ByteValueStored((byte)platformType));
            TaskCompletionSource <IExecuteResult> completionSource = new TaskCompletionSource <IExecuteResult>();
            Task <IExecuteResult> task = completionSource.Task;

            transaction.ResponseArrived += delegate(object sender, LightSingleArgEventArgs <MetadataContainer> e)
            {
                MetadataContainer rspMsg = e.Target;
                completionSource.SetResult((!rspMsg.IsAttibuteExsits(0x0A))
                             ? (rspMsg.GetAttribute(0x0F).GetValue <ResourceBlock>() == null
                                 ? ExecuteResult.Succeed(null)
                                 : ExecuteResult.Succeed(ConverterFactory.GetTickerConverter().ConvertToDomainObject(rspMsg.GetAttribute(0x0F).GetValue <ResourceBlock>())))
                             : ExecuteResult.Fail(rspMsg.GetAttribute(0x0A).GetValue <byte>(), rspMsg.GetAttribute(0x0B).GetValue <string>()));
            };
            transaction.Timeout += delegate { completionSource.SetResult(ExecuteResult.Fail(SystemErrors.Timeout, string.Format("[Async Handle] Transaction: {0} execute timeout!", transaction.Identity))); };
            transaction.Failed  += delegate { completionSource.SetResult(ExecuteResult.Fail(SystemErrors.Unknown, string.Format("[Async Handle] Transaction: {0} execute failed!", transaction.Identity))); };
            transaction.SendRequest(reqMsg);
            return(await task);
        }
Пример #3
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);
            }
        }