Example #1
0
        private static SerializedInfo ParseJsonPacket(Session session, string content)
        {
            JsonContent jsonContent            = new JsonContent(request: JObject.Parse(content));
            var         clientInvokeIdProperty = jsonContent.Request[RequestConstants.InvokeIdNodeName];
            string      clientInvokeId         = clientInvokeIdProperty == null ? string.Empty : clientInvokeIdProperty.ToString();

            return(SerializedInfo.CreateForJson(session, clientInvokeId, jsonContent));
        }
Example #2
0
        private static SerializedInfo ParseForKeepAlive(byte[] packet)
        {
            byte    sessionLength = packet[PacketConstants.SessionLengthIndex];
            string  sessionStr    = PacketConstants.SessionEncoding.GetString(packet, PacketConstants.HeadLength, sessionLength);
            Session session       = SessionMapping.Get(sessionStr);

            return(SerializedInfo.CreateForKeepAlive(session, true, packet));
        }
 public PacketContent Process(SerializedInfo request)
 {
     Debug.Assert(request.Content.ContentType == ContentType.Json);
     var methodProperty = request.Content.JsonContent.Request[RequestConstants.MethodNodeName];
     if (methodProperty == null)
         throw new NotSupportedException();
     string methodName = methodProperty.ToString();
     return MethodRequestProcessor.Process(request, methodName);
 }
        public static SerializedInfo CreateForJson(Session session, string clientInvokeId, JsonContent content)
        {
            SerializedInfo target = new SerializedInfo()
            {
                Content    = new PacketContent(content),
                ClientInfo = new ClientInfo(clientInvokeId, session)
            };

            return(target);
        }
        public static SerializedInfo CreateForKeepAlive(Session session, bool isKeepAlive, byte[] keepAlivePacket)
        {
            SerializedInfo target = new SerializedInfo()
            {
                Content    = new PacketContent(keepAlivePacket),
                ClientInfo = new ClientInfo(null, session)
            };

            return(target);
        }
        private static UnmanagedMemory BuildForKeepAlive(SerializedInfo response)
        {
            Debug.Assert(response.Content.ContentType == ContentType.KeepAlivePacket, "content type should be keepalive");
            KeepAlive keepAlive = response.Content.KeepAlive;

            keepAlive.Packet[PacketConstants.SettingIndex] = keepAlive.IsSuccess ? PacketFirstHeadByteValue.IsKeepAliveAndSuccessValue : PacketFirstHeadByteValue.IsKeepAliveAndFailedValue;
            UnmanagedMemory packet = new UnmanagedMemory(keepAlive.Packet);

            return(packet);
        }
 private static void ExecuteRequestWhenSessionNotExist(string methodName, SerializedInfo request, Token token, out PacketContent result)
 {
     result = XmlResultHelper.ErrorResult;
     if (methodName == LoginMethodName)
     {
         result = RequestTable.Default.Execute(methodName, request, token);
     }
     if (request.ClientInfo.ClientId != Session.InvalidSession)
         request.ClientInfo.UpdateSession(request.ClientInfo.ClientId);
 }
 public static UnmanagedMemory Build(SerializedInfo response)
 {
     ContentType contentType = response.Content.ContentType;
     if (contentType==ContentType.KeepAlivePacket)
     {
         return BuildForKeepAlive(response);
     }
     if (contentType == ContentType.UnmanageMemory)
     {
         return  BuildForPointer(response.Content.UnmanageMem, response.ClientInfo.ClientInvokeId);
     }
     return BuildForGeneralFormat(response);
 }
 public static PacketContent Process(SerializedInfo request, string methodName)
 {
     Token token = SessionManager.Default.GetToken(request.ClientInfo.Session);
     PacketContent result;
     if (!Application.Default.SessionMonitor.Exist(request.ClientInfo.Session))
     {
         ExecuteRequestWhenSessionNotExist(methodName, request, token, out result);
     }
     else
     {
         result = RequestTable.Default.Execute(methodName, request, token);
     }
     return result;
 }
