示例#1
0
        public void MoveUpDown()
        {
            IExplorerView     explorerView      = new ExplorerView();
            ExplorerPresenter explorerPresenter = new ExplorerPresenter();
            CommandHistory    commandHistory    = new CommandHistory();

            explorerPresenter.Attach(simulations, explorerView, null);

            Model modelToMove = Apsim.Get(simulations, "APS14.Factors.NRate") as Model;

            MoveModelUpDownCommand moveCommand = new MoveModelUpDownCommand(modelToMove, true, explorerView);

            moveCommand.Do(commandHistory);

            Model modelToMove2 = Apsim.Get(simulations, "APS14.Factors.NRate") as Model;

            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Name, "NRate");
            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Children.Count, 4);
        }
示例#2
0
        /// <summary>
        /// Create documentation based on the specified file.
        /// </summary>
        /// <param name="documentObject">The documentObject node that describes what to document.</param>
        /// <param name="apsimDirectory">The APSIM root directory.</param>
        /// <param name="destinationFolder">The folder where the PDF should be created.</param>
        /// <param name="destinationUrl">The server destination URL where all files will end up.</param>
        /// <returns>HTML snippet for a single model document.</returns>
        private static string CreateModelDocumentation(JObject documentObject, string apsimDirectory, string destinationFolder, string destinationUrl)
        {
            string href;
            string hrefName = documentObject["Name"].ToString();

            if (documentObject["URL"] != null)
            {
                href = documentObject["URL"].ToString();
                return(string.Format("<p><a href=\"{0}\" target=\"_blank\">{1}</a></p>", href, hrefName));
            }
            else
            {
                var fileName = Path.Combine(apsimDirectory, documentObject["FileName"].ToString());
                if (File.Exists(fileName))
                {
                    // Open the file.
                    var simulations = FileFormat.ReadFromFile <Simulations>(fileName, out List <Exception> creationExceptions);
                    if (creationExceptions?.Count > 0)
                    {
                        throw creationExceptions[0];
                    }

                    // Create some necessary presenters and views.
                    var mainPresenter     = new MainPresenter();
                    var explorerPresenter = new ExplorerPresenter(mainPresenter);

                    var explorerView = new ExplorerView(null);
                    explorerPresenter.Attach(simulations, explorerView, explorerPresenter);

                    // Document model.
                    if (documentObject["ModelNameToDocument"] == null)
                    {
                        Console.WriteLine("Creating documentation from " + fileName);

                        // Whole of simulation document.
                        var createDoc = new CreateFileDocumentationCommand(explorerPresenter, destinationFolder);
                        createDoc.Do();
                        href = Path.GetFileName(createDoc.FileNameWritten);
                    }
                    else
                    {
                        Console.WriteLine("Creating model description documentation from " + fileName);

                        // Specific model description documentation.
                        var modelNameToDocument = documentObject["ModelNameToDocument"].ToString();
                        var model = simulations.FindInScope(modelNameToDocument) as IModel;
                        if (model == null)
                        {
                            return(null);
                        }
                        var outputFileName = documentObject["OutputFileName"]?.ToString();
                        var createDoc      = new CreateParamsInputsOutputsDocCommand(explorerPresenter, model, destinationFolder, outputFileName);
                        createDoc.Do();
                        href = Path.GetFileName(createDoc.FileNameWritten);
                    }

                    return(string.Format("<p><a href=\"{0}/{1}\" target=\"_blank\">{2}</a></p>", destinationUrl, href, hrefName));
                }
                else
                {
                    return(null);
                }
            }
        }