示例#1
0
        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);
        }
示例#2
0
 public void Start()
 {
     foreach (var mst in this.SubMST)
     {
         this.CurrentlyExecuting = mst;
         mst.Start();
     }
     this.CurrentlyExecuting = null;
 }
示例#3
0
        private void OurRun()
        {
            string cwd   = null;
            string error = null;

            try
            {
                this.MST = this.Project.CreateModelSystem(ref error, this.ModelSystemIndex);
            }
            catch (Exception e)
            {
                SendValidationError(e.Message);
                return;
            }
            if (MST == null)
            {
                SendValidationError(error);
                return;
            }
            var MSTStructure = this.Project.ModelSystemStructure[this.ModelSystemIndex];

            try
            {
                AlertValidationStarting();
                var path = Path.Combine(this.Config.ProjectDirectory, this.Project.Name, this.RunName);
                cwd = System.IO.Directory.GetCurrentDirectory();
                System.IO.Directory.SetCurrentDirectory(path);
                MSTStructure.Save(Path.GetFullPath("RunParameters.xml"));
                if (!this.RunTimeValidation(ref error, MSTStructure))
                {
                    this.SendRuntimeValidationError(error);
                }
                else
                {
                    this.SetStatusToRunning();
                    MST.Start();
                }
            }
            catch (Exception e)
            {
                this.SendRuntimeError(e);
            }
            finally
            {
                Thread.MemoryBarrier();
                this.CleanUpModelSystem(MSTStructure);
                MSTStructure = null;
                MST          = null;
                (this.Config as Configuration).ModelSystemExited();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Thread.MemoryBarrier();
                System.IO.Directory.SetCurrentDirectory(cwd);
                SendRunComplete();
            }
        }
示例#4
0
        private void ModelSystemStartup(object modelSystemStructure)
        {
            string error   = null;
            var    mss     = modelSystemStructure as IModelSystemStructure;
            var    project = (Project)_Configuration.ProjectRepository.ActiveProject;

            if (project == null)
            {
                project = new Project("Remote", _Configuration, true);
            }
            if (project.ModelSystemStructure.Count == 0)
            {
                project.AddModelSystem(mss, new List <ILinkedParameter>(), String.Empty);
            }
            else
            {
                project.SetModelSystem(0, mss, new List <ILinkedParameter>(), new List <IRegionDisplay>(), String.Empty);
            }
            ((ProjectRepository)_Configuration.ProjectRepository).SetActiveProject(project);
            var modelSystem  = project.CreateModelSystem(ref error, 0);
            var now          = DateTime.Now;
            var runDirectory = Path.GetFullPath(Path.Combine(_Configuration.ProjectDirectory,
                                                             project.Name, String.Format("{0:##}.{1:##}.{2:##}-{3}", now.Hour, now.Minute, now.Second, Guid.NewGuid())));
            bool crashed = false;

            if (!Directory.Exists(runDirectory))
            {
                Directory.CreateDirectory(runDirectory);
            }
            Directory.SetCurrentDirectory(runDirectory);
            project.Save(Path.GetFullPath("RunParameters.xml"), ref error);
            try
            {
                if (RunTimeValidation(ref error, mss))
                {
                    _CurrentRunningModelSystem = modelSystem;
                    modelSystem.Start();
                }
            }
            catch (Exception e)
            {
                crashed = true;
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                _Messages.Add(new Message(MessageType.WriteToHostConsole, $"Client has encountered an exception {e.Message}\r\n{e.StackTrace}"));
                // wait 1 second before closing to ensure the pipes have been flushed
                Thread.Sleep(1000);
            }
            CleanUp(mss);
            _CurrentRunningModelSystem = null;
            NotifyComplete();
            if (crashed)
            {
                _Exit = true;
                Thread.MemoryBarrier();
            }
        }
