本文整理汇总了C#中Subject.Zip方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.Zip方法的具体用法?C# Subject.Zip怎么用?C# Subject.Zip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.Zip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Zip
public void Zip()
{
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.Zip(b, (x, y) => new { x, y }).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);
}
示例2: Main
protected override void Main()
{
TraceLine(Instructions.PressAnyKeyToCancel);
var queries = new Subject<IObservable<string>>();
var zipped = queries
.Zip()
.Select(list => list.Aggregate(string.Empty, (acc, cur) => acc += cur + " "))
.Take(3);
using (zipped.Subscribe(ConsoleOutput))
{
var xs = Observable.Interval(TimeSpan.FromSeconds(.5));
var ys = Observable.Interval(TimeSpan.FromSeconds(1));
var zs = Observable.Interval(TimeSpan.FromSeconds(1.5));
queries.OnNext(xs.Select(value => Text.First + ' ' + value));
queries.OnNext(ys.Select(value => Text.Second + ' ' + value));
queries.OnNext(zs.Select(value => Text.Third + ' ' + value));
queries.OnCompleted();
WaitForKey();
}
}
示例3: Zip2
public void Zip2()
{
SetScehdulerForImport();
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.Zip(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));
a.OnNext(1000);
b.OnNext(2000);
a.OnCompleted();
l.Count.Is(1); // OnNext
b.OnCompleted(); // Completed!
l.Count.Is(2); // Completed!
l[1].Kind.Is(NotificationKind.OnCompleted);
UniRx.Scheduler.SetDefaultForUnity();
}
示例4: ScanDirectoryAsync
private async Task ScanDirectoryAsync(StorageFolder storageFolder, bool doSha1, IObserver<string> starts, IObserver<FileInfo> completes)
{
foreach (var entry in await storageFolder.GetItemsAsync()) {
var folder = entry as StorageFolder; // folder
if (folder != null) {
starts.OnNext(folder.Name);
var innerStarts = new Subject<string>();
var innerCompletes = new Subject<FileInfo>();
var _ = Task.Run(() => ScanDirectoryAsync(folder, false, innerStarts, innerCompletes));
var totalSize = await innerStarts
.Zip(innerCompletes, (s, f) => (double)f.Size)
.Sum(x => x).FirstAsync();
completes.OnNext(new FileInfo { Name = folder.Name, Size = (ulong)totalSize });
}
var file = entry as StorageFile; // file
if (file != null) {
starts.OnNext(file.Name);
var fileInfo = await ScanFile(file, doSha1).ConfigureAwait(false);
completes.OnNext(fileInfo);
}
}
starts.OnCompleted();
completes.OnCompleted();
}
示例5: StartProcessing
private void StartProcessing()
{
if (IsKinectPaused)
{
IsKinectPaused = false;
}
var observableColorAndDepth = Observable.FromEventPattern<MultiSourceFrameArrivedEventArgs>(KinectManager.Instance, "ColorAndDepthSourceFrameArrived");
ColorAndDepthSourceSubscription = observableColorAndDepth
.Do(_ =>
{
++totalColorAndDepthFrames;
++colorAndDepthFrames;
if (colorAndDepthFPSTimer.ElapsedMilliseconds >= 1000)
{
ColorAndDepthFramesPerSec = colorAndDepthFrames;
colorAndDepthFrames = 0;
colorAndDepthFPSTimer.Restart();
}
})
.ObserveOn(NewThreadScheduler.Default)
.Subscribe(
e => ColorAndDepthSourceFrameArrived(e.Sender, e.EventArgs)
);
observableColorData = new Subject<byte[]>();
observableDepthData = new Subject<ushort[]>();
observableDepthSpaceData = new Subject<DepthSpacePoint[]>();
// -- Set up Automatic thresholding --
var ExecuteAutomaticThreshold = ReactiveCommand.CreateAsyncTask(param =>
{
var input = param as ushort[];
return AutomaticThreshold(input);
});
AutoThresholdSubscription = observableDepthData
.Sample(TimeSpan.FromSeconds(1))
.Where(_ => AutomaticThresholds)
.InvokeCommand(ExecuteAutomaticThreshold);
ExecuteAutomaticThreshold
.Subscribe((t) =>
{
FarThreshold = t;
NearThreshold = t - 500; // Nearthreshold is 50 cm towards the camera.
});
// --
// -- Set up Filtering --
FilterFramesSubscription = observableColorData
.Zip(observableDepthData, observableDepthSpaceData, (c, d, dsp) => Tuple.Create(c, d, dsp))
.InvokeCommand(ExecuteFilterVideoFrame);
// --
}