Exemplo n.º 1
0
        private static void TearDown(bool isTerminating, Exception ex)
        {
            var logger = _compositionRoot.Resolver.Resolve <ILoggerFactory>().CreateLogger(typeof(EntryPoint));

            if (isTerminating)
            {
                if (ex != null)
                {
                    logger.Error(ex, "*** FATAL ERROR!!! TERMINATING APPLICATION!!! ***");
                }
                else
                {
                    logger.Error("*** FATAL ERROR!!! TERMINATING APPLICATION!!! ***");
                }

                MessageBox.Show(
                    text: ex != null
                        ? $"Ocorreu um erro irrecuperável ({ex.Message}). O aplicativo será finalizado."
                        : $"Ocorreu um erro irrecuperável. O aplicativo será finalizado.",
                    caption: "Erro",
                    buttons: MessageBoxButtons.OK,
                    icon: MessageBoxIcon.Error);
            }

            try {
                _compositionRoot
                .Resolver
                .Resolve <CancellationTokenIssuer>()
                .CancelAll();
            } catch (Exception e) { logger.Error(e, e.Message); }

            _compositionRoot.TearDown();
            _compositionRoot = null;
        }
        private void Compose(ICompositionRoot compositionRoot)
        {
            var compositionRootAssembly = GetCompositionRoot(compositionRoot);
            var registrator             = _registratorProvider.Provide(compositionRootAssembly);

            compositionRoot.Compose(registrator);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Application has started..");

            var container = new WindsorContainer();

            container.Register(Component.For <ICompositionRoot>().ImplementedBy <CompositionRoot>());
            container.Register(Component.For <IConsoleWriter>().ImplementedBy <ConsoleWriter>());

            // This line is not a mistake.  Its intent is to contrast
            // registering a component as Transient vs. Singleton.
            //
            // The prior example registered this type as a singleton,
            // now we're registering this type as a Transient so the
            // output will show that new instances of ISingletonDemo are
            // created each time the dependency is fulfilled.
            container.Register(Component.For <ISingletonDemo>().ImplementedBy <SingletonDemo>().LifestyleTransient());

            ICompositionRoot composit = container.Resolve <ICompositionRoot>();

            composit.LogMessage("Hello Manik");

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;


            foreach (var gatewayControllerInfo in _gatewayControllerInfos)
            {
                _controllers.Add(new GateController(gatewayControllerInfo.Name));
            }

            Log.Log("SetCompositionRoot завершен, подсистема БУМИЗ была найдена, контроллеры подсистемы: ");
            foreach (var controller in _controllers)
            {
                Log.Log(controller.Name);
            }

            _scadaPollGatewayPart  = _compositionRoot.GetPartByName("PollGateWay");
            _scadaInteleconGateway = _scadaPollGatewayPart as IInteleconGateway;
            if (_scadaInteleconGateway == null)
            {
                throw new Exception("Не удалось найти PollGateWay через composition root");
            }
            _scadaPollGatewayPart.AddRef();
            _scadaInteleconGateway.RegisterSubSystem(this);
        }
Exemplo n.º 5
0
        public static ICompositionRoot EnableSveltoDebugWindow(this ICompositionRoot compositionRoot, EnginesRoot enginesRoot)
        {
            CompositionRoot = compositionRoot;
            EnginesRoot     = enginesRoot;

            return(compositionRoot);
        }
        private static Assembly GetCompositionRoot(ICompositionRoot compositionRoot)
        {
            var defaultCompositionRoot = compositionRoot as DefaultCompositionRoot;

            return(defaultCompositionRoot == null
                ? compositionRoot.GetType().Assembly
                : defaultCompositionRoot.TargetAssembly);
        }
        public WebHost(ICompositionRoot compositionRoot, IHttpRequestListener requestListener)
        {
            this.compositionRoot = compositionRoot ??
                                   throw new ArgumentNullException(nameof(compositionRoot));

            this.requestListener = requestListener ??
                                   throw new ArgumentNullException(nameof(requestListener));
        }
