public void TestEditParameterToDefault() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); Assert.IsNotNull(inputDirectory, "There was no parameter called input directory."); string error = null; var previousValue = inputDirectory.Value; var newValue = "NewValue"; Assert.IsTrue(inputDirectory.SetValue(newValue, ref error), "The assignment of a value to a string somehow failed!"); Assert.AreEqual(newValue, inputDirectory.Value, "The valid value was not stored in the parameter!"); Assert.IsTrue(inputDirectory.SetToDefault(ref error), "Set to default failed!"); Assert.AreEqual(previousValue, inputDirectory.Value, "We did not revert to the previous value!"); } }
public void TestUndoRedo() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); string error = null; Assert.IsTrue(session.Undo(ref error), "The undo failed!"); Assert.AreEqual(null, root.Type, "The root was not updated to the proper type after undo!"); Assert.IsTrue(session.Redo(ref error), "The undo failed!"); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type after redo!"); } }
public void TestDisablingRequiredField() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { string error = null; // build a small model system var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); // disable a module Assert.IsTrue(root.Children[0].AddCollectionMember(typeof(TestRequiredSubmodule), ref error, "SimpleChild"), error); var requiredParent = root.Children[0].Children[0]; requiredParent.Children[0].Type = typeof(TestModule); var simpleChild = requiredParent.Children[0]; Assert.AreEqual(false, simpleChild.IsDisabled, "By default simple child should not be disabled!"); Assert.IsFalse(simpleChild.SetDisabled(true, ref error), "You should not be able to disable a required submodule!"); } }
public void TestChangingAModulesName() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { string error = null; var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); var oldName = root.Name; const string newName = "New Name"; Assert.IsTrue(root.SetName(newName, ref error), "Failed to set the module's name!"); Assert.AreEqual(root.Name, newName, "The new name was not assigned!"); if (!session.Undo(ref error)) { Assert.Fail("We were unable to undo! " + error); } Assert.AreEqual(root.Name, oldName, "The old name was not restored!"); if (!session.Redo(ref error)) { Assert.Fail("We were unable to redo! " + error); } Assert.AreEqual(root.Name, newName, "The new name was not restored after redo!"); } }
public void TestAddingACollectionMember() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsFalse(collection.AddCollectionMember(typeof(int), ref error), "We were able to use an integer as a collection member!"); } }
public void TestSettingParameterInLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); var secondaryString = GetParameter(parameters, "SecondaryString"); var linkedParameterList = linkedParameters.GetLinkedParameters(); Assert.IsTrue(linkedParameterList[0].AddParameter(inputDirectory, ref error), error); Assert.IsTrue(linkedParameterList[0].AddParameter(secondaryString, ref error), error); string oldValue = linkedParameterList[0].GetValue(); string newValue = "NewValue"; Assert.IsTrue(linkedParameterList[0].SetValue(newValue, ref error)); // assign to both with through the linked parameter Assert.AreEqual(newValue, linkedParameterList[0].GetValue()); Assert.AreEqual(newValue, inputDirectory.Value); Assert.AreEqual(newValue, secondaryString.Value); // assign to both using the secondary string Assert.IsTrue(secondaryString.SetValue(oldValue, ref error)); Assert.AreEqual(oldValue, linkedParameterList[0].GetValue()); Assert.AreEqual(oldValue, inputDirectory.Value); Assert.AreEqual(oldValue, secondaryString.Value); Assert.IsTrue(session.Undo(ref error)); Assert.AreEqual(newValue, linkedParameterList[0].GetValue()); Assert.AreEqual(newValue, inputDirectory.Value); Assert.AreEqual(newValue, secondaryString.Value); Assert.IsTrue(session.Redo(ref error)); Assert.AreEqual(oldValue, linkedParameterList[0].GetValue()); Assert.AreEqual(oldValue, inputDirectory.Value); Assert.AreEqual(oldValue, secondaryString.Value); } }
public ModuleTypeSelect(ModelSystemEditingSession session, ModelSystemStructureModel selectedModule) : this() { _modelSystemSession = session; _selectedModule = selectedModule; BuildRequirements(session); FilterBox.Filter = CheckAgainstFilter; FilterBox.Display = Display; }
public static void HelpRequested(ModelSystemStructureModel modelSystemStructure) { if(modelSystemStructure != null) { var documentationControl = new DocumentationControl() { Type = modelSystemStructure.Type }; MainWindow.Us.NewDocumentationWindow(documentationControl); Keyboard.Focus(documentationControl); } }
public ModuleTypeSelect(ModelSystemEditingSession session, ModelSystemStructureModel selectedModule) : this() { ModelSystemSession = session; SelectedModule = selectedModule; BuildRequirements( session ); FilterBox.Filter = CheckAgainstFilter; FilterBox.Display = Display; }
public XTMFRunRemoteHost(IConfiguration configuration, ModelSystemStructureModel root, List <ILinkedParameter> linkedParameters, string runName, string runDirectory) : base(runName, runDirectory, configuration) { ModelSystemStructureModelRoot = root; _LinkedParameters = linkedParameters; using (MemoryStream memStream = new MemoryStream()) { WriteModelSystemToStream(memStream); _modelSystemAsString = Encoding.Unicode.GetString(memStream.ToArray()); } }
public static void HelpRequested(ModelSystemStructureModel modelSystemStructure) { if (modelSystemStructure != null) { var documentationControl = new DocumentationControl() { Type = modelSystemStructure.Type }; MainWindow.Us.NewDocumentationWindow(documentationControl); Keyboard.Focus(documentationControl); } }
public XTMFRunLocal(Project project, ModelSystemStructureModel root, Configuration configuration, string runName, bool overwrite) : base(runName, Path.Combine(configuration.ProjectDirectory, project.Name, runName), (project.ModelSystemStructure.IndexOf(root.RealModelSystemStructure) >= 0 ? (IConfiguration) new ConfigurationProxy(configuration, project) : configuration)) { // we don't make a clone for this type of run _Project = project; ModelSystemStructureModelRoot = root; RunName = runName; if (overwrite) { ClearFolder(RunDirectory); } }
/// <summary> /// /// </summary> /// <param name="getHelpFor"></param> public void LaunchHelpWindow(ModelSystemStructureModel getHelpFor = null) { var helpUI = new UserControls.Help.HelpDialog(EditorController.Runtime.Configuration); if (getHelpFor != null) { helpUI.SelectModuleContent(getHelpFor); } var document = AddNewWindow("Help", helpUI); document.IsSelected = true; Keyboard.Focus(helpUI); }
private void Run() { if (_Root == null) { InvokeRuntimeValidationError(new List <ErrorWithPath>(1) { new ErrorWithPath(null, "Model System Root not found", "The model system was not processed properly and then run!") }); return; } if (ValidateModelSystem()) { try { SetupRunDirectory(); if (!ValidateRuntimeModelSystem()) { // The call will already signal the errors. return; } _Root.Save(Path.Combine(RunDirectory, "RunParameters.xml")); ModelSystemStructureModelRoot = new ModelSystemStructureModel(null, _Root); MST.Start(); InvokeRunCompleted(); } catch (ThreadAbortException) { // This is fine just continue } catch (Exception e) { GetInnermostError(ref e); List <int> path = null; string moduleName = null; if (e is XTMFRuntimeException runtimeError) { if (runtimeError.Module != null) { path = GetModulePath(runtimeError.Module); moduleName = runtimeError.Module.Name; } else { path = null; moduleName = "Null Module"; } } InvokeRuntimeError(new ErrorWithPath(path, e.Message, e.StackTrace, moduleName, e)); } } }
public ModelSystemStructureDisplayModel(ModelSystemStructureModel baseModel) { BaseModel = baseModel; BaseChildren = baseModel.Children; Children = BaseChildren == null ? new ObservableCollection <ModelSystemStructureDisplayModel>() : new ObservableCollection <ModelSystemStructureDisplayModel>( from child in baseModel.Children select new ModelSystemStructureDisplayModel(child)); BaseModel.PropertyChanged += BaseModel_PropertyChanged; if (BaseChildren != null) { BaseChildren.CollectionChanged += BaseChildren_CollectionChanged; } }
public ModelSystemStructureDisplayModel(ModelSystemStructureModel baseModel) { BaseModel = baseModel; BaseChildren = baseModel.Children; Children = BaseChildren == null ? new ObservableCollection<ModelSystemStructureDisplayModel>() : new ObservableCollection<ModelSystemStructureDisplayModel>( from child in baseModel.Children select new ModelSystemStructureDisplayModel(child)); BaseModel.PropertyChanged += BaseModel_PropertyChanged; if(BaseChildren != null) { BaseChildren.CollectionChanged += BaseChildren_CollectionChanged; } }
public void TestRemovingModuleToLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); var linkedParameterList = linkedParameters.GetLinkedParameters(); Assert.IsTrue(linkedParameterList[0].AddParameter(inputDirectory, ref error), error); var moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(1, moduleParametersLinked.Count, "The number of module parameters that are linked should just be one!"); Assert.IsTrue(linkedParameterList[0].RemoveParameter(moduleParametersLinked[0], ref error)); Assert.IsFalse(linkedParameterList[0].RemoveParameter(moduleParametersLinked[0], ref error), "We got a true for removing a parameter that was already removed"); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(0, moduleParametersLinked.Count, "No module parameters should be left."); Assert.IsTrue(session.Undo(ref error)); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(1, moduleParametersLinked.Count, "No module parameter should be returned after undo."); Assert.IsTrue(session.Redo(ref error)); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(0, moduleParametersLinked.Count, "No module parameters should be left after redo."); } }
public ModelSystemStructureDisplayModel(ModelSystemStructureModel baseModel, ModelSystemStructureDisplayModel parent, int index) { //BaseChildren. Parent = parent; Index = index; BaseModel = baseModel; _BaseChildren = baseModel.Children; UpdateChildren(baseModel); BaseModel.PropertyChanged += BaseModel_PropertyChanged; if (_BaseChildren != null) { _BaseChildren.CollectionChanged += BaseChildren_CollectionChanged; } }
public void TestEditingModelSystem() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); } }
public void TestRemovingEntireCollection() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsFalse(collection.AddCollectionMember(typeof(int), ref error), "We were able to use an integer as a collection member!"); Assert.AreEqual(2, collection.Children.Count, "An incorrect number of children were found."); var oldChildren = collection.Children.ToList(); Assert.IsTrue(collection.RemoveAllCollectionMembers(ref error), "We were unable to remove all collection members!"); Assert.AreEqual(0, collection.Children.Count, "After removing all of the collection members, there were still elements left in the collection."); Assert.IsTrue(session.Undo(ref error), "We failed to undo the remove all!"); Assert.AreEqual(2, collection.Children.Count, "After undoing the remove all there were still issues."); for (int i = 0; i < collection.Children.Count; i++) { Assert.AreEqual(oldChildren[i], collection.Children[i], "A child was not the same as before!"); } } }
public void SelectModuleContent(ModelSystemStructureModel module) { Task.Run(() => { if (module != null) { var type = module.Type; var selectCorrectDocument = Task.Run(() => { UpdateSearch(false); Dispatcher.BeginInvoke(new Action(() => { var foundElement = SearchedItems.FirstOrDefault(element => element.Module == type); if (foundElement != null) { ResultBox.SelectedItem = foundElement; } })); }); OperationProgressing progressing = null; Dispatcher.Invoke(new Action(() => { progressing = new OperationProgressing() { Owner = MainWindow.Us }; })); Dispatcher.BeginInvoke(new Action(() => { progressing.ShowDialog(); })); selectCorrectDocument.Wait(); Dispatcher.BeginInvoke(new Action(() => { progressing.Close(); })); } }); }
public void TestNotChangingSubmoduleNameOnTypeChange() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestRequiredSubmodule), ref error), "We were unable to properly add a new collection member."); Assert.AreEqual(1, collection.Children.Count, "The collection does not have 1 child!"); var parent = collection.Children[0]; Assert.AreEqual(1, parent.Children.Count, "TestRequiredSubmodule has more than one child!"); var childToRename = parent.Children[0]; var originalName = childToRename.Name; childToRename.Type = typeof(TestRequiredSubmodule); Assert.AreEqual(originalName, childToRename.Name, "The name changed when the type changed on a non collection member!"); } }
private ObservableCollection<ModelSystemStructureDisplayModel> CreateDisplayModel(ModelSystemStructureModel root) { var ret = new ObservableCollection<ModelSystemStructureDisplayModel>() { (DisplayRoot = new ModelSystemStructureDisplayModel(root)) }; return ret; }
private string GetInputDirectory(ModelSystemStructureModel root, out ParameterModel parameter) { var inputDir = root.Type.GetProperty("InputBaseDirectory"); var attributes = inputDir.GetCustomAttributes(typeof(ParameterAttribute), true); if(attributes != null && attributes.Length > 0) { var parameterName = ((ParameterAttribute)attributes[0]).Name; var parameters = root.Parameters.GetParameters(); for(int i = 0; i < parameters.Count; i++) { if(parameters[i].Name == parameterName) { parameter = parameters[i]; return parameters[i].Value.ToString(); } } } parameter = null; return null; }