Example #1
0
        /// <summary>
        /// Обрабатывает сообщение
        /// </summary>
        /// <param name="message">Сообщение</param>
        protected void ProcessMessage(Message message)
        {
            var actionExecutionContext = new ActionExecutionContext(this);

            var actionFactories = ServiceLocationContainer
                                  .ResolveAbsolutelyAll <IActionFactoryService>()
                                  .OrderByDescending(actf => Convert.ToInt32(actf.Priority));

            actionExecutionContext.Run();

            foreach (var actionFactory in actionFactories)
            {
                var action = actionFactory.Create(message);
                if (action == null)
                {
                    continue;
                }

                if (!AllowExecute(actionExecutionContext.State, action))
                {
                    continue;
                }

                try {
                    ExecuteAction(action, actionExecutionContext);
                }
                catch (Exception ex) {
                    OnErrorOccured(this, new ErrorEventArgs(ex));
                    actionExecutionContext.Fault();
                }
                finally {
                    GC.Collect();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Обработка поведений при завершении
        /// </summary>
        private void OnApplicationStop()
        {
            var appBehaviors = ServiceLocationContainer.ResolveAbsolutelyAll <IApplicationBehavior>();

            if (appBehaviors != null)
            {
                appBehaviors.ForEach(behavior => behavior.OnStop());
            }
        }
Example #3
0
        /// <summary>
        /// Прекращает работу служб получения сообщений
        /// </summary>
        private void StopListenMessageReceivers()
        {
            var messageReceivers = ServiceLocationContainer.ResolveAbsolutelyAll <IAsyncMessageReceiverService>();

            if (messageReceivers != null)
            {
                foreach (var messageReceiver in messageReceivers)
                {
                    messageReceiver.Close();
                    messageReceiver.MessageReceived -= OnMessageReceived;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Запускает службы получения сообщений
        /// </summary>
        protected void StartListenMessageReceivers()
        {
            var messageReceivers = ServiceLocationContainer
                                   .ResolveAbsolutelyAll <IAsyncMessageReceiverService>()
                                   .OrderByDescending(receiver => Convert.ToInt32(receiver.Priority));

            if (messageReceivers != null)
            {
                foreach (var messageReceiver in messageReceivers)
                {
                    messageReceiver.MessageReceived += OnMessageReceived;
                    messageReceiver.ErrorOccured    += OnErrorOccured;
                    messageReceiver.Open();
                }
            }
        }
Example #5
0
        protected virtual void CheckApplicationResources()
        {
            var resourceCheckers = ServiceLocationContainer.ResolveAbsolutelyAll <IApplicationResource>();

            foreach (var resource in resourceCheckers)
            {
                if (!resource.CheckAvailability())
                {
                    if (resource.HasUI && ServiceLocationContainer.CanResolve <ISplashScreen>())
                    {
                        ServiceLocationContainer.Resolve <ISplashScreen>().Close();
                    }
                    resource.MakeAvailable();
                }
            }
        }