コード例 #1
0
ファイル: ImportModelSystem.cs プロジェクト: Cocotus/XTMF
 public bool Do(ref string error)
 {
     if ( this.Replace )
     {
         var modelSystems = this.Configuration.ModelSystemRepository.ModelSystems;
         for ( int i = 0; i < modelSystems.Count; i++ )
         {
             if ( modelSystems[i].Name.Equals( this.Name, StringComparison.InvariantCultureIgnoreCase ) )
             {
                 this.Configuration.ModelSystemRepository.Remove( modelSystems[i] );
                 break;
             }
         }
     }
     try
     {
         File.Copy( this.Location, Path.Combine( this.Configuration.ModelSystemDirectory, this.Name + ".xml" ), true );
     }
     catch ( IOException )
     {
     }
     ModelSystem ms = new ModelSystem( this.Configuration, this.Name );
     this.Configuration.ModelSystemRepository.Add( ms );
     this.ModelSystem = ms;
     return ms.Save( ref error );
 }
コード例 #2
0
ファイル: ProjectController.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Add a new model system to a project
 /// </summary>
 /// <param name="project">The project to add the model system to</param>
 /// <param name="modelSystem">The modelsystem to add to the project</param>
 /// <param name="error">Te returned error message in case the operation fails</param>
 /// <returns>True if the operation succeeded, false otherwise with error message</returns>
 public bool AddModelSystemToProject(IProject project, IModelSystem modelSystem, ref string error)
 {
     var command = new XTMF.Commands.AddModelSystemToProject( project, modelSystem );
     if ( this.XTMFRuntime.ProcessCommand( command, ref error ) )
     {
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: DeleteModelSystem.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Tell XTMF to delete the given project
 /// </summary>
 /// <param name="modelSystem">The project to delete</param>
 /// <param name="config">The current XTMF configuration</param>
 public DeleteModelSystem(IModelSystem modelSystem, IConfiguration config)
 {
     if ( modelSystem == null )
     {
         throw new ArgumentNullException( "modelSystem" );
     }
     this.ModelSystem = modelSystem;
     this.Config = config;
 }
コード例 #4
0
ファイル: ModelSystemController.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Rename the model system
 /// </summary>
 /// <param name="ms">The model system to rename</param>
 /// <param name="newName">The name to change the model system to</param>
 /// <param name="error">An error message in case the operation fails</param>
 /// <returns>True if successful, false with an error message in case it fails</returns>
 public bool Rename(IModelSystem ms, string newName, ref string error)
 {
     var command = new XTMF.Commands.RenameModelSystem( this.Configuration, ms, newName );
     if ( this.XTMFRuntime.ProcessCommand( command, ref error ) )
     {
         return true;
     }
     return false;
 }
コード例 #5
0
ファイル: SingleWindowGUI.xaml.cs プロジェクト: Cocotus/XTMF
 internal bool Rename(IModelSystem ms, string newName)
 {
     string error = null;
     return this.XTMF.ModelSystemController.Rename( ms, newName, ref error );
 }
コード例 #6
0
ファイル: SingleWindowGUI.xaml.cs プロジェクト: Cocotus/XTMF
 internal void Delete(IModelSystem modelSystem)
 {
     string error = null;
     this.XTMF.ModelSystemController.DeleteModelSystem( modelSystem, ref error );
 }
コード例 #7
0
ファイル: RenameModelSystem.cs プロジェクト: Cocotus/XTMF
 public RenameModelSystem(IConfiguration config, IModelSystem modelSystem, string newName)
 {
     this.Config = config;
     this.OtherName = newName;
     this.ModelSystem = modelSystem;
 }
コード例 #8
0
 /// <summary>
 /// Export the model system to the given file path
 /// </summary>
 /// <param name="modelSystem">The model system to export</param>
 /// <param name="filePath">The path to save to.</param>
 /// <param name="error">A description of the error if one occurs.</param>
 /// <returns>True if successful, false otherwise.  An error will be reported if it fails.</returns>
 public bool ExportModelSystem(IModelSystem modelSystem, string filePath, ref string error)
 {
     try
     {
         return modelSystem.Save(filePath, ref error);
     }
     catch(IOException e)
     {
         error = e.Message;
         return false;
     }
 }
コード例 #9
0
 private void Selector_ItemRightClicked(BorderIconButton button, object data)
 {
     this.CurrentModelSystem = data as IModelSystem;
 }
コード例 #10
0
 public AddModelSystemToProject(IProject project, IModelSystem modelSystem)
 {
     this.Project = project;
     this.ModelSystem = modelSystem;
 }
コード例 #11
0
 internal void LoadRoot(IModelSystemStructure root)
 {
     this.EditMode = false;
     this._ModelSystem = null;
     this._Project = null;
     this.CommandStack.Clear();
     this.Root = root;
     this.SetupModelSystem();
     this.ParameterEditor.ModelSystemStructure = null;
 }
コード例 #12
0
ファイル: ViewRunPage.xaml.cs プロジェクト: Cocotus/XTMF
 private void SaveButton_Clicked(object obj)
 {
     this.NewMSHolder = new ModelSystem( this.XTMF.XTMF.Configuration );
     QuestionData question = new QuestionData();
     question.Path = this.Path;
     question.OnSuccess = XTMFPage.ViewProjectRunPage;
     question.OnSuccessData = this.NewMSHolder;
     question.OnCancel = XTMFPage.ViewProjectRunPage;
     question.OnCancelData = null;
     question.Validate = ValidateModelSystemName;
     question.Question = "Select a unique name for the Model System";
     question.Hint = "Model System";
     question.DefaultText = System.IO.Path.GetFileName( System.IO.Path.GetDirectoryName( this.RunDirectory ) );
     this.XTMF.Navigate( XTMFPage.QuestionPage, question );
 }
コード例 #13
0
 public CreateNewModelSystemLinkedParameter(IModelSystem modelSystem, string name, string intialValue)
 {
     this.ModelSystem = modelSystem;
     this.Name = name;
     this.InitialValue = intialValue;
 }
コード例 #14
0
ファイル: ModelSystemRepository.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Add a new model system to the repository
 /// </summary>
 /// <param name="modelSystem"></param>
 public void Add(IModelSystem modelSystem)
 {
     if ( modelSystem != null )
     {
         lock ( this )
         {
             this.ModelSystems.Add( modelSystem );
             ( this.ModelSystems as List<IModelSystem> ).Sort( delegate(IModelSystem first, IModelSystem second)
             {
                 return first.Name.CompareTo( second.Name );
             } );
         }
         var msa = this.ModelSystemAdded;
         if ( msa != null )
         {
             msa( modelSystem );
         }
     }
 }
コード例 #15
0
ファイル: ModelSystemRepository.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Provides removal for a model system
 /// </summary>
 /// <param name="modelSystem"></param>
 /// <returns></returns>
 public bool Remove(IModelSystem modelSystem)
 {
     if ( modelSystem != null )
     {
         int index;
         lock ( this )
         {
             index = this.ModelSystems.IndexOf( modelSystem );
             if ( !this.ModelSystems.Remove( modelSystem ) )
             {
                 return false;
             }
         }
         var msr = this.ModelSystemRemoved;
         if ( msr != null )
         {
             msr( modelSystem, index );
         }
         // we don't need to be locked in order to delete it
         try
         {
             File.Delete( Path.Combine( this.Config.ModelSystemDirectory, modelSystem.Name + ".xml" ) );
         }
         catch
         {
             // If the file no longer exists, or couldn't have it doesn't really matter
         }
         return true;
     }
     // it is not valid to remove a model system that does not exist!
     return false;
 }
コード例 #16
0
ファイル: ModelSystemPage.xaml.cs プロジェクト: dianatle/XTMF
 public void SetActive(object data)
 {
     if (data is IModelSystemStructure)
     {
         // If we are here then we were called from the parent level
         this.CurrentModule = data as IModelSystemStructure;
         this.Context       = new ModelSystemPageContext();
         var project = this.XTMF.CurrentProject;
         this.Context.Project     = project;
         this.Context.ModelSystem = data as IModelSystemStructure;
         this.Context.CurrentNode = data as IModelSystemStructure;
         this.Delete.IsEnabled    = true;
         this.ParentNodes.Clear();
         var index = project.ModelSystemStructure.IndexOf(CurrentModule);
         if (index >= 0)
         {
             bool   editMode = false;
             string value;
             if (this.XTMF.XTMF.Configuration.AdditionalSettings.TryGetValue("EditProjects", out value))
             {
                 bool.TryParse(value, out editMode);
             }
             this.ModelSystemInterface.LoadProject(project, index, editMode);
             this.ColourKey.EditMode = editMode;
         }
         this.Run.IsEnabled = true;
     }
     else if (data is ModelSystemPageContext)
     {
         var context = data as ModelSystemPageContext;
         this.Context          = context;
         this.CurrentModule    = context.CurrentNode;
         this.Delete.IsEnabled = context.CurrentNode == context.ModelSystem;
     }
     else if (data is QuestionResult)
     {
         var result = data as QuestionResult;
         if (result.Success == true)
         {
             if (result.Data == null || result.Data is IModelSystemStructure)
             {
                 var module = result.Data as IModelSystemStructure;
                 if (module != null)
                 {
                     this.ModelSystemInterface.AddCommand(new ModuleRenameCommand(module, result.Result));
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh(module);
                 }
                 else
                 {
                     this.ModelSystemInterface.AddCommand(new ModuleRenameCommand(CurrentModule, result.Result));
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh(this.CurrentModule);
                 }
                 this.ModuleNameLabel.ToolTip        = this.ModuleNameLabel.Text;
                 this.XTMF.CheckToSave               = true;
                 this.XTMF.CurrentProject.HasChanged = true;
                 this.XTMF.Reload = true;
             }
             else if (result.Data is IModelSystem)
             {
                 IModelSystem baseMS = result.Data as IModelSystem;
                 string       error  = null;
                 var          lp     = this.Context.Project.LinkedParameters[this.Context.Project.ModelSystemStructure.IndexOf(this.Context.ModelSystem)];
                 var          ms     = this.XTMF.CreateCopy(this.Context.ModelSystem, lp, baseMS.Name, this.Context.ModelSystem.Description);
                 if (!ms.Save(ref error))
                 {
                     MessageBox.Show("Unable to save Model System!\r\n" + error, "Unable to save!", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
             if (result.Data is string)
             {
                 var    ms         = this.ModelSystemInterface.ModelSystem;
                 var    dataString = result.Data as string;
                 string error      = null;
                 if (dataString == "Rename LinkedParameter")
                 {
                     this.ModelSystemInterface.AddCommand(new XTMF.Commands.Editing.RenameLinkedParameter(this.LastLinkedParameterRequest, result.Result), ref error);
                     this.ModelSystemInterface.RefreshLinkedParameters();
                 }
             }
             return;
         }
     }
     this.ModuleIndirection.Clear();
 }
コード例 #17
0
 public SetModelSystemRootCommand(Action<IModelSystemStructure> updateRoot, IModelSystem ms, IModelSystemStructure newRoot)
 {
     this.UpdateRoot = updateRoot;
     this.ModelSystem = ms;
     this.NewRoot = newRoot;
 }
コード例 #18
0
ファイル: ModelSystemPage.xaml.cs プロジェクト: Cocotus/XTMF
 private void SaveMS_Clicked(object obj)
 {
     this.NewMSHolder = new ModelSystem( this.XTMF.XTMF.Configuration );
     QuestionData question = new QuestionData();
     question.Path = this.Path;
     question.OnSuccess = XTMFPage.ModelSystemSettingsPage;
     question.OnSuccessData = this.NewMSHolder;
     question.OnCancel = XTMFPage.ModelSystemSettingsPage;
     question.OnCancelData = this.Context;
     question.Validate = ValidateModelSystemName;
     question.Question = "Select a unique name for the Model System";
     question.Hint = "Model System";
     question.DefaultText = this.ModuleNameLabel.Text;
     this.XTMF.Navigate( XTMFPage.QuestionPage, question );
 }
コード例 #19
0
 public void LoadProject(IProject project, int currentModelSystem, bool editMode = false)
 {
     this.ModelSystemDisplay.SelectedModule = null;
     this.ParameterEditor.ModelSystemStructure = null;
     this._ModelSystem = null;
     this._Project = project;
     this.ProjectModelSystemNumber = currentModelSystem;
     this.CommandStack.Clear();
     this.Root = project.ModelSystemStructure[currentModelSystem];
     this.EditMode = editMode;
     this.SetupModelSystem();
     this.RefreshLinkedParameters();
 }
コード例 #20
0
ファイル: ModelSystemController.cs プロジェクト: Cocotus/XTMF
 private void ModelSystemController_ModelSystemAdded(IModelSystem modelSystem)
 {
     this.DataView.ItemWasAdded( modelSystem );
 }
コード例 #21
0
ファイル: DeleteLinkedParameter.cs プロジェクト: Cocotus/XTMF
 public DeleteLinkedParameter(IModelSystem modelSystem, ILinkedParameter linkedParameter)
 {
     this.ModelSystem = modelSystem;
     this.LinkedParameter = linkedParameter;
 }
コード例 #22
0
ファイル: ModelSystemController.cs プロジェクト: Cocotus/XTMF
 private void ModelSystemController_ModelSystemRemoved(IModelSystem modelSystem, int index)
 {
     this.DataView.ItemWasRemoved( modelSystem, index );
 }
コード例 #23
0
ファイル: ModelSystemController.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 /// Delete the given modelsytem
 /// </summary>
 /// <param name="modelSystem">The project to delete</param>
 /// <param name="error">A message containing the error if there was one</param>
 /// <returns>True if successful, false otherwise with an error message</returns>
 public bool DeleteModelSystem(IModelSystem modelSystem, ref string error)
 {
     var command = new XTMF.Commands.DeleteModelSystem( modelSystem, this.Configuration );
     return ( this.XTMFRuntime.ProcessCommand( command, ref error ) );
 }
コード例 #24
0
 private void EditModelSystemPage(IModelSystem pickedMS)
 {
     this.XTMF.Navigate(XTMFPage.EditModelSystem, pickedMS);
 }