Exemplo n.º 8
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            _scadaPollGatewayPart  = _compositionRoot.GetPartByName("PollGateWay");
            _scadaInteleconGateway = _scadaPollGatewayPart as IInteleconGateway;
            if (_scadaInteleconGateway == null)
            {
                throw new Exception("Не удалось найти PollGateWay через composition root");
            }
            _scadaPollGatewayPart.AddRef();

            _bumizIoManagerPart = _compositionRoot.GetPartByName("BumizIoSubSystem");
            _bumizIoManager     = _bumizIoManagerPart as IBumizIoManager;
            if (_bumizIoManager == null)
            {
                throw new Exception("Не удалось найти BumizIoSubSystem через composition root");
            }
            _bumizIoManagerPart.AddRef();

            _pulseCountersDataStoragePart = _compositionRoot.GetPartByName("BumizEvenSubSystem.PulseCounter");
            _pulseCountersDataStorage     = _pulseCountersDataStoragePart as IPulseCounterDataStorageHolder;
            if (_pulseCountersDataStorage == null)
            {
                throw new Exception("Не удалось найти держатель хранилища импульсных счетчиков через composition root");
            }
            _pulseCountersDataStoragePart.AddRef();

            _attachedControllersInfoSystemPart = _compositionRoot.GetPartByName("GatewayAttachedControllers");
            _attachedControllersInfoSystem     = _attachedControllersInfoSystemPart as IAttachedControllersInfoSystem;
            if (_attachedControllersInfoSystem == null)
            {
                throw new Exception("Не удалось найти GatewayAttachedControllers через composition root");
            }
            _attachedControllersInfoSystemPart.AddRef();

            _gatewayControllesManagerPart = _compositionRoot.GetPartByName("GatewayControllers");
            _gatewayControllesManager     = _gatewayControllesManagerPart as IGatewayControllerInfosSystem;
            if (_gatewayControllesManager == null)
            {
                throw new Exception("Не удалось найти GatewayControllers через composition root");
            }
            _gatewayControllesManagerPart.AddRef();

            foreach (var bumizControllerInfo in _bumizControllerInfos)
            {
                if (_bumizIoManager.BumizObjectExist(bumizControllerInfo.Name))
                {
                    _bumizControllers.Add(new BumizController(_bumizIoManager, _pulseCountersDataStorage, bumizControllerInfo));
                }
                else
                {
                    Log.Log("Не удалось найти информацию о связи по сети БУМИЗ для контроллера: " + bumizControllerInfo.Name);
                }
            }

            Log.Log("Подсистема подключаемых контроллеров БУМИЗ инициализирована, число контроллеров: " + _bumizControllers.Count);
        }
Exemplo n.º 9
0
        public AppTestContext(ICompositionRoot root)
        {
            this.root                 = root;
            this.appContext           = root.CreateContext();
            this.configurationManager = appContext.Resolve <IConfigurationManager>();
            this.cs = configurationManager.GetValue("csSqlDataStore");
            var dsProvider = appContext.Resolve <IDataStoreProvider>();

            this.dataStore = dsProvider.GetDataStore <ISqlDataStore>(cs);
        }
Exemplo n.º 10
0
        public App(ICompositionRoot platformCompositionRoot)
        {
            InitializeComponent();

            Container = new ServiceContainer(new ContainerOptions {
                EnablePropertyInjection = false
            });
            Container.RegisterFrom <CompositionRoot>();
            Container.RegisterFrom(platformCompositionRoot);
            MainPage = new NavigationPage(Container.GetInstance <MainPage>());
        }
