/// <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(); } } }
private void RunMainView() { var mainView = ServiceLocationContainer.Resolve <IMainView>(); mainView.Loaded += mainViewLoaded; mainView.Closed += mainViewClosed; mainView.Run(); }
protected override void CheckMainServicesExists() { base.CheckMainServicesExists(); if (!ServiceLocationContainer.CanResolve <IMainView>()) { throw new ServiceNotFoundException(typeof(IMainView).Name); } }
private void mainViewLoaded(object sender, EventArgs e) { if (ServiceLocationContainer.CanResolve <ISplashScreen>()) { ServiceLocationContainer.Resolve <ISplashScreen>().Close(); } uiWaitHandle.Set(); }
/// <summary> /// Обработка поведений при завершении /// </summary> private void OnApplicationStop() { var appBehaviors = ServiceLocationContainer.ResolveAbsolutelyAll <IApplicationBehavior>(); if (appBehaviors != null) { appBehaviors.ForEach(behavior => behavior.OnStop()); } }
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); } }
/// <summary> /// Прекращает работу служб получения сообщений /// </summary> private void StopListenMessageReceivers() { var messageReceivers = ServiceLocationContainer.ResolveAbsolutelyAll <IAsyncMessageReceiverService>(); if (messageReceivers != null) { foreach (var messageReceiver in messageReceivers) { messageReceiver.Close(); messageReceiver.MessageReceived -= OnMessageReceived; } } }
/// <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(); } } }
private void StartUI() { if (ServiceLocationContainer.CanResolve <ISplashScreen>()) { ServiceLocationContainer.Resolve <ISplashScreen>().Show(); } if (ServiceLocationContainer.CanResolve <IUiApplicationBehavior>()) { ServiceLocationContainer.Resolve <IUiApplicationBehavior>() .Initialize(); } CheckApplicationResources(); RunMainView(); }
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(); } } }
/// <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()); }