Example #10
0
        private static SerializedInfo ParseXmlPacket(Session session, string content)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(content);
            using (var nodeReader = new XmlNodeReader(doc))
            {
                nodeReader.MoveToContent();
                XElement contentNode      = XDocument.Load(nodeReader).Root;
                XElement clientInvokeNode = FetchClientInvokeNode(contentNode);
                string   clientInvokeId   = clientInvokeNode == null ? string.Empty : clientInvokeNode.Value;
                return(SerializedInfo.CreateForXml(session, clientInvokeId, contentNode));
            }
        }
        public static UnmanagedMemory Build(SerializedInfo response)
        {
            ContentType contentType = response.Content.ContentType;

            if (contentType == ContentType.KeepAlivePacket)
            {
                return(BuildForKeepAlive(response));
            }
            if (contentType == ContentType.UnmanageMemory)
            {
                return(BuildForPointer(response.Content.UnmanageMem, response.ClientInfo.ClientInvokeId));
            }
            return(BuildForGeneralFormat(response));
        }
 public static IEnumerator<int> GetInitData(SerializedInfo request,AsyncEnumerator ae)
 {
     Session session = request.ClientInfo.Session;
     Token token = SessionManager.Default.GetToken(session);
     Application.Default.StateServer.BeginGetInitData(token, null, ae.End(), null);
     yield return 1;
     try
     {
         int sequence;
         DataSet initData = Application.Default.StateServer.EndGetInitData(ae.DequeueAsyncResult(), out sequence);
         InitAndSendInitDataInPointer(request,initData);
     }
     catch (Exception ex)
     {
         SendErrorResult(request, ex);
     }
 }
        private static UnmanagedMemory BuildForGeneralFormat(SerializedInfo response)
        {
            if (!string.IsNullOrEmpty(response.ClientInfo.ClientInvokeId))
            {
                AppendClientInvokeIdToContentNode(response.Content, response.ClientInfo.ClientInvokeId);
            }
            byte[] contentBytes      = GetContentBytes(response.Content);
            byte[] sessionBytes      = GetSessionBytes(response.ClientInfo.Session.ToString());
            byte   sessionLengthByte = (byte)sessionBytes.Length;

            byte[]     contentLengthBytes = contentBytes.Length.ToCustomerBytes();
            int        packetLength       = PacketConstants.HeadLength + sessionLengthByte + contentBytes.Length;
            var        packet             = new UnmanagedMemory(packetLength);
            const byte priceByte          = 0;

            AddHeaderToPacket(packet, priceByte, sessionLengthByte, contentLengthBytes);
            AddSessionToPacket(packet, sessionBytes, PacketConstants.HeadLength);
            AddContentToPacket(packet, contentBytes, PacketConstants.HeadLength + sessionLengthByte);
            return(packet);
        }
Example #14
0
 private void ProcessRequest(SerializedInfo request)
 {
     PacketContent responseContent=null;
     try
     {
         ContentType contentType = request.Content.ContentType;
         IRequestProcessor requestProcessor;
         if (contentType == ContentType.KeepAlivePacket)
         {
             requestProcessor = KeepAliveProcessor.Default;
         }
         else if (contentType == ContentType.Xml)
         {
             requestProcessor = XmlProcessor.Default;
         }
         else if (contentType == ContentType.Json)
         {
             requestProcessor = JsonProcessor.Default;
         }
         else
         {
             throw new NotSupportedException();
         }
         responseContent = requestProcessor.Process(request);
     }
     catch (Exception ex)
     {
         responseContent = XmlResultHelper.NewErrorResult(ex.ToString()).ToPacketContent();
     }
     finally
     {
         Application.Default.SessionMonitor.Update(request.ClientInfo.Session);
         if (responseContent != null)
         {
             request.UpdateContent(responseContent);
             SendCenter.Default.Send(request);
         }
     }
 }
