/// <summary> /// Configures a new service host /// </summary> /// <param name="configureCallback">Configuration method to call</param> /// <returns>A Topshelf service host, ready to run</returns> public static Host New(Action <HostConfigurator> configureCallback) { if (configureCallback == null) { throw new ArgumentNullException("configureCallback"); } var configurator = new HostConfiguratorImpl(); Type declaringType = configureCallback.Method.DeclaringType; if (declaringType != null) { string defaultServiceName = declaringType.Namespace; if (!string.IsNullOrEmpty(defaultServiceName)) { configurator.SetServiceName(defaultServiceName); } } configureCallback(configurator); configurator.ApplyCommandLine(); ConfigurationResult result = ValidateConfigurationResult.CompileResults(configurator.Validate()); if (result.Message.Length > 0) { _log.InfoFormat("Configuration Result:\n{0}", result.Message); } return(configurator.CreateHost()); }
static string GetMessage(ConfigurationResult result) { return "There were errors configuring the rules engine:" + Environment.NewLine + string.Join(Environment.NewLine, result.Results .Select(x => string.Format("{0}: {1}", x.Key, x.Message)).ToArray()); }
public ConfigurationResult GetConfigurationList(string sessionId, BackgroundWorkerHelper bg, CxWebServiceClient client) { ConfigurationResult configuration = null; bg.DoWorkFunc = delegate(object obj) { configuration = new ConfigurationResult(); CxWSResponseConfigSetList cxWSResponseConfigSetList = client.ServiceClient.GetConfigurationSetList(sessionId); configuration.IsSuccesfull = cxWSResponseConfigSetList.IsSuccesfull; configuration.Configurations = new Dictionary <long, string>(); if (cxWSResponseConfigSetList != null && cxWSResponseConfigSetList.ConfigSetList.Length > 0) { for (int i = 0; i < cxWSResponseConfigSetList.ConfigSetList.Length; i++) { configuration.Configurations.Add(cxWSResponseConfigSetList.ConfigSetList[i].ID, cxWSResponseConfigSetList.ConfigSetList[i].ConfigSetName); } } }; if (!bg.DoWork("Receive Configuration list...")) { return(null); } return(configuration); }
public static RulesEngine New(Action <RulesEngineConfigurator> configureCallback) { if (configureCallback == null) { throw new ArgumentNullException("configureCallback"); } var configurator = new RulesEngineConfiguratorImpl(); configureCallback(configurator); ConfigurationResult result = ConfigurationResultImpl.CompileResults(configurator.ValidateConfiguration()); try { RulesEngine engine = configurator.Create(); return(engine); } catch (Exception ex) { throw new ConfigurationException(result, "An exception was thrown during rules engine creation", ex); } }
public static ServiceBuilderFactory CreateServiceBuilderFactory <TService>( Func <HostSettings, TService> serviceFactory, Action <ServiceConfigurator> callback) where TService : class, ServiceControl { if (serviceFactory == null) { throw new ArgumentNullException(nameof(serviceFactory)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } var serviceConfigurator = new ControlServiceConfigurator <TService>(serviceFactory); callback(serviceConfigurator); ServiceBuilder ServiceBuilderFactory(HostSettings x) { ConfigurationResult configurationResult = ValidateConfigurationResult.CompileResults(serviceConfigurator.Validate()); if (configurationResult.Results.Any()) { throw new HostConfigurationException("The service was not properly configured"); } ServiceBuilder serviceBuilder = serviceConfigurator.Build(); return(serviceBuilder); } return(ServiceBuilderFactory); }
public void should_return_merged_observable() { var observableResult1 = new TestConfigured(); var observable1 = Observable.Return(observableResult1); var configurationResult1 = ConfigurationResult <TestConfigured> .Create(observable : observable1); _sources[0].Handles <TestConfigured>().Returns(true); _sources[0].Get(Arg.Any <ConfigurationResult <TestConfigured> >()) .Returns(configurationResult1); var observableResult2 = new TestConfigured(); var observable2 = Observable.Return(observableResult2); var configurationResult2 = ConfigurationResult <TestConfigured> .Create(observable : observable2); _sources[1].Handles <TestConfigured>().Returns(true); _sources[1].Get(configurationResult1) .Returns(configurationResult2); var configurationResult = _cut.Resolve <TestConfigured>(); var captured = configurationResult.Observable.Capture(2); captured[0].Should().Be(observableResult1); captured[1].Should().Be(observableResult2); }
public static HostConfigurator Service <TService>(this HostConfigurator configurator, Action <ServiceConfigurator <TService> > callback) where TService : class { if (configurator == null) { throw new ArgumentNullException("configurator"); } if (callback == null) { throw new ArgumentNullException("callback"); } var serviceConfigurator = new DelegateServiceConfigurator <TService>(); callback(serviceConfigurator); configurator.UseServiceBuilder(x => { ConfigurationResult configurationResult = ValidateConfigurationResult.CompileResults(serviceConfigurator.Validate()); if (configurationResult.Results.Any()) { throw new HostConfigurationException("The service was not properly configured"); } ServiceBuilder serviceBuilder = serviceConfigurator.Build(); return(serviceBuilder); }); return(configurator); }
private void FlightPlanificationCommandExecute() { PlanificationStrategy planification = new SimplePlanification(this); ConfigurationResult.Clear(); planification.Execute().ForEach(o => ConfigurationResult.Add(o)); }
static string GetMessage(ConfigurationResult result) { return("There were errors configuring the rules engine:" + Environment.NewLine + string.Join(Environment.NewLine, result.Results .Select(x => string.Format("{0}: {1}", x.Key, x.Message)).ToArray())); }
public void Setup() { if (_endpointFactoryConfigurator != null) { ConfigurationResult result = ConfigurationResultImpl.CompileResults(_endpointFactoryConfigurator.Validate()); try { EndpointFactory = _endpointFactoryConfigurator.CreateEndpointFactory(); _endpointCache = new EndpointCache(EndpointFactory); EndpointCache = new EndpointCacheProxy(_endpointCache); } catch (Exception ex) { throw new ConfigurationException(result, "An exception was thrown during endpoint cache creation", ex); } } ServiceBusFactory.ConfigureDefaultSettings(x => { x.SetEndpointCache(EndpointCache); x.SetConcurrentConsumerLimit(4); x.SetReceiveTimeout(TimeSpan.FromMilliseconds(50)); x.EnableAutoStart(); x.DisablePerformanceCounters(); }); EstablishContext(); }
/// <summary> /// Convert XML string into ConfigurationResult object /// </summary> /// <param name="response">xml string</param> /// <returns></returns> public static ConfigurationResult ParseConfigurationResult(string response) { ConfigurationResult r = new ConfigurationResult(); r.Configurations = new Dictionary <long, string>(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(response); foreach (XmlNode xmlNode in xmlDoc.ChildNodes[1].ChildNodes) { switch (xmlNode.Name) { case "IsSuccesfull": r.IsSuccesfull = bool.Parse(xmlNode.InnerText); break; case "ReturnValue": foreach (XmlNode presetNode in xmlNode.ChildNodes) { r.Configurations.Add(int.Parse(presetNode.Attributes["Id"].Value), presetNode.Attributes["Name"].Value); } break; } } xmlDoc = null; } catch (Exception ex) { Common.Logger.Create().Error(ex.ToString()); } return(r); }
protected ConfigurationResult ConfigureExtendedSelfRead(AMIConfigureDevice ConfigureDevice) { ConfigurationResult Result = ConfigurationResult.SUCCESS; ConfigurationError ConfigError = ConfigurationError.GENERAL_ERROR; if (Table00.IsTableUsed(2265) && (Table00.DeviceClass.ToUpper().Equals(ITRD_DEVICE_CLASS) || Table00.DeviceClass.ToUpper().Equals(ITRE_DEVICE_CLASS) || Table00.DeviceClass.ToUpper().Equals(ITRF_DEVICE_CLASS) || Table00.DeviceClass.ToUpper().Equals(ITRJ_DEVICE_CLASS) || Table00.DeviceClass.ToUpper().Equals(ITRK_DEVICE_CLASS))) { ConfigError = ConfigureDevice.WriteTableByElementRange( CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifier, new int[1] { 0 }, CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifierQualifier, new int[1] { ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifierQualifier) }); } else { ConfigError = ConfigurationError.OPERATION_NOT_POSSIBLE; } // Translate to the ItronDevice ConfigurationResult error code since // the factory is using ConfigurationError and we do not want to always // rely on having the version in AMIConfiguration.dll Result = TranslateConfigError(ConfigError); return(Result); }
/// <summary> /// Configures the meter instrumentation profile config block /// with the specified program /// </summary> /// <param name="ConfigureDevice">AMIConfigureDevice object with the correct table set already loaded</param> /// <returns></returns> /// Revision History /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 03/06/12 JKW Created - Lithium /// protected ConfigurationResult ConfigureInstrumentationProfile(AMIConfigureDevice ConfigureDevice) { ConfigurationResult Result = ConfigurationResult.SUCCESS; ConfigurationError ConfigError = ConfigurationError.GENERAL_ERROR; if (Table00.IsTableUsed(2265)) { ConfigError = ConfigureDevice.WriteTableByElementRange( CentronTblEnum.MfgTbl217InstrumentationProfileIntervalLength, null, CentronTblEnum.MfgTbl217InstrumentationProfilePulseWeightSetTwo, new int[1] { ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217InstrumentationProfilePulseWeightSetTwo) }); } else { ConfigError = ConfigurationError.OPERATION_NOT_POSSIBLE; } // Translate to the ItronDevice ConfigurationResult error code since // the factory is using ConfigurationError and we do not want to always // rely on having the version in AMIConfiguration.dll Result = TranslateConfigError(ConfigError); return(Result); }
/// <summary> /// Configures the meter instrumentation profile config block /// with the specified program /// </summary> /// <param name="sProgramName">The path to the program file</param> /// <param name="configItems"></param> /// <returns></returns> /// Revision History /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 03/06/12 JKW Created - Lithium /// public ConfigurationResult PartialConfiguration(string sProgramName, BlocksForPartialConfiguration configItems) { ConfigurationResult Result = ConfigurationResult.SUCCESS; AMIConfigureDevice ConfigureDevice = new AMIConfigureDevice(m_PSEM); // Load the EDL file into the table set Result = TranslateConfigError(ConfigureDevice.LoadEDLFileToTableSet(sProgramName)); // check each flag within the enumeration reconfiguring the blocks specified if (Result == ConfigurationResult.SUCCESS && configItems.HasFlag(BlocksForPartialConfiguration.InstrumentationProfile)) { Result = ConfigureInstrumentationProfile(ConfigureDevice); } if (Result == ConfigurationResult.SUCCESS && configItems.HasFlag(BlocksForPartialConfiguration.ExtendedEnergyAndLoadProfile)) { Result = ConfigureNonBillingEnergyandLoadProfile(ConfigureDevice); } if (Result == ConfigurationResult.SUCCESS && configItems.HasFlag(BlocksForPartialConfiguration.ExtendedVoltageMonitoring)) { Result = ConfigureVoltageMonitoring(ConfigureDevice); } if (Result == ConfigurationResult.SUCCESS && configItems.HasFlag(BlocksForPartialConfiguration.ExtendedSelfRead)) { Result = ConfigureExtendedSelfRead(ConfigureDevice); } return(Result); }
public void Setup() { if (EndpointFactoryConfigurator != null) { IConfigurationResult result = ConfigurationResult.CompileResults(EndpointFactoryConfigurator.Validate()); try { EndpointFactory = EndpointFactoryConfigurator.CreateEndpointFactory(); EndpointFactoryConfigurator = null; _endpointCache = new EndpointCache(EndpointFactory); EndpointCache = new EndpointCacheProxy(_endpointCache); } catch (Exception ex) { throw new ConfigurationException(result, "An exception was thrown during endpoint cache creation", ex); } } ServiceBusFactory.ConfigureDefaultSettings(x => { x.SetEndpointCache(EndpointCache); x.SetConcurrentConsumerLimit(4); x.SetReceiveTimeout(150.Milliseconds()); x.EnableAutoStart(); }); }
public ConfigurationResult <T> Get <T>(ConfigurationResult <T> result) where T : class, IConfigured, new() { var resultOut = new T(); var observable = Observable.Empty <T>(); Console.WriteLine($"Identity getting config for {typeof(T).Namespace}."); return(new ConfigurationResult <T>(resultOut, observable)); }
private static void AssertDefaultValue(ConfigurationResult <TestConfigured> result) { var defaultTestConfigured = new TestConfigured(); result.Result.IsEnabled.Should().Be(defaultTestConfigured.IsEnabled); result.Result.AString.Should().Be(defaultTestConfigured.AString); result.Result.AnInt32.Should().Be(defaultTestConfigured.AnInt32); }
public void get_after_store_should_match_stored_result() { var original = new TestConfigured(); var configResult = new ConfigurationResult <TestConfigured>(original, _observable); _cut.Store(configResult); _cut.Get <TestConfigured>().Should().BeSameAs(original); }
public void should_store_aggregated_result_for_T() { var resolved = ConfigurationResult <TestConfigured> .Create(); _sourceResolver.Resolve <TestConfigured>().Returns(resolved); _cut.Get <TestConfigured>(); _resultStore.Received().Store(resolved); }
public void should_return_type_defaults_when_variable_cannot_be_bound_to_property() { Environment.SetEnvironmentVariable("TestConfigured.IsEnabled", "weeeeeeeeee"); Environment.SetEnvironmentVariable("TestConfigured.AnInt32", "12345678901234556789012345512312313"); var result = _cut.Get(ConfigurationResult <TestConfigured> .Create()); result.Result.IsEnabled.Should().Be(default(bool)); result.Result.AnInt32.Should().Be(default(int)); }
public void get_after_observable_fires_should_return_observed() { var original = new TestConfigured(); var replacement = new TestConfigured(); var configResult = new ConfigurationResult <TestConfigured>(original, _observable); _cut.Store(configResult); _observable.OnNext(replacement); _cut.Get <TestConfigured>().Should().BeSameAs(replacement); }
public void should_return_deserialized_config_contents() { var model = new TestConfigured(); _cut.CreateConfigFile(model); var configurationResult = _cut.Get(ConfigurationResult <TestConfigured> .Create()); configurationResult.Result.AppKey.Should().Be(model.AppKey); configurationResult.Result.IsEnabled.Should().Be(model.IsEnabled); configurationResult.Result.EnabledOn.Should().Be(model.EnabledOn); }
public void observable_should_note_drop_a_marble_when_file_is_not_updated() { var model = new TestConfigured(); _cut.CreateConfigFile(model); var observable = _cut.Get(ConfigurationResult <TestConfigured> .Create()).Observable; var result = observable.Capture(0.15); result.Should().BeNull(); }
public ConfigurationResult <T> Get <T>(ConfigurationResult <T> result) where T : class, IConfigured, new() { var pollingInterval = TimeSpan.FromSeconds(_settings.PollingIntervalInSeconds); var settingsFileInfo = GetConfigurationFileInfo <T>(); var model = GetConfigured <T>(settingsFileInfo); var observable = settingsFileInfo .PollFile(pollingInterval) .Select(ConfigFileUpdated <T>); return(new ConfigurationResult <T>(model, observable)); }
public IServiceBusEnvironment GetCurrentEnvironment() { ConfigurationResult.CompileResults(Validate()); string environment = _currentEnvironment.ToLowerInvariant(); if (_environments.ContainsKey(environment)) { return(_environments[environment]()); } return(null); }
public static IBusControl Build(this IBusFactory factory) { ConfigurationResult result = BusConfigurationResult.CompileResults(factory.Validate()); try { return(factory.CreateBus()); } catch (Exception ex) { throw new ConfigurationException(result, "An exception occurred during bus creation", ex); } }
public void LoadSettings() { ConfigurationResult result = ConfigurationManager.Read(); if (result.Success) { ErrorMessage = result.ResultMessage; _exitOnEnd = false; } _configList = result.ConfigurationFolders; _ignoreList = result.IgnoreFolders; MaxFolderCount = _configList.Count(); //MessageBox.Show($"max folder count is {MaxFolderCount}", "main window", MessageBoxButton.OK); }
public static ConfigurationResult Read() { string dataFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); ConfigurationResult retVal = new ConfigurationResult(); if (!Directory.Exists(dataFolder)) { throw new System.ArgumentException($"Program Folder {dataFolder} doesn't exist.", "original"); } string configFilename = $"{dataFolder}\\backup.cfg"; if (!File.Exists(configFilename)) { // MessageBox.Show($"Unable to read config file", "Startup Folder", MessageBoxButton.OK); throw new System.ArgumentException($"Configuration file {configFilename} doesn't exist.", "original"); } string[] lines = File.ReadAllLines(configFilename); bool onIgnore = false; foreach (var line in lines) { if (!string.IsNullOrWhiteSpace(line)) { if (line.Equals("<IGNORE>")) { onIgnore = true; continue; } string[] data = line.Split(','); if (!onIgnore && data.Length < 2) { retVal.Success = false; throw new System.ArgumentException($"Invalid row in configuration file. line is '{line}'", "original"); } if (onIgnore) { retVal.IgnoreFolders.Add(data[0].Trim()); } else { retVal.ConfigurationFolders.Add(new Config() { Source = data[0].Trim(), Destination = data[1].Trim() }); } } } return(retVal); }
public void should_get_value_from_environment_variable() { const string expectedString = "test string"; const int expectedInt = -1234; Environment.SetEnvironmentVariable("TestConfigured.IsEnabled", "false"); Environment.SetEnvironmentVariable("TestConfigured.AString", expectedString); Environment.SetEnvironmentVariable("TestConfigured.AnInt32", expectedInt.ToString()); var result = _cut.Get(ConfigurationResult <TestConfigured> .Create()); result.Result.IsEnabled.Should().BeFalse(); result.Result.AString.Should().Be(expectedString); result.Result.AnInt32.Should().Be(expectedInt); }
static void Main(string[] args) { ConfigurationResult result = ConfigurationManager.Read(); FileManager fileManager = new FileManager(); int cc = result.ConfigurationFolders.Count(); int i = 0; foreach (var item in result.ConfigurationFolders) { Console.WriteLine($"Backing up {i} of {cc}: {item.Source}"); fileManager.ProcessFolder(item, result.IgnoreFolders); } Debugger.Break(); }
protected IEndpointFactory BuildEndpointFactory() { IConfigurationResult result = ConfigurationResult.CompileResults(_endpointFactoryConfigurator.Validate()); IEndpointFactory endpointFactory; try { endpointFactory = _endpointFactoryConfigurator.CreateEndpointFactory(); } catch (Exception ex) { throw new ConfigurationException(result, "An exception was thrown during endpoint cache creation", ex); } return(endpointFactory); }
public ConfigurationException(ConfigurationResult result, string message, Exception innerException) : base(message, innerException) { Result = result; }
public ConfigurationException(ConfigurationResult result, string message) : base(message) { Result = result; }
public RulesEngineConfigurationException(ConfigurationResult result, Exception innerException) : this(GetMessage(result), innerException) { Result = result; }
public RulesEngineConfigurationException(ConfigurationResult result) : this(GetMessage(result)) { Result = result; }