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);
		}
예제 #2
0
        public static void SendSignal(this DrawNode self, ISignal signal)
        {
            if (self == null || signal == null)
                return;

            ProccessSignal(self, signal);
        }
예제 #3
0
 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;
 }
예제 #5
0
 public FeatureHash(
     IFeatureManager featureManager,
     IMemoryCache memoryCache,
     ISignal signal)
 {
     _memoryCache = memoryCache;
     _featureManager = featureManager;
     _signal = signal;
 }
예제 #6
0
 /// 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
     }
 }
예제 #7
0
        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>());
        }
예제 #8
0
		/// <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);
			}
		}
예제 #9
0
        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);
		}
예제 #11
0
        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);
            }
        }
예제 #13
0
		public override void OnSignal(ISignal signal)
		{
			if (Next == null) return;

			Process(signal);
		}
예제 #14
0
 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;
 }
예제 #17
0
 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);
     }
 }
예제 #18
0
			public void OnSignal(ISignal signal)
			{
				// no-op
			}
예제 #19
0
		/// <summary>
		/// Processor logic.
		/// </summary>
		/// <param name="signal"></param>
		protected abstract void Process(ISignal signal);
예제 #20
0
 public void RemoveHandlers(ISignal signal)
 {
     _signalHandlers.Remove(signal);
 }
예제 #21
0
 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();
 }
예제 #23
0
 public static void RemoveSignalHandlers(this DrawNode self, ISignal signal)
 {
     RemoveHandlers(self, signal);
 }
예제 #24
0
 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);
        }
예제 #26
0
 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;
        }
예제 #28
0
		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;
 }
예제 #31
0
		protected override void Process(ISignal signal)
		{
			//signal.With(this);
			Handler(signal);
		}
예제 #32
0
        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);
        }