Example #15
0
        private PacketContent ModifyOrderAction(SerializedInfo request, Token token)
        {
            var args =ArgumentsParser.Parse(request.Content);
            if (token != null && token.AppType == AppType.Mobile)
            {
                Guid orderId = new Guid(args[0]);
                string price = args[1];
                Guid? orderId2 = null;
                if (!string.IsNullOrEmpty(args[2]))
                {
                    orderId2 = new Guid(args[2]);
                }
                string price2 = args[3];
                string order1DoneLimitPrice = args[4];
                string order1DoneStopPrice = args[5];
                string order2DoneLimitPrice = args[6];
                string order2DoneStopPrice = args[7];
                bool isOco = bool.Parse(args[8]);

                Mobile.Server.Transaction transaction = Mobile.Manager.ConvertModifyRequest(token, orderId, price, orderId2, price2, order1DoneLimitPrice, order1DoneStopPrice, order2DoneLimitPrice, order2DoneStopPrice, isOco);
                XElement element = new XElement("Result");

                ICollection<XElement> errorCodes = MobileHelper.GetPlaceResultForMobile(transaction, token);
                foreach (XElement orderErrorElement in errorCodes)
                {
                    element.Add(orderErrorElement);
                }

                XElement changes = Mobile.Manager.GetChanges(request.ClientInfo.Session.ToString(), false);
                element.Add(changes);
                return element.ToPacketContent();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #16
0
 private PacketContent LogoutAction(SerializedInfo request, Token token)
 {
     PacketContent result = LoginOutService.Logout(request.ClientInfo.Session);
     if (token.AppType == AppType.Mobile)
     {
         Mobile.Manager.Logout(token);
     }
     return result;
 }
Example #17
0
 private PacketContent VerifyTransactionAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     return TransactionService.VerifyTransaction(request.ClientInfo.Session, args[0].ToGuidArray()).ToPacketContent();
 }
Example #18
0
 private PacketContent ModifyTelephoneIdentificationCodeAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     return PasswordService.ModifyTelephoneIdentificationCode(request.ClientInfo.Session, Guid.Parse(args[0]), args[1], args[2])
             .ToPacketContent();
 }
Example #19
0
 private PacketContent QuoteAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     return _Service.Quote(request.ClientInfo.Session, argList[0], double.Parse(argList[1]), int.Parse(argList[2]))
             .ToPacketContent();
 }
Example #20
0
 private PacketContent VerifyMarginPinAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     return PasswordService.VerifyMarginPin(args[0].ToGuid(), args[1]).ToPacketContent();
 }
Example #21
0
 private PacketContent PaymentInstructionInternalAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     return ClientService.PaymentInstructionInternal(request.ClientInfo.Session, args[0], args[1],
         args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9])
         .ToPacketContent();
 }
 private static void InitAndSendInitDataInPointer(SerializedInfo request,DataSet initData)
 {
     DataSet ds = Init(request.ClientInfo.Session, initData);
     request.UpdateContent(new PacketContent(ds.ToPointer()));
     SendCenter.Default.Send(request);
 }
Example #23
0
 private PacketContent PlaceAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     if (token != null && token.AppType == iExchange.Common.AppType.Mobile)
     {
         ICollection<Mobile.Server.Transaction> transactions = Mobile.Manager.ConvertPlacingRequest(token, args[0].ToXmlNode());
         XElement element = new XElement("Result");
         if (transactions != null)
         {
             foreach (Mobile.Server.Transaction transaction in transactions)
             {
                 ICollection<XElement> errorCodes =MobileHelper.GetPlaceResultForMobile(transaction, token);
                 foreach (XElement orderErrorElement in errorCodes)
                 {
                     element.Add(orderErrorElement);
                 }
             }
         }
         XElement changes = Mobile.Manager.GetChanges(request.ClientInfo.Session.ToString(), false);
         element.Add(changes);
         return element.ToPacketContent();
     }
     return TransactionService.Place(request.ClientInfo.Session, args[0].ToXmlNode()).ToPacketContent();
 }
 public static SerializedInfo CreateForXml(Session session, string clientInvokeId, XElement content)
 {
     SerializedInfo target = new SerializedInfo()
     {
         Content= new PacketContent(content),
         ClientInfo=new ClientInfo(clientInvokeId,session)
     };
     return target;
 }
Example #25
0
 private PacketContent saveLogAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     return LogService.SaveLog(request.ClientInfo.Session, argList[0], DateTime.Parse(argList[1]), argList[2], Guid.Parse(argList[3]))
         .ToPacketContent();
 }
Example #26
0
 private PacketContent RecoverPasswordDatasAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     var args = argList[0].To2DArray();
     return PasswordService.RecoverPasswordDatas(request.ClientInfo.Session, args).ToPacketContent();
 }
Example #27
0
 private PacketContent RecoverAction(SerializedInfo request, Token token)
 {
     return RecoverService.Recover(request.ClientInfo.Session, request.ClientInfo.ClientId);
 }
Example #28
0
 public UnmanagedMemory Serialize(SerializedInfo target)
 {
     return(PacketBuilder.Build(target));
 }
