Example #1
0
        public void ProjectPersistance()
        {
            var          runtime     = XTMFRuntime.CreateRuntime();
            var          controller  = runtime.ProjectController;
            const string projectName = "Test";
            CommandError error       = null;
            var          localUser   = TestHelper.GetTestUser(runtime);

            // delete the project just in case it survived
            controller.DeleteProject(localUser, projectName, out error);
            // now create it
            Assert.IsTrue(controller.CreateNewProject(localUser, projectName, out ProjectSession session, out error).UsingIf(session, () =>
            {
                var project = session.Project;
                Assert.AreEqual(projectName, project.Name);
                Assert.AreEqual(localUser, project.Owner);
            }), "Unable to create project");
            var numberOfProjects = localUser.AvailableProjects.Count;

            // Simulate a shutdown of XTMF
            runtime.Shutdown();
            //Startup XTMF again
            runtime    = XTMFRuntime.CreateRuntime();
            controller = runtime.ProjectController;
            localUser  = TestHelper.GetTestUser(runtime);
            Assert.AreEqual(numberOfProjects, localUser.AvailableProjects.Count);
            var regainedProject = localUser.AvailableProjects[0];

            Assert.AreEqual(projectName, regainedProject.Name);
        }
Example #2
0
 internal static void Register(MainWindow window, Action OnComplete)
 {
     Task.Factory.StartNew(
         () =>
     {
         OpenWindows.Run((list) =>
         {
             if (Runtime == null)
             {
                 Runtime       = new XTMFRuntime();
                 var loadError = ((Configuration)Runtime.Configuration).LoadError;
                 if (loadError != null)
                 {
                     window.Dispatcher.BeginInvoke(new Action(() =>
                     {
                         MessageBox.Show(window, loadError + "\r\nA copy of this error has been saved to your clipboard.", "Error Loading XTMF", MessageBoxButton.OK, MessageBoxImage.Error);
                         Clipboard.SetText(loadError);
                         if (((Configuration)Runtime.Configuration).LoadErrorTerminal)
                         {
                             Application.Current.Shutdown(-1);
                         }
                     }));
                 }
             }
             if (!list.Contains(window))
             {
                 list.Add(window);
             }
             if (OnComplete != null)
             {
                 OnComplete();
             }
         });
     });
 }
 /// <summary>
 /// Create a new session to edit a model system
 /// </summary>
 /// <param name="modelSystem">The model system to edit</param>
 public ModelSystemEditingSession(XTMFRuntime runtime, ModelSystem modelSystem)
 {
     Runtime = runtime;
     ModelSystem = modelSystem;
     ModelSystemModel = new ModelSystemModel(this, modelSystem);
     ModelSystemModel.PropertyChanged += ModelSystemModel_PropertyChanged;
 }
Example #4
0
        public void SwitchOwner()
        {
            var          runtime           = XTMFRuntime.CreateRuntime();
            var          userController    = runtime.UserController;
            var          projectController = runtime.ProjectController;
            CommandError error             = null;
            const string userName1         = "FirstUser";
            const string userName2         = "SecondtUser";
            const string projectName1      = "TestShareBetweenUsers1";

            // ensure the user doesn't exist before we start and then create our users
            userController.Delete(userName1);
            userController.Delete(userName2);
            Assert.IsTrue(userController.CreateNew(userName1, false, out var user1, out error), error?.Message);
            Assert.IsTrue(userController.CreateNew(userName2, false, out var user2, out error), error?.Message);
            // now we need to create a project for both users

            Assert.IsTrue(projectController.CreateNewProject(user1, projectName1, out var session1, out error), error?.Message);

            Assert.AreEqual(1, user1.AvailableProjects.Count);
            Assert.AreEqual(0, user2.AvailableProjects.Count);

            Assert.IsTrue(session1.SwitchOwner(user1, user2, out error), error?.Message);
            Assert.IsFalse(session1.SwitchOwner(user1, user2, out error));

            Assert.AreEqual(0, user1.AvailableProjects.Count);
            Assert.AreEqual(1, user2.AvailableProjects.Count);

            Assert.IsTrue(userController.Delete(user1));

            Assert.AreEqual(1, user2.AvailableProjects.Count);

            Assert.IsTrue(userController.Delete(user2));
        }
 /// <summary>
 /// Create a new editing session to edit a project's model system
 /// </summary>
 /// <param name="ProjectEditingSession">The editing session to read from</param>
 /// <param name="modelSystemIndex">The model system's index inside of the project</param>
 public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession ProjectEditingSession, int modelSystemIndex)
 {
     Runtime = runtime;
     this.ProjectEditingSession = ProjectEditingSession;
     ModelSystemIndex = modelSystemIndex;
     ModelSystemModel = new ModelSystemModel(this, this.ProjectEditingSession.Project, modelSystemIndex);
 }
