本文整理汇总了C#中Subject类的典型用法代码示例。如果您正苦于以下问题:C# Subject类的具体用法?C# Subject怎么用?C# Subject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Subject类属于命名空间,在下文中一共展示了Subject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Observer
public Observer(Subject subject, string name, string gap)
{
this.subject = subject;
this.name = name;
this.gap = gap;
subject.Notify += Update;
}
开发者ID:david--liu,项目名称:code_kata,代码行数:7,代码来源:ObserverPatternTheory.cs
示例2: DeterministicDisposal
private static void DeterministicDisposal()
{
Demo.DisplayHeader("The Using operator will make sure that the resource is disposed no matter what caused the observable to stop");
Subject<int> subject = new Subject<int>();
var observable =
Observable.Using(() => Disposable.Create(() => { Console.WriteLine("DISPOSED"); }),
_ => subject);
Console.WriteLine();
Console.WriteLine("Disposed when completed");
observable.SubscribeConsole();
subject.OnCompleted();
Console.WriteLine();
Console.WriteLine("Disposed when error occurs");
subject = new Subject<int>();
observable.SubscribeConsole();
subject.OnError(new Exception("error"));
Console.WriteLine();
Console.WriteLine("Disposed when subscription disposed");
subject = new Subject<int>();
var subscription =
observable.SubscribeConsole();
subscription.Dispose();
}
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:27,代码来源:Program.cs
示例3: AutoSuspendApplication
protected AutoSuspendApplication()
{
var host = new SuspensionHost();
var launchNew = new[] { ApplicationExecutionState.ClosedByUser, ApplicationExecutionState.NotRunning, };
host.IsLaunchingNew = _launched
.Where(x => launchNew.Contains(x.PreviousExecutionState))
.Select(_ => Unit.Default);
host.IsResuming = _launched
.Where(x => x.PreviousExecutionState == ApplicationExecutionState.Terminated)
.Select(_ => Unit.Default);
var unpausing = new[] { ApplicationExecutionState.Suspended, ApplicationExecutionState.Running, };
host.IsUnpausing = _launched
.Where(x => unpausing.Contains(x.PreviousExecutionState))
.Select(_ => Unit.Default);
var shouldPersistState = new Subject<SuspendingEventArgs>();
Suspending += (o, e) => shouldPersistState.OnNext(e);
host.ShouldPersistState =
shouldPersistState.Select(x => {
var deferral = x.SuspendingOperation.GetDeferral();
return Disposable.Create(deferral.Complete);
});
var shouldInvalidateState = new Subject<Unit>();
UnhandledException += (o, e) => shouldInvalidateState.OnNext(Unit.Default);
host.ShouldInvalidateState = shouldInvalidateState;
SuspensionHost = host;
}
开发者ID:chrisortman,项目名称:ReactiveUI,代码行数:32,代码来源:WinRTAutoSuspendApplication.cs
示例4: DayRow
public DayRow()
{
this.audience = new Audience();
this.teacher = "NoTeacher";
this.subject = new Subject();
this.KindOfWeek = SheduleRedactor.KindOfWeek.Numerator;
}
开发者ID:Cyanide-and-programming,项目名称:ScheduleRedactor,代码行数:7,代码来源:DayRow.cs
示例5: EventService
public EventService()
{
RefreshRooms = new Subject<bool>();
NotifyUnreadMessages = new Subject<IEnumerable<IMessageViewModel>>();
PushMessage = new Subject<Tuple<string, IMessageViewModel>>();
ReadRoom = new Subject<IRoomViewModel>();
}
开发者ID:nmetulev,项目名称:Modern-Gitter,代码行数:7,代码来源:EventService.cs
示例6: CurveDrawingSurface
public CurveDrawingSurface(
ICurvePool curvePool,
InputReference inputReference)
{
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Linear);
// Wichtig für "Pan" und "Zoom"
ClipToBounds = true;
_curvePool = curvePool;
_curvePool.CurveAdded += OnCurveAdded;
_curvePool.CurveRemoved += OnCurveRemoved;
inputReference.InputElement.MouseMove += (s, e) => HandleMouseMove(e);
inputReference.InputElement.MouseLeave += (s, e) => HandleMouseLeave(e);
inputReference.InputElement.MouseLeftButtonUp += (s, e) => HandleMouseLeftButtonUp(e);
inputReference.InputElement.MouseLeftButtonDown += (s, e) => HandleMouseLeftButtonDown(e);
inputReference.InputElement.MouseRightButtonUp += (s, e) => HandleMouseRightButtonUp(e);
inputReference.InputElement.MouseRightButtonDown += (s, e) => HandleMouseRightButtonDown(e);
_redrawSubject = new Subject<object>();
_redrawSubject
//.Skip(1)
.Throttle(TimeSpan.FromMilliseconds(50))
.Subscribe(it => _redrawEvent.Set());
_redrawThread = new Thread(RedrawThreadProc);
_redrawThread.IsBackground = true;
_redrawThread.SetApartmentState(ApartmentState.STA);
_redrawThread.Start();
}
开发者ID:Bruhankovi4,项目名称:Emotyper,代码行数:31,代码来源:CurveDrawingSurface.cs
示例7: AudioPlayer
internal AudioPlayer()
{
this.audioPlayerCallback = new DummyMediaPlayerCallback();
this.videoPlayerCallback = new DummyMediaPlayerCallback();
this.currentCallback = new DummyMediaPlayerCallback();
this.finishSubscription = new SerialDisposable();
this.gate = new SemaphoreSlim(1, 1);
this.playbackState = new BehaviorSubject<AudioPlayerState>(AudioPlayerState.None);
this.PlaybackState = this.playbackState.DistinctUntilChanged();
this.loadedSong = new BehaviorSubject<Song>(null);
this.TotalTime = this.loadedSong.Select(x => x == null ? TimeSpan.Zero : x.Duration);
this.currentTimeChangedFromOuter = new Subject<TimeSpan>();
var conn = Observable.Interval(TimeSpan.FromMilliseconds(300), RxApp.TaskpoolScheduler)
.CombineLatest(this.PlaybackState, (l, state) => state)
.Where(x => x == AudioPlayerState.Playing)
.Select(_ => this.CurrentTime)
.Merge(this.currentTimeChangedFromOuter)
.DistinctUntilChanged(x => x.TotalSeconds)
.Publish(TimeSpan.Zero);
conn.Connect();
this.CurrentTimeChanged = conn;
}
开发者ID:hur1can3,项目名称:Espera,代码行数:27,代码来源:AudioPlayer.cs
示例8: ZipMulti
public void ZipMulti()
{
var a = new Subject<int>();
var b = new Subject<int>();
a.OnNext(10);
b.OnNext(20);
var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
Observable.Zip(a, b).Select(xs => new { x = xs[0], y = xs[1] }).Materialize().Subscribe(x => l.Add(x));
a.OnNext(1000);
b.OnNext(2000);
a.OnCompleted();
l.Count.Is(1); // OnNext
a.OnNext(1001);
l.Count.Is(1);
b.OnNext(5);
l.Count.Is(2); // Completed!
l[1].Kind.Is(NotificationKind.OnCompleted);
}
开发者ID:gameserver,项目名称:UniRx,代码行数:27,代码来源:Observable.ConcatTest.cs
示例9: AutoSuspendHelper
public AutoSuspendHelper(UIApplicationDelegate appDelegate)
{
Reflection.ThrowIfMethodsNotOverloaded("AutoSuspendHelper", appDelegate,
"FinishedLaunching", "OnActivated", "DidEnterBackground");
RxApp.SuspensionHost.IsLaunchingNew = Observable.Never<Unit>();
RxApp.SuspensionHost.IsResuming = _finishedLaunching.Select(_ => Unit.Default);
RxApp.SuspensionHost.IsUnpausing = _activated.Select(_ => Unit.Default);
var untimelyDeath = new Subject<Unit>();
AppDomain.CurrentDomain.UnhandledException += (o,e) => untimelyDeath.OnNext(Unit.Default);
RxApp.SuspensionHost.ShouldInvalidateState = untimelyDeath;
RxApp.SuspensionHost.ShouldPersistState = _backgrounded.SelectMany(app => {
var taskId = app.BeginBackgroundTask(new NSAction(() => untimelyDeath.OnNext(Unit.Default)));
// NB: We're being force-killed, signal invalidate instead
if (taskId == UIApplication.BackgroundTaskInvalid) {
untimelyDeath.OnNext(Unit.Default);
return Observable.Empty<IDisposable>();
}
return Observable.Return(Disposable.Create(() => app.EndBackgroundTask(taskId)));
});
}
开发者ID:journeyman,项目名称:ReactiveUI,代码行数:26,代码来源:AutoSuspendHelper.cs
示例10: BasicExperiment
public void BasicExperiment()
{
var xs = new Subject<int>();
var ys = new Subject<int>();
var zs = new Subject<int>();
IObservable<int> query = xs.AsOperational() + ys - zs;
using (query.Subscribe(ConsoleOutput))
{
xs.OnNext(1);
ys.OnNext(5);
zs.OnNext(2);
xs.OnNext(2);
ys.OnNext(6);
zs.OnNext(3);
xs.OnNext(3);
xs.OnNext(4);
zs.OnNext(4);
zs.OnNext(5);
ys.OnNext(7);
ys.OnNext(8);
WaitForKey();
}
}
开发者ID:ibebbs,项目名称:Rxx,代码行数:30,代码来源:OperationalLab.cs
示例11: AdvancedExperiment
public void AdvancedExperiment()
{
var xs = new Subject<int>();
var ys = new Subject<int>();
var zs = new Subject<int>();
// Define an operational factory so that operators are only specified once.
var o = (Func<IObservable<int>, OperationalObservable<int>>)
(source => source.AsOperational(
add: (left, right) => left + (right * 5),
subtract: (left, right) => left - right,
multiply: (left, right) => left * right,
divide: (left, right) => (left * 2) / right,
negative: value => -value));
IObservable<int> query = (-o(xs) * 2) + ys - (o(zs) / 4);
using (query.Subscribe(ConsoleOutput))
{
xs.OnNext(1);
ys.OnNext(5);
zs.OnNext(4);
xs.OnNext(2);
ys.OnNext(6);
zs.OnNext(8);
xs.OnNext(3);
ys.OnNext(7);
zs.OnNext(12);
WaitForKey();
}
}
开发者ID:ibebbs,项目名称:Rxx,代码行数:34,代码来源:OperationalLab.cs
示例12: Main
static void Main(string[] args)
{
Subject<int> numbers = new Subject<int>();
var historicalScheduler = new System.Reactive.Concurrency.HistoricalScheduler(new DateTime(2015, 11, 21, 17, 10, 0));
historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 10, 0), () => numbers.OnNext(1));
historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 11, 0), () => numbers.OnNext(2));
historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 32, 0), () => numbers.OnNext(3));
historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 39, 0), () => numbers.OnNext(4));
historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 51, 0), () => historicalScheduler.Stop());
numbers.AsObservable()
.Buffer(TimeSpan.FromMinutes(20), historicalScheduler)
.Subscribe(buffer =>
{
Console.WriteLine("time is: {0}", historicalScheduler.Now);
Console.WriteLine("Buffer:");
foreach (var x in buffer)
{
Console.WriteLine("\t{0}", x);
}
});
historicalScheduler.Start();
Console.WriteLine("Press <enter> to continue");
Console.ReadLine();
}
开发者ID:tamirdresher,项目名称:Rx101,代码行数:27,代码来源:Program.cs
示例13: CombineLatest
public void CombineLatest()
{
var a = new Subject<int>();
var b = new Subject<int>();
a.OnNext(10);
b.OnNext(20);
var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
a.CombineLatest(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));
a.OnNext(1000);
b.OnNext(2000);
l[0].Value.Is(new { x = 1000, y = 2000 });
b.OnNext(3000);
l[1].Value.Is(new { x = 1000, y = 3000 });
a.OnNext(5000);
l[2].Value.Is(new { x = 5000, y = 3000 });
a.OnCompleted();
l.Count.Is(3);
a.OnNext(1001);
l.Count.Is(3);
b.OnNext(5);
l[3].Value.Is(new { x = 5000, y = 5 });
b.OnNext(500);
l[4].Value.Is(new { x = 5000, y = 500 });
b.OnCompleted();
l[5].Kind.Is(NotificationKind.OnCompleted);
}
开发者ID:MighteeCactus,项目名称:UniRx,代码行数:35,代码来源:Observable.ConcatTest.cs
示例14: Main
public void Main()
{
var subject = new Subject();
var Observer = new Observer(subject, "Center", "\t\t");
var observer2 = new Observer(subject, "Right", "\t\t\t\t");
subject.Go();
}
开发者ID:david--liu,项目名称:code_kata,代码行数:7,代码来源:ObserverPatternTheory.cs
示例15: NotifiesOfSegmentWhenFileIsCreated
public void NotifiesOfSegmentWhenFileIsCreated()
{
//need to make this test
var file = Path.GetTempFileName();
var info = new FileInfo(file);
var refresher = new Subject<Unit>();
var segmenter = new FileSegmenter(info.WatchFile(refresher), 1000);
FileSegmentCollection result = null;
using (var indexer = segmenter.Segments.Subscribe(segment => result = segment))
{
result.Should().NotBeNull();
File.AppendAllLines(file,
Enumerable.Range(1, 10000).Select(i => $"This is line number {i.ToString("00000000")}").ToArray());
refresher.Once();
result.Should().NotBeNull();
result.Count.Should().BeGreaterOrEqualTo(2);
result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Head);
result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Tail);
result.FileLength.Should().Be(info.Length);
File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => $"{i}"));
refresher.Once();
info.Refresh();
result.FileLength.Should().Be(info.Length);
File.Delete(file);
}
File.Delete(file);
}
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:35,代码来源:FileSegmentFixture.cs
示例16: ObservableCanExecuteShouldShowUpInCommand
public void ObservableCanExecuteShouldShowUpInCommand()
{
var input = new[] {true, false, false, true, false, true};
var result = (new TestScheduler()).With(sched => {
var can_execute = new Subject<bool>();
var fixture = createCommand(can_execute, sched);
var changes_as_observable = fixture.CanExecuteObservable.CreateCollection();
int change_event_count = 0;
fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
input.Run(x => {
can_execute.OnNext(x);
sched.Start();
Assert.Equal(x, fixture.CanExecute(null));
});
// N.B. We check against '5' instead of 6 because we're supposed to
// suppress changes that aren't actually changes i.e. false => false
sched.AdvanceToMs(10*1000);
return changes_as_observable;
});
// NB: Skip(1) is because CanExecuteObservable should have
// BehaviorSubject Nature(tm)
input.DistinctUntilChanged().AssertAreEqual(result.Skip(1).ToList());
}
开发者ID:gluck,项目名称:ReactiveUI,代码行数:26,代码来源:ReactiveCommandTest.cs
示例17: AutoSuspendAppDelegate
public AutoSuspendAppDelegate()
{
var host = new SuspensionHost();
host.IsLaunchingNew = Observable.Never<Unit>();
host.IsResuming = _finishedLaunching.Select(_ => Unit.Default);
host.IsUnpausing = _activated.Select(_ => Unit.Default);
var untimelyDeath = new Subject<Unit>();
AppDomain.CurrentDomain.UnhandledException += (o,e) => untimelyDeath.OnNext(Unit.Default);
host.ShouldInvalidateState = untimelyDeath;
host.ShouldPersistState = _willTerminate.Merge(_backgrounded).SelectMany(app => {
var taskId = app.BeginBackgroundTask(new NSAction(() => untimelyDeath.OnNext(Unit.Default)));
// NB: We're being force-killed, signal invalidate instead
if (taskId == UIApplication.BackgroundTaskInvalid) {
untimelyDeath.OnNext(Unit.Default);
return Observable.Empty<IDisposable>();
}
return Observable.Return(
Disposable.Create(() => app.EndBackgroundTask(taskId)));
});
SuspensionHost = host;
}
开发者ID:Omgan,项目名称:ReactiveUI,代码行数:26,代码来源:AutoSuspendAppDelegate.cs
示例18: EigenUpdateWithoutUpdateURL
public void EigenUpdateWithoutUpdateURL()
{
string dir;
string outDir;
using (Utility.WithTempDirectory(out outDir))
using (IntegrationTestHelper.WithFakeInstallDirectory(out dir)) {
var di = new DirectoryInfo(dir);
var progress = new Subject<int>();
var bundledRelease = ReleaseEntry.GenerateFromFile(di.GetFiles("*.nupkg").First().FullName);
var fixture = new InstallManager(bundledRelease, outDir);
var pkg = new ZipPackage(Path.Combine(dir, "SampleUpdatingApp.1.1.0.0.nupkg"));
var progressValues = new List<int>();
progress.Subscribe(progressValues.Add);
fixture.ExecuteInstall(dir, pkg, progress).Wait();
var filesToLookFor = new[] {
"SampleUpdatingApp\\app-1.1.0.0\\SampleUpdatingApp.exe",
"SampleUpdatingApp\\packages\\RELEASES",
"SampleUpdatingApp\\packages\\SampleUpdatingApp.1.1.0.0.nupkg",
};
filesToLookFor.ForEach(f => Assert.True(File.Exists(Path.Combine(outDir, f)), "Could not find file: " + f));
// Progress should be monotonically increasing
progressValues.Count.ShouldBeGreaterThan(2);
progressValues.Zip(progressValues.Skip(1), (prev, cur) => cur - prev).All(x => x > 0).ShouldBeTrue();
}
}
开发者ID:rzhw,项目名称:Squirrel.Windows,代码行数:32,代码来源:InstallManagerTests.cs
示例19: BufferedHandler
public BufferedHandler(TimeSpan timeDelay, int batchSize)
{
_storiesSubject = new Subject<IStory>();
_storiesSubject.Buffer(timeDelay, batchSize)
.Where(buffer => buffer.Any())
.Subscribe(OnStoriesComplete, OnComplete);
}
开发者ID:amitapl,项目名称:logmetry,代码行数:7,代码来源:BufferedHandler.cs
示例20: AskActorReq
public AskActorReq(object msg, Subject<object> subject, ProcessId to, ProcessId replyTo)
{
Message = msg;
Subject = subject;
To = to;
ReplyTo = replyTo;
}
开发者ID:ricardopieper,项目名称:language-ext,代码行数:7,代码来源:AskActor.cs
注:本文中的Subject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论