Exemplo n.º 11
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            _scadaPollGatewayPart  = _compositionRoot.GetPartByName("PollGateWay");
            _scadaInteleconGateway = _scadaPollGatewayPart as IInteleconGateway;
            if (_scadaInteleconGateway == null)
            {
                throw new Exception("Не удалось найти PollGateWay через composition root");
            }
            _scadaPollGatewayPart.AddRef();
        }
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            _bumizIoManagerPart = _compositionRoot.GetPartByName("BumizIoSubSystem");
            _bumizIoManager     = _bumizIoManagerPart as IBumizIoManager;
            if (_bumizIoManager == null)
            {
                throw new Exception("Не удалось найти BumizIoSubSystem через composition root");
            }
            _bumizIoManagerPart.AddRef();

            foreach (var pulseCounterInfo in _counterInfos)
            {
                try {
                    if (_bumizIoManager.BumizObjectExist(pulseCounterInfo.Key))
                    {
                        _availableInfos.Add(pulseCounterInfo.Value);
                    }
                    else
                    {
                        Log.Log("Не удалось найти информацию о связи по каналу БУМИЗ с объектом " + pulseCounterInfo.Key);
                    }
                }
                catch (Exception ex) {
                    Log.Log("Не удалось связать информацию по импульсному счётчику " + pulseCounterInfo.Key + " с информацией о его сетевом расположении внутри сети БУМИЗ по причине:" + ex);
                }
            }

            // Поток обмена активируется при подключении родительской системы
            if (_counterInfos.Count > 0)
            {
                if (_bumizArchivePollThread.ThreadState == ThreadState.Unstarted)
                {
                    _bumizArchivePollThread.Start();
                }
                else
                {
                    Log.Log("Странно, поток подсистемы чтения архивных данных уже был запущен!");
                }
            }
            else
            {
                Log.Log("Подсистема не будет запущена, т.к. число контроллеров в конфигурации = 0");
            }
        }
Exemplo n.º 13
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            _bumizIoManagerPart = _compositionRoot.GetPartByName("BumizIoSubSystem");
            _bumizIoManager     = _bumizIoManagerPart as IBumizIoManager;
            if (_bumizIoManager == null)
            {
                throw new Exception("Не удалось найти BumizIoSubSystem через composition root");
            }
            _bumizIoManagerPart.AddRef();

            foreach (var objSyncInfo in _objectsToSync)
            {
                try {
                    if (_bumizIoManager.BumizObjectExist(objSyncInfo))
                    {
                        _bumizNames.Add(objSyncInfo);
                    }
                    else
                    {
                        Log.Log("Не удалось связать информацию по объекту " + objSyncInfo + " с информацией о его сетевом расположении внутри сети БУМИЗ, видимо конфигурация сетевого расположения отсутствует");
                    }
                }
                catch (Exception ex) {
                    Log.Log("Не удалось связать информацию по объекту " + objSyncInfo + " с информацией о его сетевом расположении внутри сети БУМИЗ по причине:" + ex);
                }
            }

            if (_bumizNames.Count > 0)
            {
                if (_bumizTimeSyncThread.ThreadState == ThreadState.Unstarted)
                {
                    _bumizTimeSyncThread.Start();
                }
                else
                {
                    Log.Log("Странно, поток подсистемы синхронизации времени БУМИЗов уже запущен");
                }
            }
            else
            {
                Log.Log("Подсистема не будет запущена, т.к. число объектов конфигурации = 0");
            }
        }
Exemplo n.º 14
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            if (_microPacketSendThread.ThreadState == ThreadState.Unstarted)
            {
                foreach (var scadaObjectInfo in _scadaObjects)
                {
                    foreach (var scadaAddress in scadaObjectInfo.Value.ScadaAddresses)
                    {
                        // TODO: strategy selection:
                        // TODO: Add to XML configuration
                        // TODO: strategy: if working then drop
                        // TODO:    or   : if working then enqueue [ USING this strategy NOW ]
                        _perScadaAddressWorkers.Add(scadaAddress, new SingleThreadedRelayQueueWorkerProceedAllItemsBeforeStopNoLog <Action>(scadaAddress.ToString(), a =>
                        {
                            Log.Log("Executing in object's " + scadaAddress.ToString() + " thread action");
                            try
                            {
                                a();
                            }
                            catch (Exception exception)
                            {
                                Log.Log(exception);
                            }
                        }, ThreadPriority.BelowNormal, true, null));
                        //_perScadaAddressSendMicroPacketsSyncObjs.Add(scadaAddress, new object());
                    }
                }

                foreach (var scadaClient in _scadaClients)
                {
                    scadaClient.Value.DataReceived += OnScadaLinkDataReceived;
                }

                _microPacketSendThread.Start();
                Log.Log("PollGateway.SetCompositionRoot is complete OK");
            }
            else
            {
                Log.Log("PollGateway.SetCompositionRoot something strange, micro-packets send thread was already started! [ER]");
            }
        }