Example #6
0
 public ProjectEditingSession(Project project, XTMFRuntime runtime)
 {
     Project = project;
     Runtime = runtime;
     EditingSessions = new SessionData[Project.ModelSystemStructure.Count];
     project.ExternallySaved += Project_ExternallySaved;
 }
Example #7
0
        /// <summary>
        /// Load all project headers.
        /// Should only be called by system configuration.
        /// </summary>
        /// <returns>List of projects that failed to load an reason why</returns>
        private List <(string Path, string?Error)> LoadProjects(XTMFRuntime runtime)
        {
            var errors   = new List <(string Path, string?Error)>();
            var allUsers = runtime.UserController.Users;

            // go through all users and scan their directory for projects
            foreach (var user in allUsers)
            {
                string        dir     = user.UserPath;
                DirectoryInfo userDir = new DirectoryInfo(dir);
                foreach (var subDir in userDir.GetDirectories())
                {
                    var projectFile = subDir.GetFiles().FirstOrDefault(f => f.Name == "Project.xpjt");
                    if (projectFile != null)
                    {
                        string?error = null;
                        if (Project.Load(runtime.UserController, projectFile.FullName, out Project project, ref error))
                        {
                            _projects.Add(project !, ref error);
                        }
                        else
                        {
                            errors.Add((projectFile.FullName, error));
                        }
                    }
                }
            }
Example #8
0
        public void GetUserData()
        {
            XTMFRuntime runtime = XTMFRuntime.CreateRuntime();
            var         users   = runtime.UserController.Users;

            Assert.IsTrue(users.Count > 0);
        }
Example #9
0
        private static void RunModelSystemFromProjectPath(string[] args)
        {
            string  projectName     = args[0];
            string  modelSystemName = args[1];
            string  runName         = args[2];
            var     runtime         = new XTMFRuntime();
            string  error           = null;
            Project project;

            if ((project = runtime.ProjectController.Load(projectName, ref error)) == null)
            {
                Console.WriteLine("Error loading project\r\n" + error);
                return;
            }
            using (var projectSession = runtime.ProjectController.EditProject(project))
            {
                var modelSystems = projectSession.Project.ModelSystemStructure.Select((m, i) => new { MSS = m, Index = i }).Where((m, i) => m.MSS.Name == modelSystemName).ToList();
                switch (modelSystems.Count)
                {
                case 0:
                    Console.WriteLine("There was no model system in the project " + project.Name + " called " + modelSystemName + "!");
                    return;

                case 1:
                    Run(modelSystems[0].Index, projectSession, runName);
                    break;

                default:
                    Console.WriteLine("There were multiple model systems in the project " + project.Name + " called " + modelSystemName + "!");
                    return;
                }
            }
        }
Example #10
0
        public void GetProjectController()
        {
            XTMFRuntime runtime    = XTMFRuntime.CreateRuntime();
            var         controller = runtime.ProjectController;

            Assert.IsNotNull(controller);
        }
Example #11
0
 private static void Main(string[] args)
 {
     SystemEvents.PowerModeChanged += PowerHandeler;
     int port;
     if ( args.Length < 2 )
     {
         Console.WriteLine( "Usage: XTMF.RemoteClient.exe serverAddress severPort [<Optional>ConfigurationFile]" );
         return;
     }
     if ( !int.TryParse( args[1], out port ) )
     {
         Console.WriteLine( "The port needs to be number!\r\nUsage: XTMF.RemoteClient.exe [serverAddress] [severPort] [<Optional>ConfigurationFile]" );
         return;
     }
     Configuration config = null;
     if (args.Length >= 3 )
     {
         Console.WriteLine( "Using alternative configuration file '" + args[2] + "'" );
         config = new Configuration( args[2] );
     }
     XTMFRuntime xtmf = new XTMFRuntime(config);
     // fire up the remote client engine
     if ( xtmf.InitializeRemoteClient( args[0], port ) == null )
     {
         Console.WriteLine( "We were unable to start up the remote client.  Please ensure that the server address and port were correct!" );
         return;
     }
     Console.WriteLine( "Remote Client Activated" );
 }
 /// <summary>
 /// Create a new editing session to edit a project's model system
 /// </summary>
 /// <param name="ProjectEditingSession">The editing session to read from</param>
 /// <param name="modelSystemIndex">The model system's index inside of the project</param>
 public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession ProjectEditingSession, int modelSystemIndex)
 {
     Runtime = runtime;
     this.ProjectEditingSession = ProjectEditingSession;
     ModelSystemIndex = modelSystemIndex;
     Reload();
 }
