void Load(ISignal<AggregateIdentity> signal) { var id = signal.Payload.Id; var type = signal.Payload.Type; var last = _storage.LoadLast(id); if (last == null) { throw new InvalidOperationException(string.Format("Aggregate root of type {0} with id {1} not found.", type.Name, id)); } var root = (IAggregateRoot)TypeHelpers.New(type); var loadId = last.SnapshotId.HasValue ? last.SnapshotId.Value : 0; foreach (var commit in _storage.LoadSince(id, loadId)) { if (commit.Snapshot != null) { root.Apply(commit.Snapshot, true); continue; } foreach (var ev in commit.Events) { root.Apply(ev, true); } } signal.Return(root); }
public static void SendSignal(this DrawNode self, ISignal signal) { if (self == null || signal == null) return; ProccessSignal(self, signal); }
private static void RemoveHandlers(DrawNode node, ISignal signal) { if (node == null || signal == null) return; SignalHandler element; if (Handlers.TryGetValue(node, out element)) element.RemoveHandlers(signal); }
public ContentDefinitionManager( ISession session, IMemoryCache memoryCache, ISignal signal) { _signal = signal; _memoryCache = memoryCache; _session = session; }
public FeatureHash( IFeatureManager featureManager, IMemoryCache memoryCache, ISignal signal) { _memoryCache = memoryCache; _featureManager = featureManager; _signal = signal; }
/// Apply ListensTo delegates private void AssignDelegate(MonoBehaviour mediator, ISignal signal, MethodInfo method) { if (signal.GetType().BaseType.IsGenericType) { signal.listener = Delegate.CreateDelegate(signal.listener.GetType(), mediator, method); //e.g. Signal<T>, Signal<T,U> etc. } else { ((Signal)signal).AddListener((Action)Delegate.CreateDelegate(typeof(Action), mediator, method)); //Assign and cast explicitly for Type == Signal case } }
public ContentDefinitionManager( ISession session, IMemoryCache memoryCache, ISignal signal) { _signal = signal; _memoryCache = memoryCache; _session = session; _typeDefinitions = _memoryCache.GetOrCreate("TypeDefinitions", entry => new ConcurrentDictionary<string, ContentTypeDefinition>()); _partDefinitions = _memoryCache.GetOrCreate("PartDefinitions", entry => new ConcurrentDictionary<string, ContentPartDefinition>()); }
/// <summary> /// Signal processing entry point. /// </summary> /// <param name="signal"></param> public virtual void OnSignal(ISignal signal) { try { signal.Trace(this); Process(signal); } catch (Exception ex) { signal.MarkAsFaulted(ex); } }
private static void ProccessSignal(DrawNode node, ISignal signal) { SignalHandler handler; if (Handlers.TryGetValue(node, out handler)) handler.TryHandleSignal(signal); if (node.ChildrenCount == 0) return; foreach (var child in node.Children) ProccessSignal(child, signal); }
void ProcessUncommited(ISignal<UncommitedEventStream> signal) { var uncommited = signal.Payload; var root = uncommited.Root; if (!uncommited.Events.Any()) { signal.Return(new IDomainEvent[0]); return; } var last = _storage.LoadLast(root.Id); var toCommit = uncommited.Events; var commited = new List<IDomainEvent>(); var targetVersion = last != null ? last.TargetVersion + last.Events.Count : 0; var currentVersion = targetVersion; foreach (var ev in toCommit) { if (currentVersion != ev.Version) { throw new ConcurrencyException(signal.Payload.Root, ev); } commited.Add(ev); currentVersion++; } var commitId = last != null ? last.Id + 1 : 0; var snapshot = last != null ? last.Snapshot : null; var snapshotId = last != null ? last.SnapshotId : null; if (root is ISnapshotEnabled && last != null && ShouldBuildSnapshot(last)) { snapshot = (root as ISnapshotEnabled).BuildSnapshot(); snapshotId = commitId; } if (commited.Any()) { var commit = new Commit( commitId, root.Id, targetVersion, commited, snapshotId, snapshot ); _storage.Store(commit); } signal.Return(uncommited.Events); }
private static void AddHandler(DrawNode node, ISignal signal, Action handler) { if (handler == null) return; SignalHandler element; if (!Handlers.TryGetValue(node, out element)) { element = new SignalHandler(); Handlers.Add(node, element); } element.AddHandler(signal, handler); }
protected override bool ExecuteItem(JetPopupMenuItem item, ISignal<bool> closeBeforeExecute) { closeBeforeExecute.Fire(true); var occurence = item.Key as ProjectItemOccurence; if (occurence == null || occurence.ProjectItem == null) { return false; } using (CommitCookie.Commit(Solution)) { var solutionExplorer = Solution.GetComponent<ISolutionExplorer>(); return solutionExplorer.ShowInSolutionExplorer(occurence.ProjectItem, activate: true); } }
public override void OnSignal(ISignal signal) { if (Next == null) return; Process(signal); }
public static void AddSignalHandler(this DrawNode self, ISignal signal, Action handler) { AddHandler(self, signal, handler); }
public SignalGenerator(ISignal signal, double samplingRate) { this.disposed = false; this.signal = signal; this.samplingRate = samplingRate; }
public ViewModelCommandInfo(string name, ISignal signal) { Signal = signal; Name = name; }
private void AssignDelegate(object model, ISignal signal, MethodInfo method) { try { if (signal.GetType().BaseType.IsGenericType) { Type genericActionType = typeof(Action<>).MakeGenericType(signal.GetType().BaseType.GetGenericArguments()); signal.AddListener(Delegate.CreateDelegate(genericActionType, model, method)); } else { signal.AddListener((Action)Delegate.CreateDelegate(typeof(Action), model, method)); } } catch (Exception e) { Debug.LogError(e.GetType() + " " + e.Message + " " + signal.GetType().Name + " " + method.Name); } }
public void OnSignal(ISignal signal) { // no-op }
/// <summary> /// Processor logic. /// </summary> /// <param name="signal"></param> protected abstract void Process(ISignal signal);
public void RemoveHandlers(ISignal signal) { _signalHandlers.Remove(signal); }
public void TryHandleSignal(ISignal signal) { Action handler; if (_signalHandlers.TryGetValue(signal, out handler)) handler(); }
// --------------------- public SamplePoint[] SuperposeSignals(ISignal signal1, ISignal signal2, ulong samples) { throw new NotImplementedException(); }
public static void RemoveSignalHandlers(this DrawNode self, ISignal signal) { RemoveHandlers(self, signal); }
public void AddHandler(ISignal signal, Action handler) { if (_signalHandlers.ContainsKey(signal)) _signalHandlers[signal] += handler; else _signalHandlers.Add(signal, handler); }
private void AllJoynNotifier_SignalRaised(ISignal sender, IList<object> args) { Debug.WriteLine("Received Notification signal from " + sender.Name); if (OnNotification == null) return; string message = null; try { var textStructs = ((IList<object>)args[NOTIFICATION_TEXT_ARGUMENT_INDEX]).Cast<AllJoynMessageArgStructure>(); /// textStructs has type a(ss), where the first element of the struct (i.e. x[0]) is the /// language as per RFC 5646, while the second element (x[1]) is the message text. var english = textStructs.First(x => ((string)x[0]).StartsWith("en")); message = (string)english[1]; } catch (Exception ex) { Debug.WriteLine("Exception in SignalRaised: " + ex.Message); return; } Debug.WriteLine("Notification text: " + message); OnNotification(message); }
private void LampStateChangedSignal_SignalRaised(ISignal sender, IList <object> args) { _lampStateChanged?.Invoke(this, EventArgs.Empty); }
private void Dispose(bool disposing) { if (this.disposed) { return; } if(disposing) { this.signal = null; } // dispose unmanaged resources here this.disposed = true; }
internal SignalException(Exception innerException, ISignal signal) : base("Signal processing exception", innerException) { Signal = signal; }
public SignalVector(ISignal signal, SamplePoint[] samplePoints) { this.signal = signal; this.samplePoints = samplePoints; }
public SignalVector(ISignal signal, SamplePoint[] samplePoints, INoise noise) : this(signal, samplePoints) { this.noise = noise; }
protected override void Process(ISignal signal) { //signal.With(this); Handler(signal); }
protected override ISignal CreateIndicator(Symbol pair, int i, string entryOrExit) { var key = entryOrExit + "Indicator" + i + "Direction"; var intDirection = GetConfigValue(key); var direction = intDirection == 0 ? Direction.LongOnly : Direction.ShortOnly; key = entryOrExit + "Indicator" + i; var indicator = (TechnicalIndicator)GetConfigValue(key); ISignal signal = null; switch (indicator) { case TechnicalIndicator.SimpleMovingAverage: var fast = _algorithm.SMA(pair, _fastPeriod, _resolution); var slow = _algorithm.SMA(pair, _slowPeriod, _resolution); signal = new CrossingMovingAverageSignal(fast, slow, direction); break; case TechnicalIndicator.ExponentialMovingAverage: // Canonical cross moving average parameters. var fastema = _algorithm.EMA(pair, period: 50); var slowema = _algorithm.EMA(pair, period: 200); signal = new CrossingMovingAverageSignal(fastema, slowema, direction); break; case TechnicalIndicator.MovingAverageConvergenceDivergence: var macd = _algorithm.MACD(pair, fastPeriod: 12, slowPeriod: 26, signalPeriod: 9, type: MovingAverageType.Simple, resolution: _resolution); signal = new CrossingMovingAverageSignal(macd, macd.Signal, direction, 1); break; case TechnicalIndicator.Stochastic: var sto = _algorithm.STO(pair, period: 14, resolution: _resolution); signal = new OscillatorSignal(sto, new[] { 20, 80 }, direction, 3); break; case TechnicalIndicator.RelativeStrengthIndex: var rsi = _algorithm.RSI(pair, period: 11); signal = new OscillatorSignal(rsi, new[] { 30, 70 }, direction); break; case TechnicalIndicator.CommodityChannelIndex: var cci = _algorithm.CCI(pair, period: 20, movingAverageType: MovingAverageType.Simple, resolution: _resolution); signal = new OscillatorSignal(cci, new[] { -100, 100 }, direction); break; case TechnicalIndicator.MomentumPercent: var pm = _algorithm.MOMP(pair, period: 60, resolution: _resolution); signal = new OscillatorSignal(pm, new[] { -5, 5 }, direction); break; case TechnicalIndicator.WilliamsPercentR: var wr = _algorithm.WILR(pair, period: 14, resolution: _resolution); signal = new OscillatorSignal(wr, new[] { -20, -80 }, direction); break; case TechnicalIndicator.PercentagePriceOscillator: var ppo = _algorithm.MACD(pair, fastPeriod: 12, slowPeriod: 26, signalPeriod: 9, type: MovingAverageType.Simple, resolution: _resolution) .Over(_algorithm.EMA(pair, _period, resolution: _resolution)).Plus(constant: 100m); var compound = new SimpleMovingAverage(_period).Of(ppo); signal = new CrossingMovingAverageSignal(ppo, compound, direction); break; case TechnicalIndicator.None: signal = new EmptySignal(); break; case TechnicalIndicator.AverageDirectionalIndex: var adx = _algorithm.ADX(pair, _period, _resolution); signal = new OscillatorSignal(adx, new[] { 25, 25 }, direction); break; //todo: //case TechnicalIndicator.AverageTrueRange: // var atr = _algorithm.ATR(pair, _period, MovingAverageType.Simple, _resolution); // signal = new OscillatorSignal(atr, oscillatorThresholds, direction); // break; case TechnicalIndicator.BollingerBands: var bb = _algorithm.BB(pair, period: 20, k: 2); signal = new BBOscillatorSignal(bb, direction, 4); break; case TechnicalIndicator.ChannelBreakout: var delay = new Delay(5); var _max = delay.Of(_algorithm.MAX(pair, 20)); var _min = delay.Of(_algorithm.MIN(pair, 20)); var cur = _algorithm.MAX(pair, 1); //current value signal = new ChannelOscillatorSignal(cur, _max, _min, direction, 4); break; case TechnicalIndicator.DonchianTrend: var dch0 = _algorithm.DCH(pair, 20); var cur0 = _algorithm.MAX(pair, 1); signal = new DonchianSignal(cur0, dch0, 2, direction); break; } return(signal); }