public StorageConfig(dynamic config) { try { _logger = Log.ForContext <StorageConfig>(); // try loading layer configs. var layers = new List <IStorageLayerConfig> { new HybridStorageConfig(config.hybrid), new MposStorageConfig(config.mpos) }; var enabledLayers = layers.Count(layer => layer.Enabled && layer.Valid); // find the count of enabled storage layers. if (enabledLayers == 0) // make sure we have at least a single enabled layer. { _logger.Error("Storage will be not working as no valid storage configuration was found!"); Layer = NullStorageConfig.Null; Valid = false; } else if (enabledLayers > 1) // we can have either hybrid or mpos layer enabled only at a time. { _logger.Error("Storage will be not working as only a single storage configuration can be enabled!"); Layer = NullStorageConfig.Null; Valid = false; } else // the configuration meets our expectations { Layer = layers.First(layer => layer.Enabled && layer.Valid); // set the enabled layer. Valid = true; } } catch (Exception e) { Valid = false; _logger.Error(e, "Error loading storage configuration"); } }
public StorageConfig(dynamic config) { try { _logger = Log.ForContext<StorageConfig>(); // try loading layer configs. var layers = new List<IStorageLayerConfig> { new HybridStorageConfig(config.hybrid), new MposStorageConfig(config.mpos) }; var enabledLayers = layers.Count(layer => layer.Enabled && layer.Valid); // find the count of enabled storage layers. if (enabledLayers == 0) // make sure we have at least a single enabled layer. { _logger.Error("Storage will be not working as no valid storage configuration was found!"); Layer = NullStorageConfig.Null; Valid = false; } else if (enabledLayers > 1) // we can have either hybrid or mpos layer enabled only at a time. { _logger.Error("Storage will be not working as only a single storage configuration can be enabled!"); Layer = NullStorageConfig.Null; Valid = false; } else // the configuration meets our expectations { Layer = layers.First(layer => layer.Enabled && layer.Valid); // set the enabled layer. Valid = true; } } catch (Exception e) { Valid = false; _logger.Error(e, "Error loading storage configuration"); } }