Example #13
0
        /// <summary>
        /// Create a context to edit a model system for testing
        /// </summary>
        /// <param name="name">A unique name for the test</param>
        /// <param name="toExecuteFirst">The logic to execute inside of a model system context</param>
        /// <param name="toExecuteSecond">The logic to execute inside of a model system context</param>
        internal static void RunInProjectContext(string name, Action <User, ProjectSession> toExecuteFirst, Action <User, ProjectSession> toExecuteSecond)
        {
            var          runtime           = XTMFRuntime.CreateRuntime();
            var          userController    = runtime.UserController;
            var          projectController = runtime.ProjectController;
            CommandError error             = null;
            string       userName          = name + "TempUser";
            string       projectName       = "TestProject";

            // clear out the user if possible
            userController.Delete(userName);
            Assert.IsTrue(userController.CreateNew(userName, false, out var user, out error), error?.Message);
            try
            {
                Assert.IsTrue(projectController.CreateNewProject(user, projectName, out var projectSession, out error).UsingIf(projectSession, () =>
                {
                    toExecuteFirst(user, projectSession);
                }), error?.Message);

                Assert.IsTrue(projectController.GetProject(user, projectName, out var project, out error), error?.Message);
                Assert.IsTrue(projectController.GetProjectSession(user, project, out projectSession, out error).UsingIf(projectSession, () =>
                {
                    toExecuteSecond(user, projectSession);
                }), error?.Message);
            }
            finally
            {
                //cleanup
                userController.Delete(user);
            }
        }
Example #14
0
        private static void Main(string[] args)
        {
            SystemEvents.PowerModeChanged += PowerHandeler;
            int port;

            if (args.Length < 2)
            {
                Console.WriteLine("Usage: XTMF.RemoteClient.exe serverAddress severPort [<Optional>ConfigurationFile]");
                return;
            }
            if (!int.TryParse(args[1], out port))
            {
                Console.WriteLine("The port needs to be number!\r\nUsage: XTMF.RemoteClient.exe [serverAddress] [severPort] [<Optional>ConfigurationFile]");
                return;
            }
            Configuration config = null;

            if (args.Length >= 3)
            {
                Console.WriteLine("Using alternative configuration file '" + args[2] + "'");
                config = new Configuration(args[2]);
            }
            XTMFRuntime xtmf = new XTMFRuntime(config);

            // fire up the remote client engine
            if (xtmf.InitializeRemoteClient(args[0], port) == null)
            {
                Console.WriteLine("We were unable to start up the remote client.  Please ensure that the server address and port were correct!");
                return;
            }
            Console.WriteLine("Remote Client Activated");
        }
Example #15
0
 /// <summary>
 /// Create a model system model for a previous run.
 /// </summary>
 /// <param name="modelSystemEditingSession">The session to use</param>
 /// <param name="project">The project the previous run is in.</param>
 /// <param name="runFile">The path to the run file.</param>
 public ModelSystemModel(XTMFRuntime runtime, ModelSystemEditingSession modelSystemEditingSession, Project project, string runFile)
 {
     Project = project;
     ModelSystemIndex = -1;
     Name = Path.GetFileName(runFile);
     _Description = "Previous run";
     Root = new ModelSystemStructureModel(modelSystemEditingSession, runtime.ModelSystemController.LoadFromRunFile(runFile));
 }
Example #16
0
 /// <summary>
 /// Create the bus to interact with the host.
 /// </summary>
 /// <param name="serverStream">A stream that connects to the host.</param>
 /// <param name="streamOwner">Should this bus assume ownership over the stream?</param>
 /// <param name="runtime">The XTMFRuntime to work within.</param>
 public ClientBus(Stream serverStream, bool streamOwner, XTMFRuntime runtime, List <string>?extraDlls = null)
 {
     Runtime       = runtime;
     _runScheduler = new Scheduler(this);
     _clientHost   = serverStream;
     _owner        = streamOwner;
     _extraDlls    = extraDlls ?? new List <string>();
 }
Example #17
0
 public void TestStartupPerformance()
 {
     var watch = new Stopwatch();
     watch.Start();
     XTMFRuntime runtime = new XTMFRuntime();
     watch.Stop();
     Assert.IsTrue( watch.ElapsedMilliseconds < 500, "Start time is greater than 1/2 a second!" );
 }
Example #18
0
 public RunBus(string runId, Stream toClient, bool streamOwner, XTMFRuntime runtime)
 {
     _id            = runId;
     _toClient      = toClient;
     _streamOwner   = streamOwner;
     _runtime       = runtime;
     runtime.RunBus = this;
 }
