Exemplo n.º 1
0
        /// <summary>Open an .apsimx file into the current tab.</summary>
        /// <param name="fileName">The file to open</param>
        /// <param name="onLeftTabControl">If true a tab will be added to the left hand tab control.</param>
        /// <returns>The presenter</returns>
        public ExplorerPresenter OpenApsimXFileInTab(string fileName, bool onLeftTabControl)
        {
            ExplorerPresenter presenter = null;

            if (fileName != null)
            {
                presenter = this.PresenterForFile(fileName, onLeftTabControl);
                if (presenter != null)
                {
                    this.view.SelectTabContaining(presenter.GetView().MainWidget);
                    return(presenter);
                }

                this.view.ShowWaitCursor(true);
                try
                {
                    Simulations simulations = Simulations.Read(fileName);
                    presenter = (ExplorerPresenter)this.CreateNewTab(fileName, simulations, onLeftTabControl, "UserInterface.Views.ExplorerView", "UserInterface.Presenters.ExplorerPresenter");
                    if (simulations.LoadErrors.Count > 0)
                    {
                        foreach (Exception error in simulations.LoadErrors)
                        {
                            this.view.ShowMessage(error.ToString(), Simulation.ErrorLevel.Error);
                        }
                    }

                    // Add to MRU list and update display
                    Utility.Configuration.Settings.AddMruFile(fileName);
                    this.UpdateMRUDisplay();
                }
                catch (Exception err)
                {
                    string message = err.Message;
                    while (err.InnerException != null)
                    {
                        message += "\r\n" + err.InnerException.Message;
                        err      = err.InnerException;
                    }
                    this.view.ShowMessage(message, Simulation.ErrorLevel.Error);
                }

                this.view.ShowWaitCursor(false);
            }

            return(presenter);
        }
Exemplo n.º 2
0
        /// <summary>Open an .apsimx file into the current tab.</summary>
        /// <param name="fileName">The file to open.</param>
        /// <param name="onLeftTabControl">If true a tab will be added to the left hand tab control.</param>
        /// <returns>The presenter.</returns>
        public ExplorerPresenter OpenApsimXFileInTab(string fileName, bool onLeftTabControl)
        {
            ExplorerPresenter presenter = null;

            if (fileName != null)
            {
                presenter = this.PresenterForFile(fileName, onLeftTabControl);
                if (presenter != null)
                {
                    this.view.SelectTabContaining(presenter.GetView().MainWidget);
                    return(presenter);
                }

                this.view.ShowWaitCursor(true);
                try
                {
                    List <Exception> creationExceptions;
                    Simulations      simulations = FileFormat.ReadFromFile <Simulations>(fileName, out creationExceptions);
                    presenter = (ExplorerPresenter)this.CreateNewTab(fileName, simulations, onLeftTabControl, "UserInterface.Views.ExplorerView", "UserInterface.Presenters.ExplorerPresenter");
                    if (creationExceptions.Count > 0)
                    {
                        ShowError(creationExceptions);
                    }

                    // Add to MRU list and update display
                    Utility.Configuration.Settings.AddMruFile(fileName);
                    this.UpdateMRUDisplay();
                }
                catch (Exception err)
                {
                    ShowError(err);
                }

                this.view.ShowWaitCursor(false);
            }

            return(presenter);
        }