Ejemplo n.º 1
0
        public static void AddAutomaticaCoreService(this IServiceCollection services, IConfiguration configuration, bool isElectronActive)
        {
            services.AddAutomaticaDrivers();
            services.AddDispatcher();

            services.AddSingleton <ILocalizationProvider>(new LocalizationProvider(SystemLogger.Instance));

            services.AddSingleton <IVisualisationFactory, VisuTempInit>();
            services.AddSingleton <ITelegramMonitor, TelegramMonitor>();
            services.AddSingleton <IServerCloudApi, CloudApi>();
            services.AddSingleton <ICloudApi, CloudApi>();
            services.AddSingleton <ILicenseContext, AllowAllLicenseContext>();
            services.AddSingleton <ILicenseContract>(provider => provider.GetService <ILicenseContext>());
            services.AddSingleton <ILearnMode, LearnMode>();
            services.AddAutomaticaPushServices(configuration, isElectronActive);

            services.AddSingleton <IPluginInstaller, PluginInstaller>();

            if (!isElectronActive)
            {
                services.AddSingleton <IDriverNodesStoreInternal, DriverNodesStoreInternal>();
                services.AddSingleton <INodeInstanceStore, NodeInstanceStore>();
                services.AddSingleton <ILogicInstancesStore, LogicInstanceStore>();

                services.AddSingleton <LogicStore, LogicStore>();
                services.AddSingleton <ILogicStore>(a => a.GetService <LogicStore>());
                services.AddSingleton <IRuleDataHandler>(a => a.GetService <LogicStore>());

                services.AddSingleton <LoadedNodeInstancesStore, LoadedNodeInstancesStore>();
                services.AddSingleton <INodeInstanceStateHandler>(a => a.GetService <LoadedNodeInstancesStore>());
                services.AddSingleton <ILoadedNodeInstancesStore>(a => a.GetService <LoadedNodeInstancesStore>());

                services.AddSingleton <NativeUpdateHandler, NativeUpdateHandler>();
                services.AddSingleton <IUpdateHandler>(a => a.GetService <NativeUpdateHandler>());
                services.AddSingleton <IAutoUpdateHandler>(a => a.GetService <NativeUpdateHandler>());

                services.AddSingleton <ILoadedStore, LoadedStore>();
                services.AddSingleton <ILogicFactoryStore, LogicFactoryStore>();
                services.AddSingleton <IDriverFactoryStore, DriverFactoryStore>();

                services.AddSingleton <IDriverLoader, DriverLoader>();
                services.AddSingleton <ILogicLoader, LogicLoader>();

                services.AddSingleton <MqttService, MqttService>();
                services.AddSingleton <IRemoteHandler>(provider => provider.GetService <MqttService>());
                services.AddSingleton <IRemoteServerHandler>(provider => provider.GetService <MqttService>());
                services.AddSingleton <IRemoteSender, MqttPublishService>();


                services.AddSingleton <PluginHandler, PluginHandler>();
                services.AddSingleton <IPluginHandler>(a => a.GetService <PluginHandler>());
                services.AddSingleton <IPluginLoader>(a => a.GetService <PluginHandler>());

                services.AddSingleton <IRuleInstanceVisuNotify, RuleInstanceVisuNotifier>();

                services.AddSingleton <CoreServer, CoreServer>();
                services.AddSingleton <IHostedService>(provider => provider.GetService <CoreServer>());
                services.AddSingleton <ICoreServer>(provider => provider.GetService <CoreServer>());

                services.AddSingleton <INotifyDriver, NotifyDriverHandler>();
                services.AddSingleton <IRuleEngineDispatcher, RuleEngineDispatcher>();

                services.AddSingleton <IDataBroadcast, DataBroadcastService>();

                services.AddSingleton <DatabaseTrendingValueStore, DatabaseTrendingValueStore>();
            }


            var mqttServerOptions = new MqttServerOptions()
            {
                ConnectionValidator = new MqttServerConnectionValidatorDelegate(a => MqttService.ValidateConnection(a, configuration, SystemLogger.Instance))
            };

            mqttServerOptions.DefaultEndpointOptions.BoundInterNetworkAddress   = IPAddress.Any;
            mqttServerOptions.DefaultEndpointOptions.BoundInterNetworkV6Address = IPAddress.None;
            mqttServerOptions.DefaultEndpointOptions.IsEnabled         = true;
            mqttServerOptions.DefaultEndpointOptions.Port              = 1883;
            mqttServerOptions.DefaultEndpointOptions.ConnectionBacklog = 1000;

            services.AddHostedMqttServer(mqttServerOptions);

            services.AddAutomaticaVisualization(configuration);
            services.AddInternals(configuration);
        }