Example #19
0
 internal ModelSystemController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = this.XTMFRuntime.Configuration;
     this.DataView = new DataAccessView<IModelSystem>( this.Configuration.ModelSystemRepository.ModelSystems );
     // initialize the add / remove modelsystems
     ( (ModelSystemRepository)this.Configuration.ModelSystemRepository ).ModelSystemAdded += new Action<IModelSystem>( ModelSystemController_ModelSystemAdded );
     ( (ModelSystemRepository)this.Configuration.ModelSystemRepository ).ModelSystemRemoved += new Action<IModelSystem, int>( ModelSystemController_ModelSystemRemoved );
 }
Example #20
0
 private RunContext(XTMFRuntime runtime, string id, byte[] modelSystem, string cwd, string start)
 {
     _runtime                 = runtime;
     ID                       = id;
     _modelSystem             = modelSystem;
     _currentWorkingDirectory = cwd;
     HasExecuted              = false;
     StartToExecute           = start;
 }
Example #21
0
 internal ModelSystemController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime   = xtmfRuntime;
     this.Configuration = this.XTMFRuntime.Configuration;
     this.DataView      = new DataAccessView <IModelSystem>(this.Configuration.ModelSystemRepository.ModelSystems);
     // initialize the add / remove modelsystems
     ((ModelSystemRepository)this.Configuration.ModelSystemRepository).ModelSystemAdded   += new Action <IModelSystem>(ModelSystemController_ModelSystemAdded);
     ((ModelSystemRepository)this.Configuration.ModelSystemRepository).ModelSystemRemoved += new Action <IModelSystem, int>(ModelSystemController_ModelSystemRemoved);
 }
Example #22
0
 internal static XTMFRuntime CreateRuntime()
 {
     if ( Runtime == null )
     {
         // create an xtmf runtime that is able to look at the modules contained within this testing environment
         Runtime = new XTMFRuntime( new Configuration( "TestConfiguration.xml", System.Reflection.Assembly.GetExecutingAssembly() ) );
     }
     return Runtime;
 }
Example #23
0
 /// <summary>
 /// Initialize the project controller
 /// </summary>
 /// <param name="xtmfRuntime">A connection back to the XTMF we are apart of</param>
 internal ProjectController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = xtmfRuntime.Configuration;
     this.DataView = new DataAccessView<IProject>( this.Configuration.ProjectRepository.Projects );
     // initialize the hooks into added / removed
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectAdded += new Action<IProject>( ProjectController_ProjectAdded );
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectRemoved += new Action<IProject, int>( ProjectController_ProjectRemoved );
 }
Example #24
0
 /// <summary>
 /// Initialize the project controller
 /// </summary>
 /// <param name="xtmfRuntime">A connection back to the XTMF we are apart of</param>
 internal ProjectController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = xtmfRuntime.Configuration;
     this.DataView = new DataAccessView<IProject>( this.Configuration.ProjectRepository.Projects );
     // initialize the hooks into added / removed
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectAdded += new Action<IProject>( ProjectController_ProjectAdded );
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectRemoved += new Action<IProject, int>( ProjectController_ProjectRemoved );
 }
Example #25
0
 /// <summary>
 /// Creates a Run that is ready to execute.
 /// </summary>
 /// <param name="id">The ID of the run</param>
 /// <param name="modelSystemAsString">A representation of the model system as a string.</param>
 /// <param name="startToExecute">The Start that will be the point in which the model system will be invoked from.</param>
 /// <param name="runtime">The instance of XTMF that will be used.</param>
 /// <param name="cwd">The directory to run the model system in.</param>
 public Run(string id, byte[] modelSystem, string startToExecute, XTMFRuntime runtime, string cwd)
 {
     ID = id;
     _modelSystemAsData       = modelSystem;
     StartToExecute           = startToExecute;
     HasExecuted              = false;
     _runtime                 = runtime;
     _currentWorkingDirectory = cwd;
 }
Example #26
0
 internal static XTMFRuntime CreateRuntime()
 {
     if ( Runtime == null )
     {
         // create an xtmf runtime that is able to look at the modules contained within this testing environment
         Runtime = new XTMFRuntime( new Configuration( "TestConfiguration.xml", System.Reflection.Assembly.GetExecutingAssembly() ) );
     }
     return Runtime;
 }
Example #27
0
        public void TestStartupPerformance()
        {
            var watch = new Stopwatch();

            watch.Start();
            XTMFRuntime runtime = new XTMFRuntime();

            watch.Stop();
            Assert.IsTrue(watch.ElapsedMilliseconds < 500, "Start time is greater than 1/2 a second!");
        }
