public static IEnumerable <T> GetInstancesOfType <T>() { foreach (Type t in InterfaceManager.GetPluginsOfType <T>()) { yield return((T)Activator.CreateInstance(t)); } }
internal static ParameterValidationResult ValidateBuiltInLoggingParameters(KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page) { if (page == ConfigParameterPage.Connectivity) { ISettingsProvider settings = InterfaceManager.GetProviderOrDefault <ISettingsProvider>(); if (!settings?.HandleOwnLogConfiguration ?? false) { if (!string.IsNullOrWhiteSpace(configParameters[Logging.LogDaysParameterName].Value) && !int.TryParse(configParameters[Logging.LogDaysParameterName].Value, out int _)) { return(new ParameterValidationResult(ParameterValidationResultCode.Failure, "The value for log retention needs to be a number", Logging.LogDaysParameterName)); } if (!string.IsNullOrWhiteSpace(configParameters[Logging.LogLevelParameterName].Value)) { try { LogLevel.FromString(configParameters[Logging.LogLevelParameterName].Value); } catch (Exception) { return(new ParameterValidationResult(ParameterValidationResultCode.Failure, "The value for log level was unknown", Logging.LogLevelParameterName)); } } } } return(null); }
public IList <ConfigParameterDefinition> GetConfigParametersEx(KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page, int pageNumber) { IConfigParametersProviderEx provider = InterfaceManager.GetProviderOrDefault <IConfigParametersProviderEx>(); if (provider == null) { if (pageNumber > 1) { return(null); } return(this.GetConfigParameters(configParameters, page)); } var configParameterDefinitions = new List <ConfigParameterDefinition>(); if (pageNumber == 1) { Logging.AddBuiltInLoggingParameters(page, configParameterDefinitions); } provider.GetConfigParametersEx(configParameters, configParameterDefinitions, page, pageNumber); return(configParameterDefinitions); }
public IList <ConfigParameterDefinition> GetConfigParameters(KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page) { try { Logging.SetupLogger(configParameters); var configParameterDefinitions = new List <ConfigParameterDefinition>(); Logging.AddBuiltInLoggingParameters(page, configParameterDefinitions); IConfigParametersProvider provider = InterfaceManager.GetProviderOrDefault <IConfigParametersProvider>(); if (provider == null) { var providerEx = InterfaceManager.GetProviderOrDefault <IConfigParametersProviderEx>(); providerEx?.GetConfigParametersEx(configParameters, configParameterDefinitions, page, 1); } else { provider.GetConfigParameters(configParameters, configParameterDefinitions, page); } return(configParameterDefinitions); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException(), "Could not get config parameters"); throw; } }
public void OpenPasswordConnection(KeyedCollection <string, ConfigParameter> configParameters, Partition partition) { Logging.SetupLogger(configParameters); this.passwordContext = new PasswordContext() { ConnectionContext = InterfaceManager.GetProviderOrDefault <IConnectionContextProvider>()?.GetConnectionContext(configParameters, ConnectionContextOperationType.Password), ConfigParameters = configParameters }; this.InitializeProviders(this.passwordContext); }
public static T GetProviderOrThrow <T>() { T provider = InterfaceManager.GetInstancesOfType <T>().FirstOrDefault(); if (provider == null) { throw new ProviderNotFoundException($"A provider for type {typeof(T).FullName} was not found"); } return(provider); }
private IObjectImportProviderAsync GetAsyncProviderForType(SchemaType type) { foreach (IObjectImportProviderAsync provider in InterfaceManager.GetInstancesOfType <IObjectImportProviderAsync>()) { if (provider.CanImport(type)) { return(provider); } } return(null); }
private IObjectImportProvider GetProviderForType(SchemaType type) { foreach (IObjectImportProvider provider in InterfaceManager.GetInstancesOfType <IObjectImportProvider>()) { if (provider.CanImport(type)) { return(provider); } } throw new InvalidOperationException($"An import provider for the type '{type.Name}' could not be found"); }
public MACapabilities GetCapabilitiesEx(KeyedCollection <string, ConfigParameter> configParameters) { try { Logging.SetupLogger(configParameters); ICapabilitiesProvider provider = InterfaceManager.GetProviderOrThrow <ICapabilitiesProvider>(); return(provider.GetCapabilitiesEx(configParameters)); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException(), "Could not get capabilities"); throw; } }
internal static void AddBuiltInLoggingParameters(ConfigParameterPage page, List <ConfigParameterDefinition> configParameterDefinitions) { if (page == ConfigParameterPage.Connectivity) { ISettingsProvider settings = InterfaceManager.GetProviderOrDefault <ISettingsProvider>(); if (!settings?.HandleOwnLogConfiguration ?? false) { configParameterDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Logging.LogFileParameterName, string.Empty)); configParameterDefinitions.Add(ConfigParameterDefinition.CreateDropDownParameter(Logging.LogLevelParameterName, LogLevel.AllLevels.Reverse().Select(t => t.Name).ToArray(), false, "Info")); configParameterDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Logging.LogDaysParameterName, string.Empty)); configParameterDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter()); } } }
public ParameterValidationResult ValidateConfigParametersEx(KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page, int pageNumber) { IConfigParametersProviderEx provider = InterfaceManager.GetProviderOrDefault <IConfigParametersProviderEx>(); if (provider == null) { if (pageNumber > 1) { return(null); } return(this.ValidateConfigParameters(configParameters, page)); } return(provider.ValidateConfigParametersEx(configParameters, page, pageNumber)); }
public OpenImportConnectionResults OpenImportConnection(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenImportConnectionRunStep importRunStep) { Logging.SetupLogger(configParameters); this.importContext = new ImportContext() { RunStep = importRunStep, ImportItems = new BlockingCollection <CSEntryChange>(), ConfigParameters = configParameters, Types = types }; try { logger.Info("Starting {0} import", this.importContext.InDelta ? "delta" : "full"); this.importContext.ConnectionContext = InterfaceManager.GetProviderOrDefault <IConnectionContextProvider>()?.GetConnectionContext(configParameters, ConnectionContextOperationType.Import); if (!string.IsNullOrEmpty(importRunStep.CustomData)) { try { this.importContext.IncomingWatermark = JsonConvert.DeserializeObject <WatermarkKeyedCollection>(importRunStep.CustomData); } catch (Exception ex) { logger.Error(ex, "Could not deserialize watermark"); } } this.importContext.Timer.Start(); this.StartCreatingCSEntryChanges(this.importContext); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException()); throw; } return(new OpenImportConnectionResults()); }
public ParameterValidationResult ValidateConfigParameters(KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page) { try { var result = Logging.ValidateBuiltInLoggingParameters(configParameters, page); if (result != null) { return(result); } IConfigParametersProvider provider = InterfaceManager.GetProviderOrDefault <IConfigParametersProvider>(); return(provider?.ValidateConfigParameters(configParameters, page) ?? new ParameterValidationResult()); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException(), "Could not validate config parameters"); throw; } }
public Schema GetSchema(KeyedCollection <string, ConfigParameter> configParameters) { try { Logging.SetupLogger(configParameters); SchemaContext context = new SchemaContext() { ConfigParameters = configParameters, ConnectionContext = InterfaceManager.GetProviderOrDefault <IConnectionContextProvider>()?.GetConnectionContext(configParameters, ConnectionContextOperationType.Schema) }; ISchemaProvider provider = InterfaceManager.GetProviderOrThrow <ISchemaProvider>(); return(provider.GetMmsSchema(context)); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException(), "Could not retrieve schema"); throw; } }
public void OpenExportConnection(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep) { Logging.SetupLogger(configParameters); this.exportContext = new ExportContext() { ConfigParameters = configParameters }; try { logger.Info("Starting export"); this.exportContext.ConnectionContext = InterfaceManager.GetProviderOrDefault <IConnectionContextProvider>()?.GetConnectionContext(configParameters, ConnectionContextOperationType.Export); this.InitializeProviders(this.exportContext); this.exportContext.Timer.Start(); } catch (Exception ex) { logger.Error(ex.UnwrapIfSingleAggregateException()); throw; } }
public static T GetProviderOrDefault <T>() { return(InterfaceManager.GetInstancesOfType <T>().FirstOrDefault()); }
public static void SetupLogger(KeyedCollection <string, ConfigParameter> configParameters) { var settingsProvider = InterfaceManager.GetProviderOrDefault <ISettingsProvider>(); LoggingConfiguration logConfiguration; // Implementation will handle its own logging if (settingsProvider?.HandleOwnLogConfiguration ?? false) { logConfiguration = settingsProvider?.GetCustomLogConfiguration(configParameters); LogManager.Configuration = logConfiguration; LogManager.ReconfigExistingLoggers(); return; } logConfiguration = new LoggingConfiguration(); LogLevel level = LogLevel.Info; if (configParameters.Contains(LogLevelParameterName)) { string value = configParameters[LogLevelParameterName].Value; if (value != null) { level = LogLevel.FromString(value); } } if (level == LogLevel.Trace) { OutputDebugStringTarget odsTarget = new OutputDebugStringTarget(); logConfiguration.AddTarget("ods", odsTarget); LoggingRule odsRule = new LoggingRule("*", level, odsTarget); logConfiguration.LoggingRules.Add(odsRule); } EventLogTarget eventLogTarget = new EventLogTarget(); eventLogTarget.Source = settingsProvider?.ManagementAgentName ?? "Lithnet Ecma2 Framework"; eventLogTarget.Category = settingsProvider?.ManagementAgentName ?? "Lithnet Ecma2 Framework"; eventLogTarget.Layout = "${message}${newline}${exception:format=ToString}"; LoggingRule eventLogRule = new LoggingRule("*", LogLevel.Warn, eventLogTarget); logConfiguration.LoggingRules.Add(eventLogRule); if (configParameters.Contains(LogFileParameterName) && !string.IsNullOrWhiteSpace(configParameters[LogFileParameterName].Value)) { FileTarget fileTarget = new FileTarget(); logConfiguration.AddTarget("file", fileTarget); fileTarget.FileName = configParameters[LogFileParameterName].Value; fileTarget.Layout = "${longdate}|[${threadid:padding=4}]|${level:uppercase=true:padding=5}|${message}${exception:format=ToString}"; fileTarget.ArchiveEvery = FileArchivePeriod.Day; fileTarget.ArchiveNumbering = ArchiveNumberingMode.Date; if (configParameters.Contains(LogDaysParameterName) && int.TryParse(configParameters[LogDaysParameterName].Value, out int days)) { fileTarget.MaxArchiveFiles = days; } else { fileTarget.MaxArchiveFiles = 7; } LoggingRule rule2 = new LoggingRule("*", level, fileTarget); logConfiguration.LoggingRules.Add(rule2); } LogManager.Configuration = logConfiguration; LogManager.ReconfigExistingLoggers(); }