/// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.Metadata.FirstOrDefaultOfType<AutoCheckAvailabilityHelper>();
            if(helper == null) return;

            helper.MakeAwareOf(trigger);
        }
Example #2
0
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        /// <param name="identity"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }

            _diagnosticInterval        = _config.DiagnosticsInterval.GetValueOrDefault(TimeSpan.Zero);
            _batchTriggerInterval      = _config.BatchTriggerInterval.GetValueOrDefault(TimeSpan.Zero);
            _diagnosticsOutputTimer    = new Timer(DiagnosticsOutputTimer_Elapsed);
            _batchTriggerIntervalTimer = new Timer(BatchTriggerIntervalTimer_Elapsed);
            _maxEgressMessageQueue     = _config.MaxEgressMessageQueue.GetValueOrDefault(4096); // = 2 GB / 2 / (256 * 1024)
            _logger.Information($"Max. egress message queue: {_maxEgressMessageQueue} messages ({_maxEgressMessageQueue * 256 / 1024} MB)");
        }
Example #3
0
        protected virtual IMessageTrigger ParseMessage(string messageText, DependencyObject target)
        {
            var    triggerPlusMessage = messageText.Split('=');
            string messageDetail      = triggerPlusMessage.Last()
                                        .Replace("[", string.Empty)
                                        .Replace("]", string.Empty)
                                        .Trim();

            IRoutedMessage message = null;

            foreach (var keyValuePair in _messageParsers)
            {
                if (messageDetail.StartsWith(keyValuePair.Key, StringComparison.CurrentCultureIgnoreCase))
                {
                    message = keyValuePair.Value
                              .Parse(target, messageDetail.Remove(0, keyValuePair.Key.Length).Trim());
                    break;
                }
            }

            if (message == null)
            {
                message = _messageParsers[_defaultMessageParserKey]
                          .Parse(target, messageDetail);
            }

            IMessageTrigger trigger = null;

            if (triggerPlusMessage.Length == 1)
            {
                var defaults = _controller.FindDefaultsOrFail(target);
                trigger = defaults.GetDefaultTrigger();
            }
            else
            {
                var triggerDetail = triggerPlusMessage[0]
                                    .Replace("[", string.Empty)
                                    .Replace("]", string.Empty)
                                    .Trim();

                foreach (var keyValuePair in _triggerParsers)
                {
                    if (triggerDetail.StartsWith(keyValuePair.Key, StringComparison.CurrentCultureIgnoreCase))
                    {
                        trigger = keyValuePair.Value
                                  .Parse(target, triggerDetail.Remove(0, keyValuePair.Key.Length).Trim());
                        break;
                    }
                }
            }

            if (trigger == null)
            {
                throw new CaliburnException("Could not determine trigger type.");
            }

            trigger.Message = message;

            return(trigger);
        }
Example #4
0
 internal void MakeAwareOf(IMessageTrigger trigger)
 {
     if (!triggersToNotify.Contains(trigger))
     {
         triggersToNotify.Add(trigger);
     }
 }
Example #5
0
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        /// <param name="identity"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }

            _diagnosticInterval        = _config.DiagnosticsInterval.GetValueOrDefault(TimeSpan.Zero);
            _batchTriggerInterval      = _config.BatchTriggerInterval.GetValueOrDefault(TimeSpan.Zero);
            _diagnosticsOutputTimer    = new Timer(DiagnosticsOutputTimer_Elapsed);
            _batchTriggerIntervalTimer = new Timer(BatchTriggerIntervalTimer_Elapsed);
        }
Example #6
0
 public void RegisterTrigger(IMessageTrigger trigger)
 {
     if (!_triggersToNotify.Contains(trigger))
     {
         _triggersToNotify.Add(trigger);
     }
 }
Example #7
0
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger)
        {
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;

            _messageTrigger.OnMessage += MessageTriggerMessageReceived;

            if (engineConfiguration.DiagnosticsInterval.HasValue &&
                engineConfiguration.DiagnosticsInterval > TimeSpan.Zero)
            {
                _diagnosticsOutputTimer = new Timer(DiagnosticsOutputTimer_Elapsed, null, 0,
                                                    (int)engineConfiguration.DiagnosticsInterval.Value.TotalMilliseconds);
            }

            if (engineConfiguration.BatchSize.HasValue &&
                engineConfiguration.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = engineConfiguration.BatchSize.Value;
            }
            if (engineConfiguration.MaxMessageSize.HasValue &&
                engineConfiguration.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = engineConfiguration.MaxMessageSize.Value;
            }
        }