示例#5
0
        private void ModelSystemStartup(object modelSystemStructure)
        {
            string error   = null;
            var    mss     = modelSystemStructure as IModelSystemStructure;
            var    project = this.Configuration.ProjectRepository.ActiveProject;

            if (project == null)
            {
                project = new Project("Remote", this.Configuration, true);
            }
            if (project.ModelSystemStructure.Count == 0)
            {
                project.ModelSystemStructure.Add(mss);
            }
            else
            {
                project.ModelSystemStructure[0] = mss;
            }
            ((ProjectRepository)this.Configuration.ProjectRepository).SetActiveProject(project);
            var modelSystem  = project.CreateModelSystem(ref error, 0);
            var now          = DateTime.Now;
            var runDirectory = Path.GetFullPath(System.IO.Path.Combine(this.Configuration.ProjectDirectory,
                                                                       project.Name, String.Format("{0:##}.{1:##}.{2:##}-{3}", now.Hour, now.Minute, now.Second, Guid.NewGuid())));
            bool crashed = false;

            if (!Directory.Exists(runDirectory))
            {
                Directory.CreateDirectory(runDirectory);
            }
            System.IO.Directory.SetCurrentDirectory(runDirectory);
            project.Save(System.IO.Path.GetFullPath("RunParameters.xml"), ref error);
            try
            {
                if (RunTimeValidation(ref error, mss))
                {
                    this.CurrentRunningModelSystem = modelSystem;
                    modelSystem.Start();
                }
            }
            catch (Exception e)
            {
                crashed = true;
                e       = GetInternalMessage(e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            this.CleanUp(mss);
            this.CurrentRunningModelSystem = null;
            this.NotifyComplete();
            if (crashed)
            {
                this.Exit = true;
                Thread.MemoryBarrier();
            }
        }
示例#6
0
        private IModelSystemStructure CreateModelSystem(ref ErrorWithPath error)
        {
            IModelSystemStructure mstStructure;

            if (ModelSystemStructureModelRoot == null)
            {
                _MST         = ((Project)_Project).CreateModelSystem(ref error, Configuration, _ModelSystemIndex);
                mstStructure = _Project.ModelSystemStructure[_ModelSystemIndex];
            }
            else
            {
                _MST         = ((Project)_Project).CreateModelSystem(ref error, Configuration, ModelSystemStructureModelRoot.RealModelSystemStructure);
                mstStructure = ModelSystemStructureModelRoot.RealModelSystemStructure;
            }
            return(mstStructure);
        }
示例#7
0
文件: Client.cs 项目: Cocotus/XTMF
 private void ModelSystemStartup(object modelSystemStructure)
 {
     string error = null;
     var mss = modelSystemStructure as IModelSystemStructure;
     var project = this.Configuration.ProjectRepository.ActiveProject;
     if ( project == null )
     {
         project = new Project( "Remote", this.Configuration, true );
     }
     if ( project.ModelSystemStructure.Count == 0 )
     {
         project.ModelSystemStructure.Add( mss );
     }
     else
     {
         project.ModelSystemStructure[0] = mss;
     }
     ( (ProjectRepository)this.Configuration.ProjectRepository ).SetActiveProject( project );
     var modelSystem = project.CreateModelSystem( ref error, 0 );
     var now = DateTime.Now;
     var runDirectory = Path.GetFullPath( System.IO.Path.Combine( this.Configuration.ProjectDirectory,
         project.Name, String.Format( "{0:##}.{1:##}.{2:##}-{3}", now.Hour, now.Minute, now.Second, Guid.NewGuid() ) ) );
     bool crashed = false;
     if ( !Directory.Exists( runDirectory ) )
     {
         Directory.CreateDirectory( runDirectory );
     }
     System.IO.Directory.SetCurrentDirectory( runDirectory );
     project.Save( System.IO.Path.GetFullPath( "RunParameters.xml" ), ref error );
     try
     {
         if ( RunTimeValidation( ref error, mss ) )
         {
             this.CurrentRunningModelSystem = modelSystem;
             modelSystem.Start();
         }
     }
     catch ( Exception e )
     {
         crashed = true;
         e = GetInternalMessage( e );
         Console.WriteLine( e.Message );
         Console.WriteLine( e.StackTrace );
     }
     this.CleanUp( mss );
     this.CurrentRunningModelSystem = null;
     this.NotifyComplete();
     if ( crashed )
     {
         this.Exit = true;
         Thread.MemoryBarrier();
     }
 }
示例#8
0
        private void OurRun()
        {
            string cwd   = null;
            string error = null;
            IModelSystemStructure MSTStructure;

            try
            {
                if (ModelSystemStructureModelRoot == null)
                {
                    MST          = Project.CreateModelSystem(ref error, ModelSystemIndex);
                    MSTStructure = Project.ModelSystemStructure[ModelSystemIndex];
                }
                else
                {
                    MST          = ((Project)Project).CreateModelSystem(ref error, Configuration, ModelSystemStructureModelRoot.RealModelSystemStructure);
                    MSTStructure = ModelSystemStructureModelRoot.RealModelSystemStructure;
                }
            }
            catch (Exception e)
            {
                SendValidationError(e.Message);
                return;
            }
            if (MST == null)
            {
                SendValidationError(error);
                return;
            }

            try
            {
                AlertValidationStarting();
                cwd = Directory.GetCurrentDirectory();
                // check to see if the directory exists, if it doesn't create it
                DirectoryInfo info = new DirectoryInfo(RunDirectory);
                if (!info.Exists)
                {
                    info.Create();
                }
                Directory.SetCurrentDirectory(RunDirectory);
                MSTStructure.Save(Path.GetFullPath("RunParameters.xml"));
                if (!RunTimeValidation(ref error, MSTStructure))
                {
                    SendRuntimeValidationError(error);
                }
                else
                {
                    SetStatusToRunning();
                    MST.Start();
                }
            }
            catch (Exception e)
            {
                if (!(e is ThreadAbortException))
                {
                    SendRuntimeError(e);
                }
            }
            finally
            {
                Thread.MemoryBarrier();
                CleanUpModelSystem(MSTStructure);
                MSTStructure = null;
                MST          = null;
                if (Configuration is Configuration)
                {
                    ((Configuration as Configuration)).ModelSystemExited();
                }
                else
                {
                    ((Configuration as RunProxy.ConfigurationProxy)).ModelSystemExited();
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Thread.MemoryBarrier();
                Directory.SetCurrentDirectory(cwd);
                SendRunComplete();
            }
        }
示例#9
0
文件: XTMFRun.cs 项目: Cocotus/XTMF
 private void OurRun()
 {
     string cwd = null;
     string error = null;
     try
     {
         this.MST = this.Project.CreateModelSystem( ref error, this.ModelSystemIndex );
     }
     catch ( Exception e )
     {
         SendValidationError( e.Message );
         return;
     }
     if ( MST == null )
     {
         SendValidationError( error );
         return;
     }
     var MSTStructure = this.Project.ModelSystemStructure[this.ModelSystemIndex];
     try
     {
         AlertValidationStarting();
         var path = Path.Combine( this.Config.ProjectDirectory, this.Project.Name, this.RunName );
         cwd = System.IO.Directory.GetCurrentDirectory();
         System.IO.Directory.SetCurrentDirectory( path );
         MSTStructure.Save( Path.GetFullPath( "RunParameters.xml" ) );
         if ( !this.RunTimeValidation( ref error, MSTStructure ) )
         {
             this.SendRuntimeValidationError( error );
         }
         else
         {
             this.SetStatusToRunning();
             MST.Start();
         }
     }
     catch ( Exception e )
     {
         this.SendRuntimeError( e );
     }
     finally
     {
         Thread.MemoryBarrier();
         this.CleanUpModelSystem( MSTStructure );
         MSTStructure = null;
         MST = null;
         ( this.Config as Configuration ).ModelSystemExited();
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         Thread.MemoryBarrier();
         System.IO.Directory.SetCurrentDirectory( cwd );
         SendRunComplete();
     }
 }
示例#10
0
文件: ChainMST.cs 项目: Cocotus/XTMF
 public void Start()
 {
     foreach ( var mst in this.SubMST )
     {
         this.CurrentlyExecuting = mst;
         mst.Start();
     }
     this.CurrentlyExecuting = null;
 }
示例#11
0
文件: XTMFRun.cs 项目: dianatle/XTMF
        private void OurRun()
        {
            string cwd = null;
            string error = null;
            IModelSystemStructure MSTStructure;
            try
            {
                if(ModelSystemStructureModelRoot == null)
                {
                    MST = Project.CreateModelSystem(ref error, ModelSystemIndex);
                    MSTStructure = Project.ModelSystemStructure[ModelSystemIndex];
                }
                else
                {
                    MST = ((Project)Project).CreateModelSystem(ref error, Configuration, ModelSystemStructureModelRoot.RealModelSystemStructure);
                    MSTStructure = ModelSystemStructureModelRoot.RealModelSystemStructure;
                }
            }
            catch (Exception e)
            {
                SendValidationError(e.Message);
                return;
            }
            if(MST == null)
            {
                SendValidationError(error);
                return;
            }

            try
            {
                AlertValidationStarting();
                cwd = Directory.GetCurrentDirectory();
                // check to see if the directory exists, if it doesn't create it
                DirectoryInfo info = new DirectoryInfo(RunDirectory);
                if(!info.Exists)
                {
                    info.Create();
                }
                Directory.SetCurrentDirectory(RunDirectory);
                MSTStructure.Save(Path.GetFullPath("RunParameters.xml"));
                if(!RunTimeValidation(ref error, MSTStructure))
                {
                    SendRuntimeValidationError(error);
                }
                else
                {
                    SetStatusToRunning();
                    MST.Start();
                }
            }
            catch (Exception e)
            {
                if (!(e is ThreadAbortException))
                {
                    SendRuntimeError(e);
                }
            }
            finally
            {
                Thread.MemoryBarrier();
                CleanUpModelSystem(MSTStructure);
                MSTStructure = null;
                MST = null;
                if(Configuration is Configuration)
                {
                    ((Configuration as Configuration)).ModelSystemExited();
                }
                else
                {
                    ((Configuration as RunProxy.ConfigurationProxy)).ModelSystemExited();
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Thread.MemoryBarrier();
                Directory.SetCurrentDirectory(cwd);
                SendRunComplete();
            }
        }