/// <summary> /// Perform the command /// </summary> public void Do(CommandHistory CommandHistory) { Simulation clonedSimulation = null; IEvent events = null; try { List <Simulation> sims = new List <Models.Core.Simulation>(); clonedSimulation = Apsim.Clone(simulation) as Simulation; sims.Add(clonedSimulation); explorerPresenter.ApsimXFile.MakeSubstitutions(clonedSimulation); events = explorerPresenter.ApsimXFile.GetEventService(clonedSimulation); events.ConnectEvents(); explorerPresenter.ApsimXFile.Links.Resolve(clonedSimulation); List <ModelDoc> models = new List <ModelDoc>(); foreach (IModel model in Apsim.ChildrenRecursively(clonedSimulation)) { ModelDoc newModelDoc = DocumentModel(model); newModelDoc.Name = Apsim.FullPath(model); models.Add(newModelDoc); } StringWriter rawXML = new StringWriter(); XmlSerializer serialiser = new XmlSerializer(typeof(List <ModelDoc>)); serialiser.Serialize(rawXML, models); rawXML.Close(); // Load the XSL transform from the resource Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApsimNG.Resources.DebugDoc.xsl"); var transform = new XslCompiledTransform(); using (XmlReader reader = XmlReader.Create(s)) { transform.Load(reader); } // Apply the transform to the reader and write it to a temporary file. string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); string htmlFileName = Path.ChangeExtension(tempFileName, ".html"); using (XmlReader reader = XmlReader.Create(new StringReader(rawXML.ToString()))) using (XmlWriter htmlWriter = XmlWriter.Create(htmlFileName)) { transform.Transform(reader, htmlWriter); } Process.Start(htmlFileName); } finally { if (clonedSimulation != null) { events.DisconnectEvents(); explorerPresenter.ApsimXFile.Links.Unresolve(clonedSimulation, allLinks: true); } } }