public void LoadSettingsFrom(List <SettingEntityModel> settings) { if (this.step != null) { this.settings = new List <SettingEntityModel>(); string[] settingNames = this.step.SettingNames.Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries); foreach (string settingName in settingNames) { var models = from setting in settings where setting.SettingName.Equals(settingName) select setting; SettingEntityModel model = models.FirstOrDefault(); if (model != null) { this.settings.Add(model); model.Update(); } } } else { this.settings = settings; foreach (SettingEntityModel model in this.settings) { model.Update(); } } }
/// <summary> /// Handles the CellEndEdit event of the dgvSettings control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DataGridViewCellEventArgs" /> instance containing the event data.</param> private void dgvSettings_CellEndEdit(object sender, DataGridViewCellEventArgs e) { ExcelDataGridView edgv = sender as ExcelDataGridView; SettingEntityModel model = edgv.Rows[e.RowIndex].DataBoundItem as SettingEntityModel; if (model != null) { model.Update(); } }
/// <summary> /// Assigns the values to argument object. /// </summary> /// <param name="argumentObject">The argument object.</param> /// <param name="optionName">Name of the option.</param> /// <param name="argPairs">The argument pairs.</param> /// <param name="attrs">The attributes.</param> /// <exception cref="System.ArgumentException">parameter: + pair.Key + is not defined in the argument object</exception> private static void AssignValuesToArgumentObject(object argumentObject, string optionName, List <KeyValuePair <string, string> > argPairs, Dictionary <string, ArgumentParameterAttribute> attrs) { foreach (var pair in argPairs) { if (!attrs.ContainsKey(pair.Key)) { throw new ArgumentException("parameter:" + pair.Key + " is not defined in the argumentobject"); } try { SettingEntityModel setting = SettingEntityModel.GetSingle(pair.Key); setting.SettingValue = pair.Value; setting.Update(); ////SetValue(argumentObject, attrs[pair.Key], pair.Value); } catch (ArgumentException ae) { throw new ArgumentException(string.Format( "Failed to set value to ArgumentObject.{0} from parameter:{1} value:{2}. Detail Message:{3}", attrs[pair.Key].PropertyInfo.Name, pair.Key, pair.Value.SafeToString(), ae.Message)); } } // SaveAll may fail in the multi-thread case. //SettingEntityModel.SaveAll(); // set default value /* * foreach (var attr in attrs.Values) * { * if (attr.SetCount < attr.MinOccur) * { * throw new ArgumentException(string.Format("parameter:{0} has been set for {1} times, but min={2}", * attr.ParameterName, * attr.SetCount, * attr.MinOccur)); * } * if (attr.SetCount == 0 && attr.DefaultValue != null) * { * attr.PropertyInfo.SetValue(argumentObject, attr.DefaultValue, null); * } * }*/ }