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


C# Subject.Where方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            using(var fr = new FlowRuntime())
            {
                var frc = new FlowRuntimeConfiguration();
                frc.AddStream(".in", "A");
                frc.AddStream("A", "B");
                frc.AddStream("B", "C");

                frc.AddFunc<int, int>("A", i => i + 1)
                   .AddFunc<int, int>("B", i => i * 2)
                   .AddAction<int>("C", (int i) => Console.WriteLine("={0}", i));
                fr.Configure(frc);

                // Trace messages selectively using Rx
                var tracer = new Subject<IMessage>();
                tracer.Where(msg => msg.Port.OperationName == "B") // message filter
                      .Select(msg => (int)msg.Data)
                      .Subscribe(i => Console.WriteLine("{0} -> B", i), // message handler
                                 _ => { });
                fr.Message += tracer.OnNext;

                fr.Process(new Message(".in", 1));
                fr.Process(new Message(".in", 2));
                fr.Process(new Message(".in", 3));

                fr.WaitForResult(500);
            }
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:29,代码来源:Program.cs

示例2: Start

    // Use this for initialization
    void Start()
    {
        var random = new System.Random();

        TriggerStream = new Subject<float>();
        TriggerStream
            .Where(v => Grabbed)
            .SkipWhile(v => v >= 0.6f)
            .Where(v => v > 0.6f)
            .Take(1)
            .RepeatUntilDestroy(this.gameObject)
            .Subscribe(v =>
            {
                var device = this.transform.parent.gameObject.GetComponent<ControllerBehavior>().device;
                FeedBack(device, 3999, 500.0f);

                var randoms =
                    Enumerable.Range(0, bulletNum)
                    .Select(s => new Vector3(random.Next(-50, 50)/100.0f, random.Next(-50, 50)/100.0f, 1.0f).normalized);

                foreach (var e in randoms)
                {
                    var go_bullet = Instantiate(bullet, this.transform.position + Quaternion.FromToRotation(e,Vector3.forward) * this.transform.forward, Quaternion.identity) as GameObject;
                    //go_bullet.transform.localRotation *= Quaternion.Euler(new Vector3(0,0,90.0f));
                    go_bullet.GetComponent<Rigidbody>().AddForce(BulletSpeed * (go_bullet.transform.position - this.transform.position).normalized, ForceMode.Acceleration);
                    Destroy(go_bullet, 5);
                }
            }
            );
    }
开发者ID:RauziDssh,项目名称:ViveSandBox,代码行数:31,代码来源:ShotgunBehavior.cs

示例3: RightHandGesture

        public RightHandGesture(Subject<Skeleton> skeletons)
        {
            SwipeMinimalLength = 0.4f;
            SwipeMaximalHeight = 0.2f;
            SwipeMininalDuration =  250;
            SwipeMaximalDuration = 1500;
            _skeletons = skeletons;
            _handData = new Subject<HandData>();
            Data = new List<HandData>();

            _skeletons
                .Where(x=> x != null)
                //.Where(x => x.TrackingState == SkeletonTrackingState.Tracked)
                .Select(
                    x =>
                    new HandData
                        {
                            Time = DateTime.Now,
                            Position = x.Position,
                            Joint = x.Joints.First(j => j.JointType == JointType.HandRight)
                        })
                .Subscribe(OnNextRightHand, exception => Console.WriteLine(exception.Message));

            //_skeletons
            //    .Where(x=> x!=null)
            //    .Subscribe(skeleton => { Console.WriteLine("a");}, exception => { });
        }
开发者ID:merbla,项目名称:KinectUs,代码行数:27,代码来源:RightHandGesture.cs

