本文整理汇总了C#中System.Linq.CompositeDisposable.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CompositeDisposable.Add方法的具体用法?C# CompositeDisposable.Add怎么用?C# CompositeDisposable.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.CompositeDisposable
的用法示例。
在下文中一共展示了CompositeDisposable.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Listen
/// <summary>
/// Returns an IObservable that continuously updates as the user's
/// physical location changes. It is super important to make sure to
/// dispose all subscriptions to this IObservable.
/// </summary>
/// <param name="minUpdateTime">Minimum update time.</param>
/// <param name="minUpdateDist">Minimum update dist.</param>
/// <param name="includeHeading">If set to <c>true</c> include heading.</param>
public static IObservable<Position> Listen(int minUpdateTime, double minUpdateDist, bool includeHeading = false)
{
if (Implementation != null) {
return Implementation.Listen(minUpdateTime, minUpdateDist, includeHeading);
}
var ret = Observable.Create<Position>(subj => {
#if ANDROID
var geo = new Geolocator(AndroidApp.Context);
#else
var geo = new Geolocator();
#endif
var disp = new CompositeDisposable();
bool isDead = false;
if (!geo.IsGeolocationAvailable || !geo.IsGeolocationEnabled) {
return Observable.Throw<Position>(new Exception("Geolocation isn't available")).Subscribe(subj);
}
// NB: This isn't very Functional, but I'm lazy.
disp.Add(Observable.FromEventPattern<PositionEventArgs>(x => geo.PositionChanged += x, x => geo.PositionChanged -= x).Subscribe(x => {
if (isDead) return;
subj.OnNext(x.EventArgs.Position);
}));
disp.Add(Observable.FromEventPattern<PositionErrorEventArgs>(x => geo.PositionError += x, x => geo.PositionError -= x).Subscribe(ex => {
isDead = true;
var toDisp = Interlocked.Exchange(ref disp, null);
if (toDisp != null) toDisp.Dispose();
subj.OnError(new GeolocationException(ex.EventArgs.Error));
}));
return disp;
});
return ret.Multicast(new Subject<Position>()).RefCount();
}
示例2: SetUp
public void SetUp()
{
disposables = new CompositeDisposable
{
VirtualClock.Start()
};
clockName = Any.CamelCaseName();
targetId = Any.Word();
target = new CommandTarget(targetId);
store = new InMemoryStore<CommandTarget>(
_ => _.Id,
id => new CommandTarget(id))
{
target
};
configuration = new Configuration()
.UseInMemoryCommandScheduling()
.UseDependency<IStore<CommandTarget>>(_ => store)
.UseDependency<GetClockName>(c => _ => clockName)
.TraceScheduledCommands();
scheduler = configuration.CommandScheduler<CommandTarget>();
Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;
disposables.Add(ConfigurationContext.Establish(configuration));
disposables.Add(configuration);
}
开发者ID:charlesmccarthyirl,项目名称:Its.Cqrs,代码行数:30,代码来源:NonEventSourcedAggregateCommandSchedulingTests.cs
示例3: Run
public static void Run()
{
var systems = new[] { "A", "B", "C" }.Select(CreateExternalSystem);
var observables = systems.Select(s => s.ObserveHealth()).Select(obs => obs.DistinctUntilChanged(c => c.IsAvailable)).ToList();
var disposable = new CompositeDisposable();
// observe independently
disposable.Add(new CompositeDisposable(observables.Select(c => c.Subscribe(PrintHealthCheck))));
// merge
var merged = observables.Aggregate((l, r) => l.Merge(r));
disposable.Add(merged.Subscribe(PrintHealthCheck));
// combine
var combined = observables
.Aggregate(Observable.Return(Enumerable.Empty<HealthCheck>()), (agg, obs) => agg.CombineLatest(obs, (checks, check) => checks.Concat(new[] { check })));
var scan = merged.Scan(ImmutableDictionary<string, bool>.Empty, (d, check) => d.SetItem(check.ExternalSystemName, check.IsAvailable));
disposable.Add(combined.Subscribe(e => Console.WriteLine("Combined: " + string.Join(", ", e.Select(c => $"{c.ExternalSystemName}={c.IsAvailable}")))));
disposable.Add(scan.Subscribe(d => Console.WriteLine("Scanned: " + string.Join(", ", d.Select(p => $"{p.Key}={p.Value}")))));
Console.ReadKey();
disposable.Dispose();
}
示例4: SetUp
public void SetUp()
{
clockName = Any.CamelCaseName();
Clock.Reset();
disposables = new CompositeDisposable
{
Disposable.Create(Clock.Reset)
};
var configuration = new Configuration()
.UseSqlEventStore(c => c.UseConnectionString(TestDatabases.EventStore.ConnectionString))
.UseSqlStorageForScheduledCommands(c => c.UseConnectionString(TestDatabases.CommandScheduler.ConnectionString));
Configure(configuration);
disposables.Add(ConfigurationContext.Establish(configuration));
disposables.Add(configuration);
orderRepository = configuration.Repository<Order>();
accountRepository = configuration.Repository<CustomerAccount>();
clockTrigger = configuration.SchedulerClockTrigger();
clockRepository = configuration.SchedulerClockRepository();
clockRepository.CreateClock(clockName, Clock.Now());
}
示例5: SetUp
public void SetUp()
{
disposables = new CompositeDisposable
{
VirtualClock.Start()
};
clockName = Any.CamelCaseName();
targetId = Any.Word();
target = new CommandTarget(targetId);
store = new InMemoryStore<CommandTarget>(
_ => _.Id,
id => new CommandTarget(id))
{
target
};
CommandSchedulerDbContext.NameOrConnectionString =
@"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True; MultipleActiveResultSets=False; Initial Catalog=ItsCqrsTestsCommandScheduler";
configuration = new Configuration()
.UseInMemoryCommandScheduling()
.UseDependency<IStore<CommandTarget>>(_ => store)
.UseDependency<GetClockName>(c => _ => clockName)
.TraceScheduledCommands();
scheduler = configuration.CommandScheduler<CommandTarget>();
Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;
disposables.Add(ConfigurationContext.Establish(configuration));
disposables.Add(configuration);
}
示例6: SetUp
public void SetUp()
{
// disable authorization
Command<Order>.AuthorizeDefault = (o, c) => true;
Command<CustomerAccount>.AuthorizeDefault = (o, c) => true;
disposables = new CompositeDisposable
{
VirtualClock.Start()
};
customerAccountId = Any.Guid();
configuration = new Configuration()
.UseInMemoryCommandScheduling()
.UseInMemoryEventStore();
customerRepository = configuration.Repository<CustomerAccount>();
orderRepository = configuration.Repository<Order>();
customerRepository.Save(new CustomerAccount(customerAccountId).Apply(new ChangeEmailAddress(Any.Email())));
disposables.Add(ConfigurationContext.Establish(configuration));
disposables.Add(configuration);
}
示例7: SendMessage
public IObservable<Unit> SendMessage(string message, IScheduler scheduler)
{
return Observable.Create<Unit>(observer =>
{
var disposable = new CompositeDisposable();
var buffer = Encoding.UTF8.GetBytes(message);
connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
var disposableCompletedSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
{
SendNotificationToObserver(observer, connectionToken.SocketEvent);
});
var disposableActions = scheduler.Schedule(() =>
{
if (!connectionToken.Socket.SendAsync(connectionToken.SocketEvent))
{
SendNotificationToObserver(observer, connectionToken.SocketEvent);
}
});
disposable.Add(disposableCompletedSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例8: SetUp
public void SetUp()
{
disposables = new CompositeDisposable();
telemetryEvents = new List<Telemetry>();
disposables.Add(Log.TelemetryEvents().Subscribe(e => { telemetryEvents.Add(e); }));
}
示例9: SetUp
public void SetUp()
{
disposables = new CompositeDisposable
{
VirtualClock.Start()
};
configuration = new Configuration()
.UseInMemoryCommandScheduling()
.UseInMemoryEventStore(traceEvents: true);
itRepo = configuration.Repository<MarcoPoloPlayerWhoIsIt>();
disposables.Add(ConfigurationContext.Establish(configuration));
disposables.Add(configuration);
}
示例10: Subscribe
public IDisposable Subscribe(ReactiveSpace spaceListener)
{
CompositeDisposable subscriptions = new CompositeDisposable();
subscriptions.Add(spaceListener
.LockedHands()
.ObserveOn(UI)
.Subscribe(o =>
{
HandsCount++;
}));
subscriptions.Add(spaceListener
.LockedHands()
.Select(o =>
o
.ObserveOn(UI)
.Subscribe(oo =>
{
}, () =>
{
HandsCount--;
}))
.Subscribe());
subscriptions.Add(SubscribeCore(spaceListener));
subscriptions.Add(Disposable.Create(()=>HandsCount = 0));
return subscriptions;
}
示例11: Order
public void Order()
{
// It is time-dependent test (i.e. lengthy and inconsistent), which is not very good but we cannot use HistoricalScheduler to test it...
var s = Scheduler.ThreadPool;
var l = new List<int> ();
var dis = new CompositeDisposable ();
try {
dis.Add (s.Schedule (() => { Thread.Sleep (1200); l.Add (1); }));
dis.Add (s.Schedule (() => { Thread.Sleep (800); l.Add (2); }));
dis.Add (s.Schedule (() => { Thread.Sleep (50); l.Add (3); }));
Thread.Sleep (1500);
Assert.AreEqual (new int [] {3, 2, 1}, l.ToArray (), "#1");
} finally {
dis.Dispose ();
}
}
示例12: GherkinFileClassifier
public GherkinFileClassifier(ITextBuffer buffer)
{
var snapshot = buffer.CurrentSnapshot;
_spans = new List<ClassificationSpan>();
_listeners = new CompositeDisposable();
_parser = buffer.Properties.GetProperty<GherkinFileEditorParser>(typeof(GherkinFileEditorParser));
_listeners.Add(_parser.IsParsing.Where(isParsing => isParsing).Subscribe(b => _spans.Clear()));
_listeners.Add(_parser.IsParsing.Where(isParsing => !isParsing).Subscribe(b => PublishClassificationEvents()));
_listeners.Add(_parser
.ParserEvents
.Select(f => SelectClassifiable(f, snapshot))
.Subscribe((spans => _spans.AddRange(spans))));
}
示例13: SetUp
public void SetUp()
{
eventStoreDbTest = new EventStoreDbTest();
clockName = Any.CamelCaseName();
Clock.Reset();
disposables = new CompositeDisposable
{
Disposable.Create(() => eventStoreDbTest.TearDown()),
Disposable.Create(Clock.Reset)
};
var bus = new FakeEventBus();
orderRepository = new SqlEventSourcedRepository<Order>(bus);
accountRepository = new SqlEventSourcedRepository<CustomerAccount>(bus);
var configuration = new Configuration();
configuration.UseEventBus(bus)
.UseDependency<IEventSourcedRepository<Order>>(t => orderRepository)
.UseDependency<IEventSourcedRepository<CustomerAccount>>(t => accountRepository);
ConfigureScheduler(configuration);
disposables.Add(ConfigurationContext.Establish(configuration));
Console.WriteLine(new { clockName });
clockTrigger = configuration.Container.Resolve<ISchedulerClockTrigger>();
clockRepository = configuration.Container.Resolve<ISchedulerClockRepository>();
clockRepository.CreateClock(clockName, Clock.Now());
}
示例14: SubscribeCore
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener)
{
CompositeDisposable subscriptions = new CompositeDisposable();
subscriptions.Add(spaceListener
.LockedHands()
.ObserveOn(UI)
.SelectMany(h => h
.Select(hh => new
{
Group = h,
Hand = hh
}))
.Subscribe(h =>
{
var diff = 1000 + (h.Hand.PalmPosition.y - h.Group.Key.PalmPosition.y);
var bin = (int)(diff / MinInterval);
if(bin < PreviousBin)
{
if(OnMoveDown != null)
OnMoveDown();
}
if(bin > PreviousBin)
{
if(OnMoveUp != null)
OnMoveUp();
}
PreviousBin = bin;
}));
return subscriptions;
}
示例15: CompositeDisposable
private static void CompositeDisposable()
{
Demo.DisplayHeader("The CompositeDisposable - groups multiple disposables and dispose them together");
var compositeDisposable = new CompositeDisposable(
Disposable.Create(() => Console.WriteLine("1st disposed")),
Disposable.Create(() => Console.WriteLine("2nd disposed")));
compositeDisposable.Dispose();
//The same can also be written using the Add() method
compositeDisposable = new CompositeDisposable();
compositeDisposable.Add(Disposable.Create(() => Console.WriteLine("1st disposed")));
compositeDisposable.Add(Disposable.Create(() => Console.WriteLine("2nd disposed")));
compositeDisposable.Dispose();
}