Example #28
0
 /// <summary>
 /// Create a new system configuration for the given XTMF Runtime.
 /// </summary>
 /// <param name="runtime">The runtime to bind to.</param>
 /// <param name="fullPath">Optional, the path to the system configuration.</param>
 public SystemConfiguration(XTMFRuntime runtime, string?fullPath = null)
 {
     CreateDirectory(DefaultUserDirectory =
                         Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "XTMF2", "Users"));
     Modules = new ModuleRepository();
     Types   = new TypeRepository();
     // Load the entry assembly for types
     LoadAssembly(Assembly.GetEntryAssembly() !);
     // Load the baked in XTMF2 modules
     LoadAssembly(typeof(SystemConfiguration).GetTypeInfo().Assembly);
 }
Example #29
0
 public ModelSystemEditingSession OpenModelSystem(XTMFRuntime runtime)
 {
     Runtime = runtime;
     MSEditSession = null;
     InternalModel.Initialize(runtime.ModelSystemController.GetModelSystems());
     DataContext = InternalModel;
     Display.ItemsSource = InternalModel.Data;
     FilterBox.Display = Display;
     FilterBox.Filter = Filter;
     ShowDialog();
     return MSEditSession;
 }
Example #30
0
        private static void RunClient(Stream serverStream, List <string> extraDlls, SystemConfiguration?config = null)
        {
            var runtime      = XTMFRuntime.CreateRuntime(config);
            var loadedConfig = runtime.SystemConfiguration;

            foreach (var dll in extraDlls)
            {
                loadedConfig.LoadAssembly(dll);
            }
            using var clientBus = new ClientBus(serverStream, true, runtime, extraDlls);
            clientBus.ProcessRequests();
        }
Example #31
0
        private static void Run(string runID, Stream toClient, List <string> dllsToLoad)
        {
            var runtime = XTMFRuntime.CreateRuntime();
            var config  = runtime.SystemConfiguration;

            foreach (var dll in dllsToLoad)
            {
                config.LoadAssembly(dll);
            }
            using var runBus = new RunBus(runID, toClient, true, runtime);
            runBus.ProcessRequests();
        }
Example #32
0
        public void RemoveUserFromProjectTwice()
        {
            var          runtime           = XTMFRuntime.CreateRuntime();
            var          userController    = runtime.UserController;
            var          projectController = runtime.ProjectController;
            CommandError error             = null;
            const string userName1         = "FirstUser";
            const string userName2         = "SecondtUser";
            const string projectName1      = "TestShareBetweenUsers1";
            const string projectName2      = "TestShareBetweenUsers2";

            // ensure the user doesn't exist before we start and then create our users
            userController.Delete(userName1);
            userController.Delete(userName2);
            Assert.IsTrue(userController.CreateNew(userName1, false, out var user1, out error), error?.Message);
            Assert.IsTrue(userController.CreateNew(userName2, false, out var user2, out error), error?.Message);
            // now we need to create a project for both users

            Assert.IsTrue(projectController.CreateNewProject(user1, projectName1, out var session1, out error), error?.Message);
            Assert.IsTrue(projectController.CreateNewProject(user2, projectName2, out var session2, out error), error?.Message);

            // make sure we only have 1 project
            Assert.AreEqual(1, user1.AvailableProjects.Count);
            Assert.AreEqual(1, user2.AvailableProjects.Count);

            // Share project1 with user1
            Assert.IsTrue(session1.ShareWith(user1, user2, out error), error?.Message);
            Assert.AreEqual(1, user1.AvailableProjects.Count);
            Assert.AreEqual(2, user2.AvailableProjects.Count);

            Assert.IsFalse(session1.ShareWith(user1, user2, out error), error?.Message);
            Assert.IsFalse(session1.ShareWith(user2, user2, out error), error?.Message);

            Assert.IsFalse(session1.RestrictAccess(user1, user1, out error));
            Assert.IsFalse(session1.RestrictAccess(user2, user1, out error));
            Assert.IsTrue(session1.RestrictAccess(user1, user2, out error), error?.Message);
            // Ensure that we can't do it again
            Assert.IsFalse(session1.RestrictAccess(user1, user2, out error), error?.Message);

            Assert.AreEqual(1, user1.AvailableProjects.Count);
            Assert.AreEqual(1, user2.AvailableProjects.Count);

            // Delete user1 and make sure that user2 loses reference to project1
            Assert.IsTrue(userController.Delete(user1));
            Assert.AreEqual(1, user2.AvailableProjects.Count);

            // finish cleaning up
            Assert.IsTrue(userController.Delete(user2));
        }
