Ejemplo n.º 1
0
        /// <summary>Cleanup after the run.</summary>
        public void CleanupRun(string errorMessage)
        {
            _IsRunning = false;

            if (Completed != null)
            {
                Completed.Invoke(this, null);
            }

            Apsim.DisconnectEvents(this);
            Apsim.UnresolveLinks(this);
            foreach (Model child in Apsim.ChildrenRecursively(this))
            {
                Apsim.DisconnectEvents(child);
                Apsim.UnresolveLinks(child);
            }

            timer.Stop();
            if (errorMessage == null)
            {
                Console.WriteLine("Completed: " + Path.GetFileNameWithoutExtension(FileName) + " - " + Name + " [" + timer.Elapsed.TotalSeconds.ToString("#.00") + " sec]");
            }
            else
            {
                Console.WriteLine("Completed with errors: " + Path.GetFileNameWithoutExtension(FileName));
                Console.WriteLine(errorMessage);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Documents the specified model.</summary>
        /// <param name="modelNameToDocument">The model name to document.</param>
        /// <param name="tags">The auto doc tags.</param>
        /// <param name="headingLevel">The starting heading level.</param>
        public void DocumentModel(string modelNameToDocument, List <AutoDocumentation.ITag> tags, int headingLevel)
        {
            Simulation simulation = Apsim.Find(this, typeof(Simulation)) as Simulation;

            if (simulation != null)
            {
                // Find the model of the right name.
                IModel modelToDocument = Apsim.Find(simulation, modelNameToDocument);

                // If not found then find a model of the specified type.
                if (modelToDocument == null)
                {
                    modelToDocument = Apsim.Get(simulation, "[" + modelNameToDocument + "]") as IModel;
                }

                // If still not found throw an error.
                if (modelToDocument == null)
                {
                    throw new ApsimXException(this, "Could not find a model of the name " + modelNameToDocument + ". Simulation file name must match the name of the node to document.");
                }

                // Get the path of the model (relative to parentSimulation) to document so that
                // when replacements happen below we will point to the replacement model not the
                // one passed into this method.
                string pathOfSimulation      = Apsim.FullPath(simulation) + ".";
                string pathOfModelToDocument = Apsim.FullPath(modelToDocument).Replace(pathOfSimulation, "");

                // Clone the simulation
                Simulation clonedSimulation = Apsim.Clone(simulation) as Simulation;

                // Make any substitutions.
                MakeSubstitutions(new Simulation[] { clonedSimulation });

                // Now use the path to get the model we want to document.
                modelToDocument = Apsim.Get(clonedSimulation, pathOfModelToDocument) as IModel;

                // resolve all links in cloned simulation.
                Apsim.ResolveLinks(clonedSimulation);
                foreach (Model child in Apsim.ChildrenRecursively(clonedSimulation))
                {
                    Apsim.ResolveLinks(child);
                }

                // Document the model.
                modelToDocument.Document(tags, headingLevel, 0);

                // Unresolve links.
                Apsim.UnresolveLinks(clonedSimulation);
                foreach (Model child in Apsim.ChildrenRecursively(clonedSimulation))
                {
                    Apsim.UnresolveLinks(child);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>Cleanup after the run.</summary>
        public void CleanupRun()
        {
            _IsRunning = false;

            if (Completed != null)
            {
                Completed.Invoke(this, null);
            }

            Apsim.DisconnectEvents(this);
            Apsim.UnresolveLinks(this);
            foreach (Model child in Apsim.ChildrenRecursively(this))
            {
                Apsim.DisconnectEvents(child);
                Apsim.UnresolveLinks(child);
            }

            timer.Stop();
            Console.WriteLine("File: " + Path.GetFileNameWithoutExtension(this.FileName) + ", Simulation " + this.Name + " complete. Time: " + timer.Elapsed.TotalSeconds.ToString("0.00 sec"));
        }