private void RegisterObjectConfigurationMethod(ITemplate factory, MethodInfo method, ConfigurationMethodAttribute attrib) { Type objectType = method.ReturnType; if (method.GetParameters().Length != 1) { throw new NotSupportedException("Configuration methods must have only 1 parameter"); } ConfigureDelegate configDelegate = CreateMethodConfigurationDelegate(factory, method); Type defaultType = method.GetParameters().First().ParameterType; if (attrib.ConfigId != null) { RegisterObjectConfigurationMethod(attrib.ConfigId, configDelegate); } else if (attrib.RegisterAs == ConfigurationType.DefaultForType) { RegisterObjectConfigurationMethod(defaultType, configDelegate); } else if (attrib.RegisterAs == ConfigurationType.AppliesToAll) { RegisterObjectTemplateConfigurationMethod(defaultType, configDelegate); } else { string objectId = method.Name; RegisterObjectConfigurationMethod(objectId, configDelegate); } }
private ObjectConfigurationInfo CreateObjectConfiguration(ConfigureDelegate configMethod) { ObjectConfigurationInfo config = new ObjectConfigurationInfo(); config.ConfigureDelegate = configMethod; return(config); }
/// <summary> /// Assigns the config delegate. /// </summary> /// <param name="cDelegate">The config delegate.</param> /// <returns></returns> public static bool AssignConfigDelegate(ConfigureDelegate cDelegate) { if (cDelegate == null) return false; s_configCallback = cDelegate.Invoke; return true; }
/// <summary> /// Assigns the config delegate. /// </summary> /// <param name="cDelegate">The config delegate.</param> /// <returns></returns> public static bool AssignConfigDelegate(ConfigureDelegate cDelegate) { if (cDelegate == null) { return(false); } s_configCallback = cDelegate.Invoke; return(true); }
private ConfigureDelegate CreateMethodConfigurationDelegate(ITemplate factory, MethodInfo method) { ParameterInfo param = method.GetParameters().First(); ParameterExpression paramExpression = Expression.Parameter(typeof(object), "arg"); Expression castExpression = Expression.TypeAs(paramExpression, param.ParameterType); Expression factoryInstanceExpression = Expression.Constant(factory); Expression callExpression = Expression.Call(factoryInstanceExpression, method, castExpression); LambdaExpression lambda = Expression.Lambda(typeof(ConfigureDelegate), callExpression, paramExpression); ConfigureDelegate del = (ConfigureDelegate)lambda.Compile(); return(del); }
public IModule[] Build() { List <IModule> modules = new (); if (ConfigureDelegate != null) { if (!IsBuilt) { modules.Add(ConfigureDelegate.Invoke(this)); IsBuilt = true; } foreach (var builder in Builders) { modules.AddRange(builder.Build()); } } return(modules.ToArray()); }
internal void ApplyConfiguration(Configuration appliedConfiguration, bool refreshPlayer, bool force) { try { bool isAudioscrobblerUpdated = false; bool isProxyUpdated = false; if (this.configuration.LastFmSubmit != appliedConfiguration.LastFmSubmit || this.configuration.LastFmUser != appliedConfiguration.LastFmUser || this.configuration.LastFmPassword != appliedConfiguration.LastFmPassword) { isAudioscrobblerUpdated = true; } if (configuration.ProxyHost != appliedConfiguration.ProxyHost || configuration.ProxyPort != appliedConfiguration.ProxyPort || configuration.ProxyUser != appliedConfiguration.ProxyUser || configuration.ProxyPassword != appliedConfiguration.ProxyPassword) { isProxyUpdated = true; } if (force) { isAudioscrobblerUpdated = true; isProxyUpdated = true; } // // Apply this.configuration.Apply(appliedConfiguration); try { // // Title buttons this.btnClose.Visible = this.configuration.CloseButtonVisible; this.btnMinimize.Visible = this.configuration.MinimizeButtonVisible; // // Window this.TopMost = this.configuration.KeepOnTop; settingsForm.TopMost = this.configuration.KeepOnTop; // // Tool tip if (this.configuration.CloseButtonMinimizeToTray) { toolTip.SetToolTip(this.btnClose, "Close (Minimize to Tray)"); } else { toolTip.SetToolTip(this.btnClose, "Close (Exit)"); } toolTip.SetToolTip(this.btnMinimize, "Minimize"); // // G15 if (configuration.SendToG15 && g15 == null) { Debug.WriteLine("Connecting to G15"); g15 = new G15(); // first define some delegates bDelegate = new ButtonDelegate(this.ButtonDelegateImplementation); cDelegate = new ConfigureDelegate(this.ConfigureDelegateImplementation); g15.SetButtonDelegateImplementation(bDelegate); g15.SetConfigureDelegateImplementation(cDelegate); g15.OpenLCD(); } else if (!configuration.SendToG15 && g15 != null) { g15.CloseLCD(); g15 = null; } // // Refresh player if (song.Name != string.Empty) { refreshMessenger = true; refreshXfire = true; refreshSkype = true; refreshG15 = true; } if (refreshPlayer) { RefreshPlayer(false); } // // Audioscrobbler if ((isAudioscrobblerUpdated || isProxyUpdated || audioscrobbler == null) && configuration.LastFmSubmit && configuration.LastFmUser != string.Empty) { if (audioscrobbler != null) { audioscrobbler.Connected -= new EventHandler(this.AudioscrobblerConnected); } audioscrobbler = new Audioscrobbler("opa", "0.1", configuration.LastFmUser, configuration.LastFmPassword); audioscrobbler.Connected += new EventHandler(this.AudioscrobblerConnected); audioscrobbler.ConnectionFailed += new EventHandler(this.AudioscrobblerConnectionFailed); audioscrobbler.Connect( configuration.ProxyHost, configuration.ProxyPort, configuration.ProxyUser, configuration.ProxyPassword); } if (configuration.LastFmSubmit && configuration.LastFmSubmitManual) { menuLastFmSubmit.Visible = true; } else { menuLastFmSubmit.Visible = false; } // // Proxy if (isProxyUpdated) { LoadStations(); } } finally { this.configuration.Save(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } }
public void SetConfigureDelegateImplementation(ConfigureDelegate cDelegate) { lcd.AssignConfigDelegate(cDelegate); }
public IWebHost Build() { ConfigureDelegate?.Invoke(new WebHostBuilderContext(), new ConfigurationBuilder()); return(new FakeWebHost()); }
private void RegisterObjectTemplateConfigurationMethod(Type configType, ConfigureDelegate configMethod) { ObjectConfigurationInfo config = CreateObjectConfiguration(configMethod); state.ApplyToAllObjectConfigurations.Add(configType, config); }
public void RegisterObjectConfigurationMethod(string configId, ConfigureDelegate configMethod) { ObjectConfigurationInfo config = CreateObjectConfiguration(configMethod); state.NamedObjectConfigurations.Add(configId, config); }
/// <summary> /// Allows customized configurations of each matching type that is /// assignable to <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The type assignable from.</typeparam> /// <param name="configurer">The configuration action.</param> /// <returns></returns> public BasedOnDescriptor ConfigureFor <T>(ConfigureDelegate configurer) { return(basedOn.ConfigureFor <T>(configurer)); }
/// <summary> /// Allows customized configurations of each matching type. /// </summary> /// <param name = "configurer">The configuration action.</param> /// <returns></returns> public BasedOnDescriptor Configure(ConfigureDelegate configurer) { return(Configure(delegate(ComponentRegistration registration) { configurer(registration); })); }