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


C# CompositeDisposable.Add方法代码示例

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


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

示例1: HandleClients

        public static IDisposable HandleClients(TcpListener listener, Func<TcpClient, string, Task> handleClientAccessPolicy, string policyResponse)
        {
            listener.Start();

            var disposableHandler = ThreadPoolScheduler.Instance.ScheduleAsync(async (scheduler, ct) =>
            {
                var disposable = new BooleanDisposable();

                while (!disposable.IsDisposed)
                {
                    var client = await listener.AcceptTcpClientAsync();
                    await handleClientAccessPolicy(client, policyResponse);
                    await scheduler.Yield();
                }

                return disposable;
            });

            var compositeDisposable = new CompositeDisposable();

            compositeDisposable.Add(Disposable.Create(() => listener.Stop()));
            compositeDisposable.Add(disposableHandler);

            return compositeDisposable;
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:25,代码来源:PolicyHandler.cs

示例2: Initialize

        internal static void Initialize()
        {
            if (!Setting.IsLoaded || !Setting.IsBehaviorLogEnabled.Value)
            {
                return;
            }

            var disposables = new CompositeDisposable();
            try
            {
                var file = new FileStream(
                    Path.Combine(App.ConfigurationDirectoryPath, App.BehaviorLogFileName),
                    FileMode.Append,
                    FileAccess.Write,
                    FileShare.ReadWrite);
                var writer = new StreamWriter(file) { AutoFlush = true };
                _writer = writer.WriteLine;
                disposables.Add(Disposable.Create(() => _writer = null));
                disposables.Add(writer);
                disposables.Add(file);
            }
            finally
            {
                _disposable = disposables;
            }
        }
开发者ID:upsilon,项目名称:StarryEyes,代码行数:26,代码来源:BehaviorLogger.cs

示例3: Receive

        public IObservable<string> Receive(byte[] buffer, IScheduler scheduler)
        {
            return Observable.Create<string>(observer =>
                {
                    var disposable = new CompositeDisposable();
                    this.connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
                    var subject = new Subject<Unit>();

                    var disposableEventSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
                    {
                        if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                        {
                            subject.OnNext(Unit.Default);
                        }
                    });

                    var disposableActions = subject.ObserveOn(scheduler).Subscribe(_ =>
                    {
                        if (!connectionToken.Socket.ReceiveAsync(connectionToken.SocketEvent))
                        {
                            if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                            {
                                subject.OnNext(Unit.Default);
                            }
                        }
                    });

                    subject.OnNext(Unit.Default);

                    disposable.Add(disposableEventSubscription);
                    disposable.Add(disposableActions);

                    return disposable;
                });
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:35,代码来源:RedisReceiver.cs

示例4: Receive

        public IObservable<string> Receive(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, byte[] buffer)
        {
            if (connectedSocket == null)
                throw new ArgumentNullException("connectedSocket");

            if (socketEventArgs == null)
                throw new ArgumentNullException("socketEventArgs");

            return Observable.Create<string>(observer =>
            {
                var disposable = new CompositeDisposable();

                var disposableEventSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEventArgs);
                });

                var disposableActions = scheduler.Schedule(() =>
                {
                    socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
                    if (!connectedSocket.ReceiveAsync(socketEventArgs))
                    {
                        SendNotificationToObserver(observer, socketEventArgs);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:32,代码来源:SocketReceiver.cs

示例5: Connect

        public IObservable<Socket> Connect(string host, int port, IScheduler scheduler)
        {
            return Observable.Create<Socket>(observer =>
            {
                var disposable = new CompositeDisposable();

                var socket = socketFactory();
                var socketEvent = socketEventsFactory();

                socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
                socketEvent.UserToken = socket;

                var disposableEventSubscription = socketEvent.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEvent);
                });

                var disposableActions = scheduler.Schedule(() =>
                {    
                    if (!socket.ConnectAsync(socketEvent))
                    {
                        SendNotificationToObserver(observer, socketEvent);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:31,代码来源:SocketConnector.cs

示例6: SendMessage

        public IObservable<Unit> SendMessage(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, string message)
        {
            if (connectedSocket == null)
                throw new ArgumentNullException("connectedSocket");

            if (socketEventArgs == null)
                throw new ArgumentNullException("socketEventArgs");

            return Observable.Create<Unit>(observer =>
            {
                var disposable = new CompositeDisposable();
                var buffer = Encoding.UTF8.GetBytes(message);

                var disposableCompletedSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEventArgs);
                });

                var disposableActions = scheduler.Schedule(() =>
                {
                    socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
                    if (!connectedSocket.SendAsync(socketEventArgs))
                    {
                        SendNotificationToObserver(observer, socketEventArgs);
                    }
                });

                disposable.Add(disposableCompletedSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:33,代码来源:SocketTransmitter.cs

示例7: SetUp

        public void SetUp()
        {
            Clock.Reset();

            disposables = new CompositeDisposable
            {
                Disposable.Create(Clock.Reset)
            };

            schedule = GetScheduleDelegate();

            commandsScheduled = new ConcurrentBag<IScheduledCommand>();
            commandsDelivered = new ConcurrentBag<IScheduledCommand>();

            var configuration = new Configuration()
                .TraceScheduledCommands() // trace to console
                .TraceScheduledCommands(
                    onScheduling: _ => { },
                    onScheduled: c => commandsScheduled.Add(c),
                    onDelivering: _ => { },
                    onDelivered: c => commandsDelivered.Add(c));

            Configure(configuration, d => disposables.Add(d));

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
开发者ID:commonsensesoftware,项目名称:Its.Cqrs,代码行数:26,代码来源:CommandSchedulerIdempotencyTests.cs

示例8: BuildConnectionToken

        public IObservable<ConnectionToken> BuildConnectionToken(string host, int port, IScheduler scheduler)
        {
            return Observable.Create<ConnectionToken>(observer =>
            {
                var disposable = new CompositeDisposable();

                var socket = socketFactory();
                var socketEvent = socketEventsFactory();

                socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
                socketEvent.SocketClientAccessPolicyProtocol = System.Net.Sockets.SocketClientAccessPolicyProtocol.Tcp;

                var connectionToken = new ConnectionToken(socket, socketEvent);

                var disposableEventSubscription = socketEvent.Completed.Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEvent, connectionToken);
                });

                var disposableActions = scheduler.Schedule(() =>
                {    
                    if (!socket.ConnectAsync(socketEvent))
                    {
                        SendNotificationToObserver(observer, socketEvent, connectionToken);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:33,代码来源:RedisConnector.cs

示例9: SetUp

        public void SetUp()
        {
            disposables = new CompositeDisposable();

            Command<Order>.AuthorizeDefault = (order, command) => true;
            configuration = GetConfiguration();
            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
开发者ID:KimberlyPhan,项目名称:Its.Cqrs,代码行数:9,代码来源:VirtualClockWithSqlCommandSchedulingTests.cs

示例10: ShowView

			public IDisposable ShowView(FrameworkElement view) {
				var disp = new CompositeDisposable();
				disp.Add(scheduler.Schedule(() => {
					disp.Add(showView(view));
				}));
				return Disposable.Create(() => {
					scheduler.Schedule(() => {
						disp.Dispose();
					});
				});
			}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:11,代码来源:ViewPresenter.cs

示例11: Tail

        //public IObservable<string> TailV2(IFile file)
        //{
        //    return ObservableFile.WatchLines(file.GetNativePath(), Encoding.Default);
        //}

        public IObservable<string> Tail(IFile file, IScheduler scheduler = null)
        {
            return Observable.Create<string>(subj =>
            {
                var disposable = new CompositeDisposable();
                scheduler = scheduler ?? RxApp.TaskpoolScheduler;
                var abortSignal = new ManualResetEvent(false);

                disposable.Add(Disposable.Create(() => abortSignal.Set()));

                disposable.Add(scheduler.Schedule(abortSignal, (sched, state) =>
                {
                    using (var reader = new StreamReader(
                        file.GetContent().OpenStream(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                    {
                        long lastOffset = reader.BaseStream.Length;
                        if (reader.BaseStream.Length > 0)
                        {
                            // Send the last 10 kb of text to the reader.
                            lastOffset = Math.Max(0, reader.BaseStream.Length - (1024 * 10));
                        }

                        while (!state.WaitOne(100))
                        {
                            // Idle if file hasn't changed.
                            if (reader.BaseStream.Length <= lastOffset)
                            {
                                if (reader.BaseStream.Length < lastOffset)
                                {
                                    lastOffset = reader.BaseStream.Length;
                                }
                                continue;
                            }

                            // Read the data.
                            reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
                            var delta = reader.BaseStream.Length - lastOffset;
                            var buffer = new char[delta];
                            reader.ReadBlock(buffer, 0, buffer.Length);

                            // Publish the data.
                            subj.OnNext(new string(buffer));

                            // Update the offset.
                            lastOffset = reader.BaseStream.Position;
                        }
                    }
                    return Disposable.Empty;
                }));

                return disposable;
            });
        }
开发者ID:kmcginnes,项目名称:SpicyTaco.ChaseTheTail,代码行数:58,代码来源:TailService.cs

示例12: AddTwice

 public void AddTwice()
 {
     int i = 0;
     var d = new CompositeDisposable ();
     var item = Disposable.Create (() => i++);
     d.Add (item);
     d.Add (item);
     // this results in two items registered.
     Assert.AreEqual (2, d.Count, "#1");
     d.Dispose ();
     // though, since the first disposal takes effect, it never invokes Dispose() on item twice.
     Assert.AreEqual (1, i, "#2");
 }
开发者ID:jorik041,项目名称:mono-reactive,代码行数:13,代码来源:CompositeDisposableTest.cs

示例13: Schedule

        /// <summary>
        /// Schedules action to be executed after dueTime.
        /// </summary>
        public IDisposable Schedule(Action action, TimeSpan dueTime)
        {
            if (action == null)
                throw new ArgumentNullException("action");

            var dt = Scheduler.Normalize(dueTime);

            var g = new CompositeDisposable();

            g.Add(ThreadPoolScheduler.Instance.Schedule(() => g.Add(Schedule(action)), dt));

            return g;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:16,代码来源:NewThreadScheduler.cs

示例14: PrimeExperiment

    public void PrimeExperiment()
    {
      IObservable<long> xs = Observable.Interval(TimeSpan.FromSeconds(1))
        .Do(ConsoleOutput(Text.Generated))
        .Take(3);

      IObservable<long> pruned = xs.PublishLast().Prime();

      for (int r = 0; r < 2; r++)
      {
        using (var subscriptions = new CompositeDisposable())
        {
          for (int s = 0; s < 5; s++)
          {
            Thread.Sleep(TimeSpan.FromSeconds(.4));

            TraceLine(Text.SubscribingFormat, s);

            subscriptions.Add(
              pruned.Subscribe(ConsoleOutput(Text.NamedObserverFormat, s)));
          }

          Thread.Sleep(TimeSpan.FromSeconds(2));
        }
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:26,代码来源:PrimingLab.cs

示例15: AddAfterDisposal

        public void AddAfterDisposal()
        {
            int i1 = 0, i2 = 0;
            var d = new CompositeDisposable ();
            d.Add (Disposable.Create (() => i1++));
            d.Dispose ();
            Assert.AreEqual (1, i1, "#1");
            d.Dispose ();
            Assert.AreEqual (1, i1, "#2"); // no further addition

            d.Add (Disposable.Create (() => i2++));
            Assert.AreEqual (1, i2, "#3");
            d.Dispose ();
            Assert.AreEqual (1, i2, "#4"); // no further addition

            d.Add (Disposable.Create (() => i2++)); // should be immediately disposed
            Assert.AreEqual (2, i2, "#5");
        }
开发者ID:jorik041,项目名称:mono-reactive,代码行数:18,代码来源:CompositeDisposableTest.cs


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