private static void CreateChartData2(object state) { ChartDataArgument2 chartDataArgument = (ChartDataArgument2)state; try { //DataSet dataSet = this.GetChartData2(chartDataArgument.InstrumentId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); //SChart.Datas.StockData stockData = new SChart.Datas.StockData(cookieContainer); //DataSet dataSet = stockData.GetChartData2(chartDataArgument.InstrumentId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); TradingConsoleState tradingConsoleState = chartDataArgument.TradingConsoleState; Guid quotePolicyId = (Guid)tradingConsoleState.Instruments[chartDataArgument.InstrumentId]; TradingConsoleServer tradingConsoleServer = chartDataArgument.TradingConsoleServer; DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); AsyncResultManager asyncResultManager = chartDataArgument.AsyncResultManager; asyncResultManager.SetResult(chartDataArgument.AsyncResult, dataSet); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult)); //else //{ // string userIdString = string.Empty; // if (chartDataArgument.Token != null) // { // Token token = chartDataArgument.Token; // userIdString = token.UserID.ToString(); // } // AppDebug.LogEvent("TradingConsole.Service.CreateChartData2", "CookieContainer Timeout" + " UserId: " + userIdString, EventLogEntryType.Warning); // Commands commands = chartDataArgument.Commands; // commands.Add(chartDataArgument.Token, new AsyncCommand(0, chartDataArgument.AsyncResult, true, null)); //} } catch (Exception e) { _Logger.Error(e); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult, true, e)); } }
private static void CreateChartData2ForMobile(object state) { ChartDataArgument2 chartDataArgument = (ChartDataArgument2)state; try { TradingConsoleState tradingConsoleState = chartDataArgument.TradingConsoleState; Guid quotePolicyId = (Guid)tradingConsoleState.Instruments[chartDataArgument.InstrumentId]; TradingConsoleServer tradingConsoleServer = chartDataArgument.TradingConsoleServer; //DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); string dataCycle = chartDataArgument.DataCycle.ToLower(); string dateFormat = ChartQuotation.FormatMinute; //DataSet dataSet = DataAccess.GetChartData(instrumentId, quotePolicyId, dataCycle, fromTime.Value, toTime, commandTimeOut); DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); ChartQuotationCollection chartQuotationCollection = ChartQuotationCollection.Create(dataSet, dataCycle, dateFormat); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ChartQuotationCollection)); string result; using (MemoryStream stream = new MemoryStream()) { serializer.WriteObject(stream, chartQuotationCollection); stream.Seek(0, SeekOrigin.Begin); StreamReader streamReader = new StreamReader(stream); result = streamReader.ReadToEnd(); } AsyncResultManager asyncResultManager = chartDataArgument.AsyncResultManager; XElement element = XmlResultHelper.NewResult("ChartData", result); asyncResultManager.SetResult(chartDataArgument.AsyncResult, element); AsyncCommand command = new AsyncCommand(0, chartDataArgument.AsyncResult); command.Content = element.ToXmlNode(); CommandManager.Default.AddCommand(command); } catch (Exception e) { _Logger.Error(e); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult, true, e)); } }