Example #8
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.GetMetadata<DependencyObserver>();
            if (helper == null) return;

            if (trigger.Message.RelatesTo(_target))
                helper.MakeAwareOf(trigger, _dependencies);
        }
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.Metadata.FirstOrDefaultOfType<DependencyObserver>();
            if (helper == null) return;

            if (trigger.Message.RelatesTo(target))
                helper.MakeAwareOf(trigger, dependencies);
        }
Example #10
0
 /// <summary>
 /// Makes the metadata aware of the relationship between an <see cref="IMessageTrigger"/> and its dependencies.
 /// </summary>
 /// <param name="trigger">The trigger.</param>
 /// <param name="dependencies">The dependencies.</param>
 public void MakeAwareOf(IMessageTrigger trigger, IEnumerable <string> dependencies)
 {
     foreach (var dependency in dependencies)
     {
         var info = GetMonitoringInfos(dependency);
         info.RegisterTrigger(trigger);
     }
 }
Example #11
0
 /// <summary>
 /// Makes the metadata aware of the relationship between an <see cref="IMessageTrigger"/> and its dependencies.
 /// </summary>
 /// <param name="trigger">The trigger.</param>
 /// <param name="dependencies">The dependencies.</param>
 public void MakeAwareOf(IMessageTrigger trigger, IEnumerable<string> dependencies)
 {
     foreach (var dependency in dependencies)
     {
         var info = GetMonitoringInfos(dependency);
         info.RegisterTrigger(trigger);
     }
 }
 protected override void given_the_context_of()
 {
     container = Mock<IServiceLocator>();
     methodHost = new TheMethodHost();
     handler = Mock<IRoutedMessageHandler>();
     handler.Stub(x => x.Unwrap()).Return(methodHost);
     trigger = Stub<IMessageTrigger>();
     trigger.Message = Stub<IRoutedMessage>();
 }
Example #13
0
 protected override void given_the_context_of()
 {
     container  = Mock <IServiceLocator>();
     methodHost = new TheMethodHost();
     handler    = Mock <IRoutedMessageHandler>();
     handler.Stub(x => x.Unwrap()).Return(methodHost);
     trigger         = Stub <IMessageTrigger>();
     trigger.Message = Stub <IRoutedMessage>();
 }
Example #14
0
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            if (!_elementIsLoaded)
            {
                return;
            }

            FindHandlerOrFail(trigger.Message, true).UpdateAvailability(trigger);
        }
		/// <summary>
		/// Makes the metadata aware of the relationship between an <see cref="IMessageTrigger"/> and its dependencies.
		/// </summary>
		/// <param name="trigger">The trigger.</param>
		/// <param name="dependencies">The dependencies.</param>
		public void MakeAwareOf(IMessageTrigger trigger, IEnumerable<string> dependencies)
		{
			foreach (var dependency in dependencies)
			{
				var observer = GetSinglePathObserver(dependency);
				if (observer!= null)
					observer.RegisterTrigger(trigger);
			}
		}
		protected override void given_the_context_of()
		{
			_expectationsWasSet = false;

			var methodFactory = new DefaultMethodFactory();

			_handler = StrictMock<IRoutedMessageHandler>();
			_notifier = new TheNotifierClass();
			_observer = new DependencyObserver(_handler, methodFactory, _notifier);
			_trigger = Mock<IMessageTrigger>();
		}
Example #17
0
        /// <summary>
        /// Adds the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void AddTrigger(IMessageTrigger trigger)
        {
            if (_triggers == null)
            {
                _triggers = new List <IMessageTrigger>();
            }

            trigger.Attach(this);

            _triggers.Add(trigger);
        }
Example #18
0
 /// <summary>
 /// Makes the metadata aware of the relationship between an <see cref="IMessageTrigger"/> and its dependencies.
 /// </summary>
 /// <param name="trigger">The trigger.</param>
 /// <param name="dependencies">The dependencies.</param>
 public void MakeAwareOf(IMessageTrigger trigger, IEnumerable <string> dependencies)
 {
     foreach (var dependency in dependencies)
     {
         var observer = GetSinglePathObserver(dependency);
         if (observer != null)
         {
             observer.RegisterTrigger(trigger);
         }
     }
 }
