public static void Process(SerializedObject request)
        {
            XElement content = null;
            try
            {
                if (!request.IsKeepAlive)
                {
                     content = ProcessHelper(request);

                }
                else
                {
                    ProcessForKeepAlive(request);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                content = XmlResultHelper.NewErrorResult(ex.ToString());
            }
            Application.Default.SessionMonitor.Update(request.Session);
            if (content != null)
            {
                request.Content = content;
                SendCenter.Default.Send(request);
            }
        }
 public static IEnumerator<int> GetInitData(SerializedObject request, DataSet initData, AsyncEnumerator ae)
 {
     XElement result = null;
     long session = request.Session;
     Token token = SessionManager.Default.GetToken(session);
     if (initData == null)
     {
         Application.Default.StateServer.BeginGetInitData(token, null, ae.End(), null);
         yield return 1;
         int sequence;
         initData = Application.Default.StateServer.EndGetInitData(ae.DequeueAsyncResult(), out sequence);
     }
     try
     {
         var data = Init(session, initData);
         int commandSequence = data.Item2;
         DataSet ds = data.Item1;
         var dict = new Dictionary<string, string>()
         {
             {"commandSequence",commandSequence.ToString()},
             {"data",ds.ToXml()}
         };
         result = XmlResultHelper.NewResult(dict);
         request.Content = result;
         SendCenter.Default.Send(request);
     }
     catch (Exception ex)
     {
         request.Content = XmlResultHelper.NewErrorResult(ex.ToString());
         SendCenter.Default.Send(request);
     }
 }
Beispiel #3
0
 public void Send(SerializedObject item)
 {
     if (item == null)
     {
         return;
     }
     this._Queue.Enqueue(item);
     this._Event.Set();
 }
Beispiel #4
0
 public IEnumerator<int> Login(SerializedObject request, string loginID, string password, string version, int appType, AsyncEnumerator ae)
 {
     long session = request.Session;
     string connectionString = SettingManager.Default.ConnectionString;
     IsFailedCountExceed(loginID, password, connectionString);
     LoginParameter loginParameter = new LoginParameter();
     loginParameter.CompanyName = string.Empty;
     if (loginID == String.Empty)
     {
         AuditHelper.AddIllegalLogin(AppType.TradingConsole, loginID, password, this.GetLocalIP());
         Application.Default.TradingConsoleServer.SaveLoginFail(loginID, password, GetLocalIP());
         SendErrorResult(request);
         yield break;
     }
     string message = string.Empty;
     Application.Default.ParticipantService.BeginLogin(loginID, password, ae.End(), null);
     yield return 1;
     loginParameter.UserID = Application.Default.ParticipantService.EndLogin(ae.DequeueAsyncResult());
     if (loginParameter.UserID == Guid.Empty)
     {
         _Logger.ErrorFormat("{0} is not a valid user", loginID);
     }
     else
     {
         Guid programID = new Guid(SettingManager.Default.GetLoginSetting("TradingConsole"));
         Guid permissionID = new Guid(SettingManager.Default.GetLoginSetting("Run"));
         Application.Default.SecurityService.BeginCheckPermission(loginParameter.UserID, programID, permissionID, "", "", loginParameter.UserID, ae.End(), null);
         yield return 1;
         bool isAuthrized = Application.Default.SecurityService.EndCheckPermission(ae.DequeueAsyncResult(), out message);
         if (!isAuthrized)
         {
             _Logger.ErrorFormat("{0} doesn't have the right to login trader", loginID);
             loginParameter.UserID = Guid.Empty;
         }
         else
         {
             Token token = new Token(Guid.Empty, UserType.Customer, (AppType)appType);
             token.UserID = loginParameter.UserID;
             token.SessionID = session.ToString();
             SessionManager.Default.AddToken(session, token);
             Application.Default.StateServer.BeginLogin(token, ae.End(), null);
             yield return 1;
             bool isStateServerLogined = Application.Default.StateServer.EndLogin(ae.DequeueAsyncResult());
             SetLoginParameter(loginParameter, session, password, version, appType, isStateServerLogined, token);
         }
     }
     if (loginParameter.UserID == Guid.Empty)
     {
         AuditHelper.AddIllegalLogin(AppType.TradingConsole, loginID, password, this.GetLocalIP());
         Application.Default.TradingConsoleServer.SaveLoginFail(loginID, password, GetLocalIP());
         SendErrorResult(request);
     }
     else
     {
         SetResult(request, loginParameter, session, loginID, password, version, appType, connectionString);
     }
 }
Beispiel #5
0
 public XElement Execute(string methodName,SerializedObject request,Token token)
 {
     if (table.ContainsKey(methodName))
     {
         return table[methodName](request, token);
     }
     else
     {
         this._Logger.InfoFormat("the request methed {0} not exist", methodName);
         return XmlResultHelper.ErrorResult;
     }
 }
 private static void ProcessForKeepAlive(SerializedObject request)
 {
     if (Application.Default.SessionMonitor.Exist(request.Session))
     {
         request.IsKeepAliveSuccess = true;
     }
     else
     {
         request.IsKeepAliveSuccess = false;
     }
     SendCenter.Default.Send(request);
 }
 private static XElement ProcessHelper(SerializedObject request)
 {
     XElement  result = XmlResultHelper.ErrorResult;
     XElement  content = request.Content;
     if (content.Name == RequestConstants.RootNodeName)
     {
         XElement methodNode = content.Descendants().Single(m => m.Name == RequestConstants.MethodNodeName);
         if (methodNode.Name == RequestConstants.MethodNodeName)
         {
             result = ProcessMethodReqeust(request, methodNode.Value);
         }
     }
     return result;
 }
 private static XElement ProcessMethodReqeust(SerializedObject request,string methodName)
 {
     iExchange.Common.Token token = Trader.Server.Session.SessionManager.Default.GetToken(request.Session);
     XElement  result = XmlResultHelper.ErrorResult;
     XElement  content = request.Content;
     if (!Application.Default.SessionMonitor.Exist(request.Session))
     {
         if (methodName == "Login")
         {
             result = RequestTable.Default.Execute(methodName, request, token);
         }
         WhenSessionNotExistRecoverSessionToCurrentSession(request);
     }
     else
     {
         result = RequestTable.Default.Execute(methodName, request, token);
     }
     return result;
 }
Beispiel #9
0
 public static SerializedObject Parse(byte[] packet)
 {
     try
     {
         bool isPrice = packet[0] == 1 ? true : false;
         byte sessionLength = packet[1];
         byte[] contentLengthBytes = new byte[Constants.ContentHeaderLength];
         Array.Copy(packet, 2, contentLengthBytes, 0, Constants.ContentHeaderLength);
         int contentLength = contentLengthBytes.ToCustomerInt();
         byte[] contentBytes = new byte[contentLength];
         int contentIndex = Constants.HeadCount + sessionLength;
         Array.Copy(packet, contentIndex, contentBytes, 0, contentLength);
         SerializedObject target = null;
         if (isPrice)
         {
             target = new SerializedObject(isPrice, contentBytes);
         }
         else
         {
             bool isKeepAlive = (packet[0] & KeepAliveConstants.IsKeepAliveMask) == KeepAliveConstants.IsKeepAliveMask ? true : false;
             string session = Constants.SessionEncoding.GetString(packet, Constants.HeadCount, sessionLength);
             long sessionGuid = SessionMapping.Get(session);
             if (!isKeepAlive)
             {
                 string content = Constants.ContentEncoding.GetString(contentBytes);
                 string processContent = GetRidOfUnprintablesAndUnicode(content);
                 XElement contentNode = XElement.Parse(processContent, LoadOptions.None);
                 XElement clientInvokeNode = contentNode.Descendants().Single(m => m.Name == RequestConstants.InvokeIdNodeName);
                 string clientInvokeId = clientInvokeNode == null ? string.Empty : clientInvokeNode.Value;
                 target = new SerializedObject(contentInBytes: null, isPrice: isPrice, session: sessionGuid, clientInvokeId: clientInvokeId, content: contentNode);
             }
             else
             {
                 target =SerializedObject.Create(sessionGuid, isKeepAlive, packet);
             }
         }
         return target;
     }
     catch(Exception ex)
     {
         return null;
     }
 }
Beispiel #10
0
 public static byte[] Build(SerializedObject target)
 {
     byte priceByte = 0;
     if (target.IsKeepAlive)
     {
         target.KeepAlivePacket[0] = target.IsKeepAliveSuccess ? KeepAliveConstants.IsKeepAliveAndSuccessValue : KeepAliveConstants.IsKeepAliveAndFailedValue;
         return target.KeepAlivePacket;
     }
     if (!string.IsNullOrEmpty(target.ClientInvokeID))
     {
         AppendClientInvokeIdToContentNode(target.Content, target.ClientInvokeID);
     }
     byte[] contentBytes = GetContentBytes(target.Content.ToString());
     byte[] sessionBytes = GetSessionBytes(target.Session.ToString());
     byte sessionLengthByte = (byte)sessionBytes.Length;
     byte[] contentLengthBytes = contentBytes.Length.ToCustomerBytes();
     int packetLength = Constants.HeadCount + sessionLengthByte + contentBytes.Length;
     byte[] packet = new byte[packetLength];
     AddHeaderToPacket(packet, priceByte, sessionLengthByte, contentLengthBytes);
     AddSessionToPacket(packet, sessionBytes, Constants.HeadCount);
     AddContentToPacket(packet, contentBytes, Constants.HeadCount + sessionLengthByte);
     return packet;
 }
Beispiel #11
0
 private XElement  RecoverAction(SerializedObject request, Token token)
 {
     return RecoverService.Recover(request.Session, request.CurrentSession);
 }
Beispiel #12
0
        private XElement  ModifyOrderAction(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            if (token != null && token.AppType == iExchange.Common.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(order1DoneLimitPrice = 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 = this.GetPlaceResultForMobile(transaction, token);
                foreach (XElement orderErrorElement in errorCodes)
                {
                    element.Add(orderErrorElement);
                }
                return element;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #13
0
        private XElement  VerifyTransactionAction(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            return TransactionService.VerifyTransaction(request.Session, args[0].ToGuidArray());

        }
Beispiel #14
0
        private XElement  AsyncGetChartData2Action(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            return TickService.AsyncGetChartData2(request.Session, Guid.Parse(args[0]), DateTime.Parse(args[1]), DateTime.Parse(args[2]), args[3]);

        }
Beispiel #15
0
 private XElement  AssignAction(SerializedObject request, Token token)
 {
     return ClientService.Assign(request.Session);
 }
Beispiel #16
0
 private XElement  FundTransferAction(SerializedObject request, Token token)
 {
     List<string> args = XmlRequestCommandHelper.GetArguments(request.Content);
     return ClientService.FundTransfer(request.Session, args[0], args[1],
         args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]);
 }
Beispiel #17
0
        private XElement  PaymentInstructionCashAction(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            return ClientService.PaymentInstructionCash(request.Session, args[0], args[1], args[2],
                args[3], args[4], args[5], args[6], args[7], args[8]);

        }
Beispiel #18
0
 private XElement  UpdateAccountsSettingAction(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     Guid[] accountIds = argList[0].ToGuidArray();
     return AccountManager.Default.UpdateAccountSetting(request.Session, accountIds);
 }
Beispiel #19
0
        private XElement  ChangeLeverageAction(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            return ClientService.ChangeLeverage(request.Session, Guid.Parse(args[0]), int.Parse(args[1]));

        }
Beispiel #20
0
 private XElement  UpdatePasswordAction(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     return PasswordService.UpdatePassword(request.Session, argList[0], argList[1], argList[2]);
 }
Beispiel #21
0
 private XElement  GetChartDataAction(SerializedObject request, Token token)
 {
     var args = XmlRequestCommandHelper.GetArguments(request.Content);
     return TickService.GetChartData(Guid.Parse(args[0]));
 }
Beispiel #22
0
 private XElement  StatementForJava2Action(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     return StatementService.StatementForJava2(request.Session, int.Parse(argList[0]), argList[1], argList[2], argList[3], argList[4]);
 }
Beispiel #23
0
 private XElement  PlaceAction(SerializedObject request, Token token)
 {
     var args = XmlRequestCommandHelper.GetArguments(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");
         foreach (Mobile.Server.Transaction transaction in transactions)
         {
             ICollection<XElement> errorCodes = this.GetPlaceResultForMobile(transaction, token);
             foreach(XElement orderErrorElement in errorCodes){
                 element.Add(orderErrorElement);
             }
         }
         return element;
     }
     else
     {
         return TransactionService.Place(request.Session, args[0].ToXmlNode());
     }
 }
Beispiel #24
0
 private XElement  GetReportContentAction(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     return StatementService.GetReportContent(Guid.Parse(argList[0]));
 }
Beispiel #25
0
        public XElement  CancelAction(SerializedObject request, Token token)
        {
            var args = XmlRequestCommandHelper.GetArguments(request.Content);
            Guid transactionId = new Guid(args[0]);
            TransactionError transactionError = Application.Default.StateServer.Cancel(token, transactionId, CancelReason.CustomerCanceled);
            if (token.AppType == AppType.Mobile)
            {
                XElement errorElement = new XElement("Transaction");
                errorElement.SetAttributeValue("Id", transactionId);
                errorElement.SetAttributeValue("ErrorCode", transactionError.ToString());

                XElement element = new XElement("Result");
                element.Add(errorElement);
                return element;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #26
0
 private XElement  GetMerchantInfoFor99BillAction(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     Guid[] organizationIds = argList[0].ToGuidArray();
     return PaymentService.GetMerchantInfoFor99Bill(organizationIds);
 }
Beispiel #27
0
 private XElement  LogoutAction(SerializedObject request, Token token)
 {
    return LoginManager.Default.Logout(request.Session);
 }
Beispiel #28
0
 private XElement  AdditionalClientAction(SerializedObject request, Token token)
 {
     List<string> argList = XmlRequestCommandHelper.GetArguments(request.Content);
     return ClientService.AdditionalClient(request.Session, argList[0], argList[1], argList[2],
         argList[3], argList[4], argList[5], argList[6], argList[7], argList[8],
         argList[9], argList[10], argList[11], argList[12], argList[13], argList[14],
         argList[15], argList[16]);
 }
Beispiel #29
0
 private XElement GetNewsContentsAction(SerializedObject request, Token token)
 {
     var args = XmlRequestCommandHelper.GetArguments(request.Content);
     return this._Service.GetNewsContents(request.Session, args[0]);
 }
Beispiel #30
0
 private XElement  CallMarginExtensionAction(SerializedObject request, Token token)
 {
     List<string> args = XmlRequestCommandHelper.GetArguments(request.Content);
     return ClientService.CallMarginExtension(request.Session, args[0], args[1],
         args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
 }