コード例 #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (sender == ButtonStart)
     {
         this.Result = this.ThisToPreset();
         ControlClosed?.Invoke();
     }
 }
コード例 #2
0
        private void ThisFromPreset(ExportUmlOptions preset)
        {
            // access
            if (preset == null)
            {
                return;
            }

            // take over
            ComboBoxFormat.SelectedIndex = (int)preset.Format;
            TextBoxLimitValues.Text      = "" + preset.LimitInitialValue;
            CheckBoxCopyTo.IsChecked     = preset.CopyToPasteBuffer;
        }
コード例 #3
0
        //
        // Mechanics
        //

        private ExportUmlOptions ThisToPreset()
        {
            var x = new ExportUmlOptions();

            x.Format = (ExportUmlOptions.ExportFormat)ComboBoxFormat.SelectedIndex;

            if (int.TryParse(TextBoxLimitValues.Text, out int i))
            {
                x.LimitInitialValue = i;
            }

            x.CopyToPasteBuffer = CheckBoxCopyTo.IsChecked == true;

            return(x);
        }
コード例 #4
0
 private void ButtonClose_Click(object sender, RoutedEventArgs e)
 {
     this.Result = null;
     ControlClosed?.Invoke();
 }
コード例 #5
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginExportTable.ExportTableOptions>(
                    (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The OpenXML SDK is under MIT license." + Environment.NewLine +
                                   "The ClosedXML library is under MIT license." + Environment.NewLine +
                                   "The ExcelNumberFormat number parser is licensed under the MIT license." + Environment.NewLine +
                                   "The FastMember reflection access is licensed under Apache License 2.0 (Apache - 2.0).";

                lic.isStandardLicense = true;
                lic.longLicense       = AasxPluginHelper.LoadLicenseTxtFromAssemblyDir(
                    "LICENSE.txt", Assembly.GetExecutingAssembly());

                return(lic);
            }

            if (action == "get-events" && _eventStack != null)
            {
                // try access
                return(_eventStack.PopEvent());
            }

            if ((action == "export-submodel" || action == "import-submodel") &&
                args != null && args.Length >= 3 &&
                args[0] is IFlyoutProvider && args[1] is AdminShell.AdministrationShellEnv &&
                args[2] is AdminShell.Submodel)
            {
                // flyout provider
                var fop = args[0] as IFlyoutProvider;

                // which Submodel
                var env = args[1] as AdminShell.AdministrationShellEnv;
                var sm  = args[2] as AdminShell.Submodel;
                if (env == null || sm == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // handle the export dialogue
                var uc = new ExportTableFlyout((action == "export-submodel")
                    ? "Export SubmodelElements as Table"
                    : "Import SubmodelElements from Table");
                uc.Presets = this.options.Presets;
                fop?.StartFlyoverModal(uc);
                fop?.CloseFlyover();
                if (uc.Result == null)
                {
                    if (uc.CloseForHelp)
                    {
                        // give over to event stack
                        var evt = new AasxPluginResultEventDisplayContentFile();
                        evt.fn = "https://github.com/admin-shell-io/aasx-package-explorer/tree/" +
                                 "MIHO/AddPluginForKnownSubmodels/src/AasxPluginExportTable/help";
                        evt.mimeType = System.Net.Mime.MediaTypeNames.Text.Html;
                        _eventStack?.PushEvent(evt);
                    }

                    return(null);
                }

                if (action == "export-submodel")
                {
                    Export(uc.Result, fop, sm, env);
                }

                if (action == "import-submodel")
                {
                    Import(uc.Result, fop, sm, env);
                }
            }

            if (action == "export-uml" &&
                args != null && args.Length >= 3 &&
                args[0] is IFlyoutProvider && args[1] is AdminShell.AdministrationShellEnv &&
                args[2] is AdminShell.Submodel)
            {
                var fn = (args.Length >= 4) ? args[3] as string : null;

                // flyout provider (will be required in the future)
                var fop = args[0] as IFlyoutProvider;

                // which Submodel
                var env = args[1] as AdminShell.AdministrationShellEnv;
                var sm  = args[2] as AdminShell.Submodel;
                if (env == null || sm == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // prep options
                var exop = options.UmlExport;
                if (exop == null)
                {
                    exop = new ExportUmlOptions();
                }

                // dialogue for user options
                var uc = new ExportUmlFlyout();
                uc.Result = exop;
                fop?.StartFlyoverModal(uc);
                fop?.CloseFlyover();
                if (uc.Result == null)
                {
                    return(null);
                }

                // ask for filename
                var dlg = new Microsoft.Win32.SaveFileDialog();
                try
                {
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                        System.AppDomain.CurrentDomain.BaseDirectory);
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
                dlg.Title = "Select file for UML export ..";

                if (uc.Result.Format == ExportUmlOptions.ExportFormat.PlantUml)
                {
                    dlg.FileName   = "new.uml";
                    dlg.DefaultExt = "*.uml";
                    dlg.Filter     =
                        "PlantUML text file (*.uml)|*.uml|All files (*.*)|*.*";
                }
                else
                {
                    dlg.FileName   = "new.xml";
                    dlg.DefaultExt = "*.xml";
                    dlg.Filter     =
                        "XMI file (*.xml)|*.xml|All files (*.*)|*.*";
                }

                fop?.StartFlyover(new EmptyFlyout());
                var fnres = dlg.ShowDialog(fop?.GetWin32Window());
                fop?.CloseFlyover();
                if (fnres != true)
                {
                    return(null);
                }
                fn = dlg.FileName;

                // use functionality
                ExportUml.ExportUmlToFile(env, sm, uc.Result, fn);
                Log.Info($"Export UML data to file: {fn}");

                // copy?
                if (uc.Result.CopyToPasteBuffer)
                {
                    try
                    {
                        var lines = File.ReadAllText(fn);
                        Clipboard.SetData(DataFormats.Text, lines);
                        Log.Info("Export UML data copied to paste buffer.");
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }
                }
            }

            // default
            return(null);
        }