/// <summary> /// /// </summary> /// <param name="keyConfirm"></param> /// <param name="resultBackup"></param> /// <param name="newInvestor"></param> /// <returns></returns> private static StringBuilder ProcessBackupMessage(string keyConfirm, string resultBackup, Business.Investor newInvestor) { StringBuilder result = new StringBuilder(); string backupCommand = string.Empty; if (newInvestor.BackupQueue != null) { int countBackup = newInvestor.BackupQueue.Count; for (int n = 0; n < newInvestor.BackupQueue.Count; n++) { if (newInvestor.BackupQueue[n].Key == keyConfirm) { newInvestor.BackupQueue.RemoveAt(n); n--; } else { backupCommand += newInvestor.BackupQueue[n].CommandQueue + "▼"; newInvestor.BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) { result.Append("▼"); result.Append(backupCommand); result.Append(">"); result.Append(keyBackup); } else { result.Append(">"); result.Append(keyBackup); } //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; newInvestor.BackupQueue.Add(newBackupQueue); return result; }
/// <summary> /// /// </summary> /// <param name="investorID"></param> /// <param name="investorName"></param> /// <param name="investorIndex"></param> /// <returns></returns> public static string FacadeGetData(int investorID, int investorIndex, string key, int port, string keyConfirm) { string result = string.Empty; string resultBackup = string.Empty; string resultCommand = string.Empty; List<string> tempResult = new List<string>(); result = ClientFacade.GetNewTickOnInvestorOnline(investorID, key, port); Business.TypeLogin type = ClientFacade.GetTypeLogin(investorID, key); #region REMOVE CHAR //Remove Charater end "♦" if (result.Length > 1) { result = result.Remove(result.Length - 1); } //Add Character Start "◊" result += "◊"; #endregion bool isValidKey = false; if (type == Business.TypeLogin.Primary) { Business.Investor newInvestor = new Business.Investor(); if (investorIndex >= 0 && investorIndex <= Business.Market.InvestorList.Count - 1) { newInvestor = Business.Market.InvestorList[investorIndex]; if (newInvestor != null && newInvestor.InvestorID > 0 && newInvestor.InvestorID == investorID && newInvestor.LoginKey == key) { #region CHECK STATUS INVESTOR if (!newInvestor.IsOnline) { if (newInvestor.IsLogout) return string.Empty; newInvestor.IsOnline = true; newInvestor.AddInvestorToInvestorOnline(newInvestor); } #endregion Business.Market.InvestorList[investorIndex].LastConnectTime = DateTime.Now; #region GET CLIENT COMMAND SERVER if (newInvestor.ClientCommandQueue != null) { int countMessage = newInvestor.ClientCommandQueue.Count; for (int n = 0; n < newInvestor.ClientCommandQueue.Count; n++) { try { if (newInvestor.ClientCommandQueue[0] != null) { result += newInvestor.ClientCommandQueue[0] + "▼"; resultBackup += newInvestor.ClientCommandQueue[0] + "▼"; if (newInvestor.ClientCommandQueue[0] == "OLOFF14790251") { newInvestor.ClientCommandQueue.RemoveAt(0); continue; } else { tempResult.Add(newInvestor.ClientCommandQueue[0]); newInvestor.ClientCommandQueue.RemoveAt(0); } //newInvestor.ClientCommandQueue.RemoveAt(0); } else { newInvestor.ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { string _temp = ex.Message + " - GetData"; TradingServer.Facade.FacadeAddNewSystemLog(6, _temp, "[Exception]", "", newInvestor.Code); } } } #endregion #region ADD COMMAND TO INVESTOR LOGIN WITH PASSWORD READ ONLY if (Business.Market.InvestorOnline != null) { for (int n = 0; n < Business.Market.InvestorOnline.Count; n++) { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey != key) { if (tempResult != null) { int countMessage = tempResult.Count; for (int m = 0; m < countMessage; m++) { Business.Market.InvestorOnline[n].ClientCommandQueue.Add(tempResult[m]); } } } else { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey == key) { if (Business.Market.InvestorOnline[n].ClientCommandQueue != null) { for (int m = 0; m < Business.Market.InvestorOnline[n].ClientCommandQueue.Count; m++) { try { if (Business.Market.InvestorOnline[n].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[n].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } } } } } #endregion #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (newInvestor.BackupQueue != null) { int countBackup = newInvestor.BackupQueue.Count; for (int n = 0; n < newInvestor.BackupQueue.Count; n++) { if (newInvestor.BackupQueue[n].Key == keyConfirm) { newInvestor.BackupQueue.RemoveAt(n); n--; } else { backupCommand += newInvestor.BackupQueue[n].CommandQueue + "▼"; newInvestor.BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; newInvestor.BackupQueue.Add(newBackupQueue); } #endregion isValidKey = true; } else { #region SEARCH INVESTOR IN INVESTOR LIST OF CLASS MARKET if (Business.Market.InvestorList != null) { bool flag = false; int countInvestor = Business.Market.InvestorList.Count; for (int j = 0; j < Business.Market.InvestorList.Count; j++) { if (Business.Market.InvestorList[j].LoginKey != null) { if (Business.Market.InvestorList[j].InvestorID == investorID && Business.Market.InvestorList[j].LoginKey == key) { #region CHECK STATUS INVESTOR if (!Business.Market.InvestorList[j].IsOnline) { if (Business.Market.InvestorList[j].IsLogout) return string.Empty; Business.Market.InvestorList[j].IsOnline = true; Business.Market.InvestorList[j].AddInvestorToInvestorOnline(Business.Market.InvestorList[j]); } #endregion Business.Market.InvestorList[j].LastConnectTime = DateTime.Now; Business.Market.InvestorList[j].InvestorIndex = j; //SEND COMMAND UPDATE INVESTOR INDEX if (Business.Market.InvestorList[j].ClientCommandQueue == null) Business.Market.InvestorList[j].ClientCommandQueue = new List<string>(); string messageChangeIndex = "CII00434543$" + Business.Market.InvestorList[j].InvestorIndex; Business.Market.InvestorList[j].ClientCommandQueue.Add(messageChangeIndex); #region GET CLIENT COMMAND SERVER if (Business.Market.InvestorList[j].ClientCommandQueue != null) { int countMessage = Business.Market.InvestorList[j].ClientCommandQueue.Count; for (int n = 0; n < Business.Market.InvestorList[j].ClientCommandQueue.Count; n++) { try { if (Business.Market.InvestorList[j].ClientCommandQueue[0] != null) { result += Business.Market.InvestorList[j].ClientCommandQueue[0] + "▼"; resultBackup += Business.Market.InvestorList[j].ClientCommandQueue[0] + "▼"; if (Business.Market.InvestorList[j].ClientCommandQueue[0] == "OLOFF14790251") { Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); continue; } tempResult.Add(Business.Market.InvestorList[j].ClientCommandQueue[0]); Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } #endregion #region ADD COMMAND TO INVESTOR LOGIN WITH PASSWORD READ ONLY if (Business.Market.InvestorOnline != null) { for (int n = 0; n < Business.Market.InvestorOnline.Count; n++) { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey != key) { if (tempResult != null) { int countMessage = tempResult.Count; for (int m = 0; m < countMessage; m++) { Business.Market.InvestorOnline[n].ClientCommandQueue.Add(tempResult[m]); } } } else { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey == key) { if (Business.Market.InvestorOnline[n].ClientCommandQueue != null) { for (int m = 0; m < Business.Market.InvestorOnline[n].ClientCommandQueue.Count; m++) { try { if (Business.Market.InvestorOnline[n].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[n].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } } } } } #endregion #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (Business.Market.InvestorList[j].BackupQueue != null) { int countBackup = Business.Market.InvestorList[j].BackupQueue.Count; for (int n = 0; n < Business.Market.InvestorList[j].BackupQueue.Count; n++) { if (Business.Market.InvestorList[j].BackupQueue[n].Key == keyConfirm) { Business.Market.InvestorList[j].BackupQueue.RemoveAt(n); n--; } else { backupCommand += Business.Market.InvestorList[j].BackupQueue[n].CommandQueue + "▼"; Business.Market.InvestorList[j].BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; Business.Market.InvestorList[j].BackupQueue.Add(newBackupQueue); } #endregion flag = true; isValidKey = true; break; } } } if (!flag) { #region GET MESSAGE SERVER FROM INVESTOR ONLINE if (Business.Market.InvestorOnline != null) { for (int i = 0; i < Business.Market.InvestorOnline.Count; i++) { if (Business.Market.InvestorOnline[i].InvestorID == investorID && Business.Market.InvestorOnline[i].LoginKey == key) { if (Business.Market.InvestorOnline[i].ClientCommandQueue != null) { int countMessage = Business.Market.InvestorOnline[i].ClientCommandQueue.Count; for (int j = 0; j < Business.Market.InvestorOnline[i].ClientCommandQueue.Count; j++) { try { if (Business.Market.InvestorOnline[i].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; resultBackup += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (Business.Market.InvestorOnline[i].BackupQueue != null) { int countBackup = Business.Market.InvestorOnline[i].BackupQueue.Count; for (int n = 0; n < Business.Market.InvestorOnline[i].BackupQueue.Count; n++) { if (Business.Market.InvestorOnline[i].BackupQueue[n].Key == keyConfirm) { Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } else { backupCommand += Business.Market.InvestorOnline[i].BackupQueue[n].CommandQueue + "▼"; Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; Business.Market.InvestorOnline[i].BackupQueue.Add(newBackupQueue); } #endregion isValidKey = true; } } } #endregion } } #endregion } } else { #region SEARCH INVESTOR IN INVESTOR LIST OF CLASS MARKET if (Business.Market.InvestorList != null) { bool flag = false; int countInvestor = Business.Market.InvestorList.Count; for (int j = 0; j < Business.Market.InvestorList.Count; j++) { if (Business.Market.InvestorList[j].LoginKey != null) { if (Business.Market.InvestorList[j].InvestorID == investorID && Business.Market.InvestorList[j].LoginKey == key) { #region CHECK STATUS INVESTOR if (!Business.Market.InvestorList[j].IsOnline) { if (Business.Market.InvestorList[j].IsLogout) return string.Empty; Business.Market.InvestorList[j].IsOnline = true; Business.Market.InvestorList[j].AddInvestorToInvestorOnline(Business.Market.InvestorList[j]); } #endregion Business.Market.InvestorList[j].LastConnectTime = DateTime.Now; Business.Market.InvestorList[j].InvestorIndex = j; //SEND COMMAND UPDATE INVESTOR INDEX if (Business.Market.InvestorList[j].ClientCommandQueue == null) Business.Market.InvestorList[j].ClientCommandQueue = new List<string>(); string messageChangeIndex = "CII00434543$" + Business.Market.InvestorList[j].InvestorIndex; Business.Market.InvestorList[j].ClientCommandQueue.Add(messageChangeIndex); #region GET CLIENT COMMAND SERVER if (Business.Market.InvestorList[j].ClientCommandQueue != null) { int countMessage = Business.Market.InvestorList[j].ClientCommandQueue.Count; for (int n = 0; n < Business.Market.InvestorList[j].ClientCommandQueue.Count; n++) { try { if (Business.Market.InvestorList[j].ClientCommandQueue[0] != null) { result += Business.Market.InvestorList[j].ClientCommandQueue[0] + "▼"; resultBackup += Business.Market.InvestorList[j].ClientCommandQueue[0] + "▼"; if (Business.Market.InvestorList[j].ClientCommandQueue[0] == "OLOFF14790251") { Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); continue; } tempResult.Add(Business.Market.InvestorList[j].ClientCommandQueue[0]); Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorList[j].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } #endregion #region ADD COMMAND TO INVESTOR LOGIN WITH PASSWORD READ ONLY if (Business.Market.InvestorOnline != null) { for (int n = 0; n < Business.Market.InvestorOnline.Count; n++) { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey != key) { if (tempResult != null) { int countMessage = tempResult.Count; for (int m = 0; m < countMessage; m++) { Business.Market.InvestorOnline[n].ClientCommandQueue.Add(tempResult[m]); } } } else { if (Business.Market.InvestorOnline[n].InvestorID == investorID && Business.Market.InvestorOnline[n].LoginKey == key) { if (Business.Market.InvestorOnline[n].ClientCommandQueue != null) { for (int m = 0; m < Business.Market.InvestorOnline[n].ClientCommandQueue.Count; m++) { try { if (Business.Market.InvestorOnline[n].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[n].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[n].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } } } } } #endregion #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (Business.Market.InvestorList[j].BackupQueue != null) { int countBackup = Business.Market.InvestorList[j].BackupQueue.Count; for (int n = 0; n < Business.Market.InvestorList[j].BackupQueue.Count; n++) { if (Business.Market.InvestorList[j].BackupQueue[n].Key == keyConfirm) { Business.Market.InvestorList[j].BackupQueue.RemoveAt(n); n--; } else { backupCommand += Business.Market.InvestorList[j].BackupQueue[n].CommandQueue + "▼"; Business.Market.InvestorList[j].BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; Business.Market.InvestorList[j].BackupQueue.Add(newBackupQueue); } #endregion flag = true; isValidKey = true; break; } } } if (!flag) { #region GET MESSAGE SERVER FROM INVESTOR ONLINE if (Business.Market.InvestorOnline != null) { for (int i = 0; i < Business.Market.InvestorOnline.Count; i++) { if (Business.Market.InvestorOnline[i].InvestorID == investorID && Business.Market.InvestorOnline[i].LoginKey == key) { if (Business.Market.InvestorOnline[i].ClientCommandQueue != null) { int countMessage = Business.Market.InvestorOnline[i].ClientCommandQueue.Count; for (int j = 0; j < Business.Market.InvestorOnline[i].ClientCommandQueue.Count; j++) { try { if (Business.Market.InvestorOnline[i].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; resultBackup += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (Business.Market.InvestorOnline[i].BackupQueue != null) { int countBackup = Business.Market.InvestorOnline[i].BackupQueue.Count; for (int n = 0; n < Business.Market.InvestorOnline[i].BackupQueue.Count; n++) { if (Business.Market.InvestorOnline[i].BackupQueue[n].Key == keyConfirm) { Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } else { backupCommand += Business.Market.InvestorOnline[i].BackupQueue[n].CommandQueue + "▼"; Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; Business.Market.InvestorOnline[i].BackupQueue.Add(newBackupQueue); } #endregion isValidKey = true; } } } #endregion } } #endregion } } else { #region ACCOUNT READ ONLY if (Business.Market.InvestorOnline != null) { for (int i = 0; i < Business.Market.InvestorOnline.Count; i++) { if (Business.Market.InvestorOnline[i].InvestorID == investorID && Business.Market.InvestorOnline[i].LoginKey == key) { if (Business.Market.InvestorOnline[i].ClientCommandQueue != null) { int countMessage = Business.Market.InvestorOnline[i].ClientCommandQueue.Count; for (int j = 0; j < countMessage; j++) { try { if (Business.Market.InvestorOnline[i].ClientCommandQueue[0] != null) { result += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; resultBackup += Business.Market.InvestorOnline[i].ClientCommandQueue[0] + "▼"; Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } else { Business.Market.InvestorOnline[i].ClientCommandQueue.RemoveAt(0); } } catch (Exception ex) { } } } #region PROCESS DATA BACKUP if (port == 0) { string backupCommand = string.Empty; if (Business.Market.InvestorOnline[i].BackupQueue != null) { int countBackup = Business.Market.InvestorOnline[i].BackupQueue.Count; for (int n = 0; n < Business.Market.InvestorOnline[i].BackupQueue.Count; n++) { if (Business.Market.InvestorOnline[i].BackupQueue[n].Key == keyConfirm) { Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } else { backupCommand += Business.Market.InvestorOnline[i].BackupQueue[n].CommandQueue + "▼"; Business.Market.InvestorOnline[i].BackupQueue.RemoveAt(n); n--; } } } if (backupCommand.EndsWith("▼")) backupCommand = backupCommand.Remove(backupCommand.Length - 1, 1); string keyBackup = DateTime.Now.Ticks.ToString(); if (!string.IsNullOrEmpty(backupCommand)) result += "▼" + backupCommand + ">" + keyBackup; else result += ">" + keyBackup; //ADD COMMAND TO BACKUP QUEUE OF INVESTOR Business.BackupQueue newBackupQueue = new Business.BackupQueue(); newBackupQueue.Key = keyBackup; newBackupQueue.CommandQueue = resultBackup + backupCommand; Business.Market.InvestorOnline[i].BackupQueue.Add(newBackupQueue); } #endregion isValidKey = true; } } } #endregion } #region REMOVE CHAR //if (result.Length > 1) //{ // result = result.Remove(result.Length - 1); //} #endregion if (!isValidKey) { result = "OLOFF14790251"; } return result; }