public void CreateInstance() { Type typeForCurrentPlatform = GetTypeForCurrentPlatform(); if (m_createGameObject) { GameObject gameObject = new GameObject(); gameObject.name = typeForCurrentPlatform.ToString(); string[] array = typeForCurrentPlatform.ToString().Split('.'); if (array.Length > 0) { m_instance = gameObject.AddComponent(Type.GetType(array[array.Length - 1])); } Transform rootObject = GetRootObject(); if (rootObject != null) { gameObject.transform.parent = rootObject; } } else { m_instance = Activator.CreateInstance(typeForCurrentPlatform); } IConfigurable configurable = m_instance as IConfigurable; if (configurable != null) { IDictionary <string, object> dictionaryForSystem = base.Configurator.GetDictionaryForSystem(GetTypeForCurrentPlatform()); configurable.Configure(dictionaryForSystem); } }
/// <summary> Build a SQLExceptionConverter instance. </summary> /// <param name="dialect">The defined dialect. </param> /// <param name="properties">The configuration properties. </param> /// <returns> An appropriate <see cref="ISQLExceptionConverter"/> instance. </returns> /// <remarks> /// First, looks for a <see cref="Cfg.Environment.SqlExceptionConverter"/> property to see /// if the configuration specified the class of a specific converter to use. If this /// property is set, attempt to construct an instance of that class. If not set, or /// if construction fails, the converter specific to the dialect will be used. /// </remarks> public static ISQLExceptionConverter BuildSQLExceptionConverter(Dialect.Dialect dialect, IDictionary <string, string> properties) { ISQLExceptionConverter converter = null; string converterClassName; properties.TryGetValue(Cfg.Environment.SqlExceptionConverter, out converterClassName); if (!string.IsNullOrEmpty(converterClassName)) { converter = ConstructConverter(converterClassName, dialect.ViolatedConstraintNameExtracter); } if (converter == null) { log.Info("Using dialect defined converter"); converter = dialect.BuildSQLExceptionConverter(); } IConfigurable confConv = converter as IConfigurable; if (confConv != null) { try { confConv.Configure(properties); } catch (HibernateException e) { log.Warn("Unable to configure SQLExceptionConverter", e); throw; } } return(converter); }
protected virtual void DoConfigureComponent(object instance) { if (instance is IConfigurable) { IConfigurable configurable = instance as IConfigurable; configurable.Configure(this); } }
//----------------------------------------------------------------- // Read the configuration files private async Task InitialConfig() { this.Configure(configManager); foreach (var tp in allTestPoints) { configManager.SetTestPoint(tp.TestPointName); await Task.Run(() => { IConfigurable configurableObject = tp as IConfigurable; if (configurableObject != null) { configurableObject.Configure(configManager); } if (tp.Tasks != null) { foreach (var tt in tp.Tasks) { configurableObject = tt as IConfigurable; if (configurableObject != null) { configurableObject.Configure(configManager); } tt.StatusHandle = progressHandler; } } }); } if (engineeringMode.Checked) { string id = ConfigurationManager.AppSettings["TestID"]; if (!string.IsNullOrEmpty(id)) { operatorId.Text = id; } string sn = ConfigurationManager.AppSettings["TestSN"]; if (!string.IsNullOrEmpty(sn)) { uutSerialNumber.Text = sn; } } operatorId.BackColor = Color.Yellow; }
internal static IRuleBuilderInitial <T, TElement> WithRuleId <T, TElement>(this IConfigurable <PropertyRule, IRuleBuilderInitial <T, TElement> > ruleBuilder, long ruleId) { return(ruleBuilder.Configure(c => { // Set rule type in context so it can be returned in error object foreach (var validator in c.Validators) { validator.CustomStateProvider = s => ruleId; } })); }
private static void Configure(TableIdGeneratorParams parameters, IConfigurable generator) { var parms = new Dictionary <string, string> { { TableGenerator.TableParamName, parameters.TableName }, { TableGenerator.ColumnParamName, parameters.ColumnName }, { TableHiLoGenerator.MaxLo, parameters.InMemoryIncrementSize.ToString() } }; generator.Configure(parameters.ColumnType, parms, parameters.Dialect); }
public static TNext UseFullPropertyName <TConfiguration, TNext>( this IConfigurable <TConfiguration, TNext> @this) where TConfiguration : PropertyRule { return(@this.Configure(cfg => { cfg.MessageBuilder = context => { context.MessageFormatter.AppendPropertyName(context.PropertyName); return context.GetDefaultMessage(); }; })); }
static void configureElements() { const string progressText = "Configuring network elements."; ProgressLogger.Starting(progressText); foreach (Identificable identificable in identificables.Values) { IConfigurable configurable = identificable as IConfigurable; if (configurable != null) { Logger.Log(identificable, "Configuring."); configurable.Configure(); } } ProgressLogger.Finished(progressText); }
/// <summary> /// Creates an <see cref="IIdentifierGenerator"/> from the named strategy. /// </summary> /// <param name="strategy"> /// The name of the generator to create. This can be one of the NHibernate abbreviations (ie - <c>native</c>, /// <c>sequence</c>, <c>guid.comb</c>, etc...), a full class name if the Type is in the NHibernate assembly, or /// a full type name if the strategy is in an external assembly. /// </param> /// <param name="type">The <see cref="IType"/> that the retured identifier should be.</param> /// <param name="parms">An <see cref="IDictionary"/> of <c><param></c> values from the mapping.</param> /// <param name="dialect">The <see cref="Dialect.Dialect"/> to help with Configuration.</param> /// <returns> /// An instantiated and configured <see cref="IIdentifierGenerator"/>. /// </returns> /// <exception cref="MappingException"> /// Thrown if there are any exceptions while creating the <see cref="IIdentifierGenerator"/>. /// </exception> public static IIdentifierGenerator Create(string strategy, IType type, IDictionary parms, Dialect.Dialect dialect) { try { System.Type clazz = (System.Type)idgenerators[strategy]; if ("native".Equals(strategy)) { if (dialect.SupportsIdentityColumns) { clazz = typeof(IdentityGenerator); } else if (dialect.SupportsSequences) { clazz = typeof(SequenceGenerator); } else { clazz = typeof(TableHiLoGenerator); } } if (clazz == null) { clazz = ReflectHelper.ClassForName(strategy); } IIdentifierGenerator idgen = ( IIdentifierGenerator )Activator.CreateInstance(clazz); // configure if the generator supports it. IConfigurable configurable = idgen as IConfigurable; if (configurable != null) { configurable.Configure(type, parms, dialect); } return(idgen); } catch (Exception e) { string message = "could not instantiate id generator"; if (strategy != null) { message += " for strategy '" + strategy + "'"; } throw new MappingException(message, e); } }
protected override TEntity DoCreateEntity() { Type t = typeof(TEntity); if (t.IsAssignableFrom(typeof(IConfigurable))) { //la configuracion no es del factory, es del componente. object output = Activator.CreateInstance(typeof(TEntity)); IConfigurable configurable = output as IConfigurable; configurable.Configure(this.InstanceConfiguration); return((TEntity)output); } else { ConstructorInfo[] info = t.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); Type c = null; foreach (var i in info) { var prms = i.GetParameters(); if (prms.Length == 1) { c = prms[0].ParameterType; break; } } if (c == null) { return((TEntity)Activator.CreateInstance(typeof(TEntity))); } else { object instanceConfig = this.InstanceConfiguration.GetConfiguration(c); object output = Activator.CreateInstance(typeof(TEntity), instanceConfig); return((TEntity)output); } } }
private void AddConfiguredServices() { foreach (ServiceElement service in Configuration.Services) { Type registerAs = service.ServiceType ?? service.InstanceType; if (rootWorkItem.Services.Get(registerAs) != null) { rootWorkItem.Services.Remove(registerAs); } object serviceinstance = rootWorkItem.Services.AddNew(service.InstanceType, registerAs); IConfigurable tmpConfigurable = serviceinstance as IConfigurable; if (tmpConfigurable != null) { tmpConfigurable.Configure(service.Parameters); } } }
public void configure() { // shortcut to resource library var reslib = PartResourceLibrary.Instance.resourceDefinitions; // reset extra cost and mass extra_cost = 0.0; extra_mass = 0.0; // find modules unlocked by tech unlocked = new List <ConfigureSetup>(); foreach (ConfigureSetup setup in setups) { // if unlocked if (setup.tech.Length == 0 || Lib.HasTech(setup.tech)) { // unlock unlocked.Add(setup); } } // make sure configuration include all available slots // this also create default configuration // - we don it only in the editor // - we avoid corner case when cfg was never set up (because craft was never in VAB) if (Lib.IsEditor() || selected.Count == 0) { while (selected.Count < Math.Min(slots, (uint)unlocked.Count)) { selected.Add(unlocked.Find(k => selected.IndexOf(k.name) == -1).name); } } // for each setup foreach (ConfigureSetup setup in setups) { // detect if the setup is selected bool active = selected.Contains(setup.name); // detect if the setup was previously selected bool prev_active = prev_selected.Contains(setup.name); // for each module specification in the setup foreach (ConfigureModule cm in setup.modules) { // try to find the module PartModule m = find_module(cm); // if the module exist if (m != null) { // call configure/deconfigure functions on module if available IConfigurable configurable_module = m as IConfigurable; if (configurable_module != null) { configurable_module.Configure(active); } // enable/disable the module m.isEnabled = active; m.enabled = active; } } // for each resource specification in the setup foreach (ConfigureResource cr in setup.resources) { // ignore non-existing resources if (!reslib.Contains(cr.name)) { continue; } // get resource unit cost double unit_cost = reslib[cr.name].unitCost; // parse resource amount and capacity double amount = Lib.Parse.ToDouble(cr.amount); double capacity = Lib.Parse.ToDouble(cr.maxAmount); // (de)install resource if ((prev_active != (active && capacity > 0.0)) || (reconfigure_cs && initialized)) { // if previously selected if (prev_active) { // remove the resources Lib.RemoveResource(part, cr.name, amount, capacity); } // if selected if (active && capacity > 0.0) { // add the resources // - in flight, do not add amount Lib.AddResource(part, cr.name, Lib.IsFlight() ? 0.0 : amount, capacity); } } // add resource cost if (active) { extra_cost += amount * unit_cost; } } // add setup extra cost and mass if (active) { extra_cost += setup.cost; extra_mass += setup.mass; } } // remember previously selected setups prev_selected.Clear(); foreach (string s in selected) { prev_selected.Add(s); } // save configuration WriteArchive archive = new WriteArchive(); archive.save(selected.Count); foreach (string s in selected) { archive.save(s); } cfg = archive.serialize(); // save previous configuration archive = new WriteArchive(); archive.save(prev_selected.Count); foreach (string s in prev_selected) { archive.save(s); } prev_cfg = archive.serialize(); // in the editor if (Lib.IsEditor()) { // for each part in the symmetry group (avoid infinite recursion) if (!avoid_inf_recursion) { avoid_inf_recursion = true; foreach (Part p in part.symmetryCounterparts) { // get the Configure module Configure c = p.FindModulesImplementing <Configure>().Find(k => k.title == title); // both modules will share configuration c.selected = selected; // re-configure the other module c.configure(); } avoid_inf_recursion = false; } } // refresh this part ui MonoUtilities.RefreshContextWindows(part); // refresh VAB ui if (Lib.IsEditor()) { GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } // this was configured at least once initialized = true; }
void ConfigureTarget(IConfigurable target) { target.Configure(config); }
internal static IRuleBuilderInitial <Vacancy, TElement> RunCondition <TElement>(this IConfigurable <PropertyRule, IRuleBuilderInitial <Vacancy, TElement> > ruleBuilder, VacancyRuleSet condition) { return(ruleBuilder.Configure(c => c.ApplyCondition(context => context.CanRunValidator(condition), ApplyConditionTo.AllValidators))); }