Skip to content

Commit

Permalink
Fix the local development again (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandur authored Sep 8, 2022
1 parent 99ab8ba commit 9cdeb36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void ConfigureServices(IServiceCollection services)
if (NetworkServerConfiguration.ClientCertificateMode is not ClientCertificateMode.NoCertificate)
_ = services.AddSingleton<IClientCertificateValidatorService, ClientCertificateValidatorService>();

_ = NetworkServerConfiguration.RunningAsIoTEdgeModule
_ = NetworkServerConfiguration.RunningAsIoTEdgeModule || NetworkServerConfiguration.IsLocalDevelopment
? services.AddSingleton<ModuleConnectionHost>()
: services.AddHostedService<CloudControlHost>()
.AddSingleton<ILnsRemoteCallHandler, LnsRemoteCallHandler>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,17 @@ public class NetworkServerConfiguration
/// </summary>
public string RedisConnectionString { get; private set; }

/// <summary>
/// Specifies the pool size for upstream AMQP connection
/// </summary>
public uint IotHubConnectionPoolSize { get; internal set; } = 1;

/// <summary>
/// Specificies wether we are running in local development mode.
/// </summary>
public bool IsLocalDevelopment { get; set; }


/// <summary>
/// Specifies the Processing Delay in Milliseconds
/// </summary>
Expand All @@ -153,9 +160,9 @@ public static NetworkServerConfiguration CreateFromEnvironmentVariables()
// Create case insensitive dictionary from environment variables
var envVars = new CaseInsensitiveEnvironmentVariables(Environment.GetEnvironmentVariables());
config.ProcessingDelayInMilliseconds = envVars.GetEnvVar("PROCESSING_DELAY_IN_MS", config.ProcessingDelayInMilliseconds);

config.IsLocalDevelopment = envVars.GetEnvVar("LOCAL_DEVELOPMENT", false);
// We disable IoT Edge runtime either when we run in the cloud or during local development.
config.RunningAsIoTEdgeModule = !(envVars.GetEnvVar("CLOUD_DEPLOYMENT", false) || envVars.GetEnvVar("LOCAL_DEVELOPMENT", false));
config.RunningAsIoTEdgeModule = !(envVars.GetEnvVar("CLOUD_DEPLOYMENT", false) || config.IsLocalDevelopment);
var iotHubHostName = envVars.GetEnvVar("IOTEDGE_IOTHUBHOSTNAME", envVars.GetEnvVar("IOTHUBHOSTNAME", string.Empty));
config.IoTHubHostName = !string.IsNullOrEmpty(iotHubHostName) ? iotHubHostName : throw new InvalidOperationException("Either 'IOTEDGE_IOTHUBHOSTNAME' or 'IOTHUBHOSTNAME' environment variable should be populated");

Expand Down Expand Up @@ -204,7 +211,7 @@ public static NetworkServerConfiguration CreateFromEnvironmentVariables()
: throw new NotSupportedException($"'IOTHUB_CONNECTION_POOL_SIZE' needs to be between 1 and {AmqpConnectionPoolSettings.AbsoluteMaxPoolSize}.");

config.RedisConnectionString = envVars.GetEnvVar("REDIS_CONNECTION_STRING", string.Empty);
if (!config.RunningAsIoTEdgeModule && string.IsNullOrEmpty(config.RedisConnectionString))
if (!config.RunningAsIoTEdgeModule && !config.IsLocalDevelopment && string.IsNullOrEmpty(config.RedisConnectionString))
throw new InvalidOperationException("'REDIS_CONNECTION_STRING' can't be empty if running network server as part of a cloud only deployment.");

return config;
Expand Down

0 comments on commit 9cdeb36

Please sign in to comment.