Example #33
0
        public void CreateUser()
        {
            var          runtime        = XTMFRuntime.CreateRuntime();
            var          userController = runtime.UserController;
            CommandError error          = null;
            const string userName       = "******";

            // ensure the user doesn't exist before we start
            userController.Delete(userName);
            Assert.IsTrue(userController.CreateNew(userName, false, out var user, out error));
            Assert.IsNull(error);
            Assert.IsFalse(userController.CreateNew(userName, false, out var secondUser, out error));
            Assert.IsNotNull(error);
            error = null;
            Assert.IsTrue(userController.Delete(user));
        }
Example #34
0
 public ModelSystemEditingSession OpenModelSystem(XTMFRuntime runtime)
 {
     ExportButton.IsEnabled = true;
     Runtime = runtime;
     MSEditSession = null;
     InternalModel.Initialize(runtime.ModelSystemController.GetModelSystems());
     DataContext = InternalModel;
     lock (InternalModel.Data)
     {
         Display.ItemsSource = InternalModel.Data;
     }
     FilterBox.Display = Display;
     FilterBox.Filter = Filter;
     ShowDialog();
     return MSEditSession;
 }
Example #35
0
        private ModelSystem CreateSpecificTestModelSystem(XTMFRuntime runtime)
        {
            var controller = runtime.ModelSystemController;

            controller.Delete("TestModelSystem");
            var    modelSystem = controller.LoadOrCreate("TestModelSystem");
            string error       = null;

            using (var session = controller.EditModelSystem(modelSystem))
            {
                var root = session.ModelSystemModel.Root;
                root.Type = typeof(TestSpecificGenericModuleMST);
                Assert.IsTrue(session.Save(ref error));
            }
            return(modelSystem);
        }
Example #36
0
 public ProjectEditingSession OpenProject(XTMFRuntime runtime)
 {
     ExportButton.IsEnabled = false;
     Runtime      = runtime;
     PEditSession = null;
     InternalModel.Initialize(runtime.ProjectController.GetProjects());
     DataContext = InternalModel;
     lock (InternalModel.Data)
     {
         Display.ItemsSource = InternalModel.Data;
     }
     FilterBox.Display = Display;
     FilterBox.Filter  = Filter;
     ShowDialog();
     return(PEditSession);
 }
Example #37
0
 public ModelSystemEditingSession OpenModelSystem(XTMFRuntime runtime)
 {
     ExportButton.IsEnabled = true;
     Runtime       = runtime;
     MSEditSession = null;
     InternalModel.Initialize(runtime.ModelSystemController.GetModelSystems());
     DataContext = InternalModel;
     lock (InternalModel.Data)
     {
         Display.ItemsSource = InternalModel.Data;
     }
     FilterBox.Display = Display;
     FilterBox.Filter  = Filter;
     ShowDialog();
     return(MSEditSession);
 }
Example #38
0
        public ModelSystemsDisplay(XTMFRuntime runtime)
        {
            InitializeComponent();
            Runtime = runtime;
            var modelSystemRepository = ((ModelSystemRepository)Runtime.Configuration.ModelSystemRepository);

            Display.ItemsSource = new ProxyList <IModelSystem>(modelSystemRepository.ModelSystems);
            modelSystemRepository.ModelSystemAdded   += ModelSystemRepository_ModelSystemAdded;
            modelSystemRepository.ModelSystemRemoved += ModelSystemRepository_ModelSystemRemoved;
            FilterBox.Display = Display;
            FilterBox.Filter  = (o, filterString) =>
            {
                var modelSystem = o as ModelSystem;
                return(modelSystem.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0);
            };
            Loaded += ModelSystemsDisplay_Loaded;
        }
Example #39
0
        public ProjectsDisplay(XTMFRuntime runtime)
        {
            InitializeComponent();
            Runtime = runtime;
            var projectRepository = ((ProjectRepository)runtime.Configuration.ProjectRepository);

            Loaded += ProjectsDisplay_Loaded;
            Display.ItemsSource               = new XTMF.Gui.Collections.ProxyList <IProject>(projectRepository.Projects);
            projectRepository.ProjectAdded   += ProjectRepository_ProjectAdded;
            projectRepository.ProjectRemoved += ProjectRepository_ProjectRemoved;
            FilterBox.Display = Display;
            FilterBox.Filter  = (o, filterString) =>
            {
                var project = o as IProject;
                return(project.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0);
            };
        }
