Ejemplo n.º 1
0
        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));
        }
        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);
            }
        }
Ejemplo n.º 3
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);
 }