示例4: doStuff

		public static void doStuff()
		{
			//IObservable is equivalent zu IEnumerable
			//x.Subscribe ist equivalent zur foreach-schleife
			//Subject = Observable && Observer zu gleich!!! 
		
			var source = new Subject<int> ();
			var vinylsource = new Subject<Vinyl> ();


			var diskThread = new Thread(() =>
            {
				int j=0;
				var vinyls=new Vinyl[] {
						new Vinyl("Queen","Queen",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Queen II",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Sheer Heart Attack",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","A Night at the Opera",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","A Day at the Races",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","News of the World",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Jazz",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","The Game",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Hot Spaces",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","The Works",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","A Kind of Magic",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","The Miracle",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Innuendo",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","Made in Heaven",33,25,13.99m,Currency.EUR),
						new Vinyl("Queen","The Cosmos Rocks",33,25,13.99m,Currency.EUR)
				};

                vinylsource
                         .Where(x => x.Diskname.Length > 10)
                         .Subscribe(x => Console.WriteLine(x.Diskname));
                
                while (j<vinyls.Length){
					
					Thread.Sleep(500);
					vinylsource.OnNext(vinyls[j]);
                    j++;
                }
			});
			diskThread.Start ();

			var t = new Thread(() =>
				{ 
					int i=0;
					while (true){
						/*Befehle im Thread die blockieren (wie Sleep) --> schlecht. sehr schlecht. */
						Thread.Sleep(1000);
						Console.WriteLine("Thread "+i);
						source.OnNext(i);
						//source.OnError(); //beendet stream wenn hinig
						//source.OnCompleted(); //beendet stream wenn es dezidiert start und endpunkt gibt
						i++;
					}
				});
			//t.Start ();
		}
开发者ID:rkerschbaumer,项目名称:oom,代码行数:59,代码来源:dontKnowHowToPull.cs

示例5: ClientGameEngine

        private ClientGameEngine()
        {
            MediaPlayer = new System.Media.SoundPlayer(@"resources/Audio/BesiegedIntro.wav");
            m_TcpBinding = new NetTcpBinding(SecurityMode.None, true)
                {
                    ReliableSession = { InactivityTimeout = new TimeSpan(0, 2, 0) },
                    SendTimeout = new TimeSpan(0, 2, 0),
                    ReceiveTimeout = new TimeSpan(0, 2, 0),
                    OpenTimeout = new TimeSpan(0, 1, 0),
                    CloseTimeout = new TimeSpan(0, 1, 0),
                    MaxReceivedMessageSize = 2147483647,
                    ReaderQuotas =
                    {
                        MaxArrayLength = 2147483647,
                        MaxBytesPerRead = 2147483647,
                        MaxStringContentLength = 2147483647,
                        MaxDepth = 2147483647,
                    },
                };

            GamesCollection = new ObservableCollection<GameInfoMessage>();
            PlayerCollection = new ObservableCollection<PlayerInfoMessage>();
            ChatMessageCollection = new ObservableCollection<string>();

            AllPlayersReady = new MonitoredValue<bool>(false);
            IsServerConnected = new MonitoredValue<bool>(false);
            IsServerConnected.ValueChanged += (from, to) =>
            {
                if (!to)
                {
                    Action postRender = () => RenderMessageDialog.RenderMessage("Unable to establish connection to server");
                    ChangeState(m_PreviousGameState, postRender);
                }
                else
                {
                    Task.Factory.StartNew(() => ChangeState(MultiplayerMenuState.Get()), CancellationToken.None, TaskCreationOptions.None, GlobalResources.m_TaskScheduler);
                }
            };

            EndpointAddress endpointAddress = new EndpointAddress(String.Format("net.tcp://{0}:{1}/BesiegedServer/BesiegedMessage", ClientSettings.Default.ServerIP, ClientSettings.Default.ServerPort));
            m_DuplexChannelFactory = new DuplexChannelFactory<IBesiegedServer>(m_ClientCallback, m_TcpBinding, endpointAddress);
            m_BesiegedServer = m_DuplexChannelFactory.CreateChannel();

            m_DuplexChannelFactory.Faulted += (s, ev) => MessageBox.Show("Its faulted");

            var MessageSubject = new Subject<BesiegedMessage>();

            var messagePublisher = m_ClientCallback.MessageQueue
                     .GetConsumingEnumerable()
                     .ToObservable(TaskPoolScheduler.Default)
                     .Subscribe(MessageSubject);

            //var messagePublisher = observableMessages.Publish();

            // All generic client messages are handled here
            var genericServerMessageSubscriber = MessageSubject
                .Where(message => message is GenericClientMessage)
                .Subscribe(message =>
                {
                    var genericMessage = message as GenericClientMessage;
                    switch (genericMessage.MessageEnum)
                    {
                        case ClientMessage.ClientMessageEnum.ConnectSuccessful:
                            m_ClientId = genericMessage.ClientId;
                            IsServerConnected.Value = true;
                            break;

                        case ClientMessage.ClientMessageEnum.AllPlayersReady:
                            AllPlayersReady.Value = true;
                            break;

                        case ClientMessage.ClientMessageEnum.PlayerNotReady:
                            AllPlayersReady.Value = false;
                            break;

                        case ClientMessage.ClientMessageEnum.StartGame:
                            ChangeState(PlayingGameState.Get());
                            break;

                        case ClientMessage.ClientMessageEnum.GameDisbanded:
                            if (IsGameCreator)
                            {
                                ChangeState(MultiplayerMenuState.Get());
                            }
                            else
                            {
                                Action disbandedAction = () => RenderMessageDialog.RenderMessage("The game creator has disbanded the game");
                                ChangeState(MultiplayerMenuState.Get(), disbandedAction);
                            }
                            IsGameCreator = false;
                            ResetLobby();
                            break;

                        case ClientMessage.ClientMessageEnum.GameNotFound:
                            Action notFoundAction = () => RenderMessageDialog.RenderMessage("The game you are trying to reach was not found");
                            ChangeState(MultiplayerMenuState.Get(), notFoundAction);
                            break;

                        case ClientMessage.ClientMessageEnum.RemoveGame:
                            Action removeGameAction = () =>
//.........这里部分代码省略.........
开发者ID:WonderPanda,项目名称:Besieged,代码行数:101,代码来源:ClientGameEngine.cs

示例6: Where

        public void Where()
        {
            {
                var a = new Subject<int>();

                var list = new List<int>();
                a.Where(x => x % 3 == 0).Subscribe(x => list.Add(x));

                a.OnNext(3);
                a.OnNext(5);
                a.OnNext(7);
                a.OnNext(9);
                a.OnNext(300);
                a.OnCompleted();

                list.IsCollection(3, 9, 300);
            }

            {
                var a = new Subject<int>();

                var list = new List<int>();
                a.Where((x, i) => (x + i) % 3 == 0).Subscribe(x => list.Add(x));

                a.OnNext(3); // 3 + 0
                a.OnNext(5); // 5 + 1
                a.OnNext(7); // 7 + 2
                a.OnNext(9); // 9 + 3
                a.OnNext(300); // 300 + 4
                a.OnCompleted();

                list.IsCollection(3, 5, 7, 9);
            }
            {
                var a = new Subject<int>();

                var list = new List<int>();
                a.Where(x => x % 3 == 0).Where(x => x % 5 == 0).Subscribe(x => list.Add(x));

                a.OnNext(3);
                a.OnNext(5);
                a.OnNext(7);
                a.OnNext(9);
                a.OnNext(300);
                a.OnCompleted();

                list.IsCollection(300);
            }

            {
                var a = new Subject<int>();

                var list = new List<int>();
                a.Where((x, i) => (x + i) % 3 == 0).Where(x => x % 5 == 0).Subscribe(x => list.Add(x));

                a.OnNext(3); // 3 + 0
                a.OnNext(5); // 5 + 1
                a.OnNext(7); // 7 + 2
                a.OnNext(9); // 9 + 3
                a.OnNext(300); // 300 + 4
                a.OnCompleted();

                list.IsCollection(5);
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:65,代码来源:UnitTests.cs

示例7: InitializeObservable

 private void InitializeObservable()
 {
     IsExistsMoreStationsAndBusStops = true;
     IsExistsMoreStations = true;
     IsExistsMoreBusStops = true;
     stationsAndBusStopsScheduler = new Subject<Unit>();
     stationsScheduler = new Subject<Unit>();
     busStopsScheduler = new Subject<Unit>();
     readerSubject = new Subject<StationViewModel>();
     readerSubject
         .BufferWithCount(20)
         .Zip(stationsAndBusStopsScheduler, (l, _) => l)
         .Subscribe(s => s.ForEach(
             i => StationsAndBusStops.Add(i)),
             () => IsExistsMoreStationsAndBusStops = false);
     readerSubject
         .Where(v => !v.IsBusStop)
         .BufferWithCount(20)
         .Zip(stationsScheduler, (l, _) => l)
         .Subscribe(s => s.ForEach(
             i => Stations.Add(i)),
             () => IsExistsMoreStations = false);
     readerSubject
         .Where(v => v.IsBusStop)
         .BufferWithCount(20)
         .Zip(busStopsScheduler, (l, _) => l)
         .Subscribe(s => s.ForEach(
             i => BusStops.Add(i)),
             () => IsExistsMoreBusStops = false);
 }
开发者ID:karno,项目名称:NagoyaMetro,代码行数:30,代码来源:SelectStationViewModel.cs

示例8: Where

 public void Where()
 {
     SetScehdulerForImport();
     {
         var a = new Subject<int>();
         var list = new List<int>();
         a.Where(x => x % 3 == 0).Subscribe(x => list.Add(x));
         a.OnNext(3);
         a.OnNext(5);
         a.OnNext(7);
         a.OnNext(9);
         a.OnNext(300);
         a.OnCompleted();
         list.IsCollection(3, 9, 300);
     }
     {
         var a = new Subject<int>();
         var list = new List<int>();
         a.Where((x, i) => (x + i) % 3 == 0).Subscribe(x => list.Add(x));
         a.OnNext(3); // 3 + 0
         a.OnNext(5); // 5 + 1
         a.OnNext(7); // 7 + 2
         a.OnNext(9); // 9 + 3
         a.OnNext(300); // 300 + 4
         a.OnCompleted();
         list.IsCollection(3, 5, 7, 9);
     }
     {
         var a = new Subject<int>();
         var list = new List<int>();
         a.Where(x => x % 3 == 0).Where(x => x % 5 == 0).Subscribe(x => list.Add(x));
         a.OnNext(3);
         a.OnNext(5);
         a.OnNext(7);
         a.OnNext(9);
         a.OnNext(300);
         a.OnCompleted();
         list.IsCollection(300);
     }
     {
         var a = new Subject<int>();
         var list = new List<int>();
         a.Where((x, i) => (x + i) % 3 == 0).Where(x => x % 5 == 0).Subscribe(x => list.Add(x));
         a.OnNext(3); // 3 + 0
         a.OnNext(5); // 5 + 1
         a.OnNext(7); // 7 + 2
         a.OnNext(9); // 9 + 3
         a.OnNext(300); // 300 + 4
         a.OnCompleted();
         list.IsCollection(5);
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:53,代码来源:TestImporter.cs

示例9: TakeUntilFull

 public void TakeUntilFull()
 {
     var received = "";
     var subject = new Subject<int>();
     subject.TakeUntil(subject.Where(x => x > ____)).Subscribe(x => received += x);
     subject.OnNext(Range.Create(1, 9).ToArray());
     Assert.AreEqual("12345", received);
 }
开发者ID:nickh,项目名称:rxkoans,代码行数:8,代码来源:Lesson1ObservableStreams.cs

示例10: Should_notify_with_null_when_right_do_not_have_data

        public void Should_notify_with_null_when_right_do_not_have_data()
        {
            var bets = new Subject<Currency>();
            var ex = new Subject<ExRate>();

            var betsWithExRate = from g in ex.GroupBy(x => x.Currency)
                                 from b in bets.Where(b => b.Code == g.Key).WithLatest(g, (b, x) =>
                                 {
                                     b.ExRate = x.Rate;
                                     return b;
                                 })
                                 select b;

            var received = new List<Currency>();
            using (betsWithExRate.Subscribe(i => received.Add(i)))
            {
                ex.OnNext(new ExRate { Currency = "CNY", Rate = null });
                bets.OnNext(new Currency { Id = 1, Code = "CNY" });
                ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.5m });
                ex.OnNext(new ExRate { Currency = "MYR", Rate = 2.5m });
                bets.OnNext(new Currency { Id = 2, Code = "CNY" });
                ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.6m });
                bets.OnNext(new Currency { Id = 3, Code = "CNY" });

                Assert.AreEqual(3, received.Count);
                Assert.AreEqual(null, received[0].ExRate);
                Assert.AreEqual(2.5m, received[1].ExRate);
                Assert.AreEqual(2.6m, received[2].ExRate);
            }
        }
开发者ID:Misterhex,项目名称:Jittuu.Rx.AddOn,代码行数:30,代码来源:Observable.WithLatest.Tests.cs

示例11: Main

        private static void Main(string[] args)
        {
            ServiceHost svcHost = null;
            try
            {
                NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true)
                    {
                        ReliableSession = { InactivityTimeout = new TimeSpan(0, 2, 0) },
                        SendTimeout = new TimeSpan(0, 2, 0),
                        ReceiveTimeout = new TimeSpan(0, 2, 0),
                        OpenTimeout = new TimeSpan(0, 1, 0),
                        CloseTimeout = new TimeSpan(0, 1, 0),
                        MaxReceivedMessageSize = 2147483647,
                        ReaderQuotas =
                            {
                                MaxArrayLength = 2147483647,
                                MaxBytesPerRead = 2147483647,
                                MaxStringContentLength = 2147483647,
                                MaxDepth = 2147483647,
                            },
                    };

                svcHost = new ServiceHost(typeof(BesiegedServer.BesiegedServer), new Uri("net.tcp://172.21.72.122:31337/BesiegedServer/"));
                svcHost.AddServiceEndpoint(typeof(Framework.ServiceContracts.IBesiegedServer), binding, "BesiegedMessage");
                svcHost.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = false });
                svcHost.Open();

                // Configure a client callback for the server itself to force start the process
                m_ServerClient = new ServerClient();
                EndpointAddress endpointAddress = new EndpointAddress("net.tcp://172.21.72.122:31337/BesiegedServer/BesiegedMessage");
                DuplexChannelFactory<IBesiegedServer> duplexChannelFactory = new DuplexChannelFactory<IBesiegedServer>(m_ServerClient, new NetTcpBinding(SecurityMode.None, true), endpointAddress);
                m_BesiegedServer = duplexChannelFactory.CreateChannel();

                Task.Factory.StartNew(() =>
                {
                    var startServer = new GenericServerMessage() { MessageEnum = ServerMessage.ServerMessageEnum.StartServer };
                    m_BesiegedServer.SendMessage(startServer.ToXml());
                });

                var subject = new Subject<BesiegedMessage>();

                var messagePublisher = m_ServerClient.MessageQueue
                    .GetConsumingEnumerable()
                    .ToObservable(TaskPoolScheduler.Default)
                    .Subscribe(subject);

                // All generic server messages are handled here
                var genericServerMessageSubscriber = subject
                    .Where(message => message is GenericServerMessage)
                    .Subscribe(message =>
                    {
                        var genericMessage = message as GenericServerMessage;
                        switch (genericMessage.MessageEnum)
                        {
                            case ServerMessage.ServerMessageEnum.StartServer:
                                break;

                            case ServerMessage.ServerMessageEnum.ServerStarted:
                                ConsoleLogger.Push("Server has started.");
                                break;

                            default:
                                ConsoleLogger.Push("Unhandled GenericServerMessage was received: " + genericMessage.MessageEnum.ToString());
                                break;
                        }
                    });

                // All server messages are handled here
                var m_ServerMessageSubscriber = subject
                    .Where(message => message is ServerMessage && !(message is GenericServerMessage))
                    .Subscribe(message =>
                    {
                        // do stuff with server bound messages here
                    });
            }
            catch (Exception ex)
            {
                ConsoleLogger.Push(ex.Message);
            }
            finally
            {
                while (true)
                {
                    var serverMessage = Console.ReadLine().Trim().ToString().ToLower();
                    if (serverMessage == "exit") break;
                    else if (serverMessage == "?" || serverMessage == "help" || serverMessage == "\\help")
                    {
                        ConsoleLogger.Push("Besieged Server Commands\nexit: Stops the server.");
                    }
                    else if (serverMessage == "list")
                    {
                        //var clients = GameObject.GetClients();
                        //if (clients.Count <= 0)
                        //{
                        //    Console.Write("> ");
                        //    continue;
                        //}
                        //Console.WriteLine("Connected Clients");
                        //foreach (BesiegedLogic.Objects.Client client in clients)
                        //{
//.........这里部分代码省略.........
开发者ID:WonderPanda,项目名称:Besieged,代码行数:101,代码来源:Program.cs

示例12: LoadContent

        /// <summary>
        /// Load graphics content for the screen.
        /// </summary>
        public virtual void LoadContent(ContentManager shared)
        {
            Subject<VirtualControllerState> subject = new Subject<VirtualControllerState>();

              Input = new ScreenInput(subject.Where((state) => IsActive));
              Input.ButtonPresses.Subscribe(OnButtonPressed);
              Input.ButtonReleases.Subscribe(OnButtonReleased);
              Input.PointChanges.Subscribe(OnPointChanged);

              InputSubscription = TopLevel.Input.Subscribe(subject);
              // TODO: Add Connected/Disconnected events (maybe)
        }
开发者ID:comp380team3,项目名称:PuzzlePathDimension,代码行数:15,代码来源:GameScreen.cs

示例13: Where

        public void Where()
        {
            var subject = new Subject<string>();

            subject.Where(x => x.Length > 3).Subscribe(x => Debug.WriteLine(x));

            subject.OnNext("telerik");
            subject.OnNext("has");
            subject.OnNext("a");
            subject.OnNext("party");
        }
开发者ID:TheAngryByrd,项目名称:ReactiveExtensionsDemo,代码行数:11,代码来源:ReactiveLinq.cs


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