public bool Do(ref string error) { this.OldRoot = this.ModelSystem.ModelSystemStructure; this.ModelSystem.ModelSystemStructure = this.NewRoot; this.UpdateRoot( this.NewRoot ); return true; }
private void RebuildQuickParameters(IModelSystemStructure current) { var parameters = current.Parameters; if (parameters != null) { foreach (var par in parameters) { if (par.QuickParameter) { this.QuickParameters.Add(par); } } } IList <IModelSystemStructure> desc = current.Children; if (desc == null) { return; } foreach (var child in desc) { this.RebuildQuickParameters(child); } }
private void AddMultiRunCommand() { var listToUs = ModelSystemReflection.BuildModelStructureChain(Config, this); for (int i = listToUs.Count - 1; i >= 0; i--) { var multiRunFramework = listToUs[i].Module as MultiRun.MultiRunModelSystem; if (multiRunFramework != null) { multiRunFramework.TryAddBatchCommand("LaunchProgram.ShutdownExternalProgram", (node) => { var path = multiRunFramework.GetAttributeOrError(node, "Path", "In 'LaunchProgram.ShutdownExternalProgram' we were unable to find an xml attribute called 'Path'!\r\nPlease add this to your batch script."); IModelSystemStructure selectedModule = null; IModelSystemStructure multiRunFrameworkChild = null; if (!ModelSystemReflection.FindModuleStructure(Config, multiRunFramework.Child, ref multiRunFrameworkChild)) { throw new XTMFRuntimeException("We were unable to find the multi-run frameworks child module's model system structure!"); } if (!ModelSystemReflection.GetModelSystemStructureFromPath(multiRunFrameworkChild, path, ref selectedModule)) { throw new XTMFRuntimeException("We were unable to find a module with the path '" + path + "'!"); } var toShutdown = selectedModule.Module as LaunchProgram; if (toShutdown == null) { throw new XTMFRuntimeException("The module with the path '" + path + "' was not of type 'TMG.Frameworks.Extensibility.LaunchProgram'!"); } toShutdown.ShutdownProgram(); }, true); break; } } }
private BindingList <ModelParameterProxy> GetParameters(IModelSystemStructure mss) { BindingList <ModelParameterProxy> ret = new BindingList <ModelParameterProxy>(); if (this.ModuleChangedLast) { if (mss == null || mss.IsCollection || mss.Parameters == null) { return(ret); } var parameters = mss.Parameters.Parameters; for (int i = 0; i < parameters.Count; i++) { if (this.IsEditing | !parameters[i].SystemParameter) { ret.Add(new ModelParameterProxy(parameters[i], this.LinkedParameters)); } } } else { var parameters = this.Parameters; if (parameters == null) { return(ret); } for (int i = 0; i < parameters.Count; i++) { ret.Add(new ModelParameterProxy(parameters[i], this.LinkedParameters)); } } return(ret); }
public ModuleSwapCommand(List<ILinkedParameter> linkedParameters, IModelSystemStructure parent, int index, IModelSystemStructure newValue) : base(linkedParameters, parent.Children[index]) { this.Parent = parent; this.NewValue = newValue; this.Index = index; }
/// <summary> /// Create a new model system /// </summary> /// <param name="name">The name of the project</param> /// <param name="description">A description of the project</param> /// <param name="error">An error message string in case of an error</param> /// <returns>The model system that was created, null if there was an error</returns> public IModelSystem CreateModelSystem(string name, string description, IModelSystemStructure strucuture, List <ILinkedParameter> linkedParameters, ref string error) { var command = new XTMF.Commands.CreateNewModelSystem(this.Configuration, name, description, strucuture, linkedParameters); return(this.XTMFRuntime.ProcessCommand(command, ref error) ? command.GeneratedModelSystem : null); }
public SetProjectRootCommand(Action<IModelSystemStructure> updateRoot, IProject project, int index, IModelSystemStructure newRoot) { this.UpdateRoot = updateRoot; this.Project = project; this.Index = index; this.NewRoot = newRoot; }
private void AssignValue(string[] parts, int currentIndex, IModelSystemStructure currentStructure, float value) { if (currentIndex == parts.Length - 1) { AssignValue(parts[currentIndex], currentStructure, value, parts); return; } if (currentStructure.Children != null) { for (int i = 0; i < currentStructure.Children.Count; i++) { if (currentStructure.Children[i].Name == parts[currentIndex]) { if (currentStructure.Children[i] is IModelSystemStructure2 cs2 && cs2.IsDisabled) { continue; } AssignValue(parts, currentIndex + 1, currentStructure.Children[i], value); return; } } } throw new XTMFRuntimeException(this, "Unable to find a child module in '" + parts[currentIndex] + "' named '" + parts[currentIndex + 1] + "' in order to assign parameters! \r\n" + parts.Aggregate((previous, next) => previous + " " + next)); }
public bool RuntimeValidation(ref string error) { IModelSystemStructure ourStructure = null; foreach (var mst in XtmfConfig.ProjectRepository.ActiveProject.ModelSystemStructure) { if (FindUs(mst, ref ourStructure)) { foreach (var child in ourStructure.Children) { if (child.ParentFieldName == "MainClient") { ClientStructure = child; break; } } break; } } if (ClientStructure == null) { error = "In '" + Name + "' we were unable to find the Client Model System!"; return(false); } return(true); }
public bool RuntimeValidation(ref string error) { foreach (var mst in XtmfConfig.ProjectRepository.ActiveProject.ModelSystemStructure) { if (FindUs(mst, ref OurStructure)) { foreach (var child in OurStructure.Children) { if (child.ParentFieldName == "ClientModelSystem") { ClientStructure = child; break; } } break; } } if (OurStructure == null) { error = "In '" + Name + "' we were unable to find ourselves through XTMF inside of project " + XtmfConfig.ProjectRepository.ActiveProject.Name; return(false); } if (ClientStructure == null) { error = "In '" + Name + "' we were unable to find our client model system!"; return(false); } return(true); }
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 SetupParameters(IModelSystemStructure module) { this.ShowingParameters = true; if (module.Type != null || (!this.EditMode)) { this.ModuleNameDisplay.Text = module.Name; this.ModuleNameSpaceDisplay.Text = module.Type == null ? String.Empty : module.Type.FullName; this.OurTabPanel.SelectedIndex = this.OurTabPanel.Items.IndexOf(this.SettingsTab); } else { this.ModuleNameDisplay.Text = "No Module Selected"; this.ModuleNameSpaceDisplay.Text = String.Empty; this.OurTabPanel.SelectedIndex = this.OurTabPanel.Items.IndexOf(this.ModuleTab); } new Task(delegate() { SetupViableModules(module); this.Dispatcher.BeginInvoke(new Action(delegate() { if (this.ParameterEditor.ModelSystemStructure != module) { this.ParameterEditor.ModelSystemStructure = module; this.ParameterEditor.Opacity = 0f; } })); }).Start(); }
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); }
public SetProjectRootCommand(Action <IModelSystemStructure> updateRoot, IProject project, int index, IModelSystemStructure newRoot) { this.UpdateRoot = updateRoot; this.Project = project; this.Index = index; this.NewRoot = newRoot; }
private void WriteModule(IModelSystemStructure module, StreamWriter writer) { if (module.IsMetaModule) { return; } writer.WriteLine($"\"{module.Name}_{module.GetHashCode()}\" " + $"[shape=box," + $"label=<{module.Name}"); if (IncludeModuleType && module.Type != null) { writer.Write($"<BR/><FONT POINT-SIZE=\"10\">{module.Type}</FONT>"); } if (IncludeDescriptions && module.Type != null && !string.IsNullOrEmpty(module.Description)) { writer.Write($"<BR/><FONT POINT-SIZE=\"10\">{module.Description}</FONT>"); } writer.Write(">,"); writer.Write("]\r\n"); if (module.Children != null) { foreach (var childModule in module.Children) { WriteModule(childModule, writer); } } }
/// <summary> /// Clone the given model system with a new name /// </summary> /// <param name="root"></param> /// <param name="name"></param> /// <param name="error"></param> /// <returns></returns> public bool CloneModelSystemAs(IModelSystemStructure root, string name, ref string error) { lock (EditingSessionsLock) { var index = Project.ModelSystemStructure.IndexOf(root); if (index < 0) { error = "The model system was not found within the project!"; return(false); } // If it is currently being edited, save that version var editingSession = EditingSessions.FirstOrDefault(s => s.Session != null && s.Session.IsEditing(root)); if (editingSession.Session != null) { return(editingSession.Session.SaveAsModelSystem(name, ref error)); } else { List <ILinkedParameter> lp; var ms = Runtime.ModelSystemController.LoadOrCreate(name); ms.Name = name; ms.Description = Project.ModelSystemDescriptions[index]; ms.ModelSystemStructure = Project.CloneModelSystemStructure(out lp, index); ms.LinkedParameters = lp; return(ms.Save(ref error)); } } }
public bool Do(ref string error) { this.OldRoot = this.Project.ModelSystemStructure[this.Index]; this.Project.ModelSystemStructure[this.Index] = this.NewRoot; this.UpdateRoot( this.NewRoot ); return true; }
private void AssignValue(string variableName, IModelSystemStructure currentStructure, float value) { var parameters = currentStructure.Parameters.Parameters; for (int i = 0; i < parameters.Count; i++) { if (parameters[i].Name == variableName) { var type = currentStructure.Module.GetType(); if (parameters[i].OnField) { var field = type.GetField(parameters[i].VariableName); field.SetValue(currentStructure.Module, value); return; } else { var field = type.GetProperty(parameters[i].VariableName); field.SetValue(currentStructure.Module, value, null); return; } } } throw new XTMFRuntimeException(this, String.Format("In '{0}' we were unable to find a variable named '{1}' in '{2}'.", Name, variableName, currentStructure.Name)); }
/// <summary> /// Validate the model system before starting to execute it /// </summary> /// <param name="error">If there is an error, the error message will be stored in here</param> /// <param name="currentPoint">The current point through the tree we are testing</param> /// <returns></returns> private bool RunTimeValidation(ref string error, IModelSystemStructure currentPoint) { try { // if there is a module at this point if (currentPoint.Module != null) { if (!currentPoint.Module.RuntimeValidation(ref error)) { return(false); } } // check to see if there are descendants that need to be checked if (currentPoint.Children != null) { foreach (var module in currentPoint.Children) { if (!this.RunTimeValidation(ref error, module)) { Console.WriteLine("Validation error in module " + module.Name + "\r\n" + error); return(false); } } } // if all of our children are alright, and we are also alright this part of the tree is ready to run return(true); } catch { return(false); } }
public bool Do(ref string error) { this.OldRoot = this.ModelSystem.ModelSystemStructure; this.ModelSystem.ModelSystemStructure = this.NewRoot; this.UpdateRoot(this.NewRoot); return(true); }
public bool Do(ref string error) { this.OldRoot = this.Project.ModelSystemStructure[this.Index]; this.Project.ModelSystemStructure[this.Index] = this.NewRoot; this.UpdateRoot(this.NewRoot); return(true); }
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 void EditModelSystemTemplate(IModelSystemStructure msscopy, int i) { IModuleParameters parameterList; // First edit our children foreach (var child in msscopy.Children) { if (child.ParentFieldType.Name == "INetworkAssignment") { parameterList = child.Parameters; foreach (var param in parameterList.Parameters) { if (param.Name == "Emme Project Folder") { param.Value = String.Format("{0}-{1}/Database", this.NetworkBaseDirectory, i); } } } } // after they are setup we just need to tune a couple of our parameters parameterList = msscopy.Parameters; foreach (var param in parameterList.Parameters) { if (param.Name == "Emme Input Output") { param.Value = String.Format("{0}-{1}/Database/cache/scalars.311", this.NetworkBaseDirectory, i); } else if (param.Name == "Emme Macro Output") { param.Value = String.Format("{0}-{1}/Database/cache/boardings_predicted.621", this.NetworkBaseDirectory, i); } } }
private void Load(IConfiguration config, string name) { if (name != null) { string error = null; try { var fileName = Path.Combine(_Config.ModelSystemDirectory, name + ".xml"); using (Stream stream = File.OpenRead(fileName)) { LoadFromStream(stream, config, ref error); } } catch { Description = string.Empty; if (_ModelSystemStructure == null) { _ModelSystemStructure = new ModelSystemStructure(_Config, Name, typeof(IModelSystemTemplate)) { Required = true }; } else { _ModelSystemStructure.ParentFieldType = typeof(IModelSystemTemplate); _ModelSystemStructure.Required = true; } } } }
private static void AssignValue(string fullPath, string variableName, IModelSystemStructure currentStructure, string value) { if (currentStructure == null) { throw new XTMFRuntimeException("Unable to assign '" + variableName + "', the module is null!"); } var p = currentStructure.Parameters; if (p == null) { throw new XTMFRuntimeException("The structure '" + currentStructure.Name + "' has no parameters!"); } var parameters = p.Parameters; bool any = false; if (parameters != null) { for (int i = 0; i < parameters.Count; i++) { if (parameters[i].Name == variableName) { AssignValue(parameters[i], value); any = true; } } } if (!any) { throw new XTMFRuntimeException("Unable to find a parameter named '" + variableName + "' for module '" + currentStructure.Name + "' in order to assign it a parameter!\r\nFull Path:'" + fullPath + "'"); } }
private void ModelSystemDisplay_ChildMoved(object control, IModelSystemStructure parentToAlter, int startingPlace, int destinationPlace) { // implement the move // make sure that it is actually moving if (startingPlace == destinationPlace) { return; } // if it is figure out in what direction if (startingPlace < destinationPlace) { // if we are moving down then move things up var temp = parentToAlter.Children[startingPlace]; for (int i = startingPlace; i < destinationPlace; i++) { parentToAlter.Children[i] = parentToAlter.Children[i + 1]; } parentToAlter.Children[destinationPlace] = temp; } else { var temp = parentToAlter.Children[startingPlace]; for (int i = startingPlace; i > destinationPlace; i--) { parentToAlter.Children[i] = parentToAlter.Children[i - 1]; } parentToAlter.Children[destinationPlace] = temp; } this.Save(); this.SetupModelSystem(); }
/// <summary> /// Get a model system structure from a path string relative to the root /// </summary> /// <param name="root">The point to start the path relative to.</param> /// <param name="path">The path to explore</param> /// <param name="structure">The structure at the end of the path</param> /// <returns>True if a model system structure with that path was found, false otherwise</returns> public static bool GetModelSystemStructureFromPath(IModelSystemStructure root, string path, ref IModelSystemStructure structure) { var parts = SplitNameToParts(path); IModelSystemStructure current = root; for (int i = 0; i < parts.Length; i++) { var children = current.Children; if (children == null) { return(false); } bool found = false; for (int j = 0; j < children.Count; j++) { if (children[j].Name == parts[i]) { current = children[j]; found = true; break; } } if (!found) { return(false); } } structure = current; return(true); }
private IModelSystemStructure CleanupModelSystem(string originalCWD, IModelSystemStructure mstStructure, Exception caughtError) { void DisposeModelSystem(IModelSystemStructure ms) { if (ms.Module is IDisposable disp) { try { disp.Dispose(); } catch { } } var children = ms.Children; if (children != null) { foreach (var child in children) { DisposeModelSystem(child); } } } Thread.MemoryBarrier(); DisposeModelSystem(mstStructure); mstStructure = null; _MST = null; if (Configuration is Configuration configuration) { configuration.ModelSystemExited(); } else { ((ConfigurationProxy)Configuration).ModelSystemExited(); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Thread.MemoryBarrier(); GetInnermostError(ref caughtError); if (caughtError != null) { if (caughtError is XTMFRuntimeException runError) { InvokeRuntimeError(new ErrorWithPath(GetModulePath(runError.Module), runError.Message, runError.StackTrace, runError.Module.Name)); } else { InvokeRuntimeError(new ErrorWithPath(null, caughtError.Message, caughtError.StackTrace)); } } else { InvokeRunCompleted(); } Directory.SetCurrentDirectory(originalCWD); return(mstStructure); }
public CreateNewModelSystem(IConfiguration config, string name, string description, IModelSystemStructure strucuture, List <ILinkedParameter> linkedParameters) { this.Config = config; this.Name = name; this.Description = description; this.Strucuture = strucuture; this.LinkedParameters = linkedParameters; }
private void Copy_Click(object sender, RoutedEventArgs e) { this.ExitedOnClick = true; if (this.SelectedElement != null) { this.CopyBuffer = this.SelectedElement.Clone(); } }
public ModelSystemDisplayStructure(IModelSystemStructure mss) { this.Structure = mss; this._Name = mss.Name; this._Description = mss.Description; this.Type = mss.Type; BuildChildren(); }
public void Add(IModelSystemStructure p) { if (this.Children == null) { this.Children = new List <IModelSystemStructure>(); } this.Children.Add(p); }
private void Swap() { var temp = this.Parent.Children[this.Index]; this.NewValue.ParentFieldType = temp.ParentFieldType; this.NewValue.ParentFieldName = temp.ParentFieldName; this.Parent.Children[this.Index] = this.NewValue; this.NewValue = temp; }
public CreateNewModelSystem(IConfiguration config, string name, string description, IModelSystemStructure strucuture, List<ILinkedParameter> linkedParameters) { this.Config = config; this.Name = name; this.Description = description; this.Strucuture = strucuture; this.LinkedParameters = linkedParameters; }
internal void Refresh(IModelSystemStructure element) { this.ModelSystemDisplay.Refresh(); this.RefreshLinkedParameters(); this.ModuleNameDisplay.Text = this.ModelSystemDisplay.SelectedModule != null ? this.ModelSystemDisplay.SelectedModule.Name : "No Module Selected"; this.Save(); }
internal void Unload() { lock (this) { _IsLoaded = false; _ModelSystemStructure = null; LinkedParameters = null; } }
/// <summary> /// Map the linked parameters to finish making a clone /// </summary> /// <param name="originalLinkedParameters"></param> /// <param name="newModelSystemStructure"></param> /// <param name="oldModelSystemStructure"></param> public static List<ILinkedParameter> MapLinkedParameters(List<ILinkedParameter> originalLinkedParameters, IModelSystemStructure newModelSystemStructure, IModelSystemStructure oldModelSystemStructure) { var ret = new List<ILinkedParameter>( originalLinkedParameters.Count ); //first make a cloned copy of the original parameters for ( int i = 0; i < originalLinkedParameters.Count; i++ ) { ret.Add( CopyLinkedParameter( originalLinkedParameters[i] ) ); } // now that we have a copy we need to walk the model system and live translate it. WalkAndMoveParameters( ret, newModelSystemStructure, oldModelSystemStructure ); return ret; }
public bool Do(ref string error) { if ( this.MSS == null ) { this.MSS = this.ModelSystem.ModelSystemStructure.Clone(); if ( !SetupLinkedParameters( ref error ) ) { return false; } } this.Project.LinkedParameters.Add( this.CopiedLinkedParameters ); this.Project.ModelSystemStructure.Add( this.MSS ); return true; }
public bool RuntimeValidation(ref string error) { foreach ( var mst in this.XtmfConfig.ProjectRepository.ActiveProject.ModelSystemStructure ) { if ( FindUs( mst, ref this.OurStructure ) ) { foreach ( var child in OurStructure.Children ) { if ( child.ParentFieldName == "ClientModelSystem" ) { this.ClientStructure = child; break; } } break; } } if ( this.OurStructure == null ) { error = "In '" + this.Name + "' we were unable to find ourselves through XTMF inside of project " + this.XtmfConfig.ProjectRepository.ActiveProject.Name; return false; } if ( this.ClientStructure == null ) { error = "In '" + this.Name + "' we were unable to find our client model system!"; return false; } return true; }
/// <summary> /// Get a model system structure from a path string relative to the root /// </summary> /// <param name="root">The point to start the path relative to.</param> /// <param name="path">The path to explore</param> /// <param name="structure">The structure at the end of the path</param> /// <returns>True if a model system structure with that path was found, false otherwise</returns> public static bool GetModelSystemStructureFromPath(IModelSystemStructure root, string path, ref IModelSystemStructure structure) { var parts = SplitNameToParts(path); IModelSystemStructure current = root; for(int i = 0; i < parts.Length; i++) { var children = current.Children; if(children == null) { return false; } bool found = false; for(int j = 0; j < children.Count; j++) { if(children[j].Name == parts[i]) { current = children[j]; found = true; break; } } if(!found) { return false; } } structure = current; return true; }
public AddToModuleListCommand(IModelSystemStructure parent, IModelSystemStructure child) { this.Parent = parent; this.Child = child; }
private static Parameter[] GetParameters(IModelSystemStructure mss) { var list = mss.Parameters; if ( list == null ) { return null; } var length = list.Parameters.Count; Parameter[] ret = new Parameter[length]; for ( int i = 0; i < length; i++ ) { ret[i] = new Parameter() { Type = list.Parameters[i].Type == null ? "No Type" : ConvertTypeName( list.Parameters[i].Type ), Name = list.Parameters[i].Name, Description = list.Parameters[i].Description }; } return ret; }
private static SubModule[] GetSubmodules(IModelSystemStructure mss) { var list = mss.Children; if ( list == null ) { return null; } var length = list.Count; SubModule[] ret = new SubModule[length]; for ( int i = 0; i < length; i++ ) { ret[i] = new SubModule() { Type = list[i].ParentFieldType == null ? "Unknown" : ConvertTypeName( list[i].ParentFieldType ), Name = list[i].ParentFieldName, Description = list[i].Description, Required = list[i].Required }; } return ret; }
private void CleanUp(IModelSystemStructure mss) { if ( mss.Module != null ) { var disp = mss.Module as IDisposable; if ( disp != null ) { disp.Dispose(); } mss.Module = null; } if ( mss.Children != null ) { foreach ( var child in mss.Children ) { CleanUp( child ); } } }
/// <summary> /// Validate the model system before starting to execute it /// </summary> /// <param name="error">If there is an error, the error message will be stored in here</param> /// <param name="currentPoint">The current point through the tree we are testing</param> /// <returns></returns> private bool RunTimeValidation(ref string error, IModelSystemStructure currentPoint) { try { // if there is a module at this point if ( currentPoint.Module != null ) { if ( !currentPoint.Module.RuntimeValidation( ref error ) ) { return false; } } // check to see if there are descendants that need to be checked if ( currentPoint.Children != null ) { foreach ( var module in currentPoint.Children ) { if ( !this.RunTimeValidation( ref error, module ) ) { Console.WriteLine( "Validation error in module " + module.Name + "\r\n" + error ); return false; } } } // if all of our children are alright, and we are also alright this part of the tree is ready to run return true; } catch { return false; } }
private static void WalkAndMoveParameters(List<ILinkedParameter> ret, IModelSystemStructure newModelSystemStructure, IModelSystemStructure oldModelSystemStructure) { // we only need to walk if we are not a collection since collections can not have parameters if ( !oldModelSystemStructure.IsCollection ) { // for each linked parameter for ( int i = 0; i < ret.Count; i++ ) { //check the links to see if they are attached to the old system var parameters = ret[i].Parameters; for ( int k = 0; k < parameters.Count; k++ ) { if ( parameters[k].BelongsTo == oldModelSystemStructure ) { var variableName = parameters[k].VariableName; var newModuleParameters = newModelSystemStructure.Parameters.Parameters; for ( int j = 0; j < newModuleParameters.Count; j++ ) { if ( variableName == newModuleParameters[j].VariableName ) { parameters[k] = newModuleParameters[j]; break; } } } } } } var oldChildren = oldModelSystemStructure.Children; if ( oldChildren == null ) return; var newChildren = newModelSystemStructure.Children; // Now that we have finished mapping all of the variables inside of this we need to walk the children for ( int i = 0; i < oldModelSystemStructure.Children.Count; i++ ) { WalkAndMoveParameters( ret, newChildren[i], oldChildren[i] ); } }
/// <summary> /// Retrieve the model system structure for the module the given root. /// </summary> /// <param name="root">The base module to look at</param> /// <param name="toFind">An instance of the module we are trying to find</param> /// <param name="modelSystemStructure">The resulting model system structure</param> /// <returns>True if the module was found, false otherwise.</returns> public static bool FindModuleStructure(IModelSystemStructure root, IModule toFind, ref IModelSystemStructure modelSystemStructure) { if(root.Module == toFind) { modelSystemStructure = root; return true; } if(root.Children != null) { foreach(var child in root.Children) { if(FindModuleStructure(child, toFind, ref modelSystemStructure)) { return true; } } } // Then we didn't find it in this tree return false; }
/// <summary> /// Gets the ancestry of a module from the given root. /// </summary> /// <param name="root">The first node to look at.</param> /// <param name="toFind">The module to find</param> /// <param name="chain">The chain to store the results into.</param> /// <returns>True if we found the module, false otherwise</returns> public static bool BuildModelStructureChain(IModelSystemStructure root, IModule toFind, List<IModelSystemStructure> chain) { if(root.Module == toFind) { chain.Add(root); return true; } if(root.Children != null) { foreach(var child in root.Children) { if(BuildModelStructureChain(child, toFind, chain)) { chain.Insert(0, root); return true; } } } // Then we didn't find it in this tree return false; }
private void EditModelSystemTemplate(IModelSystemStructure msscopy, int i) { IModuleParameters parameterList; // First edit our children foreach ( var child in msscopy.Children ) { if ( child.ParentFieldType.Name == "INetworkEstimationAI" ) { parameterList = child.Parameters; foreach ( var param in parameterList.Parameters ) { if ( param.Name == "Random Seed" ) { param.Value = this.RandomNumberGenerator.Next(); } } } else if ( child.ParentFieldType.Name == "INetworkAssignment" ) { parameterList = child.Parameters; foreach ( var param in parameterList.Parameters ) { if ( param.Name == "Emme Project Folder" ) { param.Value = String.Format( "{0}-{1}/Database", this.NetworkBaseDirectory, ( i + 1 ) ); } } } } // after they are setup we just need to tune a couple of our parameters parameterList = msscopy.Parameters; foreach ( var param in parameterList.Parameters ) { if ( param.Name == "Emme Input Output" ) { param.Value = String.Format( "{0}-{1}/Database/cache/scalars.311", this.NetworkBaseDirectory, ( i + 1 ) ); } else if ( param.Name == "Emme Macro Output" ) { param.Value = String.Format( "{0}-{1}/Database/cache/boardings_predicted.621", this.NetworkBaseDirectory, ( i + 1 ) ); } } }
/// <summary> /// Retrieve the model system structure from the active project /// </summary> /// <param name="config">The XTMF runtime configuration</param> /// <param name="toFind">The module to find the model system structure of</param> /// <param name="modelSystemStructure">The model system structure of the given module</param> /// <returns>True if the module was found, false otherwise</returns> public static bool FindModuleStructure(IConfiguration config, IModule toFind, ref IModelSystemStructure modelSystemStructure) { return FindModuleStructure(config.ProjectRepository.ActiveProject, toFind, ref modelSystemStructure); }
internal int IndexOf(ModelSystemDisplayStructure[] oldChildren, IModelSystemStructure modelSystemStructure) { for ( int i = 0; i < oldChildren.Length; i++ ) { if ( oldChildren[i].Structure == modelSystemStructure ) { return i; } } return -1; }
public static void AssignValue(IModelSystemStructure root, string parameterName, string value) { string[] parts = SplitNameToParts(parameterName); AssignValue(parameterName, parts, 0, root, value); }
private static void AssignValue(string fullPath, string variableName, IModelSystemStructure currentStructure, string value) { if(currentStructure == null) { throw new XTMFRuntimeException("Unable to assign '" + variableName + "', the module is null!"); } var p = currentStructure.Parameters; if(p == null) { throw new XTMFRuntimeException("The structure '" + currentStructure.Name + "' has no parameters!"); } var parameters = p.Parameters; bool any = false; if(parameters != null) { for(int i = 0; i < parameters.Count; i++) { if(parameters[i].Name == variableName) { AssignValue(parameters[i], value); any = true; } } } if(!any) { throw new XTMFRuntimeException("Unable to find a parameter named '" + variableName + "' for module '" + currentStructure.Name + "' in order to assign it a parameter!\r\nFull Path:'"+ fullPath + "'"); } }
private static void AssignValue(string fullPath, string[] parts, int currentIndex, IModelSystemStructure currentStructure, string value) { if(currentIndex == parts.Length - 1) { AssignValue(fullPath, parts[currentIndex], currentStructure, value); return; } if(currentStructure.Children != null) { for(int i = 0; i < currentStructure.Children.Count; i++) { if(currentStructure.Children[i].Name == parts[currentIndex]) { AssignValue(fullPath, parts, currentIndex + 1, currentStructure.Children[i], value); return; } } } throw new XTMFRuntimeException("Unable to find a child module in '" + parts[currentIndex] + "' named '" + parts[currentIndex + 1] + "' in order to assign parameters!\r\nFull Path:'" + fullPath + "'"); }
public ContainedModelSystemModel(IModelSystemStructure ms, IProject project) { Root = ms; RealIndex = project.ModelSystemStructure.IndexOf(ms); }
private bool FindUs(IModelSystemStructure mst, ref IModelSystemStructure modelSystemStructure) { if ( mst.Module == this ) { modelSystemStructure = mst; return true; } if ( mst.Children != null ) { foreach ( var child in mst.Children ) { if ( FindUs( child, ref modelSystemStructure ) ) { return true; } } } // Then we didn't find it in this tree return false; }
private bool LoadChildFromXTMF(ref string error) { IModelSystemStructure ourStructure = null; if(ModelSystemReflection.FindModuleStructure(Config, this, ref ourStructure)) { foreach(var child in ourStructure.Children) { if(child.ParentFieldName == "Child") { ChildStructure = child; break; } } } if(ChildStructure == null) { error = "In '" + Name + "' we were unable to find the Client Model System!"; return false; } return true; }
/// <summary> /// Retrieve the model system structure from the given project /// </summary> /// <param name="project">The project to analyze</param> /// <param name="toFind">The module to find the structure of</param> /// <param name="modelSystemStructure">The model system structure of the module to find.</param> /// <returns>True if the module was found, false otherwise</returns> public static bool FindModuleStructure(IProject project, IModule toFind, ref IModelSystemStructure modelSystemStructure) { foreach(var ms in project.ModelSystemStructure) { if(FindModuleStructure(ms, toFind, ref modelSystemStructure)) { return true; } } return false; }