本文整理汇总了C#中IObservable.Select方法的典型用法代码示例。如果您正苦于以下问题:C# IObservable.Select方法的具体用法?C# IObservable.Select怎么用?C# IObservable.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObservable
的用法示例。
在下文中一共展示了IObservable.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MobileApiInfo
public MobileApiInfo(IObservable<IReadOnlyList<MobileClient>> connectedClients, IObservable<bool> isPortOccupied)
{
if (connectedClients == null)
throw new ArgumentNullException("connectedClients");
if (isPortOccupied == null)
throw new ArgumentNullException("isPortOccupied");
this.IsPortOccupied = isPortOccupied;
this.VideoPlayerToggleRequest = connectedClients.Select(x => x.Select(y => y.VideoPlayerToggleRequest).Merge()).Switch();
this.ConnectedClientCount = connectedClients.Select(x => x.Count);
}
示例2: JoinRoom
public IObservable<ChatEvent> JoinRoom(string room, string user, IObservable<string> messages)
{
// Get or create the room being requested.
var roomStream = this.GetOrAddRoom(room);
// Send a happy little join message.
roomStream.OnNext(new ChatEvent
{
User = user,
Message = "Joined!",
Time = DateTime.UtcNow,
Type = "presence"
});
// Turn incoming messages into chat events and pipe them into the room.
messages.Select(message => new ChatEvent
{
User = user,
Message = message,
Time = DateTime.UtcNow
})
.Subscribe(
roomStream.OnNext,
() => roomStream.OnNext(new ChatEvent
{
User = user,
Message = "Left.",
Time = DateTime.UtcNow,
Type = "presence"
}));
return roomStream;
}
示例3: RiakStreamedMapReduceResult
internal RiakStreamedMapReduceResult(IObservable<RpbMapRedResp> responseReader)
{
_responseReader = responseReader
.Select(item => new RiakMapReduceResultPhase(item.phase, new List<RpbMapRedResp> { item }))
.ToEnumerable()
.ToList();
}
示例4: Calculate
public virtual IObservable<double> Calculate(IObservable<double> samples)
{
var q = new Queue<double>();
var sma = double.NaN;
return samples.Select(x =>
{
q.Enqueue(x);
if (double.IsNaN(sma))
{
sma = x;
return x;
}
if (q.Count <= N)
{
sma = q.Sum() / q.Count;
}
else
{
sma = sma + (x / N) - (q.Dequeue() / N);
}
return sma;
});
}
示例5: Threshold
public Threshold(IObservable<int> thresholdState)
{
//this.WhenAny(vm => vm.Good, vm => vm.Bad, vm => vm.OK, (g, b, o) =>
//{
//});
this.Good = new Range();
this.Bad = new Range();
this.OK = new Range();
var obs = thresholdState.Select(value =>
{
if (value.Between(this.Good.Min, this.Good.Max))
return "Good";
if (value.Between(this.OK.Min, this.ok.Max))
return "OK";
if (value.Between(this.Bad.Min, this.bad.Max))
return "Bad";
return "";
});
this.state = obs.ToProperty(this, vm => vm.State);
obs.Subscribe(_ =>
{
Trace.WriteLine(_);
});
}
示例6: MainWindowViewModel
public MainWindowViewModel()
{
_iTunes = new iTunes().AddTo(CompositeDisposable);
var currentTrack = Observable.Interval(TimeSpan.FromSeconds(0.5))
.Select(_ => _iTunes.GetCurrentTrack())
.Where(track => track != null)
.DistinctUntilChanged()
.Publish();
Title = currentTrack.Select(x => x.Name).ToReactiveProperty();
Album = currentTrack.Select(x => x.Album).ToReactiveProperty();
Artist = currentTrack.Select(x => x.Artist).ToReactiveProperty();
var artwork = currentTrack.Select(x => x.Artwork.FirstOrDefault())
.Where(x => x != null)
.DistinctUntilChanged();
_colors = artwork.SelectMany(x => x.GetStreamAsync())
.Select(x => new Bitmap(x))
.Select(Analyzer.GetColors);
MainColor = _colors.Select(x => x.Item1.ToMediaColor()).ToReactiveProperty();
AccentColor = _colors.Select(x => x.Item2.ToMediaColor()).ToReactiveProperty();
SubColor = _colors.Select(x => x.Item3.ToMediaColor()).ToReactiveProperty();
Artwork = artwork.SelectMany(x => x.GetStreamAsync())
.Select(x =>
{
var image = x.ToBitmapImage();
image.Freeze();
return image;
})
.ToReactiveProperty();
InvertedMainColor = MainColor.CombineLatest(AccentColor, (main, accent) =>
{
var mainLuminance = Hsb.GetLuminance(main.ToDrawingColor());
var accentHsb = Hsb.FromColor(accent.ToDrawingColor());
var b = mainLuminance > 50 ? 0.1f : 0.9f;
return accentHsb.SetBrightness(b).ToColor().ToMediaColor();
}).ToReactiveProperty();
currentTrack.Connect().AddTo(CompositeDisposable);
}
示例7: ValidateFullName
private static IObservable<string> ValidateFullName(IObservable<string> fullNames)
{
return fullNames.Select(
fullName =>
{
if (string.IsNullOrWhiteSpace(fullName)) return "Must specify a full name";
return null;
});
}
示例8: SkeletonDispatcher
public SkeletonDispatcher(IObservable<IEnumerable<SkeletonData>> skeletons)
{
Contract.Requires(skeletons != null);
mySkeletonSubscription =
skeletons
.Select(sds => sds.Where(sd => sd.TrackingState != SkeletonTrackingState.NotTracked))
.Subscribe(OnSkeletonsProduced);
}
示例9: PegCompiler
public PegCompiler(IObservable<Grammar> grammars)
{
var compileResults = grammars
.Select(r => r == null ? new Compiler.CompileResult(r) : Compiler.PegCompiler.Compile(r))
.Publish();
this.Codes = compileResults.Select(r => r.Code);
this.Errors = compileResults.Select(r => r.Errors.ToList().AsReadOnly());
this.disposable = compileResults.Connect();
}
示例10: Calculate
/// <summary>
/// Calculates the Count of given samples.
/// </summary>
/// <param name="samples"></param>
public static IObservable<Decimal> Calculate(IObservable<double> samples)
{
var result = (Decimal)0;
return samples.Select(x =>
{
result += Convert.ToDecimal(x);
return result;
});
}
示例11: Calculate
/// <summary>
/// Calculates the Count of given samples.
/// </summary>
/// <param name="samples"></param>
public static IObservable<UInt64> Calculate(IObservable<double> samples)
{
var result = (UInt64)0;
return samples.Select(x =>
{
result++;
return result;
});
}
示例12: HandleExceptionOccurredMessages
public HandleExceptionOccurredMessages(
IPublisher publisher,
IDispatchServices dispatch,
IObservable<ExceptionOccurred> exceptionStream1,
IObservable<ExceptionMsg> exceptionStream2)
{
_publisher = publisher;
exceptionStream1.Select(ex => ex.Exception)
.Merge(exceptionStream2.Select(ex => ex.Exception))
.ObserveOn(dispatch)
.Subscribe(HandleNextException);
}
示例13: Filter
public static IObservable<List<float>> Filter(IObservable<List<float>> src, Func<IObservable<float>, IObservable<float>> filter)
{
var channels = new List<IObservable<float>>(8);
for (var index = 0; index < 8; index++)
{
var chIndex = index;
var channel = filter(src.Select(values => values[chIndex]));
channels.Add(channel);
}
return channels.Zip(ilist => ilist.ToList());
}
示例14: Center
public IObservable<PointF> Center(IObservable<List<float>> channelsObservable)
{
return channelsObservable.Select(channels =>
{
if (channels != null && channels.Count == 4)
{
return CalculateCenterOf(channels);
}
return GeometricalCenter;
});
}
示例15: ToIterate_Complete
IEnumerable<IObservable<Object>> ToIterate_Complete(IObservable<int> xs, IObservable<int> ys, IObservable<int> zs, IObserver<int> observer)
{
observer.OnNext(1);
yield return xs.Select(x => new Object());
observer.OnNext(2);
yield return ys.Select(x => new Object());
observer.OnNext(3);
observer.OnCompleted();
yield return zs.Select(x => new Object());
observer.OnNext(4);
}