예제 #1
0
 private void ModelHelpLinkLabel_Clicked(object sender, EventArgs e)
 {
     //Check internet connection and choose either local or online help files
     try
     {
         if (ModelHelpURL != "")
         {
             string helpURL = "";
             // does offline help exist
             var    directory   = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
             string offlinePath = Path.Combine(directory, "CLEM\\Help");
             if (File.Exists(Path.Combine(offlinePath, "Default.htm")))
             {
                 helpURL = "file:///" + offlinePath.Replace(@"\", "/") + "/" + ModelHelpURL.TrimStart('/');
             }
             // is this application online for online help
             if (NetworkInterface.GetIsNetworkAvailable())
             {
                 // set to web address
                 // not currently available during development until web help is launched
                 helpURL = "https://www.apsim.info/clem/" + ModelHelpURL.TrimStart('/');
             }
             if (helpURL == "")
             {
                 helpURL = "https://www.apsim.info";
             }
             ProcessUtilities.ProcessStart(helpURL);
         }
     }
     catch (Exception ex)
     {
         ShowError(ex);
     }
 }
예제 #2
0
        public void CreateFileDocumentation(object sender, EventArgs e)
        {
            try
            {
                explorerPresenter.MainPresenter.ShowMessage("Creating documentation...", Simulation.MessageType.Information);
                explorerPresenter.MainPresenter.ShowWaitCursor(true);

                IModel modelToDocument = explorerPresenter.CurrentNode;

                PdfWriter pdf             = new PdfWriter();
                string    fileNameWritten = Path.ChangeExtension(explorerPresenter.ApsimXFile.FileName, ".pdf");
                pdf.Write(fileNameWritten, modelToDocument.Document());

                explorerPresenter.MainPresenter.ShowMessage($"Written {fileNameWritten}", Simulation.MessageType.Information);

                // Open the document.
                ProcessUtilities.ProcessStart(fileNameWritten);
            }
            catch (Exception err)
            {
                explorerPresenter.MainPresenter.ShowError(err);
            }
            finally
            {
                explorerPresenter.MainPresenter.ShowWaitCursor(false);
            }
        }
예제 #3
0
        public void CreateFileDocumentation(object sender, EventArgs e)
        {
            try
            {
                if (this.explorerPresenter.Save())
                {
                    explorerPresenter.MainPresenter.ShowMessage("Creating documentation...", Simulation.MessageType.Information);
                    explorerPresenter.MainPresenter.ShowWaitCursor(true);

                    var modelToDocument = explorerPresenter.CurrentNode as IModel;

                    var destinationFolder = Path.GetDirectoryName(explorerPresenter.ApsimXFile.FileName);
                    CreateFileDocumentationCommand command = new CreateFileDocumentationCommand(explorerPresenter, destinationFolder);
                    string fileNameWritten = command.FileNameWritten;

                    command.Do();
                    explorerPresenter.MainPresenter.ShowMessage("Written " + fileNameWritten, Simulation.MessageType.Information);

                    // Open the document.
                    ProcessUtilities.ProcessStart(fileNameWritten);
                }
            }
            catch (Exception err)
            {
                explorerPresenter.MainPresenter.ShowError(err);
            }
            finally
            {
                explorerPresenter.MainPresenter.ShowWaitCursor(false);
            }
        }
예제 #4
0
 public void OnHelp(object sender, EventArgs e)
 {
     try
     {
         ProcessUtilities.ProcessStart("https://apsimnextgeneration.netlify.com/");
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
예제 #5
0
 private void OnWebsiteClicked(object sender, EventArgs e)
 {
     try
     {
         ProcessUtilities.ProcessStart("https://apsimnextgeneration.netlify.com");
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
예제 #6
0
 private void HelpBtnClicked(object sender, EventArgs e)
 {
     try
     {
         ProcessUtilities.ProcessStart("https://apsimnextgeneration.netlify.com/usage/memo/");
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
예제 #7
0
파일: SeriesView.cs 프로젝트: lie112/ApsimX
 /// <summary>Show the filter help.</summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void Help_ButtonPressEvent(object sender, ButtonReleaseEventArgs args)
 {
     try
     {
         if (args.Event.Button == 1)
         {
             ProcessUtilities.ProcessStart("https://apsimnextgeneration.netlify.com/usage/graphs/graphfilters/");
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
예제 #8
0
 /// <summary>
 /// User is requesting more detail about a release.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnViewMoreDetail(object sender, EventArgs e)
 {
     try
     {
         int selIndex = GetSelIndex();
         if (selIndex >= 0)
         {
             Upgrade[] upgradeList = oldVersions.Active ? allUpgrades : upgrades;
             ProcessUtilities.ProcessStart(upgradeList[selIndex].InfoUrl);
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
예제 #9
0
        /// <summary>
        /// Trap widget events to get a left button mouse click.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="args">Event arguments.</param>
        private void OnWidgetEventAfter(object sender, WidgetEventAfterArgs args)
        {
            try
            {
                if (args.Event.Type == Gdk.EventType.ButtonRelease)
                {
                    Gdk.EventButton evt = (Gdk.EventButton)args.Event;

                    if (evt.Button == 1)
                    {
                        // we shouldn't follow a link if the user has selected something
                        textView.Buffer.GetSelectionBounds(out TextIter start, out TextIter end);
                        if (start.Offset == end.Offset)
                        {
                            textView.WindowToBufferCoords(TextWindowType.Widget, (int)evt.X, (int)evt.Y, out int x, out int y);
                            TextIter iter = textView.GetIterAtLocation(x, y);
                            // fixme: When we remove gtk2 deps, we can eliminate this check
                            if (iter.Equals(TextIter.Zero))
                            {
                                return;
                            }

                            foreach (var tag in iter.Tags)
                            {
                                if (tag is LinkTag linkTag)
                                {
                                    // convert modified absolute paths in links for parser acceptance back to real link
                                    // allows tags in URL to link to absolute c: path
                                    if (linkTag.URL.Contains("[drive]"))
                                    {
                                        linkTag.URL = linkTag.URL.Replace("[drive]", ":");
                                        linkTag.URL = linkTag.URL.Replace("../", "/");
                                    }
                                    ProcessUtilities.ProcessStart(linkTag.URL);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ShowError(err);
            }
        }
예제 #10
0
        public async void ExportDataStoreToEXCEL(object sender, EventArgs e)
        {
            List <DataTable> tables = new List <DataTable>();

            try
            {
                string fileName = Path.ChangeExtension(storage.FileName, ".xlsx");

                // Show a message in the GUI.
                explorerPresenter.MainPresenter.ShowMessage("Exporting to excel...", Simulation.MessageType.Information);

                // Show a progress bar - this is currently the only way to get the stop/cancel button to appear.
                explorerPresenter.MainPresenter.ShowProgress(0, true);

                CancellationTokenSource cts = new CancellationTokenSource();

                // Read data from database (in the background).
                Task readTask = Task.Run(() =>
                {
                    ushort i = 0;
                    foreach (string tableName in storage.Reader.TableNames)
                    {
                        cts.Token.ThrowIfCancellationRequested();
                        DataTable table = storage.Reader.GetData(tableName);
                        table.TableName = tableName;
                        tables.Add(table);

                        double progress = 0.5 * (i + 1) / storage.Reader.TableNames.Count;
                        explorerPresenter.MainPresenter.ShowProgress(progress);

                        i++;
                    }
                }, cts.Token);

                // Add a handler to the stop button which cancels the excel export..
                EventHandler <EventArgs> stopHandler = (_, __) =>
                {
                    cts.Cancel();
                    explorerPresenter.MainPresenter.HideProgressBar();
                    explorerPresenter.MainPresenter.ShowMessage("Export to excel was cancelled.", Simulation.MessageType.Information, true);
                };
                explorerPresenter.MainPresenter.AddStopHandler(stopHandler);

                try
                {
                    // Wait for data to be read.
                    await readTask;

                    if (readTask.IsFaulted)
                    {
                        throw new Exception("Failed to read data from datastore", readTask.Exception);
                    }

                    if (readTask.IsCanceled || cts.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    // Start the excel export as a task.
                    // todo: progress reporting and proper cancellation would be nice.
                    Task exportTask = Task.Run(() => Utility.Excel.WriteToEXCEL(tables.ToArray(), fileName), cts.Token);

                    // Wait for the excel file to be generated.
                    await exportTask;

                    if (exportTask.IsFaulted)
                    {
                        throw new Exception($"Failed to export to excel", exportTask.Exception);
                    }

                    if (exportTask.IsCanceled || cts.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    // Show a success message.
                    explorerPresenter.MainPresenter.ShowMessage($"Excel successfully created: {fileName}", Simulation.MessageType.Information);

                    try
                    {
                        // Attempt to open the file - but don't display any errors if it doesn't work.
                        ProcessUtilities.ProcessStart(fileName);
                    }
                    catch
                    {
                    }
                }
                finally
                {
                    // Remove callback from the stop button.
                    explorerPresenter.MainPresenter.RemoveStopHandler(stopHandler);

                    // Remove the progress bar and stop button.
                    explorerPresenter.MainPresenter.HideProgressBar();
                }
            }
            catch (Exception err)
            {
                explorerPresenter.MainPresenter.ShowError(err);
            }
            finally
            {
                // Disposing of datatables isn't strictly necessary, but if we don't,
                // it could be a while before the memory is reclaimed.
                tables.ForEach(t => t.Dispose());
            }
        }