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

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

            if (appBehaviors != null)
            {
                appBehaviors.ForEach(behavior => behavior.OnStop());
            }
        }
示例#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);
     }
 }
示例#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;
                }
            }
        }
示例#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();
                }
            }
        }
示例#9
0
        private void StartUI()
        {
            if (ServiceLocationContainer.CanResolve <ISplashScreen>())
            {
                ServiceLocationContainer.Resolve <ISplashScreen>().Show();
            }

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

            CheckApplicationResources();
            RunMainView();
        }
示例#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();
                }
            }
        }
示例#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());
        }