public static string GetSubscribedStateChanges() { Dictionary <string, string> items = new Dictionary <string, string>(); if (Global.State.Subscriptions["schedulerRunning"].Subscribed && Global.State.Subscriptions["schedulerRunning"].IsReady()) { bool update = (Global.State.SchedulerTC.State == ThreadControlState.Running) != (bool)Global.State.Subscriptions["schedulerRunning"].State; if (update) { bool val = (Global.State.SchedulerTC.State == ThreadControlState.Running); Global.State.Subscriptions["schedulerRunning"].State = val; items.Add("schedulerRunning", UC.BoolToJSBool(val)); } } if (Global.State.Subscriptions["applicationStats"].Subscribed && Global.State.Subscriptions["applicationStats"].IsReady()) { items.Add("applicationStats", SerializerMethods.SerializeApplicationStats()); } if (Global.State.Subscriptions["threadControlTree"].Subscribed && Global.State.Subscriptions["threadControlTree"].IsReady()) { lock (Global.State.ThreadControlTreeLock) { long change = GetThreadControlTreeChangeValue(); if (change != (long)Global.State.Subscriptions["threadControlTree"].State) { Global.State.Subscriptions["threadControlTree"].State = change; items.Add("threadControlTree", SerializerMethods.SerializeThreadControlTree()); } } } // don't do this if we already have a threadControlTree if (Global.State.Subscriptions["threadControlState"].Subscribed && !items.ContainsKey("threadControlTree") && Global.State.Subscriptions["threadControlState"].IsReady()) { lock (Global.State.ThreadControlTreeLock) { string json = GetSerializedThreadControlChangedState(); string state = UC.MD5Hash(json); if (!string.IsNullOrWhiteSpace(json) && state != (string)Global.State.Subscriptions["threadControlState"].State) { Global.State.Subscriptions["threadControlState"].State = state; items.Add("threadControlState", json); } } } if (Global.State.Subscriptions["threadControlLog"].Subscribed && Global.State.Subscriptions["threadControlLog"].IsReady()) { Tools.LogObjects.Log log = RecursiveFindLogByThreadControlId(Global.State.SelectedThreadControlId, Global.State.ThreadControlTree); if (log != null && (log.ChangedSinceLastRead(Verbosity.Verbose) || Global.State.ThreadControlIdChanged)) { items.Add("threadControlLog", "\"" + System.Web.HttpUtility.JavaScriptStringEncode(log.Read(Verbosity.Verbose)) + "\""); } } Global.State.ThreadControlIdChanged = false; return(SerializerMethods.DictionarySerializedValuesToJSON(items)); }
public static void TryBuildPayload() { if (IsSubscribed) { Current++; if (Current >= Frequency) { Current = 0; lock (LockObj) { Dictionary <string, string> items = new Dictionary <string, string>(); if (Global.State.AlgoTraderSubscriptions["main"] == true) { AlgoTraderMain main = new AlgoTraderMain(); main.CurrentTime = AlgoTraderState.CurrentTime.ToString(); main.SelectedSymbol = SelectedSymbol; main.SelectedStrategyName = AlgoTraderMethods.GetStrategyName(SelectedStrategyId); main.SelectedStrategyId = SelectedStrategyId; using (var output = new StringWriter()) { JSON.Serialize(main, output, Options.PrettyPrint); items.Add("algoTraderMain", output.ToString()); } } if (Global.State.AlgoTraderSubscriptions["log"] == true) { UIObjects.AlgoTraderLog log = new UIObjects.AlgoTraderLog(); log.Log = Global.State.AlgoTrader.TC.Log.Read(Verbosity.Verbose); //log.Log = System.Web.HttpUtility.JavaScriptStringEncode(Global.State.AlgoTrader.TC.Log.Read(Verbosity.Verbose)); using (var output = new StringWriter()) { JSON.Serialize(log, output, Options.PrettyPrint); items.Add("algoTraderLog", output.ToString()); } } if (Global.State.AlgoTraderSubscriptions["overview"] == true) { AlgoTraderOverview overview = buildOverviewObject(); using (var output = new StringWriter()) { JSON.Serialize(overview, output, Options.PrettyPrint); items.Add("algoTraderOverview", output.ToString()); } } if (Global.State.AlgoTraderSubscriptions["chart"] == true) { AlgoTraderChart chart = buildChartObject(); using (var output = new StringWriter()) { JSON.Serialize(chart, output, Options.Default); items.Add("algoTraderChart", output.ToString()); } } Payload = SerializerMethods.DictionarySerializedValuesToJSON(items); } } } }