Пример #1
0
        private string GetSecurityToken(VrtuConfig vconfig)
        {
            List <Claim> claimset = new List <Claim>();

            claimset.Add(new Claim($"http://{vconfig.Hostname}/name", vconfig.VirtualRtuId.ToLowerInvariant()));
            return(CreateJwt($"http://{vconfig.Hostname.ToLowerInvariant()}/", $"http://{vconfig.Hostname.ToLowerInvariant()}/", claimset, vconfig.SymmetricKey, vconfig.LifetimeMinutes.Value));
        }
Пример #2
0
        public static ILoggingBuilder AddLogging(this ILoggingBuilder builder, VrtuConfig config)
        {
            LogLevel logLevel = config.LoggingLevel;

            builder.AddConsole();
            builder.SetMinimumLevel(logLevel);

            return(builder);
        }
Пример #3
0
        public ScadaClientAdapter(VrtuConfig config, IChannel channel, ILogger logger)
        {
            Id = Guid.NewGuid().ToString();

            this.config  = config;
            this.channel = channel;
            this.logger  = logger;
            subscribed   = new HashSet <byte>();
            mapper       = new MbapMapper("vrtu");
            OpenWebSocketAsync().GetAwaiter();
        }
Пример #4
0
 public VirtualRtuPipeline(VrtuConfig config, IChannel input, IChannel output, List <IFilter> inputFiters, List <IFilter> outputFilters, ILogger logger = null)
 {
     Id            = Guid.NewGuid().ToString();
     this.config   = config;
     this.logger   = logger;
     InputChannel  = input;
     OutputChannel = output;
     InputFilters  = inputFiters;
     OutputFilters = outputFilters;
     map           = RtuMap.LoadAsync(config.StorageConnectionString, config.Container, config.Filename).GetAwaiter().GetResult();
 }
Пример #5
0
        //public static IServiceCollection AddModuleConfiguration(this IServiceCollection services, out ModuleConfig config)
        //{
        //    IConfigurationBuilder builder = new ConfigurationBuilder();
        //    builder.AddJsonFile("./secrets.json")
        //        .AddEnvironmentVariables("MC_");
        //    IConfigurationRoot root = builder.Build();
        //    config = new ModuleConfig();
        //    ConfigurationBinder.Bind(root, config);
        //    services.AddSingleton<ModuleConfig>(config);

        //    return services;
        //}

        public static IServiceCollection AddModuleConfiguration(this IServiceCollection services, out VrtuConfig config)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("./secrets.json")
            .AddEnvironmentVariables("VRTU_");
            IConfigurationRoot root = builder.Build();

            config = new VrtuConfig();
            root.Bind(config);
            services.AddSingleton(config);

            return(services);
        }
Пример #6
0
        public VirtualRtuChannel(VrtuConfig config, ILogger logger = null)
        {
            this.config = config;
            map         = RtuMap.LoadAsync(config.StorageConnectionString, config.Container, config.Filename).GetAwaiter().GetResult();

            this.logger      = logger;
            subscriptions    = new HashSet <byte>();
            name             = Guid.NewGuid().ToString();
            cache            = new LocalCache(name);
            cache.OnExpired += Cache_OnExpired;

            securityToken = GetSecurityToken(config);
            endpointUrl   = new Uri($"wss://{config.Hostname}/ws/api/connect");
        }
Пример #7
0
 public DiagnosticsConnection(VrtuConfig config, PiraeusMqttClient mqttClient, ILogger logger = null)
 {
     this.name           = config.VirtualRtuId;
     this.mqttClient     = mqttClient;
     this.logger         = logger;
     this.cache          = new LocalCache("vrtudiag");
     this.inputPiSystem  = UriGenerator.GetVirtualRtuDiagnosticsPiSystem(config.Hostname, config.VirtualRtuId);
     this.outputPiSystem = UriGenerator.GetVirtualRtuTelemetryPiSystem(config.Hostname, config.VirtualRtuId);
     if (!string.IsNullOrEmpty(config.InstrumentationKey))
     {
         tconfig = new TelemetryConfiguration(config.InstrumentationKey);
         tconfig.DisableTelemetry = true;
         tclient = new TelemetryClient(tconfig);
     }
 }
Пример #8
0
 public static Pipeline Create(VrtuConfig config, IChannel input, IChannel output, List <IFilter> inputFiters,
                               List <IFilter> outputFilters, ILogger logger = null)
 {
     return(new VirtualRtuPipeline(config, input, output, inputFiters, outputFilters, logger));
 }
Пример #9
0
 public VirtualRtuService(VrtuConfig config, Logger logger = null)
 {
     this.config = config;
     this.logger = logger;
 }
Пример #10
0
 public ScadaClientListener(VrtuConfig config, ILogger logger = null)
 {
     this.config = config;
     this.logger = logger;
     pipelines   = new Dictionary <string, Pipeline>();
 }
Пример #11
0
 public WebSocketConnection(VrtuConfig config, ILogger logger = null)
 {
     hostname      = config.Hostname;
     securityToken = GetSecurityToken(config);
     this.logger   = logger;
 }