当前位置: 首页>>代码示例>>C#>>正文


C# IMessageBus.AsObservable方法代码示例

本文整理汇总了C#中IMessageBus.AsObservable方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageBus.AsObservable方法的具体用法?C# IMessageBus.AsObservable怎么用?C# IMessageBus.AsObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageBus的用法示例。


在下文中一共展示了IMessageBus.AsObservable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DemoTileListener

        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();
        }
开发者ID:jorik041,项目名称:demo,代码行数:9,代码来源:DemoTileListener.cs

示例2: EditorController

        /// <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);
        }
开发者ID:jorik041,项目名称:demo,代码行数:11,代码来源:EditorController.cs

示例3: Initialize

        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);
        }
开发者ID:jorik041,项目名称:demo,代码行数:31,代码来源:ActionStreetMapBehaviour.cs

示例4: Awake

        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);
                });
        }
开发者ID:yuta0023,项目名称:demo,代码行数:44,代码来源:GpsTrackBehaviour.cs

示例5: IrcConnection

        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();
        }
开发者ID:attila3453,项目名称:alsing,代码行数:50,代码来源:IrcConnection.cs

示例6: Initialize

        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);
            });
        }
开发者ID:RagnarDanneskjold,项目名称:utymap,代码行数:21,代码来源:Program.cs

示例7: AttachParser


//.........这里部分代码省略.........
               .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();

        }
开发者ID:attila3453,项目名称:alsing,代码行数:101,代码来源:IrcConnection.cs

示例8: Start

 void Start()
 {
     _messageBus= ApplicationManager.Instance.GetService<IMessageBus>();
     _messageBus.AsObservable<TerrainInputMode>().Subscribe(m => _inputMode = m);
 }
开发者ID:jorik041,项目名称:demo,代码行数:5,代码来源:TerrainDrawBehaviour.cs


注:本文中的IMessageBus.AsObservable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。