本文整理汇总了C#中System.Linq.CompositeDisposable类的典型用法代码示例。如果您正苦于以下问题:C# CompositeDisposable类的具体用法?C# CompositeDisposable怎么用?C# CompositeDisposable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompositeDisposable类属于System.Linq命名空间,在下文中一共展示了CompositeDisposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Activate
public IDisposable Activate()
{
var disp = new CompositeDisposable(blocks.SelectMany(x => x()));
Interlocked.Exchange(ref activationHandle, disp).Dispose();
return Disposable.Create(Deactivate);
}
示例3: 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());
}
示例4: 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();
}
示例5: 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;
});
}
示例6: 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;
}
示例7: App
public App()
{
var dir = System.AppDomain.CurrentDomain.BaseDirectory;
this.WindowPlacement = new WindowPlace(dir + @"placement.config");
this.disposables = new CompositeDisposable();
}
示例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()
};
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
示例10: LockChildren
protected virtual IDisposable LockChildren(LockTypes lockType)
{
var result = new CompositeDisposable();
lock (ChildLocksSync)
{
foreach (var child in ChildLocks)
{
if (lockType == LockTypes.Read)
{
result.AddIfNotNull(child.AcquireReadLockIfNotHeld());
}
else if (lockType == LockTypes.UpgradeableRead)
{
result.AddIfNotNull(child.AcquireUpgradeableReadLock());
}
else if (lockType == LockTypes.Write)
{
result.AddIfNotNull(child.AcquireWriteLockIfNotHeld());
}
else
{
throw new NotSupportedException(lockType.ToString());
}
}
}
return result;
}
示例11: 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;
}
示例12: SelectDisposableShouldWork
public void SelectDisposableShouldWork()
{
var scheduler = new TestScheduler();
var disposables = new List<BooleanDisposable>();
var list = new CompositeDisposable();
scheduler.CreateColdObservable(
new Recorded<Notification<long>>(100, Notification.CreateOnNext(0L)),
new Recorded<Notification<long>>(200, Notification.CreateOnNext(1L)),
new Recorded<Notification<long>>(300, Notification.CreateOnNext(2L)),
new Recorded<Notification<long>>(400, Notification.CreateOnNext(3L)),
new Recorded<Notification<long>>(400, Notification.CreateOnCompleted<long>())
)
.SelectDisposable(list, i => {
var d = new BooleanDisposable();
disposables.Add(d);
return d;
}, (i, _) => i)
.Subscribe()
.DisposeWith(list);
scheduler.AdvanceTo(300);
disposables.Count.Should().Be(3);
disposables.Select(d => d.IsDisposed).Should().NotContain(true);
list.Dispose();
disposables.Select(d => d.IsDisposed).Should().NotContain(false);
}
示例13: UIPair
/// <param name="type">The UIViewType</param>
/// <param name="v">The IView</param>
/// <param name="vm">The IViewModel. Might be null because the 2fa view shares the same viewmodel as the login dialog, so it's
/// set manually in the view outside of this</param>
public UIPair(UIViewType type, ExportLifetimeContext<IView> v, [AllowNull]ExportLifetimeContext<IViewModel> vm)
{
viewType = type;
view = v;
viewModel = vm;
handlers = new CompositeDisposable();
}
示例14: SetUp
public void SetUp()
{
aggregateId = Any.Guid();
sequenceNumber = Any.PositiveInt();
disposables = new CompositeDisposable
{
ConfigurationContext.Establish(new Configuration()
.UseSqlStorageForScheduledCommands(c => c.UseConnectionString(TestDatabases.CommandScheduler.ConnectionString)))
};
if (clockName == null)
{
clockName = Any.CamelCaseName();
using (var db = Configuration.Current.CommandSchedulerDbContext())
{
db.Clocks.Add(new CommandScheduler.Clock
{
Name = clockName,
StartTime = Clock.Now(),
UtcNow = Clock.Now()
});
db.SaveChanges();
}
}
using (var db = Configuration.Current.CommandSchedulerDbContext())
{
db.Database.ExecuteSqlCommand("delete from PocketMigrator.AppliedMigrations where MigrationScope = 'CommandSchedulerCleanup'");
}
}
示例15: 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());
}