Example #19
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.GetMetadata <AutoCheckAvailabilityHelper>();

            if (helper == null)
            {
                return;
            }

            helper.MakeAwareOf(trigger);
        }
        protected override void given_the_context_of()
        {
            expectationsWasSet = false;

            var methodFactory = new DefaultMethodFactory();

            handler  = StrictMock <IRoutedMessageHandler>();
            notifier = new TheNotifierClass();
            observer = new DependencyObserver(handler, methodFactory, notifier);
            trigger  = Mock <IMessageTrigger>();
        }
Example #21
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.GetMetadata <ItemDependencyObserver>();

            if (helper == null)
            {
                return;
            }

            if (trigger.Message.RelatesTo(_target))
            {
                helper.MakeAwareOf(trigger, _dependencies);
            }
        }
Example #22
0
 /// <summary>
 /// Attaches the trigger and prepares it to send actions.
 /// </summary>
 /// <param name="uiElement">The UI element.</param>
 /// <param name="trigger">The trigger.</param>
 public void AttachTrigger(DependencyObject uiElement, IMessageTrigger trigger)
 {
     if(trigger.Message is IRoutedMessageHandler)
     {
         var node = new InteractionNode(uiElement, this);
         node.RegisterHandler(trigger.Message as IRoutedMessageHandler);
         node.AddTrigger(trigger);
     }
     else
     {
         var node = FindOrAddNode(uiElement);
         node.AddTrigger(trigger);
     }
 }
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            var helper = messageHandler.Metadata.FirstOrDefaultOfType <DependencyObserver>();

            if (helper == null)
            {
                return;
            }

            if (trigger.Message.RelatesTo(target))
            {
                helper.MakeAwareOf(trigger, dependencies);
            }
        }
 /// <summary>
 /// Attaches the trigger and prepares it to send actions.
 /// </summary>
 /// <param name="uiElement">The UI element.</param>
 /// <param name="trigger">The trigger.</param>
 public void AttachTrigger(DependencyObject uiElement, IMessageTrigger trigger)
 {
     if (trigger.Message is IRoutedMessageHandler)
     {
         var node = new InteractionNode(uiElement, this);
         node.RegisterHandler(trigger.Message as IRoutedMessageHandler);
         node.AddTrigger(trigger);
     }
     else
     {
         var node = FindOrAddNode(uiElement);
         node.AddTrigger(trigger);
     }
 }
Example #25
0
        /// <summary>
        /// Adds the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void AddTrigger(IMessageTrigger trigger)
        {
            if (triggers == null)
            {
                triggers = new List <IMessageTrigger>();
            }

            trigger.Attach(this);
            triggers.Add(trigger);

            if (elementIsLoaded)
            {
                PrepareTrigger(trigger);
            }

            Log.Info("Trigger {0} attached.", trigger);
        }
Example #26
0
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            if (trigger.Message != this)
            {
                return;
            }

            CreateActionMessage();

            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, Source);

            trigger.UpdateAvailabilty(isAvailable);
            TryUpdateParentAvailability(isAvailable);

            action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));

            Log.Info("Made handler aware of filters for {0}.", Command);
        }
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if (actionMessage == null)
            {
                var ex = new CaliburnException("The handler cannot update availability for this trigger.");
                Log.Error(ex);
                throw ex;
            }

            Log.Info("Requesting update avaiability for {0}.", actionMessage);

            var  action      = FindActionHandler(actionMessage);
            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, node);

            trigger.UpdateAvailabilty(isAvailable);
        }
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            if (trigger.Message != this)
            {
                return;
            }

            CreateActionMessage();

            if (_action.HasTriggerEffects())
            {
                bool isAvailable = _action.ShouldTriggerBeAvailable(_actionMessage, Source);
                trigger.UpdateAvailabilty(isAvailable);
                TryUpdateParentAvailability(isAvailable);
            }

            _action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));
        }