Exemplo n.º 15
0
        private static void ConfigureCompositionRoot()
        {
            var supportAssemblies = new[] {
                Assembly.Load("InfoFenix.Bootstrap"),
                Assembly.Load("InfoFenix.Configuration"),
                Assembly.Load("InfoFenix.CQRS"),
                Assembly.Load("InfoFenix.Data"),
                Assembly.Load("InfoFenix.Domains"),
                Assembly.Load("InfoFenix.IoC"),
                Assembly.Load("InfoFenix.Logging"),
                Assembly.Load("InfoFenix.Migrations"),
                Assembly.Load("InfoFenix.Office"),
                Assembly.Load("InfoFenix.PubSub"),
                Assembly.Load("InfoFenix.Search"),
                Assembly.Load("InfoFenix.Services"),
                typeof(EntryPoint).Assembly
            };
            var defaultServiceRegistrations = new IServiceRegistration[] {
                new ClientServiceRegistration(supportAssemblies),
                new BootstrapServiceRegistration(supportAssemblies),
                new DataServiceRegistration(),
                new CQRSServiceRegistration(supportAssemblies),
                new PubSubServiceRegistration(),
                new SearchServiceRegistration(),
                new LoggingServiceRegistration(),
                new ServicesServiceRegistration()
            };
            var useRemoteSearchDatabaseServiceRegistrations = new IServiceRegistration[] {
                new NullWordDocumentServiceRegistration()
            };
            var autonomousModeServiceRegistrations = new IServiceRegistration[] {
                new WordDocumentServiceRegistration()
            };

            _compositionRoot = new CompositionRoot();
            _compositionRoot.Compose(defaultServiceRegistrations);
            _compositionRoot.Compose(AppSettings.Instance.UseRemoteSearchDatabase ? useRemoteSearchDatabaseServiceRegistrations : autonomousModeServiceRegistrations);
            _compositionRoot.StartUp();
        }
Exemplo n.º 16
0
 public abstract void SetCompositionRoot(ICompositionRoot root);
 public CompositionRootRegisterer Registerer(ICompositionRoot compositionRoot)
 {
     compositionRoot.Register(_serviceCollection, _configuration);
     return(this);
 }
Exemplo n.º 18
0
 public HttpRequestHandler(IRouter router, IModelBinder modelBinder, ICompositionRoot compositionRoot)
 {
     this.router          = router;
     this.modelBinder     = modelBinder;
     this.compositionRoot = compositionRoot;
 }
Exemplo n.º 19
0
 public UserConsumer(ICompositionRoot compositionRoot, IMapper mapper, ILogger <UserConsumer> logger)
 {
     _userService = compositionRoot.GetImplementation <IUserService>();
     _mapper      = mapper;
     _logger      = logger;
 }
Exemplo n.º 20
0
        public CompositorThread(ICompositionRoot activity)
        {
            _activity = activity;

            _activity.Window !.TakeSurface(this);
        }
 public DefaultDocumentGeneratorFactory(ICompositionRoot compositionRoot)
 {
     _compositionRoot = compositionRoot ?? throw new ArgumentNullException(nameof(compositionRoot));
 }
Exemplo n.º 22
0
 public SelfHost(ICompositionRoot root, ILogService log)
 {
     RegisterControllers(root.GetAll <IController>());
     _log = log;
 }
Exemplo n.º 23
0
 public static void Start(ICompositionRoot activity)
 => _current ??= new CompositorThread(activity);
