public AddParameterToLinkedParameters(List<ILinkedParameter> linkedParameters, ILinkedParameter linkedParameter, IModuleParameter parameter) { if ( linkedParameters == null ) throw new ArgumentNullException( "linkedParameters" ); this.LinkedParameters = linkedParameters; this.LinkedParameter = linkedParameter; this.Parameter = parameter; }
private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure mss, IModelSystemStructure newMSS) { if ( mss == p.BelongsTo ) { foreach ( var param in newMSS.Parameters.Parameters ) { if ( param.Name == p.Name ) { return param; } } return null; } var list = mss.Children; var newList = newMSS.Children; if ( list == null | newList == null ) { return null; } for ( int i = 0; i < list.Count; i++ ) { var ret = GetCorrespondingParameter( p, list[i], newList[i] ); if ( ret != null ) { return ret; } } return null; }
private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure mss, IModelSystemStructure newMSS) { if (mss == p.BelongsTo) { foreach (var param in newMSS.Parameters.Parameters) { if (param.Name == p.Name) { return(param); } } return(null); } var list = mss.Children; var newList = newMSS.Children; if (list == null | newList == null) { return(null); } for (int i = 0; i < list.Count; i++) { var ret = GetCorrespondingParameter(p, list[i], newList[i]); if (ret != null) { return(ret); } } return(null); }
private void lpContextMenu_SelectFileRequested(IModuleParameter parameter) { var module = parameter.BelongsTo; var currentRoot = this.GetRoot(module); var inputDirectory = GetInputDirectory(currentRoot); if (inputDirectory != null) { string fileName = this.OpenFile(); if (fileName == null) { return; } TransformToRelativePath(inputDirectory, ref fileName); if (this.AddCommand(new Commands.Editing.ParameterChangeCommand(parameter, fileName, this.GetLinkParameters()))) { this.ParameterEditor.RefreshParameters(); this.QuickParameterControl.RefreshParameters(); this.Save(); } else { MessageBox.Show("Unable to set file name'" + fileName + "'!", "Unable set file name", MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Executes the specified parameters. /// </summary> /// <param name="params">The parameters.</param> public void Execute(IModuleParameter @params) { FileInfo fileInfo = new FileInfo(@params.Filename); if (fileInfo.Extension == ".jpg" || fileInfo.Extension == ".gif" || fileInfo.Extension == ".png") { System.Console.Write("Smashing image " + fileInfo.FullName); Bitmap img = new Bitmap(fileInfo.FullName); img.SetResolution(150, 150); switch (fileInfo.Extension) { case ".jpg": img.Save(fileInfo.FullName, ImageFormat.Jpeg); break; case ".gif": img.Save(fileInfo.FullName, ImageFormat.Gif); break; case ".png": img.Save(fileInfo.FullName, ImageFormat.Png); break; default: break; } System.Console.WriteLine("Done."); } }
private static string LookupName(IModuleParameter reference, IModelSystemStructure current) { var param = current.Parameters; if (param != null) { int index = param.Parameters.IndexOf(reference); if (index >= 0) { return(current.Parameters.Parameters[index].Name); } } var childrenList = current.Children; if (childrenList != null) { for (int i = 0; i < childrenList.Count; i++) { var res = LookupName(reference, childrenList[i]); if (res != null) { // make sure to use an escape character before the . to avoid making the mistake of reading it as another index return(string.Concat(current.IsCollection ? i.ToString() : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res)); } } } return(null); }
private static void AssignValueNoTypeCheck <T>(IConfiguration config, IModuleParameter parameter, T t) { var currentStructure = parameter.BelongsTo; if (currentStructure == null) { throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter doesn't belong to any module!"); } if (currentStructure.Module == null) { // If any ancestors of the model system structure were disabled ignore this if (BuildModelStructureChain(config, currentStructure) .Any(mss => mss is IModelSystemStructure2 mss2 && mss2.IsDisabled)) { return; } throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The currentstructure.Module was null!"); } parameter.Value = t; var type = currentStructure.Module.GetType(); if (parameter.OnField) { var field = type.GetField(parameter.VariableName); field.SetValue(currentStructure.Module, t); } else { var field = type.GetProperty(parameter.VariableName); field.SetValue(currentStructure.Module, t, null); } }
public static void AssignValue <T>(IConfiguration config, IModuleParameter parameter, T t) { if (parameter.Type != typeof(T)) { throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter " + parameter.Name + " was not of type " + typeof(T).FullName + "!"); } AssignValueNoTypeCheck(config, parameter, t); }
public ParameterChangeCommand(IModuleParameter parameter, string newValue, List<ILinkedParameter> linkedParameters) { this.Before = parameter.Value.ToString(); this.AttachedParameter = parameter; this.After = newValue; this.LinkedParameters = linkedParameters; this.ContainedIn = null; }
public ParameterChangeCommand(IModuleParameter parameter, string newValue, List <ILinkedParameter> linkedParameters) { this.Before = parameter.Value.ToString(); this.AttachedParameter = parameter; this.After = newValue; this.LinkedParameters = linkedParameters; this.ContainedIn = null; }
public ModelParameterProxy(IModuleParameter realParam, List <ILinkedParameter> linkedParameters) { this.RealParameter = realParam; if (realParam.BelongsTo != null) { this.ModuleName = realParam.BelongsTo.Name; } else { this.ModuleName = null; } this.Name = realParam.Name; if (realParam.Value == null) { FixType(realParam); } else { this.Type = realParam.Type; } this.Description = realParam.Description; this.Quick = this.TempQuick = realParam.QuickParameter; this.ToolTipText = this.Name + " : " + this.ModuleName; if (this.Type == typeof(DateTime)) { DateTime v = (DateTime)realParam.Value; this.Value = v.ToShortTimeString(); } else { this.Value = realParam.Value.ToString(); } if (linkedParameters != null) { bool found = false; // check to see if it is in a linked parameter for (int i = 0; i < linkedParameters.Count; i++) { if (linkedParameters[i] != null) { for (int j = 0; j < linkedParameters[i].Parameters.Count; j++) { if (linkedParameters[i].Parameters[j] == realParam) { this.LinkedParameter = linkedParameters[i].Name; found = true; break; } } if (found) { break; } } } } this.TempValue = this.Value; }
public ModelParameterProxy(IModuleParameter realParam, List<ILinkedParameter> linkedParameters) { this.RealParameter = realParam; if ( realParam.BelongsTo != null ) { this.ModuleName = realParam.BelongsTo.Name; } else { this.ModuleName = null; } this.Name = realParam.Name; if ( realParam.Value == null ) { FixType( realParam ); } else { this.Type = realParam.Type; } this.Description = realParam.Description; this.Quick = this.TempQuick = realParam.QuickParameter; this.ToolTipText = this.Name + " : " + this.ModuleName; if ( this.Type == typeof( DateTime ) ) { DateTime v = (DateTime)realParam.Value; this.Value = v.ToShortTimeString(); } else { this.Value = realParam.Value.ToString(); } if ( linkedParameters != null ) { bool found = false; // check to see if it is in a linked parameter for ( int i = 0; i < linkedParameters.Count; i++ ) { if ( linkedParameters[i] != null ) { for ( int j = 0; j < linkedParameters[i].Parameters.Count; j++ ) { if ( linkedParameters[i].Parameters[j] == realParam ) { this.LinkedParameter = linkedParameters[i].Name; found = true; break; } } if ( found ) { break; } } } } this.TempValue = this.Value; }
/// <summary> /// Remove a parameter from this linked parameter /// </summary> /// <param name="parameter">The parameter to remove</param> /// <returns>If we removed it from this linked parameter. /// If it is not contained, it will return false!</returns> public bool Remove(IModuleParameter parameter, ref string error) { if (!this.Parameters.Remove(parameter)) { error = "The parameter '" + parameter.Name + "' was not contained within '" + this.Name + "'!"; return(false); } return(true); }
public AddParameterToLinkedParameters(List <ILinkedParameter> linkedParameters, ILinkedParameter linkedParameter, IModuleParameter parameter) { if (linkedParameters == null) { throw new ArgumentNullException("linkedParameters"); } this.LinkedParameters = linkedParameters; this.LinkedParameter = linkedParameter; this.Parameter = parameter; }
private void FixType(IModuleParameter realParam) { var moduleType = realParam.BelongsTo.Type; if (SearchFields(moduleType, realParam.Name)) { return; } SearchProperties(moduleType, realParam.Name); }
internal ParameterModel GetParameterModel(IModuleParameter moduleParameter) { var owner = GetModelFor(moduleParameter.BelongsTo as ModelSystemStructure); if (owner != null) { return(GetParameterModel(owner, moduleParameter)); } return(null); }
public bool RuntimeValidation(ref string error) { _parameter = Functions.ModelSystemReflection.FindParameter(_config, this, ParameterPath); if (_parameter == null) { error = "In '" + Name + "' we were unable to find a parameter with the path '" + ParameterPath + "'!"; return(false); } return(true); }
private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter) { var parameters = owner.Parameters.Parameters; if (parameters != null) { for (int i = 0; i < parameters.Count; i++) { if (parameters[i].RealParameter == moduleParameter) { return(parameters[i]); } } } return(null); }
private static void LoadParameters(IModelSystemStructure modelSystemStructure, XmlNode child, Dictionary <int, Type> lookUp) { if (child.HasChildNodes) { foreach (XmlNode paramChild in child.ChildNodes) { if (paramChild.Name == "Param") { var paramNameAttribute = paramChild.Attributes["Name"]; var paramTIndexAttribute = paramChild.Attributes["TIndex"]; var paramTypeAttribute = paramChild.Attributes["Type"]; var paramValueAttribute = paramChild.Attributes["Value"]; var paramQuickParameterAttribute = paramChild.Attributes["QuickParameter"]; if (paramNameAttribute != null || paramTypeAttribute != null || paramValueAttribute != null) { string name = paramNameAttribute.InnerText; if (modelSystemStructure.Parameters != null) { IModuleParameter selectedParam = null; foreach (var p in modelSystemStructure.Parameters) { if (p.Name == name) { selectedParam = p; break; } } // we will just ignore parameters that no longer exist if (selectedParam != null) { if (paramQuickParameterAttribute != null) { bool quick; if (bool.TryParse(paramQuickParameterAttribute.InnerText, out quick)) { selectedParam.QuickParameter = quick; } } AssignTypeValue(paramTIndexAttribute, paramTypeAttribute, paramValueAttribute, selectedParam, lookUp); } } } } } } }
private void ParameterUpdate(IModuleParameter parameter, string newValue) { List <ILinkedParameter> linkedParameters = null; if (_Project != null) { if (this._Project.LinkedParameters != null) { linkedParameters = this._Project.LinkedParameters[this._Project.ModelSystemStructure.IndexOf(this.Root)]; } } else { linkedParameters = this.ModelSystem.LinkedParameters; } this.AddCommand(new ParameterChangeCommand(parameter, newValue, linkedParameters)); }
public static void AssignValue(IConfiguration config, IModuleParameter parameter, string value) { string error = null; object trueValue; if (parameter == null) { throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter was null!"); } if ((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null) { AssignValueNoTypeCheck(config, parameter, trueValue); } else { throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name); } }
public static void AssignValue(IModuleParameter parameter, string value) { string error = null; object trueValue; if (parameter == null) { throw new XTMFRuntimeException("The parameter was null!"); } var currentStructure = parameter.BelongsTo; if (currentStructure == null) { throw new XTMFRuntimeException("The parameter doesn't belong to any module!"); } if (value == null) { throw new XTMFRuntimeException("The value was null!"); } if (currentStructure.Module == null) { throw new XTMFRuntimeException("The currentstructure.Module was null!"); } if ((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null) { parameter.Value = trueValue; var type = currentStructure.Module.GetType(); if (parameter.OnField) { var field = type.GetField(parameter.VariableName); field.SetValue(currentStructure.Module, trueValue); } else { var field = type.GetProperty(parameter.VariableName); field.SetValue(currentStructure.Module, trueValue, null); } } else { throw new XTMFRuntimeException("We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name); } }
private void OpenFile(IModuleParameter parameter, bool openWith, bool openDirectory) { var module = parameter.BelongsTo; var parameterValue = parameter.Value.ToString(); var currentRoot = this.GetRoot(module); var inputDirectory = GetInputDirectory(currentRoot); if (inputDirectory != null) { var fileName = this.GetRelativePath(inputDirectory, parameterValue); if (openDirectory) { openWith = false; fileName = System.IO.Path.GetDirectoryName(fileName); } try { Process toRun = new Process(); if (openWith) { toRun.StartInfo.FileName = "Rundll32.exe"; toRun.StartInfo.Arguments = "Shell32.dll,OpenAs_RunDLL " + fileName; } else { toRun.StartInfo.FileName = fileName; } toRun.Start(); } catch { MessageBox.Show("Unable to load file '" + fileName + "'!", "Unable to open", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Unable to find input directory.", "Unable to open", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void AssignValue(IModuleParameter parameter, string value) { string error = null; object trueValue; if(parameter == null) { throw new XTMFRuntimeException("The parameter was null!"); } var currentStructure = parameter.BelongsTo; if(currentStructure == null) { throw new XTMFRuntimeException("The parameter doesn't belong to any module!"); } if(value == null) { throw new XTMFRuntimeException("The value was null!"); } if(currentStructure.Module == null) { throw new XTMFRuntimeException("The currentstructure.Module was null!"); } if((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null) { parameter.Value = trueValue; var type = currentStructure.Module.GetType(); if(parameter.OnField) { var field = type.GetField(parameter.VariableName); field.SetValue(currentStructure.Module, trueValue); } else { var field = type.GetProperty(parameter.VariableName); field.SetValue(currentStructure.Module, trueValue, null); } } else { throw new XTMFRuntimeException("We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name); } }
/// <summary> /// Add a new parameter to this linkedParameter set /// </summary> /// <param name="parameter">The parameter to add</param> /// <returns>If we were able to add the parameter</returns> public bool Add(IModuleParameter parameter, ref string error) { // you can't have the same parameter multiple times! if ( parameter == null ) { error = "The parameter does not exist!"; return false; } if ( this.Parameters.Contains( parameter ) ) { error = "The parameter '" + parameter.Name + "' already exists within the linked parameter '" + this.Name + "'."; return false; } var value = ArbitraryParameterParser.ArbitraryParameterParse( parameter.Type, this.Value, ref error ); if ( value == null ) { return false; } parameter.Value = value; this.Parameters.Add( parameter ); return true; }
/// <summary> /// Add a new parameter to this linkedParameter set /// </summary> /// <param name="parameter">The parameter to add</param> /// <returns>If we were able to add the parameter</returns> public bool Add(IModuleParameter parameter, ref string error) { // you can't have the same parameter multiple times! if (parameter == null) { error = "The parameter does not exist!"; return(false); } if (this.Parameters.Contains(parameter)) { error = "The parameter '" + parameter.Name + "' already exists within the linked parameter '" + this.Name + "'."; return(false); } var value = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, this.Value, ref error); if (value == null) { return(false); } parameter.Value = value; this.Parameters.Add(parameter); return(true); }
private void lpContextMenu_OpenFileLocationRequested(IModuleParameter parameter) { OpenFile(parameter, false, true); }
private void lpContextMenu_AddToLinkedParameterRequested(ILinkedParameter linkedParameter, IModuleParameter parameter) { string error = null; if(parameter == null) { MessageBox.Show("No parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if(linkedParameter == null) { MessageBox.Show("No linked parameter parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if(!this.AddCommand(new AddParameterToLinkedParameters(this.GetLinkParameters(), linkedParameter, parameter), ref error)) { MessageBox.Show(error, "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); } this.ParameterEditor.RefreshParameters(); // this will actually refresh everything this.QuickParameterControl_ParameterChanged(); }
private bool LinkedParameterEditor_RemoveLinkedParameterParameter(ILinkedParameter lp, IModuleParameter param) { if(!this.AddCommand(new RemoveParameterFromLinkedParameter(lp, param))) { return false; } this.ParameterEditor.RefreshParameters(); this.Save(); return true; }
internal ParameterModel GetParameterModel(IModuleParameter moduleParameter) { var owner = GetModelFor(moduleParameter.BelongsTo as ModelSystemStructure); if(owner != null) { return GetParameterModel(owner, moduleParameter); } return null; }
private List <ILinkedParameter> LoadLinkedParameters(ModelSystemStructure root, Stream stream) { var ret = new List <ILinkedParameter>(); string error = null; using (XmlReader reader = XmlReader.Create(stream)) { bool skipRead = false; while (!reader.EOF && (skipRead || reader.Read())) { skipRead = false; if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.LocalName) { case "LinkedParameter": { string linkedParameterName = "Unnamed"; string valueRepresentation = null; var startingDepth = reader.Depth; while (reader.MoveToNextAttribute()) { if (reader.NodeType == XmlNodeType.Attribute) { if (reader.LocalName == "Name") { linkedParameterName = reader.ReadContentAsString(); } else if (reader.LocalName == "Value") { valueRepresentation = reader.ReadContentAsString(); } } } LinkedParameter lp = new LinkedParameter(linkedParameterName); lp.SetValue(valueRepresentation, ref error); ret.Add(lp); skipRead = true; while (reader.Read()) { if (reader.Depth <= startingDepth) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } if (reader.LocalName == "Reference") { string variableLink = null; while (reader.MoveToNextAttribute()) { if (reader.Name == "Name") { variableLink = reader.ReadContentAsString(); } } if (variableLink != null) { IModuleParameter param = GetParameterFromLink(variableLink, root); if (param != null) { // in any case if there is a type error, just throw it out lp.Add(param, ref error); } } } } } break; } } } return(ret); }
private static void AssignTypeValue(XmlAttribute paramTIndex, XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam, Dictionary<int, Type> lookUp) { string error = null; var temp = ArbitraryParameterParser.ArbitraryParameterParse(selectedParam.Type, paramValueAttribute.InnerText, ref error); if(temp != null) { // don't overwrite the default if we are loading something bad selectedParam.Value = temp; } }
private void OpenFile(IModuleParameter parameter, bool openWith, bool openDirectory) { var module = parameter.BelongsTo; var parameterValue = parameter.Value.ToString(); var currentRoot = this.GetRoot(module); var inputDirectory = GetInputDirectory(currentRoot); if(inputDirectory != null) { var fileName = this.GetRelativePath(inputDirectory, parameterValue); if(openDirectory) { openWith = false; fileName = System.IO.Path.GetDirectoryName(fileName); } try { Process toRun = new Process(); if(openWith) { toRun.StartInfo.FileName = "Rundll32.exe"; toRun.StartInfo.Arguments = "Shell32.dll,OpenAs_RunDLL " + fileName; } else { toRun.StartInfo.FileName = fileName; } toRun.Start(); } catch { MessageBox.Show("Unable to load file '" + fileName + "'!", "Unable to open", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Unable to find input directory.", "Unable to open", MessageBoxButton.OK, MessageBoxImage.Error); } }
private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure newMSS) { return GetCorrespondingParameter( p, this.ModelSystem.ModelSystemStructure, newMSS ); }
private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure oldMSS) { return GetCorrespondingParameter( p, oldMSS, this.GeneratedModelSystem.ModelSystemStructure ); }
private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter) { var parameters = owner.Parameters.Parameters; if(parameters != null) { for(int i = 0; i < parameters.Count; i++) { if(parameters[i].RealParameter == moduleParameter) { return parameters[i]; } } } return null; }
private void lpContextMenu_OpenFileWithRequested(IModuleParameter parameter) { OpenFile(parameter, true, false); }
public RemoveParameterFromLinkedParameter(ILinkedParameter linkedParameter, IModuleParameter parameter) { this.LinkedParameter = linkedParameter; this.Parameter = parameter; }
private void lpContextMenu_SelectFileRequested(IModuleParameter parameter) { var module = parameter.BelongsTo; var currentRoot = this.GetRoot(module); var inputDirectory = GetInputDirectory(currentRoot); if(inputDirectory != null) { string fileName = this.OpenFile(); if(fileName == null) { return; } TransformToRelativePath(inputDirectory, ref fileName); if(this.AddCommand(new Commands.Editing.ParameterChangeCommand(parameter, fileName, this.GetLinkParameters()))) { this.ParameterEditor.RefreshParameters(); this.QuickParameterControl.RefreshParameters(); this.Save(); } else { MessageBox.Show("Unable to set file name'" + fileName + "'!", "Unable set file name", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private string LookupName(IModuleParameter reference) { return LookupName(reference, ModelSystemStructure); }
private void ParameterUpdate(IModuleParameter parameter, string newValue) { List<ILinkedParameter> linkedParameters = null; if(_Project != null) { if(this._Project.LinkedParameters != null) { linkedParameters = this._Project.LinkedParameters[this._Project.ModelSystemStructure.IndexOf(this.Root)]; } } else { linkedParameters = this.ModelSystem.LinkedParameters; } this.AddCommand(new ParameterChangeCommand(parameter, newValue, linkedParameters)); }
private void LoadFromStream(Stream stream, IConfiguration config, ref string error) { if (_LinkedParameters == null) { _LinkedParameters = new List <ILinkedParameter>(); } else { _LinkedParameters.Clear(); } ModelSystemStructure = XTMF.ModelSystemStructure.Load(stream, config); ModelSystemStructure.Required = true; // restart to get to the linked parameters stream.Seek(0, SeekOrigin.Begin); using (XmlReader reader = XmlReader.Create(stream)) { bool skipRead = false; while (!reader.EOF && (skipRead || reader.Read())) { skipRead = false; if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.LocalName) { case "LinkedParameter": { string linkedParameterName = "Unnamed"; string valueRepresentation = null; var startingDepth = reader.Depth; while (reader.MoveToNextAttribute()) { if (reader.NodeType == XmlNodeType.Attribute) { if (reader.LocalName == "Name") { linkedParameterName = reader.ReadContentAsString(); } else if (reader.LocalName == "Value") { valueRepresentation = reader.ReadContentAsString(); } } } LinkedParameter lp = new LinkedParameter(linkedParameterName); lp.SetValue(valueRepresentation, ref error); _LinkedParameters.Add(lp); skipRead = true; while (reader.Read()) { if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } if (reader.LocalName == "Reference") { string variableLink = null; while (reader.MoveToNextAttribute()) { if (reader.Name == "Name") { variableLink = reader.ReadContentAsString(); } } if (variableLink != null) { IModuleParameter param = GetParameterFromLink(variableLink); if (param != null) { // in any case if there is a type error, just throw it out lp.Add(param, ref error); } } } } } break; case "Description": { bool textLast = false; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { textLast = true; break; } if (reader.NodeType == XmlNodeType.Element) { skipRead = true; break; } } if (textLast) { Description = reader.ReadContentAsString(); } } break; } } } }
private static void BackupTypeLoader(XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam) { switch(paramTypeAttribute.InnerText) { case "System.String": { selectedParam.Value = paramValueAttribute.InnerText; } break; case "System.Int32": { Int32 temp; if(Int32.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Int64": { Int64 temp; if(Int64.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.DateTime": { DateTime temp; if(DateTime.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Single": { Single temp; if(Single.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Double": { Double temp; if(Double.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Boolean": { bool temp; if(Boolean.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Char": { char temp; if(Char.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; default: { //TODO: Unable to load a type we don't know about, should add this to a Log entry or something } break; } }
private static void AssignTypeValue(XmlAttribute paramTIndex, XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam, Dictionary <int, Type> lookUp) { string error = null; var temp = ArbitraryParameterParser.ArbitraryParameterParse(selectedParam.Type, paramValueAttribute.InnerText, ref error); if (temp != null) { // don't overwrite the default if we are loading something bad selectedParam.Value = temp; } }
private void Load(IConfiguration config, string name) { if (name != null) { var fileName = Path.Combine(Config.ModelSystemDirectory, name + ".xml"); if (_LinkedParameters == null) { _LinkedParameters = new List <ILinkedParameter>(); } else { _LinkedParameters.Clear(); } try { ModelSystemStructure = XTMF.ModelSystemStructure.Load(fileName, config); using (XmlReader reader = XmlReader.Create(fileName)) { bool skipRead = false; while (!reader.EOF && (skipRead || reader.Read())) { skipRead = false; if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.LocalName) { case "LinkedParameter": { string linkedParameterName = "Unnamed"; string valueRepresentation = null; var startingDepth = reader.Depth; while (reader.MoveToNextAttribute()) { if (reader.NodeType == XmlNodeType.Attribute) { if (reader.LocalName == "Name") { linkedParameterName = reader.ReadContentAsString(); } else if (reader.LocalName == "Value") { valueRepresentation = reader.ReadContentAsString(); } } } LinkedParameter lp = new LinkedParameter(linkedParameterName); string error = null; lp.SetValue(valueRepresentation, ref error); _LinkedParameters.Add(lp); skipRead = true; while (reader.Read()) { if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } if (reader.LocalName == "Reference") { string variableLink = null; while (reader.MoveToNextAttribute()) { if (reader.Name == "Name") { variableLink = reader.ReadContentAsString(); } } if (variableLink != null) { IModuleParameter param = GetParameterFromLink(variableLink); if (param != null) { // in any case if there is a type error, just throw it out lp.Add(param, ref error); } } } } } break; case "Description": { bool textLast = false; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { textLast = true; break; } else if (reader.NodeType == XmlNodeType.Element) { skipRead = true; break; } } if (textLast) { Description = reader.ReadContentAsString(); } } break; } } } } catch { Description = string.Empty; if (_ModelSystemStructure == null) { _ModelSystemStructure = new ModelSystemStructure(Config, Name, typeof(IModelSystemTemplate)); _ModelSystemStructure.Required = true; } else { _ModelSystemStructure.ParentFieldType = typeof(IModelSystemTemplate); _ModelSystemStructure.Required = true; } } } }
private string LookupName(IModuleParameter reference) { return(LookupName(reference, ModelSystemStructure)); }
private bool LinkedParameterEditor_RemoveLinkedParameterParameter(ILinkedParameter lp, IModuleParameter param) { if (!this.AddCommand(new RemoveParameterFromLinkedParameter(lp, param))) { return(false); } this.ParameterEditor.RefreshParameters(); this.Save(); return(true); }
private string LookupName(IModuleParameter reference, IModelSystemStructure current) { var param = current.Parameters; if (param != null) { int index = param.Parameters.IndexOf(reference); if (index >= 0) { return current.Parameters.Parameters[index].Name; } } var childrenList = current.Children; if (childrenList != null) { for (int i = 0; i < childrenList.Count; i++) { var res = LookupName(reference, childrenList[i]); if (res != null) { // make sure to use an escape character before the . to avoid making the mistake of reading it as another index return string.Concat(current.IsCollection ? i.ToString() : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res); } } } return null; }
private static void BackupTypeLoader(XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam) { switch (paramTypeAttribute.InnerText) { case "System.String": { selectedParam.Value = paramValueAttribute.InnerText; } break; case "System.Int32": { Int32 temp; if (Int32.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Int64": { Int64 temp; if (Int64.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.DateTime": { DateTime temp; if (DateTime.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Single": { Single temp; if (Single.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Double": { Double temp; if (Double.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Boolean": { bool temp; if (Boolean.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; case "System.Char": { char temp; if (Char.TryParse(paramValueAttribute.InnerText, out temp)) { selectedParam.Value = temp; } } break; default: { //TODO: Unable to load a type we don't know about, should add this to a Log entry or something } break; } }
private void lpContextMenu_AddToLinkedParameterRequested(ILinkedParameter linkedParameter, IModuleParameter parameter) { string error = null; if (parameter == null) { MessageBox.Show("No parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (linkedParameter == null) { MessageBox.Show("No linked parameter parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!this.AddCommand(new AddParameterToLinkedParameters(this.GetLinkParameters(), linkedParameter, parameter), ref error)) { MessageBox.Show(error, "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning); } this.ParameterEditor.RefreshParameters(); // this will actually refresh everything this.QuickParameterControl_ParameterChanged(); }
/// <summary> /// Remove a parameter from this linked parameter /// </summary> /// <param name="parameter">The parameter to remove</param> /// <returns>If we removed it from this linked parameter. /// If it is not contained, it will return false!</returns> public bool Remove(IModuleParameter parameter, ref string error) { if ( !this.Parameters.Remove( parameter ) ) { error = "The parameter '" + parameter.Name + "' was not contained within '" + this.Name + "'!"; return false; } return true; }
private void FixType(IModuleParameter realParam) { var moduleType = realParam.BelongsTo.Type; if ( SearchFields( moduleType, realParam.Name ) ) { return; } SearchProperties( moduleType, realParam.Name ); }