Example #29
0
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            if (trigger.Message != this)
            {
                var ex = new CaliburnException("The handler cannot update availability for this trigger.");
                Log.Error(ex);
                throw ex;
            }

            if (Command != null)
            {
                CreateActionMessage();

                bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, Source);
                trigger.UpdateAvailabilty(isAvailable);
                TryUpdateParentAvailability(isAvailable);
            }
        }
Example #30
0
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if (actionMessage == null)
            {
                return;
            }

            var action = _host.GetAction(actionMessage);

            if (action.HasTriggerEffects())
            {
                bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, _node);
                trigger.UpdateAvailabilty(isAvailable);
            }

            action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));
        }
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            if (trigger.Message != this)
            {
                throw new CaliburnException("The handler cannot update availability for this trigger.");
            }

            if (Command != null)
            {
                CreateActionMessage();

                if (_action.HasTriggerEffects())
                {
                    bool isAvailable = _action.ShouldTriggerBeAvailable(_actionMessage, Source);
                    trigger.UpdateAvailabilty(isAvailable);
                    TryUpdateParentAvailability(isAvailable);
                }
            }
        }
Example #32
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            if (!AffectsTriggers || !IsGetter)
            {
                return;
            }

            var helper = messageHandler.GetMetadata <DependencyObserver>();

            if (helper == null)
            {
                return;
            }

            if (trigger.Message.RelatesTo(Target))
            {
                helper.MakeAwareOf(trigger, new[] { MethodName });
            }
        }
Example #33
0
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if (actionMessage == null)
            {
                throw new CaliburnException("The handler cannot update availability for this trigger.");
            }

            var action = _host.GetAction(actionMessage);

            if (!action.HasTriggerEffects())
            {
                return;
            }

            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, _node);

            trigger.UpdateAvailabilty(isAvailable);
        }
Example #34
0
        void PrepareTrigger(IMessageTrigger messageTrigger)
        {
            var handler = FindHandlerOrFail(messageTrigger.Message, false);

            if (handler != null)
            {
                handler.MakeAwareOf(messageTrigger);
            }

            if (!elementIsLoaded)
            {
                return;
            }

            var eventTrigger = messageTrigger as EventMessageTrigger;

            if (eventTrigger != null && eventTrigger.EventName == "Loaded")
            {
                ProcessMessage(eventTrigger.Message, new RoutedEventArgs());
            }
        }
Example #35
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            if (!AffectsTriggers || !trigger.Message.RelatesTo(Member))
            {
                return;
            }

            var depObserver = messageHandler.Metadata.FirstOrDefaultOfType <DependencyObserver>();

            if (IsGetter && depObserver != null)
            {
                depObserver.MakeAwareOf(trigger, new[] { MethodName });
            }

            var evtMonitor = messageHandler.Metadata.FirstOrDefaultOfType <EventMonitor>();

            if (evtMonitor != null)
            {
                evtMonitor.MakeAwareOf(trigger);
            }
        }
        /// <summary>
        /// Create engine
        /// </summary>
        /// <param name="messageTrigger"></param>
        /// <param name="encoder"></param>
        /// <param name="messageSink"></param>
        /// <param name="engineConfiguration"></param>
        /// <param name="logger"></param>
        /// <param name="identity"></param>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            _messageTrigger.OnMessage += MessageTriggerMessageReceived;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }
        }
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if (actionMessage == null)
            {
                return;
            }

            var  handler     = FindActionHandler(actionMessage);
            bool isAvailable = handler.ShouldTriggerBeAvailable(actionMessage, node);

            trigger.UpdateAvailabilty(isAvailable);

            Log.Info("Making handlers aware of {0}.", trigger);

            var action = handler as IAction;

            if (action != null)
            {
                action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));
            }
        }
Example #38
0
        /// <summary>
        /// Adds the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void AddTrigger(IMessageTrigger trigger)
        {
            if (_triggers == null)
                _triggers = new List<IMessageTrigger>();

            trigger.Attach(this);

            _triggers.Add(trigger);
        }
 internal void MakeAwareOf(IMessageTrigger trigger)
 {
     if(!_triggersToNotify.Contains(trigger))
         _triggersToNotify.Add(trigger);
 }
		public void RegisterTrigger(IMessageTrigger trigger)
		{
			if (!_triggersToNotify.Contains(trigger))
				_triggersToNotify.Add(trigger);
		}
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            if(trigger.Message != this) 
                return;
			
            CreateActionMessage();

            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, Source);
            trigger.UpdateAvailabilty(isAvailable);
            TryUpdateParentAvailability(isAvailable);

            action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));

            Log.Info("Made handler aware of filters for {0}.", Command);
        }
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if(actionMessage == null)
            {
                var ex = new CaliburnException("The handler cannot update availability for this trigger.");
                Log.Error(ex);
                throw ex;
            }
            
            Log.Info("Requesting update avaiability for {0}.", actionMessage);

            var action = FindActionHandler(actionMessage);
            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, _node);
            trigger.UpdateAvailabilty(isAvailable);
        }