Example #29
0
 private PacketContent GetTimeInfoAction(SerializedInfo request, Token token)
 {
     return TimeService.GetTimeInfo().ToPacketContent();
 }
Example #30
0
 private PacketContent LoginAction(SerializedInfo request, Token token)
 {
     LoginRequest loginRequest = new LoginRequest(request, token);
     loginRequest.Execute();
     return null;
 }
Example #31
0
 private PacketContent UpdateQuotePolicyDetailAction(SerializedInfo request, Token token)
 {
     var args =ArgumentsParser.Parse(request.Content);
     TraderState state = SessionManager.Default.GetTradingConsoleState(request.ClientInfo.Session);
     return Application.Default.TradingConsoleServer.UpdateQuotePolicyDetail(args[0].ToGuid(), args[1].ToGuid(), state)
             .ToPacketContent();
 }
 private static void SendErrorResult(SerializedInfo request,Exception ex)
 {
     _Logger.Error(ex);
     request.UpdateContent( XmlResultHelper.ErrorResult);
     SendCenter.Default.Send(request);
 }
Example #33
0
        private PacketContent QueryOrderAction(SerializedInfo request, Token token)
        {
            var args =ArgumentsParser.Parse(request.Content);

            if (token.AppType == AppType.Mobile)
            {
                Guid? instrumentId = null;
                if (!string.IsNullOrEmpty(args[0]))
                {
                    instrumentId = new Guid(args[0]);
                }
                int lastDays = int.Parse(args[1]);
                int orderStatus = int.Parse(args[2]);
                int orderType = int.Parse(args[3]);
                XElement result = new XElement("Result");
                result.Add(Mobile.Manager.QueryOrder(token, instrumentId, lastDays, orderStatus, orderType));
                return result.ToPacketContent();
            }
            return this._Service.OrderQuery(request.ClientInfo.Session, args[0].ToGuid(), args[1], args[2], args[3].ToInt())
                    .ToPacketContent();
        }
 public static SerializedInfo CreateForKeepAlive(Session session, bool isKeepAlive, byte[] keepAlivePacket)
 {
     SerializedInfo target = new SerializedInfo()
     {
         Content = new PacketContent(keepAlivePacket),
         ClientInfo = new ClientInfo(null, session)
     };
     return target;
 }
Example #35
0
 private PacketContent UpdateAccountsSettingAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     Guid[] accountIds = argList[0].ToGuidArray();
     return AccountManager.Default.UpdateAccountSetting(request.ClientInfo.Session, accountIds)
         .ToPacketContent();
 }
Example #36
0
 private PacketContent UpdateInstrumentSettingAction(SerializedInfo request, Token token)
 {
     var argList =ArgumentsParser.Parse(request.Content);
     string[] instrumentIds = argList[0].Split(StringConstants.ArrayItemSeparator);
     if (token.AppType == AppType.Mobile)
     {
         var quotePolicyIds = Mobile.Manager.UpdateInstrumentSetting(token, instrumentIds);
         InstrumentManager.Default.UpdateInstrumentSetting(request.ClientInfo.Session, quotePolicyIds);
         if (Mobile.Manager.IsTradeStateInitialized(token))
         {
             return Mobile.Manager.GetChanges(request.ClientInfo.Session.ToString(), true).ToPacketContent();
         }
         var root = new XElement("Result");
         root.Add(new XElement("Account"));
         return root.ToPacketContent();
     }
     return InstrumentManager.Default.UpdateInstrumentSetting(request.ClientInfo.Session, instrumentIds)
         .ToPacketContent();
 }
Example #37
0
 private PacketContent UpdatePasswordAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     return PasswordService.UpdatePassword(request.ClientInfo.Session, argList[0], argList[1], argList[2])
         .ToPacketContent();
 }
Example #38
0
 private PacketContent StatementForJava2Action(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     return StatementService.StatementForJava2(request.ClientInfo.Session, int.Parse(argList[0]), argList[1], argList[2], argList[3], argList[4])
         .ToPacketContent();
 }
Example #39
0
 private PacketContent GetTickByTickHistoryDataAction(SerializedInfo request, Token token)
 {
     List<string> argList =ArgumentsParser.Parse(request.Content);
     return _Service.AsyncGetTickByTickHistoryData2(request.ClientInfo.Session, Guid.Parse(argList[0]), DateTime.Parse(argList[1]), DateTime.Parse(argList[2])).ToPacketContent();
 }