Example #40
0
        public void ModelSystemPersistance()
        {
            var          runtime           = XTMFRuntime.CreateRuntime();
            var          userController    = runtime.UserController;
            var          projectController = runtime.ProjectController;
            CommandError error             = null;
            const string userName          = "******";
            const string projectName       = "TestProject";
            const string modelSystemName   = "ModelSystem1";

            // clear out the user if possible
            userController.Delete(userName);
            Assert.IsTrue(userController.CreateNew(userName, false, out var user, out error), error?.Message);
            Assert.IsTrue(projectController.CreateNewProject(user, projectName, out var session, out error).UsingIf(session, () =>
            {
                Assert.IsTrue(session.CreateNewModelSystem(user, modelSystemName, out var modelSystemHeader, out error), error?.Message);
                Assert.IsTrue(session.Save(out error));
            }), error?.Message);
Example #41
0
        public void CreateNewProject()
        {
            var          runtime    = XTMFRuntime.CreateRuntime();
            var          controller = runtime.ProjectController;
            CommandError error      = null;
            var          localUser  = TestHelper.GetTestUser(runtime);

            // delete the project in case it has survived.
            controller.DeleteProject(localUser, "Test", out error);
            Assert.IsTrue(controller.CreateNewProject(localUser, "Test", out ProjectSession session, out error).UsingIf(session, () =>
            {
                var project = session.Project;
                Assert.AreEqual("Test", project.Name);
                Assert.AreEqual(localUser, project.Owner);
            }), "Unable to create project");
            Assert.IsTrue(controller.DeleteProject(localUser, "Test", out error));
            Assert.IsFalse(controller.DeleteProject(localUser, "Test", out error));
        }
Example #42
0
        public void Window_Loaded(object sender, RoutedEventArgs e)
        {
            bool   glass = false;
            string value;

            if (this.FirstLoad)
            {
                this.Background = new SolidColorBrush(Color.FromRgb(16, 25, 39));
                this.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    this.XTMF = new XTMFRuntime();
                    BindToControllers();
                    LoadData();
                    Initialize();
                    App.Current.Exit += new ExitEventHandler(Current_Exit);
                    this.Navigate(XTMFPage.StartPage);
                    this.FirstLoad = false;
                    if (this.XTMF.Configuration.AdditionalSettings.TryGetValue("UseGlass", out value))
                    {
                        bool.TryParse(value, out glass);
                    }
                    if (glass && !ApplyGlass() || !glass)
                    {
                        this.Background = new SolidColorBrush(Color.FromRgb(16, 25, 39));
                        this.XTMF.Configuration.AdditionalSettings["UseGlass"] = "false";
                    }
                }));
                this.FirstLoad = true;
            }
            else
            {
                if (this.XTMF.Configuration.AdditionalSettings.TryGetValue("UseGlass", out value))
                {
                    bool.TryParse(value, out glass);
                }
                if (glass && !ApplyGlass() || !glass)
                {
                    this.Background = new SolidColorBrush(Color.FromRgb(16, 25, 39));
                    this.XTMF.Configuration.AdditionalSettings["UseGlass"] = "false";
                }
            }
        }
Example #43
0
 internal static void Register(MainWindow window, Action OnComplete)
 {
     Task.Factory.StartNew(
         () =>
     {
         OpenWindows.Run( (list) =>
         {
             if ( Runtime == null )
             {
                 Runtime = new XTMFRuntime();
             }
             if ( !list.Contains( window ) )
             {
                 list.Add( window );
             }
             if ( OnComplete != null )
             {
                 OnComplete();
             }
         } );
     } );
 }
Example #44
0
 /// <summary>
 /// Create a model editing session for a previous run.  This will be read-only!
 /// </summary>
 /// <param name="runtime">A link to the XTMFRuntime</param>
 /// <param name="projectSession">The project this is for.</param>
 /// <param name="runFile">The location of the previous run.</param>
 public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession projectSession, string runFile)
 {
     this.Runtime = runtime;
     ProjectEditingSession = projectSession;
     ModelSystemIndex = -1;
     ModelSystemModel = new ModelSystemModel(Runtime, this, projectSession.Project, runFile);
 }
Example #45
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="xtmfRuntime"></param>
 internal RunController(XTMFRuntime xtmfRuntime)
 {
     // TODO: Complete member initialization
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = this.XTMFRuntime.Configuration;
 }
Example #46
0
 public void InitializeXTMF()
 {
     var configurationFileName = "";
     var config = new Configuration(configurationFileName);
     var xtmf = new XTMFRuntime( config );
 }
Example #47
0
 public ProjectEditingSession(Project project, XTMFRuntime runtime)
 {
     Project = project;
     Runtime = runtime;
     EditingSessions = new SessionData[Project.ModelSystemStructure.Count];
 }