Example #43
0
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            if(!_elementIsLoaded) 
                return;

            FindHandlerOrFail(trigger.Message, true).UpdateAvailability(trigger);
        }
			public void AddTrigger(IMessageTrigger trigger)
			{
				_triggers.Add(trigger);
			}
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            if (!AffectsTriggers || !trigger.Message.RelatesTo(Member))
                return;

            var depObserver = messageHandler.Metadata.FirstOrDefaultOfType<DependencyObserver>();
            if (IsGetter(_isInZoomMethod)  && depObserver != null)
                depObserver.MakeAwareOf(trigger, new[] { _isInZoomMethodName });
            if (IsGetter(_selectedItemsMethod) && depObserver != null)
                depObserver.MakeAwareOf(trigger, new[] { _selectedItemsMethodName });

            //var evtMonitor = messageHandler.Metadata.FirstOrDefaultOfType<EventMonitor>();
            //if (evtMonitor != null)
            //    evtMonitor.MakeAwareOf(trigger);
           
        }
Example #46
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            if (!AffectsTriggers)
                return;

            var helper = messageHandler.Metadata.FirstOrDefaultOfType<DependencyObserver>();
            if (helper == null) return;

            if (trigger.Message.RelatesTo(_target))

            {
                //helper.MakeAwareOf(trigger, new[] { _target.Name });
                var actionMessage = trigger.Message as ActionMessage;
                if (actionMessage == null) return;

                //var handler = helper.Host.FindActionHandler(actionMessage);
                bool isAvailable = Execute(actionMessage, trigger.Node,null);
                trigger.UpdateAvailabilty(isAvailable);
            }
        }
 public void AttachTrigger(DependencyObject uiElement, IMessageTrigger trigger)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Create engine
        /// </summary>
        public DataFlowProcessingEngine(IMessageTrigger messageTrigger, IMessageEncoder encoder,
                                        IMessageSink messageSink, IEngineConfiguration engineConfiguration, ILogger logger,
                                        IIdentity identity)
        {
            _config         = engineConfiguration;
            _messageTrigger = messageTrigger;
            _messageSink    = messageSink;
            _messageEncoder = encoder;
            _logger         = logger;
            _identity       = identity;

            if (_config.BatchSize.HasValue && _config.BatchSize.Value > 1)
            {
                _dataSetMessageBufferSize = _config.BatchSize.Value;
            }
            if (_config.MaxMessageSize.HasValue && _config.MaxMessageSize.Value > 0)
            {
                _maxEncodedMessageSize = _config.MaxMessageSize.Value;
            }

            _diagnosticInterval        = _config.DiagnosticsInterval.GetValueOrDefault(TimeSpan.Zero);
            _batchTriggerInterval      = _config.BatchTriggerInterval.GetValueOrDefault(TimeSpan.Zero);
            _diagnosticsOutputTimer    = new Timer(DiagnosticsOutputTimer_Elapsed);
            _batchTriggerIntervalTimer = new Timer(BatchTriggerIntervalTimer_Elapsed);
            _maxOutgressMessages       = _config.MaxOutgressMessages.GetValueOrDefault(4096); // = 1 GB

            _encodingBlock = new TransformManyBlock <DataSetMessageModel[], NetworkMessageModel>(
                async input => {
                try {
                    if (_dataSetMessageBufferSize == 1)
                    {
                        return(await _messageEncoder.EncodeAsync(input, _maxEncodedMessageSize).ConfigureAwait(false));
                    }
                    else
                    {
                        return(await _messageEncoder.EncodeBatchAsync(input, _maxEncodedMessageSize).ConfigureAwait(false));
                    }
                }
                catch (Exception e) {
                    _logger.Error(e, "Encoding failure");
                    return(Enumerable.Empty <NetworkMessageModel>());
                }
            },
                new ExecutionDataflowBlockOptions());

            _batchDataSetMessageBlock = new BatchBlock <DataSetMessageModel>(
                _dataSetMessageBufferSize,
                new GroupingDataflowBlockOptions());

            _batchNetworkMessageBlock = new BatchBlock <NetworkMessageModel>(
                _networkMessageBufferSize,
                new GroupingDataflowBlockOptions());

            _sinkBlock = new ActionBlock <NetworkMessageModel[]>(
                async input => {
                if (input != null && input.Any())
                {
                    _logger.Debug("Sink block in engine {Name} triggered with {count} messages",
                                  Name, input.Length);
                    await _messageSink.SendAsync(input).ConfigureAwait(false);
                }
                else
                {
                    _logger.Warning("Sink block in engine {Name} triggered with empty input",
                                    Name);
                }
            },
                new ExecutionDataflowBlockOptions());
            _batchDataSetMessageBlock.LinkTo(_encodingBlock);
            _encodingBlock.LinkTo(_batchNetworkMessageBlock);
            _batchNetworkMessageBlock.LinkTo(_sinkBlock);

            _messageTrigger.OnMessage      += MessageTriggerMessageReceived;
            _messageTrigger.OnCounterReset += MessageTriggerCounterResetReceived;

            if (_diagnosticInterval > TimeSpan.Zero)
            {
                _diagnosticsOutputTimer.Change(_diagnosticInterval, _diagnosticInterval);
            }
        }
