本文整理汇总了C#中Subject.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.Select方法的具体用法?C# Subject.Select怎么用?C# Subject.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var s = new Subject<int>();
var plan1 = s.Select(i => i).And(Observable.Return(1)).And(Observable.Return("A")).And(Observable.Return(0.1)).Then(Tuple.Create);
var plan2 = s.Select(i => i).And(Observable.Return(2)).And(Observable.Return("A")).And(Observable.Return(0.1)).Then(Tuple.Create);
var plan3 = s.Select(i => i).And(Observable.Return(3)).And(Observable.Return("A")).And(Observable.Return(0.1)).Then(Tuple.Create);
Observable.When(plan1, plan2, plan3)
.Subscribe(t =>
Console.WriteLine("{0} {1} {2} {3}", t.Item1, t.Item2, t.Item3, t.Item4));
s.OnNext(100);
s.OnNext(1);
s.OnCompleted();
}
示例2: SuspensionService
/// <summary>
/// Initializes a new instance of the <see cref="SuspensionService"/> class.
/// Based on WinRTSuspensionHost in ReactiveUI.Mobile
/// </summary>
public SuspensionService(Application app, ISubject<LaunchActivatedEventArgs> launched)
{
var launchNew = new[] { ApplicationExecutionState.ClosedByUser, ApplicationExecutionState.NotRunning, };
this.IsLaunchingNew = launched
.Where(x => launchNew.Contains(x.PreviousExecutionState))
.Select(x => x.Arguments);
this.IsResuming = launched
.Where(x => x.PreviousExecutionState == ApplicationExecutionState.Terminated)
.Select(x => x.Arguments);
var unpausing = new[] { ApplicationExecutionState.Suspended, ApplicationExecutionState.Running, };
this.IsUnpausing = launched
.Where(x => unpausing.Contains(x.PreviousExecutionState))
.Select(x => x.Arguments);
var shouldPersistState = new Subject<SuspendingEventArgs>();
app.Suspending += (o, e) => shouldPersistState.OnNext(e);
this.ShouldPersistState =
shouldPersistState.Select(x =>
{
var deferral = x.SuspendingOperation.GetDeferral();
return Disposable.Create(deferral.Complete);
});
var shouldInvalidateState = new Subject<Unit>();
app.UnhandledException += (o, e) => shouldInvalidateState.OnNext(Unit.Default);
this.ShouldInvalidateState = shouldInvalidateState;
}
示例3: Run
public void Run()
{
var subject = new Subject<int>();
subject.Select(x => x).Subscribe(x => { Console.WriteLine(x); throw new Exception(); }, ex =>
{
ShowStackTrace();
Console.WriteLine("called ex 1");
//throw ex;
});
try
{
subject.OnNext(2);
}
catch
{
}
try
{
subject.OnNext(1);
}
catch
{
}
}
示例4: UseObserverTest1
public void UseObserverTest1()
{
var subject = new Subject<string>();
var result = new List<Tuple<int, string>>();
subject
.Select(x => new Tuple<int, string>(0, x))
.UseObserver((observer, value, i) =>
{
observer.OnNext(new Tuple<int, string>(i, value.Item2));
},
null,
observer =>
{
observer.OnNext(new Tuple<int, string>(-1, "end"));
})
.Subscribe(result.Add);
subject.OnNext("a");
subject.OnNext("b");
subject.OnNext("c");
subject.OnCompleted();
result.Is(
new Tuple<int, string>(0, "a"),
new Tuple<int, string>(1, "b"),
new Tuple<int, string>(2, "c"),
new Tuple<int, string>(-1, "end"));
}
示例5: SetUp
public void SetUp()
{
_serverUpdateStream = new Subject<Either<FullUpdate, DeltaUpdate>>();
_dictionaryModificationStream = _serverUpdateStream
.Select(either =>
{
if (either.IsLeft)
{
return DictionaryModification.Replace(either.Left.Values["key"], (Update)either.Left);
}
else
{
return DictionaryModification.Upset(either.Right.Values["key"], (Update)either.Right);
}
});
_observableDictionary = _dictionaryModificationStream.ToObservableDictionary((key, existing, update) =>
{
var fullUpdate = new FullUpdate(key)
{
Values = new Dictionary<string, string>(existing.Values)
};
foreach (var kvp in update)
{
fullUpdate.Values[kvp.Key] = kvp.Value;
}
return fullUpdate;
});
}
示例6: AutoSuspendHelper
public AutoSuspendHelper(Application app)
{
Reflection.ThrowIfMethodsNotOverloaded("AutoSuspendHelper", app, "OnLaunched");
var launchNew = new[] { ApplicationExecutionState.ClosedByUser, ApplicationExecutionState.NotRunning, };
RxApp.SuspensionHost.IsLaunchingNew = _activated
.Where(x => launchNew.Contains(x.PreviousExecutionState))
.Select(_ => Unit.Default);
RxApp.SuspensionHost.IsResuming = _activated
.Where(x => x.PreviousExecutionState == ApplicationExecutionState.Terminated)
.Select(_ => Unit.Default);
var unpausing = new[] { ApplicationExecutionState.Suspended, ApplicationExecutionState.Running, };
RxApp.SuspensionHost.IsUnpausing = _activated
.Where(x => unpausing.Contains(x.PreviousExecutionState))
.Select(_ => Unit.Default);
var shouldPersistState = new Subject<SuspendingEventArgs>();
app.Suspending += (o, e) => shouldPersistState.OnNext(e);
RxApp.SuspensionHost.ShouldPersistState =
shouldPersistState.Select(x => {
var deferral = x.SuspendingOperation.GetDeferral();
return Disposable.Create(deferral.Complete);
});
var shouldInvalidateState = new Subject<Unit>();
app.UnhandledException += (o, e) => shouldInvalidateState.OnNext(Unit.Default);
RxApp.SuspensionHost.ShouldInvalidateState = shouldInvalidateState;
}
示例7: 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;
}
示例8: Select
public void Select()
{
var subject = new Subject<string>();
subject.Select(x => x.Length).Subscribe(x => Debug.WriteLine(x));
subject.OnNext("telerik");
subject.OnNext("has");
subject.OnNext("a");
subject.OnNext("party");
}
示例9: ThrottlingExampleViewModel
public ThrottlingExampleViewModel()
{
Output = new ObservableCollection<string>();
FirstNames = new ReadOnlyCollection<string>(new List<string> {"Joe", "Bill", "Victor"});
LastNames = new ReadOnlyCollection<string>(new List<string> {"Smith", "White", "Black"});
var uiScheduler = new SynchronizationContextScheduler(SynchronizationContext.Current);
_requestParametersObservable = new Subject<Tuple<string, string>>();
_requestParametersObservable// .SubscribeOn(NewThreadScheduler.Default).Select(LoadData)
//.Select(parameters => Observable.Start(() => LoadData(parameters), ThreadPoolScheduler.Instance))
.Select(parameters => Observable.FromAsync(token => LoadDataAsync(parameters, token)))
.Switch()
.ObserveOn(DispatcherScheduler.Current)
.Subscribe(WriteData);
}
示例10: Demo3
public void Demo3()
{
var namesToLook = new Subject<string>();
namesToLook.Select(partialName => _userSearchService.FindUser(partialName))
.Switch()
.Subscribe(users =>
{
Console.WriteLine(string.Join(",", users.Select(p => p.Login)));
});
Console.ReadKey();
namesToLook.OnNext("a");
Console.ReadKey();
namesToLook.OnNext("b");
Console.ReadKey();
namesToLook.OnNext("c");
Console.WriteLine("done!");
Console.ReadKey();
}
示例11: ConcatExperiment
public void ConcatExperiment()
{
var xs = new Subject<int>();
var ys = new Subject<int>();
var zs = new Subject<int>();
IObservable<string> query =
xs.Select(v => v.ToString(CultureInfo.CurrentCulture)).AsOperational()
+ ","
+ ys.Select(v => v.ToString(CultureInfo.CurrentCulture))
+ "-"
+ zs.Select(v => v.ToString(CultureInfo.CurrentCulture));
using (query.Subscribe(ConsoleOutput))
{
xs.OnNext(1);
ys.OnNext(2);
zs.OnNext(3);
xs.OnNext(4);
ys.OnNext(5);
zs.OnNext(6);
xs.OnNext(7);
ys.OnNext(8);
zs.OnNext(9);
WaitForKey();
}
}
示例12: ResultSelectorWithIndex
public void ResultSelectorWithIndex()
{
SetScehdulerForImport();
{
// OnCompleted Case
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnNext((100, 1, 400, 1, 1))", "OnCompleted()");
}
{
// OnError A
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnError(new Exception());
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnError(System.Exception)");
}
{
// OnError B
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnError(new Exception());
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnError(System.Exception)");
}
UniRx.Scheduler.SetDefaultForUnity();
}
示例13: SelectorWithIndex
public void SelectorWithIndex()
{
{
// OnCompleted Case
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnNext((400, 1))", "OnCompleted()");
}
{
// OnError A
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnError(new Exception());
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
}
{
// OnError B
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnError(new Exception());
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
}
}
示例14: UpdateAppAsync
public static Task<ReleaseEntry> UpdateAppAsync(this IUpdateManager This, Action<int> progress)
{
var checkSubj = new Subject<int>();
var downloadSubj = new Subject<int>();
var applySubj = new Subject<int>();
var ret = This.CheckForUpdate(false, checkSubj)
.SelectMany(x => This.DownloadReleases(x.ReleasesToApply, downloadSubj).TakeLast(1).Select(_ => x))
.SelectMany(x => This.ApplyReleases(x, applySubj).TakeLast(1).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).LastOrDefault()))
.PublishLast();
var allProgress = Observable.Merge(
checkSubj.Select(x => (double)x / 3.0),
downloadSubj.Select(x => (double)x / 3.0),
applySubj.Select(x => (double)x / 3.0))
.Scan(0.0, (acc, x) => acc + x);
allProgress.Subscribe(x => progress((int) x));
ret.Connect();
return ret.ToTask();
}
示例15: Durability
public void Durability()
{
{
var s1 = new Subject<int>();
var list = new List<int>();
var d = s1.Subscribe(xx =>
{
list.Add(xx);
Observable.Return(xx)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(x));
});
try { s1.OnNext(5); } catch { }
try { s1.OnNext(1); } catch { }
try { s1.OnNext(10); } catch { }
list.IsCollection(5, 5, 1, 10, 10);
d.Dispose();
s1.OnNext(1000);
list.Count.Is(5);
}
{
var s1 = new Subject<int>();
var list = new List<int>();
var d = s1.Select(x => x).Take(1000).Subscribe(xx =>
{
list.Add(xx);
Observable.Return(xx)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(x));
});
try { s1.OnNext(5); } catch { }
try { s1.OnNext(1); } catch { }
try { s1.OnNext(10); } catch { }
list.IsCollection(5, 5, 1, 10, 10);
d.Dispose();
s1.OnNext(1000);
list.Count.Is(5);
}
}