Exemplo n.º 24
0
        public override void SetCompositionRoot(ICompositionRoot root)
        {
            _compositionRoot = root;

            _attachedControllersInfoSystemPart = _compositionRoot.GetPartByName("GatewayAttachedControllers");
            _attachedControllersInfoSystem     = _attachedControllersInfoSystemPart as IAttachedControllersInfoSystem;
            if (_attachedControllersInfoSystem == null)
            {
                throw new Exception("Не удалось найти GatewayAttachedControllers через composition root");
            }
            _attachedControllersInfoSystemPart.AddRef();

            _gatewayControllesManagerPart = _compositionRoot.GetPartByName("GatewayControllers");
            _gatewayControllesManager     = _gatewayControllesManagerPart as IGatewayControllerInfosSystem;
            if (_gatewayControllesManager == null)
            {
                throw new Exception("Не удалось найти GatewayControllers через composition root");
            }
            _gatewayControllesManagerPart.AddRef();


            _scadaPollGatewayPart  = _compositionRoot.GetPartByName("PollGateWay");
            _scadaInteleconGateway = _scadaPollGatewayPart as IInteleconGateway;
            if (_scadaInteleconGateway == null)
            {
                throw new Exception("Не удалось найти PollGateWay через composition root");
            }
            _scadaPollGatewayPart.AddRef();
            _scadaInteleconGateway.RegisterSubSystem(this);


            var commandManager = new InteleconCommandManager <string, IInteleconCommand>(new List <ICommandReplyArbiter <IInteleconCommand> > {
                new CommandReplyArbiterAttached()
            }, true);

            _commandManagerSystemSide = commandManager;
            _commandManagerSystemSide.ReplyWithoutRequestWasAccepted += CommandManagerSystemSideOnReplyWithoutRequestWasAccepted;

            Log.Log("Background worker Inited OK");

            _loraControllerInfos = XmlFactory.GetObjectsConfigurationsFromXml(Path.Combine(Env.CfgPath, "LoraControllerInfos.xml"));
            _mqttTopicStart      = "application/1/node/";
            _loraControllers     = new List <LoraControllerFullInfo>();
            // need to create full info about controllers:
            Log.Log("Creating full information for each lora controller...");
            foreach (var loraControllerInfo in _loraControllerInfos)
            {
                Log.Log("Lora object: " + loraControllerInfo.Name + ":");
                var rxTopicName = _mqttTopicStart + loraControllerInfo.DeviceId + "/rx";
                var txTopicName = _mqttTopicStart + loraControllerInfo.DeviceId + "/tx";
                var attachedControllerConfig = _attachedControllersInfoSystem.GetAttachedControllerConfigByName(loraControllerInfo.Name);

                var fullLoraConfig = new LoraControllerFullInfo(loraControllerInfo, rxTopicName, txTopicName, attachedControllerConfig);
                _loraControllers.Add(fullLoraConfig);
                Log.Log(fullLoraConfig);
            }

            if (_loraControllers.Count > 0)
            {
                Log.Log("Starting MQTT driver...");
                _mqttDriver = new MqttDriver(_mqttBrokerHost, _mqttBrokerPort, _loraControllers, commandManager);
                Log.Log("MQTT driver has been started");
            }

            Log.Log("Lora controllers subsystem was loaded! Built _loraControllers count = " + _loraControllers.Count);
        }
Exemplo n.º 25
0
 public BookController(IBus bus, ICompositionRoot compositionRoot, ILogger <BookController> logger)
 {
     _bus         = bus;
     _bookService = compositionRoot.GetImplementation <IBookService>();
     _logger      = logger;
 }
Exemplo n.º 26
0
 /// <inheritdoc />
 public IStashboxContainer ComposeBy(ICompositionRoot compositionRoot)
 {
     this.ThrowIfDisposed();
     compositionRoot.Compose(this);
     return(this);
 }
 /// <inheritdoc />
 public IStashboxContainer ComposeBy(ICompositionRoot compositionRoot)
 {
     compositionRoot.Compose(this);
     return(this);
 }
 public void SetCompositionRoot(ICompositionRoot root)
 {
     _relayPart.SetCompositionRoot(root);
 }
Exemplo n.º 29
0
 public override void SetCompositionRoot(ICompositionRoot root)
 {
     // Get all needed c.parts with adding refs to them
 }
Exemplo n.º 30
0
 public UserController(IBus bus, ICompositionRoot compositionRoot, ILogger <UserController> logger)
 {
     _bus         = bus;
     _userService = compositionRoot.GetImplementation <IUserService>();
     _logger      = logger;
 }