Example #49
0
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;

            if (actionMessage == null)
                throw new CaliburnException("The handler cannot update availability for this trigger.");

            var action = _host.GetAction(actionMessage);
            if (!action.HasTriggerEffects()) return;

            bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, _node);
            trigger.UpdateAvailabilty(isAvailable);
        }
Example #50
0
        /// <summary>
        /// Makes the filter aware of the <see cref="IMessageTrigger"/>.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IRoutedMessageHandler messageHandler, IMessageTrigger trigger)
        {
            if (!AffectsTriggers || !IsGetter)
                return;

            var helper = messageHandler.GetMetadata<DependencyObserver>();
            if (helper == null) return;

            if (trigger.Message.RelatesTo(Target))
                helper.MakeAwareOf(trigger, new[] { MethodName });
        }
Example #51
0
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;
            if (actionMessage == null) return;

            var action = _host.GetAction(actionMessage);

            if (action.HasTriggerEffects())
            {
                bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, _node);
                trigger.UpdateAvailabilty(isAvailable);
            }

            action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));
        }
        /// <summary>
        /// Updates the availability of the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void UpdateAvailability(IMessageTrigger trigger)
        {
            if(trigger.Message != this)
            {
                var ex = new CaliburnException("The handler cannot update availability for this trigger.");
                Log.Error(ex);
                throw ex;
            }

			if (Command != null)
			{
				CreateActionMessage();

                bool isAvailable = action.ShouldTriggerBeAvailable(actionMessage, Source);
                trigger.UpdateAvailabilty(isAvailable);
                TryUpdateParentAvailability(isAvailable);
			}
        }
Example #53
0
        /// <summary>
        /// Adds the trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void AddTrigger(IMessageTrigger trigger)
        {
            if(_triggers == null)
                _triggers = new List<IMessageTrigger>();

            trigger.Attach(this);

            _triggers.Add(trigger);

            Log.Info("Trigger {0} attached.", trigger);
        }
        /// <summary>
        /// Makes the handler aware of a specific trigger.
        /// </summary>
        /// <param name="trigger">The trigger.</param>
        public void MakeAwareOf(IMessageTrigger trigger)
        {
            var actionMessage = trigger.Message as ActionMessage;
            if(actionMessage == null) return;

            var handler = FindActionHandler(actionMessage);
            bool isAvailable = handler.ShouldTriggerBeAvailable(actionMessage, _node);
            trigger.UpdateAvailabilty(isAvailable);

            Log.Info("Making handlers aware of {0}.", trigger);

            var action = handler as IAction;
            if(action != null)
                action.Filters.HandlerAware.Apply(x => x.MakeAwareOf(this, trigger));
        }