public IActionResult ManufacturerConnectForm(string deviceId)
        {
            try
            {
                var hanAdapter = new HanAdapterContainer(HanAdapterRepository.LoadAdapter(deviceId), deviceId);

                var manufacturerParametersView = hanAdapter.ManufacturerParametersView;
                if (manufacturerParametersView != null)
                {
                    this.ViewData["ManufacturerParametersViewName"] = manufacturerParametersView;
                    return(this.PartialView("_ManufacturerParametersFormPartial", deviceId));
                }
            }
            catch (UnknownManufacturerException ex)
            {
                return(this.NotFound($"Es wurde kein Smart Meter Gateway-Hersteller mit der ID \"{ex.FlagId}\" gefunden."));
            }
            catch (Exception)
            {
            }

            return(this.PartialView("_ManufacturerParametersFormEmptyPartial", deviceId));
        }
示例#2
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        public static void Main(string[] args)
        {
            var commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);
            var logFileOption          = commandLineApplication.Option("-l|--log <logfile>", "Datei in der Programmmeldungen protokolliert werden.", CommandOptionType.SingleValue);
            var logLevelOption         = commandLineApplication.Option("--loglevel <loglevel>", "Log Level: verbose, debug, info, warning, error, fatal. Standard ist info", CommandOptionType.SingleValue);
            var testFileOption         = commandLineApplication.Option("-t|--test <testconfig>", "Aktiviert den Test-HAN-Adapter mit der angegebenen Konfigurationsdatei.", CommandOptionType.SingleValue);

            commandLineApplication.HelpOption("-? | -h | --help");
            commandLineApplication.Execute(args);

            var logLevelSwitch = new LoggingLevelSwitch {
                MinimumLevel = LogEventLevel.Information
            };

            if (logLevelOption.HasValue())
            {
                switch (logLevelOption.Value().ToLowerInvariant())
                {
                case "verbose":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Verbose;
                    break;

                case "debug":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Debug;
                    break;

                case "info":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Information;
                    break;

                case "warning":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Warning;
                    break;

                case "error":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Error;
                    break;

                case "fatal":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Fatal;
                    break;
                }
            }

            if (logFileOption.HasValue())
            {
                Console.WriteLine("Using log file: {0}", logFileOption.Value());

                Log.Logger = new LoggerConfiguration()
                             .MinimumLevel.ControlledBy(logLevelSwitch)
#if DEBUG
                             .WriteTo.Trace()
#endif
                             .WriteTo.ColoredConsole()
                             .WriteTo.File(logFileOption.Value())
                             .CreateLogger();
            }
            else
            {
                Log.Logger = new LoggerConfiguration()
                             .MinimumLevel.ControlledBy(logLevelSwitch)
#if DEBUG
                             .WriteTo.Trace()
#endif
                             .WriteTo.ColoredConsole()
                             .CreateLogger();
            }

            Log.Information(
                "Starting TRuDI {0} on {1}",
                Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion,
                System.Runtime.InteropServices.RuntimeInformation.OSDescription);

            if (testFileOption.HasValue())
            {
                // Check for a configuration file/directory used by the example/simulation HAN adapter
                var testConfigFile = testFileOption.Value();
                if (!string.IsNullOrWhiteSpace(testConfigFile) &&
                    (File.Exists(testConfigFile) || Directory.Exists(testConfigFile)))
                {
                    Log.Information("Using test configuration file: {0}", testConfigFile);

                    CommandLineArguments.TestConfiguration = testConfigFile;
                    HanAdapterRepository.ActivateExampleHanAdapter();
                }
                else
                {
                    Log.Warning("Configuration file not found: {0}", testConfigFile);
                }
            }

            var cultureInfo = new CultureInfo("de-DE");
            CultureInfo.DefaultThreadCurrentCulture = cultureInfo;

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var webhost = BuildWebHost();

            var doneEvent = new ManualResetEventSlim(false);
            using (var cts = new CancellationTokenSource())
            {
                Log.Information("Using backend port: {0}", backendServerPort);

                AttachCtrlcSigtermShutdown(cts, doneEvent);

                try
                {
                    webhost.Start();
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to start backend: {0}", ex.Message);
                    Console.WriteLine($"##### TRUDI-BACKEND-ERROR: {ex.Message} #####");
                    doneEvent.Set();
                    return;
                }

                // If the webhost is listening on the port: send it to the Electron frontend
                Console.WriteLine($"##### TRUDI-BACKEND-PORT: {backendServerPort} #####");

                cts.Token.WaitHandle.WaitOne();
                doneEvent.Set();
            }
        }
        public void VerifyParameters()
        {
            if (this.pkcs12file.HasValue())
            {
                if (File.Exists(this.pkcs12file.Value()))
                {
                    this.ClientCert = File.ReadAllBytes(this.pkcs12file.Value());

                    if (this.password.HasValue())
                    {
                        this.Password = this.password.Value();
                    }
                }
                else
                {
                    throw new Exception($"Specified PKCS#12 file wasn't found: {this.pkcs12file.Value()}");
                }
            }
            else
            {
                if (!this.username.HasValue() || !this.password.HasValue())
                {
                    throw new Exception("No username/password or client certificate was specified.");
                }

                this.Username = this.username.Value();
                this.Password = this.password.Value();
            }

            if (!this.serverId.HasValue())
            {
                throw new Exception("No device ID was specified.");
            }

            var id = new ServerId(this.serverId.Value());

            if (!id.IsValid || id.Medium != ObisMedium.Communication)
            {
                throw new Exception($"Invalid device id: {this.serverId.Value()}");
            }

            this.ServerId = this.serverId.Value();

            if (!this.address.HasValue())
            {
                throw new Exception("No IP address was specified.");
            }

            if (!IPAddress.TryParse(this.address.Value(), out var ip))
            {
                throw new Exception($"Invalid IP address: {this.address.Value()}");
            }

            if (!this.port.HasValue())
            {
                throw new Exception("No port was specified.");
            }

            if (!ushort.TryParse(this.port.Value(), out var p))
            {
                throw new Exception($"Invalid port: {this.port.Value()}");
            }

            this.IpEndpoint = new IPEndPoint(ip, p);

            if (this.timeout.HasValue())
            {
                if (!uint.TryParse(this.timeout.Value(), out var t))
                {
                    throw new Exception($"Invalid timeout: {this.timeout.Value()}");
                }

                this.Timeout = t;
            }

            try
            {
                var hanAdapterInfo = HanAdapterRepository.LoadAdapter(this.ServerId);
                this.HanAdapter = hanAdapterInfo.CreateInstance();
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to load the HAN adapter: {ex.Message}", ex);
            }
        }
示例#4
0
 /// <summary>
 /// Loads the HAN adapter for the specified server ID.
 /// </summary>
 /// <param name="serverId">The server identifier to load the HAN adapter for.</param>
 public void LoadAdapter(string serverId)
 {
     this.activeHanAdapter = new HanAdapterContainer(HanAdapterRepository.LoadAdapter(serverId), serverId);
 }