/// <summary>
        ///     Run the model if it is contained inside of a project.
        /// </summary>
        /// <param name="runName"></param>
        /// <param name="error">A message in case of error</param>
        /// <param name="executeNow">Should the run start executing now or wait for all other runs to finish first?</param>
        /// <param name="forceLocal">Execute in the local process, overriding default behaviour.</param>
        /// <returns>A reference to the run.</returns>
        public XTMFRun Run(string runName, ref string error, bool overwrite = false, bool executeNow = true,
                           bool forceLocal = false)
        {
            // this needs to block as if a command is running
            lock (_SessionLock)
            {
                if (!CanRun)
                {
                    error = "You can not run this model system.";
                    return(null);
                }

                lock (_RunningLock)
                {
                    XTMFRun run;
                    if (_ModelSystemIndex >= 0)
                    {
                        var cloneProject = ProjectEditingSession.CreateCloneProject(ProjectEditingSession.Project);
                        cloneProject.ModelSystemStructure[_ModelSystemIndex] =
                            ModelSystemModel.Root.RealModelSystemStructure;
                        cloneProject.ModelSystemDescriptions[_ModelSystemIndex] = ModelSystemModel.Description;
                        cloneProject.LinkedParameters[_ModelSystemIndex]        =
                            ModelSystemModel.LinkedParameters.GetRealLinkedParameters();


                        if (((Configuration)Configuration).RemoteHost)
                        {
                            run = XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                           _Runtime.Configuration, runName, overwrite);
                        }
                        else
                        {
                            run =
                                Debugger.IsAttached || forceLocal ||
                                !((Configuration)Configuration).RunInSeperateProcess
                                    ? XTMFRun.CreateLocalRun(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                             _Runtime.Configuration, runName, overwrite)
                                    : XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                               _Runtime.Configuration, runName, overwrite);
                        }


                        run.ProjectSavedByRun += (theRun, newMSS) =>
                        {
                            string e = null;
                            ProjectEditingSession.Project.ModelSystemStructure[_ModelSystemIndex] = newMSS;
                            ProjectEditingSession.Project.Save(ref e);
                            Reload();
                            ProjectWasExternallySaved?.Invoke(this, new EventArgs());
                        };
                    }
                    else
                    {
                        run = XTMFRun.CreateLocalRun(ProjectEditingSession.Project, ModelSystemModel.Root,
                                                     _Runtime.Configuration, runName, overwrite);
                    }
                    return(run);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Run the model if it is contained inside of a project.
 /// </summary>
 /// <param name="runName"></param>
 /// <param name="error">A message in case of error</param>
 /// <returns></returns>
 public XTMFRun Run(string runName, ref string error)
 {
     // this needs to block as if a command is running
     lock (SessionLock)
     {
         if (!CanRun)
         {
             error = "You can not run this model system.";
             return(null);
         }
         lock (RunningLock)
         {
             if (AnyRunning)
             {
                 error = "Only one run can be executing at the same time!";
                 return(null);
             }
             XTMFRun run;
             if (ModelSystemIndex >= 0)
             {
                 Project cloneProject = ProjectEditingSession.CreateCloneProject(ProjectEditingSession.Project);
                 cloneProject.ModelSystemStructure[ModelSystemIndex]    = ModelSystemModel.Root.RealModelSystemStructure;
                 cloneProject.ModelSystemDescriptions[ModelSystemIndex] = ModelSystemModel.Description;
                 cloneProject.LinkedParameters[ModelSystemIndex]        = ModelSystemModel.LinkedParameters.GetRealLinkedParameters();
                 run = new XTMFRun(cloneProject, ModelSystemIndex, ModelSystemModel, Runtime.Configuration, runName);
             }
             else
             {
                 run = new XTMFRun(ProjectEditingSession.Project, ModelSystemModel.Root, Runtime.Configuration, runName);
             }
             this._Run.Add(run);
             AnyRunning                  = true;
             _IsRunning                  = true;
             run.RunComplete            += () => TerminateRun(run);
             run.ValidationError        += (e) => TerminateRun(run);
             run.RuntimeValidationError += (e) => TerminateRun(run);
             return(run);
         }
     }
 }