Ejemplo n.º 1
0
    public void Execute(MainPresenter mainPresenter)
    {
        // Set the current working directory to the bin folder.
        string binFolder = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);

        Directory.SetCurrentDirectory(binFolder);

        // Get the environment variable 'ModelName'
        string modelName = System.Environment.GetEnvironmentVariable("ModelName");

        // Open wheat validation in a tab
        string fileName = Path.Combine(binFolder, @"..\Tests\Validation\" + modelName + @"\" + modelName + ".apsimx");

        if (File.Exists(fileName))
        {
            mainPresenter.OpenApsimXFileInTab(fileName, true);

            // Get the presenter for this tab.
            ExplorerPresenter presenter = mainPresenter.Presenters1[0] as ExplorerPresenter;
            if (presenter != null)
            {
                presenter.SelectNode(".Simulations");

                // Export the model to HTML
                string folderName = Path.Combine(binFolder, @"..\Documentation\PDF");
                Directory.CreateDirectory(folderName);

                var command = new CreateDocCommand(presenter);
                command.Do(null);

                // Copy the file into the PDF directory.
                File.Copy(command.FileNameWritten, @"..\Documentation\PDF\" + modelName + ".pdf");
            }
        }
        // Close the user interface.
        mainPresenter.Close(false);
    }
Ejemplo n.º 2
0
    private void Document(string fileName)
    {
        try
        {
            if (File.Exists(fileName))
            {
                masterPresenter.OpenApsimXFileInTab(fileName, true);
                // Get the presenter for this tab.
                ExplorerPresenter presenter = masterPresenter.Presenters1[0] as ExplorerPresenter;
                if (presenter != null)
                {
                    presenter.SelectNode(".Simulations");

                    // Export the file to PDF
                    string folderName = Path.Combine(binFolder, "..", "Documentation", "PDF");
                    Directory.CreateDirectory(folderName);

                    CreateDocCommand command = new CreateDocCommand(presenter);
                    command.Do(null);

                    // Copy the file into the PDF directory.
                    string outputFileName = Path.ChangeExtension(Path.Combine(folderName, Path.GetFileNameWithoutExtension(fileName)), ".pdf");
                    File.Move(command.FileNameWritten, outputFileName);
                }
            }
            else
            {
                throw new Exception(string.Format("Attempted to document file {0} but this file does not exist.", fileName));
            }
        }
        finally
        {
            // Close the user interface.
            masterPresenter.Close(false);
        }
    }