Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 2
0
        private void RunMainView()
        {
            var mainView = ServiceLocationContainer.Resolve <IMainView>();

            mainView.Loaded += mainViewLoaded;
            mainView.Closed += mainViewClosed;
            mainView.Run();
        }
Ejemplo n.º 3
0
 protected override void CheckMainServicesExists()
 {
     base.CheckMainServicesExists();
     if (!ServiceLocationContainer.CanResolve <IMainView>())
     {
         throw new ServiceNotFoundException(typeof(IMainView).Name);
     }
 }
Ejemplo n.º 4
0
 private void mainViewLoaded(object sender, EventArgs e)
 {
     if (ServiceLocationContainer.CanResolve <ISplashScreen>())
     {
         ServiceLocationContainer.Resolve <ISplashScreen>().Close();
     }
     uiWaitHandle.Set();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Обработка поведений при завершении
        /// </summary>
        private void OnApplicationStop()
        {
            var appBehaviors = ServiceLocationContainer.ResolveAbsolutelyAll <IApplicationBehavior>();

            if (appBehaviors != null)
            {
                appBehaviors.ForEach(behavior => behavior.OnStop());
            }
        }
Ejemplo n.º 6
0
 protected override void ExecuteAction(IAction action, ActionExecutionContext context)
 {
     if (action is IUiAction)
     {
         var syncContext = ServiceLocationContainer.Resolve <ISynchronizationContextManager>();
         syncContext.Execute(action, context);
     }
     else
     {
         action.Execute(context);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Прекращает работу служб получения сообщений
        /// </summary>
        private void StopListenMessageReceivers()
        {
            var messageReceivers = ServiceLocationContainer.ResolveAbsolutelyAll <IAsyncMessageReceiverService>();

            if (messageReceivers != null)
            {
                foreach (var messageReceiver in messageReceivers)
                {
                    messageReceiver.Close();
                    messageReceiver.MessageReceived -= OnMessageReceived;
                }
            }
        }
Ejemplo n.º 8
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();
                }
            }
        }
Ejemplo n.º 9
0
        private void StartUI()
        {
            if (ServiceLocationContainer.CanResolve <ISplashScreen>())
            {
                ServiceLocationContainer.Resolve <ISplashScreen>().Show();
            }

            if (ServiceLocationContainer.CanResolve <IUiApplicationBehavior>())
            {
                ServiceLocationContainer.Resolve <IUiApplicationBehavior>()
                .Initialize();
            }

            CheckApplicationResources();
            RunMainView();
        }
Ejemplo n.º 10
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();
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Конфигурирует контейнер службами по умолчанию
        /// </summary>
        protected virtual void ConfigureContainerForDefaultServices()
        {
            //serviceLocationContainer = serviceContainer.CreateChildContainer();
            //ServiceLocationContainer.AddNewExtension<TypeTrackingExtension>();
            var unityLocator = new UnityServiceLocator(ServiceLocationContainer);

            ServiceLocationContainer.RegisterInstance <IServiceLocator>(unityLocator,
                                                                        new ContainerControlledLifetimeManager());
            ServiceLocationContainer.RegisterInstance <IParentContainer>(unityLocator,
                                                                         new ContainerControlledLifetimeManager());

            var exceptionService = new ExceptionReceiverService();

            ServiceLocationContainer.RegisterInstance <IExceptionHandlerService>(exceptionService,
                                                                                 new ContainerControlledLifetimeManager());
            ServiceLocationContainer.RegisterInstance <IAsyncMessageReceiverService>(
                "ExceptionReceiver", exceptionService,
                new ContainerControlledLifetimeManager());
        }