本文整理汇总了C#中Event.Snapshot方法的典型用法代码示例。如果您正苦于以下问题:C# Event.Snapshot方法的具体用法?C# Event.Snapshot怎么用?C# Event.Snapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Event
的用法示例。
在下文中一共展示了Event.Snapshot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Accumulate
private static Behavior<double> Accumulate(
Event<int> ePulses, Behavior<double> calibration) {
BehaviorLoop<int> total = new BehaviorLoop<int>();
total.Loop(ePulses.Snapshot(total,(pulses_, total_) => pulses_ + total_).Hold(0));
return Behavior<double>.Lift(
(total_, calibration_) => total_ * calibration_,
total, calibration);
}
示例2: CapturePrice
public static Behavior<Double> CapturePrice(
Event<Fuel> eStart,
Behavior<Double> price1, Behavior<Double> price2,
Behavior<Double> price3)
{
Event<Optional<Double>> ePrice1 = eStart.Snapshot(price1,
(f, p) => f == Fuel.ONE ? Optional<double>.Of(p)
: Optional<double>.Empty());
Event<Optional<Double>> ePrice2 = eStart.Snapshot(price2,
(f, p) => f == Fuel.TWO ? Optional<double>.Of(p)
: Optional<double>.Empty());
Event<Optional<Double>> ePrice3 = eStart.Snapshot(price3,
(f, p) => f == Fuel.THREE ? Optional<double>.Of(p)
: Optional<double>.Empty());
return Event<double>.FilterOptional(
ePrice1.Merge(ePrice2.Merge(ePrice3))
).Hold(0.0);
}
示例3: perFuel
static Behavior<String> perFuel(
Event<UpDown> eNozzle,
Behavior<Double> price)
{
Behavior<Double> capPrice = eNozzle.Snapshot(price).Hold(0.0);
Behavior<UpDown> nozzle = eNozzle.Hold(UpDown.DOWN);
return Behavior<UpDown>.Lift(
(u, price_) => u.Equals(UpDown.UP) ? Formatters.FormatPrice(price_) : "",
nozzle,
capPrice);
}
示例4: WhenSetDown
private static Event<End> WhenSetDown(Event<UpDown> eNozzle,
Fuel nozzleFuel,
Behavior<Optional<Fuel>> fillActive)
{
return Event<End>.FilterOptional(
eNozzle.Snapshot(fillActive,
(u,f) => u == UpDown.DOWN &&
f.Equals(Optional<Fuel>.Of(nozzleFuel))
? Optional<End>.Of(End.END)
: Optional<End>.Empty()));
}
示例5: Accumulate
public static Behavior<double> Accumulate(
Event<Unit> eClearAccumulator,
Event<int> ePulses,
Behavior<double> calibration) {
BehaviorLoop<int> total = new BehaviorLoop<int>();
total.Loop(ePulses.Snapshot(total,
(pulses_, total_) => pulses_ + total_)
.Merge(eClearAccumulator.Map(f => 0))
.Hold(0));
return Behavior<double>.Lift(
(total_, calibration_) => total_ * calibration_,
total, calibration);
}
示例6: Keypad
public Keypad(Event<Key> eKeypad, Event<Unit> eClear)
{
BehaviorLoop<int> value = new BehaviorLoop<int>();
this.Value = value;
Event<int> eKeyUpdate = Event<int>.FilterOptional(
eKeypad.Snapshot(
value,
(key, value_) =>
{
if (key == Key.CLEAR)
return Optional<int>.Of(0);
else
{
int x10 = value_ * 10;
return x10 >= 1000
? Optional<int>.Empty()
: Optional<int>.Of(
key == Key.ZERO
? x10
: key == Key.ONE
? x10 + 1
: key == Key.TWO
? x10 + 2
: key == Key.THREE
? x10 + 3
: key == Key.FOUR
? x10 + 4
: key == Key.FIVE
? x10 + 5
: key == Key.SIX
? x10 + 6
: key == Key.SEVEN
? x10 + 7
: key == Key.EIGHT
? x10 + 8
: x10 + 9
);
}
})
);
value.Loop(
eKeyUpdate.Merge(eClear.Map(u => 0))
.Hold(0));
EBeep = eKeyUpdate.Map(k => Unit.UNIT);
}
示例7: NotifyPointOfSale
public NotifyPointOfSale(
LifeCycle lc,
Event<Unit> eClearSale,
Fill fi)
{
Behavior<Boolean> locked = lc.EStart.Map(u => true).Merge(eClearSale.Map(u => false)).Hold(false);
EStart = lc.EStart.Gate(locked.Map(l => !l));
EEnd = lc.EEnd.Gate(locked);
FuelFlowing = EStart.Map(f => Optional<Fuel>.Of(f))
.Merge(EEnd.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
FillActive = EStart.Map(f => Optional<Fuel>.Of(f))
.Merge(eClearSale.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
EBeep = eClearSale;
ESaleComplete = Event<Sale>.FilterOptional(
EEnd.Snapshot(
Behavior<Sale>.Lift(
(oFuel, price_, dollars, liters) => oFuel.IsPresent ? Optional<Sale>.Of(new Sale(oFuel.Get(), price_, dollars, liters)) : Optional<Sale>.Empty(),
FuelFlowing,
fi.Price,
fi.DollarsDelivered,
fi.LitersDelivered)));
}