本文整理汇总了C#中IObservable.CombineLatest方法的典型用法代码示例。如果您正苦于以下问题:C# IObservable.CombineLatest方法的具体用法?C# IObservable.CombineLatest怎么用?C# IObservable.CombineLatest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObservable
的用法示例。
在下文中一共展示了IObservable.CombineLatest方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LineScroller
public LineScroller(FileInfo file,
IObservable<ILineProvider> latest,
IObservable<ScrollRequest> scrollRequest,
ILogger logger,
IScheduler scheduler = null)
{
if (file == null) throw new ArgumentNullException(nameof(file));
if (latest == null) throw new ArgumentNullException(nameof(latest));
if (logger == null) throw new ArgumentNullException(nameof(logger));
logger.Info($"Constructing file tailer for {file.FullName}");
var lines = new SourceCache<Line, LineKey>(l=>l.Key);
Lines = lines.AsObservableCache();
var locker = new object();
scrollRequest = scrollRequest.Synchronize(locker);
var aggregator = latest.CombineLatest(scrollRequest, (currentLines, scroll) => currentLines.ReadLines(scroll).ToArray())
.Subscribe(currentPage =>
{
var previous = lines.Items.ToArray();
var added = currentPage.Except(previous,Line.TextStartComparer).ToArray();
var removed = previous.Except(currentPage, Line.TextStartComparer).ToArray();
lines.Edit(innerCache =>
{
if (removed.Any()) innerCache.Remove(removed);
if (added.Any()) innerCache.AddOrUpdate(added);
});
});
_cleanUp = new CompositeDisposable(Lines, lines, aggregator);
}
示例2: Emit
public IObservable<NavigationInformation> Emit(IObservable<NavigationInformation> Navigation)
{
ICanPortHandler canPortHandler = _canPortHandlerProvider.OpenPort();
IObservable<long> speedSampler = Observable.Interval(TimeSpan.FromMilliseconds(200));
IObservable<long> gpsSampler = Observable.Interval(TimeSpan.FromMilliseconds(1000));
var sub = new CompositeDisposable(
canPortHandler,
Navigation.CombineLatest(speedSampler, (n, i) => n)
.Sample(speedSampler)
.Subscribe(n => EmitSpeed(canPortHandler.Port, n.Speed)),
Navigation.CombineLatest(gpsSampler, (n, i) => n)
.Sample(gpsSampler)
.Subscribe(n => EmitPosition(canPortHandler.Port, n.Position, n.Reliability)));
Navigation.Subscribe(_ => { }, sub.Dispose);
return Navigation;
}
示例3: TestParser
public TestParser(IObservable<dynamic> parsers, IObservable<string> subjects)
{
var testParserResults = subjects
.CombineLatest(parsers, (subject, parser) => new { subject, parser = (object)parser })
.ObserveOn(Scheduler.Default)
.Select(p => ParseTest(p.parser, p.subject))
.Publish()
.RefCount();
this.Results = testParserResults.Select(r => r.Result);
this.Errors = testParserResults.Select(r => r.Errors);
}
示例4: PegParser
public PegParser(IObservable<string> subjects, IObservable<string> fileNames)
{
var internalParseResults = subjects.CombineLatest(fileNames, (subject, filename) => new { subject, filename })
.Throttle(TimeSpan.FromMilliseconds(10), Scheduler.Default)
.Select(p => Parse(p.subject, p.filename))
.Publish();
this.Grammars = internalParseResults.Select(g => g.Grammar);
this.Errors = internalParseResults.Select(g => g.Errors.AsReadOnly());
this.LexicalElements = internalParseResults.Select(g => g.LexicalElements);
this.disposable = internalParseResults.Connect();
}
示例5: CsCompiler
public CsCompiler(IObservable<Tuple<string, Grammar>> codeAndGrammar, IObservable<string> fileNames)
{
var csCompilerResults = codeAndGrammar
.CombineLatest(fileNames, (cg, fileName) => new { code = cg.Item1, grammar = cg.Item2, fileName })
.Throttle(TimeSpan.FromMilliseconds(10), Scheduler.Default)
.Select(p => Compile(p.code, p.grammar, p.fileName))
.Publish();
this.Parsers = csCompilerResults.Select(r => r.Parser);
this.Errors = csCompilerResults.Select(r => r.Errors.AsReadOnly());
this.disposable = csCompilerResults.Connect();
}
示例6: Emit
public IObservable<NavigationInformation> Emit(IObservable<NavigationInformation> Navigation)
{
var udpClient = new UdpClient();
udpClient.Connect(RemoteAddress, Port);
IObservable<long> speedSampler = Observable.Interval(TimeSpan.FromMilliseconds(500));
IObservable<long> gpsSampler = Observable.Interval(TimeSpan.FromMilliseconds(1000));
var sub = new CompositeDisposable(
udpClient,
Navigation.CombineLatest(speedSampler, (n, i) => n)
.Sample(speedSampler)
.TimeInterval()
.Scan(0.0, (dst, tn) => dst + (tn.Interval.TotalHours * tn.Value.Speed * 1000))
.Subscribe(disstance => EmitSpeed(udpClient, disstance)),
Navigation.CombineLatest(gpsSampler, (n, i) => n)
.Sample(gpsSampler)
.Subscribe(n => EmitPosition(udpClient, n.Position, n.Reliability)));
Navigation.Subscribe(_ => { }, sub.Dispose);
return Navigation;
}
示例7: TestParser
public TestParser(IObservable<dynamic> parsers, IObservable<string> subjects, IObservable<string> fileNames)
{
var testParserResults = subjects
.CombineLatest(fileNames, (subject, fileName) => new { subject, fileName })
.CombineLatest(parsers, (p, parser) => new { p.subject, p.fileName, parser = (object)parser })
.Throttle(TimeSpan.FromMilliseconds(10), Scheduler.Default)
.Select(p => ParseTest(p.parser, p.subject, p.fileName))
.Publish();
this.Results = testParserResults.Select(r => r.Result);
this.Errors = testParserResults.Select(r => r.Errors.AsReadOnly());
this.disposable = testParserResults.Connect();
}
示例8: Start
void Start () {
//Time
rx_player_time = source.rx_score.Select(score=>{
return score.time.played_for;
});
rx_goal_time = source.rx_score.SelectMany(score=>{
return score.settings.time.rx_game_length;
});
//Distance
rx_player_distance = source.rx_score.Select(score=>{
return score.time.distance_covered;
});
rx_distance_target = source.rx_score.Select(score=>{
return score.settings.win_condition.distance_covered;
});
//Icons
rx_player_time.CombineLatest(rx_goal_time, (player, goal)=>{
return new {player = player, goal = goal};
}).Subscribe(data => {
update_section(data.player, data.goal, time_icon, GameTimer.to_stopwatch, time_recorded_text, time_goal_text);
});
rx_player_distance.CombineLatest(rx_distance_target, (player, goal)=>{
return new {player = player, goal = goal};
}).Subscribe(data => {
update_section(data.player, data.goal.target, distance_icon, (distance)=>{
return distance.ToString("0.00")+" m";
}, distance_recorded_text, distance_goal_text);
//Handle the score totals since we have the needed data.
float flat_score = data.goal.flat_value(data.player);
float range_score = data.goal.range_value(data.player);
float total_score = flat_score + range_score;
ScoreDetailedForm.format_score_text(flat_score_text, flat_score);
ScoreDetailedForm.format_score_text(range_score_text, range_score);
ScoreDetailedForm.format_score_text(total_score_text, total_score);
});
//Average Speed
rx_player_time.CombineLatest(rx_player_distance, (time, distance)=>{
return distance/time;
}).Subscribe(speed=>{
average_speed_text.text = speed.ToString("0.00")+" m/s";
});
//Flat Score
}
开发者ID:mrunderhill89,项目名称:guardian_of_the_fields_the_strawberry_jam,代码行数:49,代码来源:ScoreTimelineView.cs
示例9: Add
private static IObservable<Vector3<int>> Add(IObservable<Vector3<int>> arg1, IObservable<Vector3<int>> arg2)
{
return arg1.CombineLatest(arg2, (a, b) => a + b);
}