public void Reset(SyncState state) { Game gamestate = new Game(); gamestate.Sync(state); this.EnqueueCallback(delegate { Game.State = gamestate; }); }
public void Sync(SyncState state) { this.ActiveTradableSecurities.Clear(); this.ActiveTransportationAssets.Clear(); this.ActiveSecurities.Clear(); this.Securities.Clear(); this.Accounts.Clear(); this.Currencies.Clear(); this.TradingLimitTable.Clear(); this.PortfolioTable.Clear(); this.Spreads.Clear(); this.RiskTypes.Clear(); this.PropertyChanged = null; this.Assets.Clear(); this.OrderTable.Clear(); this.TimeSalesTable.Clear(); this.ElectricityCharts.Clear(); this._NLV = 0m; state.Current.CopyTo(this.Current); state.General.CopyTo(this.General); state.TraderType.CopyTo(this.TraderType); state.Trader.CopyTo(this.Trader); this.OrderHistoryTable.ClearAndMerge(new ProtoTable(state.OrderHistoryTable).Table); this.TransactionTable.ClearAndMerge(new ProtoTable(state.TransactionTable).Table); this.OrderTable.BeginLoadData(); if (state.Securities != null) { SecurityParameters[] securities = state.Securities; for (int i = 0; i < securities.Length; i++) { SecurityParameters securityParameters = securities[i]; this.OrderTable.Columns["Ticker"].DefaultValue = securityParameters.Ticker; DataTable table = new ProtoTable(state.OrderTables[securityParameters.Ticker]).Table; int num = 0; foreach (DataRow dataRow in table.Rows) { if ((string)dataRow["TraderID"] == this.Trader.TraderID) { num++; } this.OrderTable.Rows.Add(dataRow.ItemArray); } using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(state.SecurityCharts[securityParameters.Ticker])) { using (System.IO.MemoryStream memoryStream2 = new System.IO.MemoryStream(state.VolumeCharts[securityParameters.Ticker])) { this.Securities.Add(securityParameters.Ticker, new SecurityItem(securityParameters, state.Trader.TraderID, this.OrderTable, this.OrderHistoryTable) { HistoryChart = Serializer.Deserialize<ChartItem<SecurityChartPoint>>(memoryStream), VolumeChart = Serializer.Deserialize<ChartItem<SecurityVolumeChartPoint>>(memoryStream2) }); this.Securities[securityParameters.Ticker].InitializeVolume(); this.Securities[securityParameters.Ticker].InitializeLadder(table, this.Trader.TraderID); this.Securities[securityParameters.Ticker].OpenLimitOrders = num; } } } this.OrderTable.Columns["Ticker"].DefaultValue = System.DBNull.Value; } this.OrderTable.EndLoadData(); if (state.Accounts != null) { foreach (System.Collections.Generic.KeyValuePair<string, decimal> current in state.Accounts) { this.Accounts.Add(current.Key, new AccountItem { Balance = current.Value }); } } if (state.CurrencyParameters != null) { CurrencyParameters[] currencyParameters = state.CurrencyParameters; for (int j = 0; j < currencyParameters.Length; j++) { CurrencyParameters currencyParameters2 = currencyParameters[j]; this.Currencies.Add(currencyParameters2.Ticker, currencyParameters2); } } if (state.RiskTypes != null) { RiskTypeParameters[] riskTypes = state.RiskTypes; for (int k = 0; k < riskTypes.Length; k++) { RiskTypeParameters riskTypeParameters = riskTypes[k]; this.RiskTypes.Add(riskTypeParameters.Name, riskTypeParameters); } } if (state.TradingLimits != null) { TradingLimitUpdateMessage[] tradingLimits = state.TradingLimits; for (int l = 0; l < tradingLimits.Length; l++) { TradingLimitUpdateMessage tradingLimitUpdateMessage = tradingLimits[l]; this.TradingLimitTable.Rows.Add(new object[] { tradingLimitUpdateMessage.Name, tradingLimitUpdateMessage.Gross, tradingLimitUpdateMessage.Net }); } } if (state.SecurityPortfolio != null) { PortfolioUpdateMessage[] securityPortfolio = state.SecurityPortfolio; for (int m = 0; m < securityPortfolio.Length; m++) { PortfolioUpdateMessage portfolioUpdateMessage = securityPortfolio[m]; this.PortfolioTable.Rows.Add(new object[] { portfolioUpdateMessage.Ticker, portfolioUpdateMessage.Position, portfolioUpdateMessage.VWAP, this.Securities[portfolioUpdateMessage.Ticker].Parameters.UnitMultiplier, (this.Securities[portfolioUpdateMessage.Ticker].Parameters.Type == SecurityType.FUTURE) ? 0 : 1, this.Securities[portfolioUpdateMessage.Ticker].Parameters.Type }); } } if (state.Spreads != null) { SpreadParameters[] spreads = state.Spreads; for (int n = 0; n < spreads.Length; n++) { SpreadParameters spreadParameters = spreads[n]; this.Spreads.Add(spreadParameters.Ticker, spreadParameters); } } this.AssetInfoTable.ClearAndMerge(new System.Collections.Generic.List<AssetParameters>(state.Assets ?? new AssetParameters[0]).ToDataTable("")); if (state.AssetLeaseCount != null) { AssetItemUpdateMessage[] assetLeaseCount = state.AssetLeaseCount; for (int num2 = 0; num2 < assetLeaseCount.Length; num2++) { AssetItemUpdateMessage assetItemUpdateMessage = assetLeaseCount[num2]; this.AssetInfoTable.Rows.Find(assetItemUpdateMessage.Ticker)["LeaseCount"] = assetItemUpdateMessage.LeaseCount; } } this.AssetTable.ClearAndMerge(new System.Collections.Generic.List<AssetUpdateMessage>(state.AssetPortfolio ?? new AssetUpdateMessage[0]).ToDataTable("")); this.OTCOrderTable.ClearAndMerge(new ProtoTable(state.OTCOrderTable).Table); if (state.Attribution != null) { foreach (System.Collections.Generic.KeyValuePair<string, decimal> current2 in state.Attribution) { if (this.Securities.ContainsKey(current2.Key)) { this.PortfolioTable.Rows.Find(current2.Key)["Realized"] = current2.Value; } if (this.AssetInfoTable.Rows.Find(current2.Key) != null) { this.AssetInfoTable.Rows.Find(current2.Key)["Realized"] = current2.Value; } } } this.NewsTable.ClearAndMerge(new ProtoTable(state.NewsTable).Table); using (System.IO.MemoryStream memoryStream3 = new System.IO.MemoryStream(state.TraderChart)) { this.TraderChart = Serializer.Deserialize<ChartItem<TraderChartPoint>>(memoryStream3); } if (state.ElectricityCharts != null) { this.ElectricityCharts.AddRange(state.ElectricityCharts); } foreach (SecurityItem current3 in this.Securities.Values) { string ticker = current3.Parameters.Ticker; current3.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Volume") { this.PortfolioTable.Rows.Find(ticker)["Volume"] = ((SecurityItem)sender).Volume; return; } if (e.PropertyName == "Last") { this.PortfolioTable.Rows.Find(ticker)["Last"] = ((SecurityItem)sender).Last; return; } if (e.PropertyName == "Bid") { this.PortfolioTable.Rows.Find(ticker)["Bid"] = ((SecurityItem)sender).Bid; return; } if (e.PropertyName == "Ask") { this.PortfolioTable.Rows.Find(ticker)["Ask"] = ((SecurityItem)sender).Ask; return; } if (e.PropertyName == "BidSize") { this.PortfolioTable.Rows.Find(ticker)["BidSize"] = ((SecurityItem)sender).BidSize; return; } if (e.PropertyName == "AskSize") { this.PortfolioTable.Rows.Find(ticker)["AskSize"] = ((SecurityItem)sender).AskSize; return; } if (e.PropertyName == "VWAP") { this.PortfolioTable.Rows.Find(ticker)["SecurityVWAP"] = ((SecurityItem)sender).VWAP; } }; } this.OpenOrderView.RowFilter = string.Format("VolumeRemaining<>0 AND TraderID='{0}'", this.Trader.TraderID.DataTableStringEscape()); this.NewsUnreadView.RaiseUpdate(); this.OTCPendingOrderView.RaiseUpdate(); foreach (SecurityItem current4 in this.Securities.Values) { current4.BidView.RaiseUpdate(); current4.AskView.RaiseUpdate(); } }
public void Sync(SyncState state) { ServiceManager.Execute(delegate(IClientService x) { x.SyncReceived(); }); ((Client)ThreadHelper.MainThread).SetLoadingStatus("Syncing..."); Game game = new Game(); game.Sync(state); Game.State = game; ConnectedTradersManager.Initialize(); ChatManager.Initialize(); lock (this.SyncRoot) { this.IsSynced = true; this.EnqueueOrderedUpdate(null); while (this.PresyncQueue.Count > 0) { Action a = this.PresyncQueue.Dequeue(); ThreadHelper.MainThread.BeginInvokeIfRequired(a); } } ((Client)ThreadHelper.MainThread).SetLoadingStatus("UI..."); ThreadHelper.MainThread.BeginInvokeIfRequired(delegate { GameManager.UpdateStatus(Game.State.Current); ((Client)ThreadHelper.MainThread).SetUIState(Client.UIState.ACTIVE); }); }