Example #48
0
 public ProjectEditingSession OpenProject(XTMFRuntime runtime)
 {
     Runtime = runtime;
     PEditSession = null;
     InternalModel.Initialize(runtime.ProjectController.GetProjects());
     DataContext = InternalModel;
     Display.ItemsSource = InternalModel.Data;
     FilterBox.Display = Display;
     FilterBox.Filter = Filter;
     ShowDialog();
     return PEditSession;
 }
Example #49
0
 internal static ModelSystem GetModelSystem(XTMFRuntime runtime, string name)
 {
     var controller = runtime.ModelSystemController;
     return controller.LoadOrCreate( name );
 }
Example #50
0
 public ModelSystemController(XTMFRuntime runtime)
 {
     Runtime = runtime;
     Repository = Runtime.Configuration.ModelSystemRepository as ModelSystemRepository;
 }
Example #51
0
 public ProjectEditingSession OpenProject(XTMFRuntime runtime)
 {
     ExportButton.IsEnabled = false;
     Runtime = runtime;
     PEditSession = null;
     InternalModel.Initialize(runtime.ProjectController.GetProjects());
     DataContext = InternalModel;
     lock (InternalModel.Data)
     {
         Display.ItemsSource = InternalModel.Data;
     }
     FilterBox.Display = Display;
     FilterBox.Filter = Filter;
     ShowDialog();
     return PEditSession;
 }
Example #52
0
 /// <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 static bool CloneModelSystemAs(XTMFRuntime Runtime, IModelSystemStructure root, List<ILinkedParameter> linkedParameters, string description, string name, ref string error)
 {
     var ms = Runtime.ModelSystemController.LoadOrCreate(name);
     ms.Name = name;
     ms.Description = description;
     ms.ModelSystemStructure = root;
     ms.LinkedParameters = linkedParameters;
     var ret = ms.Save(ref error);
     // make sure we don't reuse any references
     ms.Unload();
     return ret;
 }
Example #53
0
 public void Window_Loaded(object sender, RoutedEventArgs e)
 {
     bool glass = false;
     string value;
     if ( this.FirstLoad )
     {
         this.Background = new SolidColorBrush( Color.FromRgb( 16, 25, 39 ) );
         this.Dispatcher.BeginInvoke( new Action( delegate()
         {
             this.XTMF = new XTMFRuntime();
             BindToControllers();
             LoadData();
             Initialize();
             App.Current.Exit += new ExitEventHandler( Current_Exit );
             this.Navigate( XTMFPage.StartPage );
             this.FirstLoad = false;
             if ( this.XTMF.Configuration.AdditionalSettings.TryGetValue( "UseGlass", out value ) )
             {
                 bool.TryParse( value, out glass );
             }
             if ( glass && !ApplyGlass() || !glass )
             {
                 this.Background = new SolidColorBrush( Color.FromRgb( 16, 25, 39 ) );
                 this.XTMF.Configuration.AdditionalSettings["UseGlass"] = "false";
             }
         } ) );
         this.FirstLoad = true;
     }
     else
     {
         if ( this.XTMF.Configuration.AdditionalSettings.TryGetValue( "UseGlass", out value ) )
         {
             bool.TryParse( value, out glass );
         }
         if ( glass && !ApplyGlass() || !glass )
         {
             this.Background = new SolidColorBrush( Color.FromRgb( 16, 25, 39 ) );
             this.XTMF.Configuration.AdditionalSettings["UseGlass"] = "false";
         }
     }
 }
Example #54
0
 public NetworkingController(XTMFRuntime xtmfRuntime)
 {
     // TODO: Complete member initialization
     this.XTMFRuntime = xtmfRuntime;
 }
 private ModelSystem CreateTestModelSystem(XTMFRuntime runtime)
 {
     var controller = runtime.ModelSystemController;
     controller.Delete("TestModelSystem");
     var modelSystem = controller.LoadOrCreate("TestModelSystem");
     string error = null;
     using (var session = controller.EditModelSystem(modelSystem))
     {
         var root = session.ModelSystemModel.Root;
         root.Type = typeof(TestModelSystemTemplate);
         Assert.IsTrue(session.Save(ref error));
     }
     return modelSystem;
 }
Example #56
0
 /// <summary>
 /// Create a new session to edit a model system
 /// </summary>
 /// <param name="modelSystem">The model system to edit</param>
 public ModelSystemEditingSession(XTMFRuntime runtime, ModelSystem modelSystem)
 {
     Runtime = runtime;
     ModelSystem = modelSystem;
     ModelSystemModel = new ModelSystemModel(this, modelSystem);
 }