public VarBars(IMessageBus ether, int contractId, int numBarsToStore, int BarLength) { Ether = ether; ContractId = contractId; NumBarsToStore = numBarsToStore; VarBudget = 0.0001 * BarLength / 86400.0; Bars = new CircularBuffer <Bar>(NumBarsToStore); Ether.AsObservable <Market>().Where(x => x.ContractId == ContractId).Subscribe(x => { UpdateBar(x); }, e => { Debug.WriteLine(e.ToString()); throw e; }); // Subscribe to end-of-day heartbeats. Ether.AsObservable <Heartbeat>().Where(x => x.IsDaily()).Subscribe(x => { CompleteBar(); }, e => { Debug.WriteLine(e.ToString()); throw e; }); currentBar = null; quadraticVariation = 0; }
public DemoTileListener(IMessageBus messageBus, PerformanceLogger logger) { _logger = logger; messageBus.AsObservable <TileLoadStartMessage>().Do(m => OnTileBuildStarted(m.TileCenter)).Subscribe(); messageBus.AsObservable <TileLoadFinishMessage>().Do(m => OnTileBuildFinished(m.Tile)).Subscribe(); messageBus.AsObservable <TileDestroyMessage>().Do(m => OnTileDestroyed(m.Tile)).Subscribe(); }
public void RunGame() { _logger.Start(); var config = ConfigBuilder.GetDefault() .Build(); var componentRoot = TestHelper.GetGameRunner(_container, config); _messageBus = _container.Resolve <IMessageBus>(); _trace = _container.Resolve <ITrace>(); _tileListener = new DemoTileListener(_messageBus, _logger); // start game on default position componentRoot.RunGame(StartGeoCoordinate); _geoPositionObserver = _container.Resolve <ITileController>(); _mapPositionObserver = _container.Resolve <ITileController>(); _messageBus.AsObservable <GeoPosition>().Do(position => { _trace.Debug(LogTag, "GeoPosition: {0}", position.ToString()); _geoPositionObserver.OnNext(position.Coordinate); }).Subscribe(); _messageBus.AsObservable <Vector2d>().Do(position => { _trace.Debug(LogTag, "MapPosition: {0}", position.ToString()); _mapPositionObserver.OnNext(position); }).Subscribe(); }
public DemoTileListener(IMessageBus messageBus, ITrace trace) { _trace = trace; messageBus.AsObservable <TileLoadStartMessage>().Do(m => OnTileBuildStarted(m.TileCenter)).Subscribe(); messageBus.AsObservable <TileLoadFinishMessage>().Do(m => OnTileBuildFinished(m.Tile)).Subscribe(); messageBus.AsObservable <TileDestroyMessage>().Do(m => OnTileDestroyed(m.Tile)).Subscribe(); }
public DemoTileListener(IMessageBus messageBus, ITrace trace) { _messageBus = messageBus; _trace = trace; _messageBus.AsObservable<TileLoadStartMessage>().Do(m => OnTileBuildStarted(m.TileCenter)).Subscribe(); _messageBus.AsObservable<TileLoadFinishMessage>().Do(m => OnTileBuildFinished(m.Tile)).Subscribe(); _messageBus.AsObservable<TileDestroyMessage>().Do(m => OnTileDestroyed(m.Tile)).Subscribe(); }
public MapGenTileListener(MapGenManager manager) { m_manager = manager; IMessageBus messageBus = m_manager.GetService <IMessageBus>(); messageBus.AsObservable <TileLoadFinishMessage>().Do(m => OnTileLoadFinish(m.Tile)).Subscribe(); messageBus.AsObservable <WorldLoadFinishMessage>().Do(m => OnWorldLoadFinish()).Subscribe(); }
/// <summary> Creates instance of <see cref="EditorController"/>. </summary> public EditorController(ITileModelEditor tileModelEditor, IMessageBus messageBus) { _tileModelEditor = tileModelEditor; messageBus.AsObservable<TerrainPointMessage>().Subscribe(HandlePointMessage); messageBus.AsObservable<TerrainPolylineMessage>().Subscribe(HandlePolylineMessage); messageBus.AsObservable<TerrainPolygonMessage>().Subscribe(HandlePolygonMessage); messageBus.AsObservable<EditorActionMode>().Subscribe(a => _actionMode = a); }
private void Initialize() { // wait for loading.. //gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; var thirdPersonControll = gameObject.GetComponent<ThirdPersonController>(); _initialGravity = thirdPersonControll.gravity; thirdPersonControll.gravity = 0; _appManager = ApplicationManager.Instance; _messageBus = _appManager.GetService<IMessageBus>(); _appManager.CreateConsole(true); _messageBus.AsObservable<GameRunner.GameStartedMessage>() .Where(msg => msg.Tile.RenderMode == RenderMode.Scene) .Take(1) .Delay(TimeSpan.FromSeconds(2)) // give extra seconds.. .ObserveOnMainThread() .Subscribe(_ => { var position = transform.position; var elevation = _appManager.GetService<IElevationProvider>() .GetElevation(new MapPoint(position.x, position.z)); transform.position = new Vector3(position.x, elevation + 90, position.z); thirdPersonControll.gravity = _initialGravity; }); // ASM should be started from non-UI thread Observable.Start(() => _appManager.RunGame(), Scheduler.ThreadPool); }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService<ITileController>(); _messageBus = appManager.GetService<IMessageBus>(); _trace = appManager.GetService<ITrace>(); var elevationProvider = appManager.GetService<IElevationProvider>(); _messageBus.AsObservable<GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable<TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService <ITileController>(); _messageBus = appManager.GetService <IMessageBus>(); _trace = appManager.GetService <ITrace>(); var elevationProvider = appManager.GetService <IElevationProvider>(); _messageBus.AsObservable <GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable <TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }
void Start() { var rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = true; _tileController .Where(tile => tile.IsDisposed) .ObserveOn(Scheduler.MainThread) .Subscribe(tile => { _trace.Info(LogCategory, "Remove tile: {0}", tile.ToString()); Destroy(tile.GameObject); }); _tileController .Where(tile => !tile.IsDisposed) .SelectMany(tile => _mapDataLoader.Load(tile) .Select(u => new Tuple <Tile, Union <Element, Mesh> >(tile, u)) .ObserveOn(Scheduler.MainThread) .DoOnCompleted(() => { if (rigidBody.isKinematic) { var position = transform.position; var coordinate = GeoUtils.ToGeoCoordinate(GetWorldZeroPoint(), position.x, position.z); var height = (float)_appManager.GetService <MapElevationLoader>().Load(tile.QuadKey, coordinate); transform.position = new Vector3(position.x, height + 2, position.z); rigidBody.isKinematic = false; } })) .SubscribeOn(Scheduler.ThreadPool) .ObserveOn(Scheduler.MainThread) .Subscribe(t => t.Item2.Match(e => _modelBuilder.BuildElement(t.Item1, e), m => _modelBuilder.BuildMesh(t.Item1, m))); _messageBus .AsObservable <OnZoomRequested>() .Subscribe(msg => { var newLevel = msg.IsZoomOut ? 14 : 16; if (newLevel == _levelOfDetails) { return; } _levelOfDetails = newLevel; _messageBus.Send(new OnZoomChanged(newLevel)); }); // NOTE: code below loads region tile by tile. // The region is specified by rectangle defined in world coordinates. // float size = 600; // square side size (in meters) // Scheduler.ThreadPool.Schedule(() => _tileController.OnRegion(new Rectangle(-size / 2, -size / 2, size, size), _levelOfDetails)); }
public BarList(IMessageBus ether, int contractId, int numBarsToStore, int barLengthInSeconds) { Ether = ether; if (barLengthInSeconds < Ether.EpochSecs) { throw new Exception("Error, bars shorter than " + Ether.EpochSecs + "s are not possible!"); } if (barLengthInSeconds % Ether.EpochSecs != 0) { throw new Exception("Error, bar length must be a multiple of " + Ether.EpochSecs + "s"); } ContractId = contractId; MaxBars = numBarsToStore; BarLength = barLengthInSeconds; Bars = new CircularBuffer <Bar>(MaxBars); // Subscribe to the contract's ticks. Ether.AsObservable <Market>().Where(x => x.ContractId == ContractId).Subscribe(x => { Update(x); }, e => { Debug.WriteLine(e.ToString()); throw e; }); // Subscribe to the epoch heartbeats that will signal the completion of bars. Ether.AsObservable <Heartbeat>().Where(x => x.Timestamp.TimeOfDay.TotalSeconds % BarLength == 0).Subscribe(x => { CompleteBar(x.Timestamp); }, e => { Debug.WriteLine(e.ToString()); throw e; }); }
private void AttachAddressLocator() { _messageBus .AsObservable <GameStarted>() .ObserveOnMainThread() .Subscribe(_ => { gameObject.AddComponent <AddressLocatorBehaviour>() .SetCommandController(_console.CommandController) .GetObservable() .Subscribe(address => { _currentAddress = address; }); }); }
public IrcConnection(IMessageBus messageBus) : base(messageBus) { commands = new IrcCommands(this.WriteLine); this.messageBus = messageBus; var myMessages = messageBus .AsObservable<DataReceivedMessage>() .Where(m => m.Connection == this); //only handle messages sent by this connection AttachParser(messageBus, myMessages); myMessages .Where(m => Patterns.ActionRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** ActionRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.CtcpRequestRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** CtcpRequestRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.InviteRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** InviteRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.TopicRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** TopicRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.KickRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** KickRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.CtcpReplyRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** CtcpReply Message ****")) .Subscribe(); }
public IrcConnection(IMessageBus messageBus) : base(messageBus) { commands = new IrcCommands(this.WriteLine); this.messageBus = messageBus; var myMessages = messageBus .AsObservable <DataReceivedMessage>() .Where(m => m.Connection == this); //only handle messages sent by this connection AttachParser(messageBus, myMessages); myMessages .Where(m => Patterns.ActionRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** ActionRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.CtcpRequestRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** CtcpRequestRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.InviteRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** InviteRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.TopicRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** TopicRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.KickRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** KickRegex Message ****")) .Subscribe(); myMessages .Where(m => Patterns.CtcpReplyRegex.IsMatch(m.Data)) .Do(_ => Console.ForegroundColor = ConsoleColor.Gray) .Do(m => Console.WriteLine("*** CtcpReply Message ****")) .Subscribe(); }
private void Initialize() { // initialize services _compositionRoot = TestHelper.GetCompositionRoot(_worldZeroPoint); // get local references _messageBus = _compositionRoot.GetService<IMessageBus>(); _trace = _compositionRoot.GetService<ITrace>(); _tileController = _compositionRoot.GetService<ITileController>(); SetupMapData(); // set observer to react on geo position changes _messageBus.AsObservable<GeoPosition>() .ObserveOn(Scheduler.MainThread) .Subscribe(position => { _trace.Debug(TraceCategory, "GeoPosition: {0}", position.ToString()); _tileController.OnPosition(position.Coordinate, LevelOfDetails); }); }
private void Initialize() { // initialize services _compositionRoot = TestHelper.GetCompositionRoot(_worldZeroPoint); // get local references _messageBus = _compositionRoot.GetService <IMessageBus>(); _trace = _compositionRoot.GetService <ITrace>(); _tileController = _compositionRoot.GetService <ITileController>(); SetupMapData(); // set observer to react on geo position changes _messageBus.AsObservable <GeoPosition>() .ObserveOn(Scheduler.MainThread) .Subscribe(position => { _trace.Debug(TraceCategory, "GeoPosition: {0}", position.ToString()); _tileController.OnPosition(position.Coordinate, LevelOfDetails); }); }
private void InitialiseBasicSubscriptions(IMessageBus Ether) { // Inform PMS and any components that we exist! Ether.Send(new StrategyInfo(Id)); // Subscribe to relevant ticks, check exit orders and then pass on to the derived strategy. Ether.AsObservable <Market>().Where(x => Contracts.Keys.Contains(x.ContractId)).Subscribe(x => { CheckAndSendExitOrders(x, NetQuantity[x.ContractId]); OnTick(x); }, e => { Debug.WriteLine(e.ToString()); }); Ether.AsObservable <Bar>().Where(x => Contracts.Keys.Contains(x.ContractId)).Subscribe(x => { CheckAndSendExitOrders(x.LastMarket, NetQuantity[x.ContractId]); OnBar(x); OnTick(x.LastMarket); }, e => { Debug.WriteLine(e.ToString()); }); // Subscribe to relevant order executions, update NetQuantity and then pass on to the // derived strategy. Ether.AsObservable <OrderExecution>().Where(x => x.StrategyId == Id).Subscribe(x => { NetQuantity[x.ContractId] += x.FilledQuantity; if (NetQuantity[x.ContractId] == 0) { StopLossOrders[x.ContractId] = null; TakeProfitOrders[x.ContractId] = null; } // Send the position sizer execution info. Sizer.ProcessOrderExecution(x); OnExecution(x); }, e => { Debug.WriteLine(e.ToString()); }); // Subscribe to PnL infos, update account value and then pass on to the derived strategy. Ether.AsObservable <PnLInfo>().Where(x => x.StrategyId == Id).Subscribe(x => { CurrentAccountValue = x.CurrentAccountValue; // Send the position sizer PnL info. Sizer.ProcessPnLInfo(x); OnPnL(x); }, e => { Debug.WriteLine(e.ToString()); }); // Subscribe to updates of the trading hours for any contracts and update MarketHours. Ether.AsObservable <MarketHours>().Where(x => Contracts.Keys.Contains(x.ContractId)).Subscribe(x => { MarketHours[x.ContractId] = x; }, e => { Debug.WriteLine(e.ToString()); }); }
void Start() { _messageBus = ApplicationManager.Instance.GetService <IMessageBus>(); _messageBus.AsObservable <TerrainInputMode>().Subscribe(m => _inputMode = m); _messageBus.AsObservable <EditorActionMode>().Subscribe(a => _actionMode = a); }
private void AttachParser(IMessageBus messageBus, IObservable<DataReceivedMessage> myMessages) { //send typed ping message myMessages .Select(m => Patterns.PingRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcPingMessage { Connection = this, ServerName = f.Groups[1].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed notice message myMessages .Select(m => Patterns.NoticeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcNoticeMessage { Connection = this, Message = f.Groups[2].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed reply message myMessages .Select(m => Patterns.ReplyCodeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcReplyCodeMessage { Connection = this, Message = f.Groups[2].Value,Code=int.Parse(f.Groups[1].Value) }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed error message myMessages .Select(m => Patterns.ErrorRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcErrorMessage { Connection = this, Message = f.Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed Mode message myMessages .Select(m => Patterns.ModeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcModeMessage { Connection = this, Message = f.Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed join message myMessages .Select(m => Patterns.JoinRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcJoinMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant(), }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed part message myMessages .Select(m => Patterns.PartRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcPartMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant() }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed part message myMessages .Select(m => Patterns.QuitRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcQuitMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed channel message myMessages .Select(m => Patterns.MessageRegex.Match(m.Data)) .Where(f => f.Success) .Where(f => f.Groups[3].Value.StartsWith("#")) .Select(f => new IrcChannelSayMessage { Connection = this, User = f.Groups[1].Value, UserIdentity=f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant(), Message=f.Groups[4].Value } ) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed private message myMessages .Select(m => Patterns.MessageRegex.Match(m.Data)) .Where(f => f.Success) .Where(f => !f.Groups[3].Value.StartsWith("#")) .Select(f => new IrcPrivateSayMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, ToUser = f.Groups[3].Value, Message = f.Groups[4].Value } ) .Do(m => messageBus.Send(m)) .Subscribe(); myMessages .Select(m => Patterns.NickRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcNickMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, NewNick = f.Groups[3].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); var replyCodes = messageBus.AsObservable<IrcReplyCodeMessage>(); //send typed channel info replyCodes .Where(m => m.Code == 332) .Select(m => SendChannelInfo(m)) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed channel member info replyCodes .Where(m => m.Code == 353) .Do(m => SendChannelMembers(m)) .Subscribe(); }
private void SubscribeToLocalEvents() { _messageBus.AsObservable <TerrainPointMessage>().Subscribe(msg => _client.Send(msg.Id, msg)); _messageBus.AsObservable <TerrainPolylineMessage>().Subscribe(msg => _client.Send(msg.Id, msg)); }
public IBSource(IMessageBus ether, string hostname, int port, int clientId, string accountName, bool useVarBars, int barLength) { Ether = ether; Hostname = hostname; Port = port; ClientId = clientId; AccountName = accountName; UseVarBars = useVarBars; BarLength = barLength; if (BarLength < Ether.EpochSecs) { throw new Exception(string.Format("Error, TWSSource bar length ({0}) is less than the Ether's epoch interval ({1})!", BarLength, ether.EpochSecs)); } // Set synch context for IBClient SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); IsConnected = false; Signal = new IB.EReaderMonitorSignal(); Client = new IBClient(Signal); // Contract details, currently just market hours. Client.ContractDetails += ContractDetailsHandler; Client.ContractDetailsEnd += (reqId => Debug.WriteLine(reqId)); // Tick data. Client.TickPrice += TickPriceHandler; Client.TickSize += TickSizeHandler; Client.TickGeneric += TickGenericHandler; Client.TickString += TickStringHandler; Client.TickOptionCommunication += TickOptionHandler; Client.TickEFP += EFPDataHandler; // Historical data. Client.HistoricalData += HistoricalDataHandler; Client.HistoricalDataUpdate += HistoricalDataUpdateHandler; Client.HistoricalDataEnd += HistoricalDataEndHandler; // Account and portfolio updates. Client.UpdateAccountTime += AccountTimeHandler; Client.UpdateAccountValue += AccountValueHandler; Client.UpdatePortfolio += PortfolioInfoHandler; // Errors. Client.Error += ErrorHandler; Client.ConnectionClosed += ConnectionClosedHandler; // Server time. Client.CurrentTime += CurrentTimeHandler; // Instance variables. Contracts = new Dictionary <int, Tuple <Contract, Market> >(); Bars = new Dictionary <int, IBarList>(); AccountInfo = new AccountInfo(AccountName); // Daily things-to-do. Ether.AsObservable <Heartbeat>().Where(x => x.IsHourly()).Subscribe(x => { // At 5AM each day, we request contract details so we can see when the contracts are traded. foreach (var c in Contracts.Keys) { RequestContractDetails(c * 9999, Contracts[c].Item1); } }, e => { Debug.WriteLine(e.ToString()); }); }
void Start() { _messageBus= ApplicationManager.Instance.GetService<IMessageBus>(); _messageBus.AsObservable<TerrainInputMode>().Subscribe(m => _inputMode = m); }
private void AttachParser(IMessageBus messageBus, IObservable <DataReceivedMessage> myMessages) { //send typed ping message myMessages .Select(m => Patterns.PingRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcPingMessage { Connection = this, ServerName = f.Groups[1].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed notice message myMessages .Select(m => Patterns.NoticeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcNoticeMessage { Connection = this, Message = f.Groups[2].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed reply message myMessages .Select(m => Patterns.ReplyCodeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcReplyCodeMessage { Connection = this, Message = f.Groups[2].Value, Code = int.Parse(f.Groups[1].Value) }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed error message myMessages .Select(m => Patterns.ErrorRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcErrorMessage { Connection = this, Message = f.Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed Mode message myMessages .Select(m => Patterns.ModeRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcModeMessage { Connection = this, Message = f.Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed join message myMessages .Select(m => Patterns.JoinRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcJoinMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant(), }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed part message myMessages .Select(m => Patterns.PartRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcPartMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant() }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed part message myMessages .Select(m => Patterns.QuitRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcQuitMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed channel message myMessages .Select(m => Patterns.MessageRegex.Match(m.Data)) .Where(f => f.Success) .Where(f => f.Groups[3].Value.StartsWith("#")) .Select(f => new IrcChannelSayMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, Channel = f.Groups[3].Value.ToUpperInvariant(), Message = f.Groups[4].Value } ) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed private message myMessages .Select(m => Patterns.MessageRegex.Match(m.Data)) .Where(f => f.Success) .Where(f => !f.Groups[3].Value.StartsWith("#")) .Select(f => new IrcPrivateSayMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, ToUser = f.Groups[3].Value, Message = f.Groups[4].Value } ) .Do(m => messageBus.Send(m)) .Subscribe(); myMessages .Select(m => Patterns.NickRegex.Match(m.Data)) .Where(f => f.Success) .Select(f => new IrcNickMessage { Connection = this, User = f.Groups[1].Value, UserIdentity = f.Groups[2].Value, NewNick = f.Groups[3].Value, }) .Do(m => messageBus.Send(m)) .Subscribe(); var replyCodes = messageBus.AsObservable <IrcReplyCodeMessage>(); //send typed channel info replyCodes .Where(m => m.Code == 332) .Select(m => SendChannelInfo(m)) .Do(m => messageBus.Send(m)) .Subscribe(); //send typed channel member info replyCodes .Where(m => m.Code == 353) .Do(m => SendChannelMembers(m)) .Subscribe(); }