示例#1
0
        // Creates a new instance of NetworkServerConfiguration by reading values from environment variables
        public static NetworkServerConfiguration CreateFromEnviromentVariables()
        {
            var config = new NetworkServerConfiguration();

            // Create case insensitive dictionary from environment variables
            var envVars = new CaseInsensitiveEnvironmentVariables(Environment.GetEnvironmentVariables());

            config.RunningAsIoTEdgeModule = !string.IsNullOrEmpty(envVars.GetEnvVar("IOTEDGE_APIVERSION", string.Empty));
            config.IoTHubHostName         = envVars.GetEnvVar("IOTEDGE_IOTHUBHOSTNAME", string.Empty);
            config.GatewayHostName        = envVars.GetEnvVar("IOTEDGE_GATEWAYHOSTNAME", string.Empty);
            config.EnableGateway          = envVars.GetEnvVar("ENABLE_GATEWAY", config.EnableGateway);
            config.GatewayID        = envVars.GetEnvVar("IOTEDGE_DEVICEID", string.Empty);
            config.HttpsProxy       = envVars.GetEnvVar("HTTPS_PROXY", string.Empty);
            config.Rx2DataRate      = envVars.GetEnvVar("RX2_DATR", string.Empty);
            config.Rx2DataFrequency = envVars.GetEnvVar("RX2_FREQ", config.Rx2DataFrequency);
            config.IoTEdgeTimeout   = envVars.GetEnvVar("IOTEDGE_TIMEOUT", config.IoTEdgeTimeout);
            config.FacadeServerUrl  = envVars.GetEnvVar("FACADE_SERVER_URL", string.Empty);
            config.FacadeAuthCode   = envVars.GetEnvVar("FACADE_AUTH_CODE", string.Empty);
            config.LogToHub         = envVars.GetEnvVar("LOG_TO_HUB", config.LogToHub);
            config.LogLevel         = envVars.GetEnvVar("LOG_LEVEL", config.LogLevel);
            config.LogToConsole     = envVars.GetEnvVar("LOG_TO_CONSOLE", config.LogToConsole);
            config.LogToUdp         = envVars.GetEnvVar("LOG_TO_UDP", config.LogToUdp);
            config.LogToUdpAddress  = envVars.GetEnvVar("LOG_TO_UDP_ADDRESS", string.Empty);
            config.LogToUdpPort     = envVars.GetEnvVar("LOG_TO_UDP_PORT", config.LogToUdpPort);

            return(config);
        }
示例#2
0
        // Creates a new instance of NetworkServerConfiguration by reading values from environment variables
        public static NetworkServerConfiguration CreateFromEnvironmentVariables()
        {
            var config = new NetworkServerConfiguration();

            // Create case insensitive dictionary from environment variables
            var envVars = new CaseInsensitiveEnvironmentVariables(Environment.GetEnvironmentVariables());

            config.RunningAsIoTEdgeModule = !string.IsNullOrEmpty(envVars.GetEnvVar("IOTEDGE_APIVERSION", string.Empty));
            config.IoTHubHostName         = envVars.GetEnvVar("IOTEDGE_IOTHUBHOSTNAME", string.Empty);
            config.GatewayHostName        = envVars.GetEnvVar("IOTEDGE_GATEWAYHOSTNAME", string.Empty);
            config.EnableGateway          = envVars.GetEnvVar("ENABLE_GATEWAY", config.EnableGateway);
            config.GatewayID    = envVars.GetEnvVar("IOTEDGE_DEVICEID", string.Empty);
            config.HttpsProxy   = envVars.GetEnvVar("HTTPS_PROXY", string.Empty);
            config.Rx2DataRate  = envVars.GetEnvVar("RX2_DATR", -1) is var datrNum && (DataRateIndex)datrNum is var datr && Enum.IsDefined(datr) ? datr : null;
            config.Rx2Frequency = envVars.GetEnvVar("RX2_FREQ") is { } someFreq?Hertz.Mega(someFreq) : null;

            config.IoTEdgeTimeout = envVars.GetEnvVar("IOTEDGE_TIMEOUT", config.IoTEdgeTimeout);

            // facadeurl is allowed to be null as the value is coming from the twin in production.
            var facadeUrl = envVars.GetEnvVar("FACADE_SERVER_URL", string.Empty);

            config.FacadeServerUrl     = string.IsNullOrEmpty(facadeUrl) ? null : new Uri(envVars.GetEnvVar("FACADE_SERVER_URL", string.Empty));
            config.FacadeAuthCode      = envVars.GetEnvVar("FACADE_AUTH_CODE", string.Empty);
            config.LogLevel            = envVars.GetEnvVar("LOG_LEVEL", config.LogLevel);
            config.LogToConsole        = envVars.GetEnvVar("LOG_TO_CONSOLE", config.LogToConsole);
            config.LogToTcp            = envVars.GetEnvVar("LOG_TO_TCP", config.LogToTcp);
            config.LogToHub            = envVars.GetEnvVar("LOG_TO_HUB", config.LogToHub);
            config.LogToTcpAddress     = envVars.GetEnvVar("LOG_TO_TCP_ADDRESS", string.Empty);
            config.LogToTcpPort        = envVars.GetEnvVar("LOG_TO_TCP_PORT", config.LogToTcpPort);
            config.NetId               = new NetId(envVars.GetEnvVar("NETID", config.NetId.NetworkId));
            config.AllowedDevAddresses = envVars.GetEnvVar("AllowedDevAddresses", string.Empty)
                                         .Split(";")
                                         .Select(s => DevAddr.TryParse(s, out var devAddr) ? (true, Value: devAddr) : default)