예제 #1
0
파일: Program.cs 프로젝트: i-Asset/basyx
        public static void Test4()
        {
            // MAKE or LOAD prefs
            InputFilePrefs prefs  = new InputFilePrefs();
            var            preffn = "prefs.json";

            try {
                if (File.Exists(preffn))
                {
                    Log.WriteLine(2, "Opening {0} for reading preferences ..", preffn);
                    var init = File.ReadAllText(preffn);
                    Log.WriteLine(2, "Parsing preferences ..");
                    prefs = JsonConvert.DeserializeObject <InputFilePrefs>(init);
                }
                else
                {
                    Log.WriteLine(2, "Using built-in preferences ..");
                    var init = @"{ 'filerecs' : [
                            { 'fn' : 'data\\thumb-usb.jpeg',                'submodel' : 'thumb',   'targetdir' : '/',                      'args' : [ ] },
                            { 'fn' : 'data\\USB_Hexagon.stp',               'submodel' : 'cad',     'targetdir' : '/aasx/cad/',             'args' : [ '0173-1#02-ZBQ121#003' ] },
                            { 'fn' : 'data\\USB_Hexagon.igs',               'submodel' : 'cad',     'targetdir' : '/aasx/cad/',             'args' : [ '0173-1#02-ZBQ128#008' ] },
                            { 'fn' : 'data\\FES_100500.edz',                'submodel' : 'cad',     'targetdir' : '/aasx/cad/',             'args' : [ '0173-1#02-ZBQ133#002' ] },
                            { 'fn' : 'data\\USB_Hexagon_offen.jpeg',        'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Drawings', '0173-1#02-ZWY722#001', 'Product rendering open', 'V1.2', '0173-1#02-ZHK61a#002' ] },
                            { 'fn' : 'data\\USB_Hexagon_geschlossen.jpeg',  'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Presales', '0173-1#02-ZWX723#001', 'Product rendering closed', 'V1.2c', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_presales_DE.PDF',     'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Presales', '0173-1#02-ZWX723#001', 'Steuerungen CECC', 'V2.1.3', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_presales_EN.PDF',     'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Presales', '0173-1#02-ZWX723#001', 'Controls CECC', 'V2.1.4', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\USB_storage_medium_datasheet_EN.pdf', 'submodel' : 'docu', 'targetdir' : '/aasx/documentation/', 'args' : [ 'Technical specification', '0173-1#02-ZWX724#001', 'Datenblatt Steuerung CECC-LK', 'V1.0', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_install_DE.PDF',      'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Installation', '0173-1#02-ZWX725#001', 'Kurzbeschreibung Steuerung CECC-LK', 'V3.2a', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_install_EN.PDF',      'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Installation', '0173-1#02-ZWX725#001', 'Brief description control CECC-LK', 'V3.6b', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_fullmanual_DE.PDF',   'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Manual', '0173-1#02-ZWX727#001', 'Beschreibung Steuerung CECC-LK', '1403a', '0173-1#02-ZHK622#001' ] },
                            { 'fn' : 'data\\docu_cecc_fullmanual_EN.PDF',   'submodel' : 'docu',    'targetdir' : '/aasx/documentation/',   'args' : [ 'Manual', '0173-1#02-ZWX727#001', 'Description Steuerung CECC-LK', '1403a', '0173-1#02-ZHK622#001' ] },
                        ],  'webrecs' : [
                            { 'url' : 'https://www.festo.com/net/de_de/SupportPortal/Downloads/385954/407353/CECC_2013-05a_8031104e2.pdf',          'submodel' : 'docu',      'args' : [ 'Installation', '0173-1#02-ZWX725#001', 'Controlador CECC', '2013-05a', '0173-1#02-ZHK662#002' ] },
                            { 'url' : 'https://www.festo.com/net/SupportPortal/Files/407352/CECC_2013-05a_8031105x2.pdf',                           'submodel' : 'docu',      'args' : [ 'Installation', '0173-1#02-ZWX725#001', 'Controllore CECC', '2013-05a', '0173-1#02-ZHK699#003' ] },
                        ] }";
                    Log.WriteLine(3, "Dump of built-in preferences: {0}", init);
                    Log.WriteLine(2, "Parsing preferences ..");
                    prefs = JsonConvert.DeserializeObject <InputFilePrefs>(init);
                }
            } catch (Exception ex) {
                Console.Error.Write("While parsing preferences: " + ex.Message);
                Environment.Exit(-1);
            }

            // REPOSITORY
            var repo = new AdminShellNS.UriIdentifierRepository();

            try {
                if (!repo.Load("uri-repository.xml"))
                {
                    repo.InitRepository("uri-repository.xml");
                }
            } catch (Exception ex) {
                Console.Error.Write("While accessing URI repository: " + ex.Message);
                Environment.Exit(-1);
            }

            // AAS ENV
            var aasenv1 = new AdminShell.AdministrationShellEnv();

            try
            {
                // ASSET
                var asset1 = new AdminShell.Asset();
                aasenv1.Assets.Add(asset1);
                asset1.SetIdentification("URI", "http://pk.festo.com/3s7plfdrs35", "3s7plfdrs35");
                asset1.AddDescription("EN", "Festo USB Stick");
                asset1.AddDescription("DE", "Festo USB Speichereinheit");

                // CAD
                Log.WriteLine(2, "Creating submodel CAD ..");
                var subCad = CreateSubmodelCad(prefs, repo, aasenv1);

                // DOCU
                Log.WriteLine(2, "Creating submodel DOCU ..");
                var subDocu = CreateSubmodelDocumentation(prefs, repo, aasenv1);

                // DATASHEET
                Log.WriteLine(2, "Creating submodel DATASHEET ..");
                var subDatasheet = CreateSubmodelDatasheet(prefs, repo, aasenv1);
                //var subDatasheet = CreateSubmodelDatasheetSingleItems(repo, aasenv1);

                // VIEW1
                var view1 = CreateStochasticViewOnSubmodels(new AdminShell.Submodel[] { subCad, subDocu, subDatasheet }, "View1");

                // ADMIN SHELL
                Log.WriteLine(2, "Create AAS ..");
                var aas1 = AdminShell.AdministrationShell.CreateNew("URI", repo.CreateOneTimeId(), "1", "0");
                aas1.derivedFrom = new AdminShell.AssetAdministrationShellRef(new AdminShell.Key("AssetAdministrationShell", false, "URI", "www.admin-shell.io/aas/sample-series-aas/1/1"));
                aasenv1.AdministrationShells.Add(aas1);
                aas1.assetRef = asset1.GetReference();

                // Link things together
                Log.WriteLine(2, "Linking entities to AAS ..");
                aas1.submodelRefs.Add(subCad.GetReference() as AdminShell.SubmodelRef);
                aas1.submodelRefs.Add(subDocu.GetReference() as AdminShell.SubmodelRef);
                aas1.submodelRefs.Add(subDatasheet.GetReference() as AdminShell.SubmodelRef);
                aas1.AddView(view1);

                if (true)
                {
                    asset1.assetIdentificationModelRef = new AdminShell.SubmodelRef(subDatasheet.GetReference() as AdminShell.SubmodelRef);
                }
            }
            catch (Exception ex)
            {
                Console.Error.Write("While building AAS: {0} at {1}", ex.Message, ex.StackTrace);
                Environment.Exit(-1);
            }

            if (true)
            {
                try {
                    //
                    // Test serialize
                    // this generates a "sample.xml" is addition to the package below .. for direct usag, e.g.
                    //
                    Log.WriteLine(2, "Test serialize sample.xml ..");
                    using (var s = new StreamWriter("sample.xml"))
                    {
                        var serializer = new XmlSerializer(aasenv1.GetType());
                        var nss        = new XmlSerializerNamespaces();
                        nss.Add("aas", "http://www.admin-shell.io/aas/1/0");
                        nss.Add("IEC61360", "http://www.admin-shell.io/IEC61360/1/0");
                        serializer.Serialize(s, aasenv1, nss);
                    }
                } catch (Exception ex) {
                    Console.Error.Write("While test serializing XML: {0} at {1}", ex.Message, ex.StackTrace);
                    Environment.Exit(-1);
                }
            }

            //
            // Make PACKAGE
            //

            try {
                // use the library function
                var opcfn = "sample-admin-shell.aasx";
                Log.WriteLine(2, "Creating package {0} ..", opcfn);
                var package = new AdminShell.PackageEnv(aasenv1);

                // supplementary files
                Log.WriteLine(2, "Adding supplementary files ..");
                foreach (var fr in prefs.filerecs)
                {
                    Log.WriteLine(2, "  + {0}", fr.fn);
                    package.AddSupplementaryFileToStore(fr.fn, fr.targetdir, Path.GetFileName(fr.fn), fr.submodel == "thumb");
                }

                // save
                Log.WriteLine(2, "Saving ..");
                package.SaveAs(opcfn, writeFreshly: true);
                package.Close();
            } catch (Exception ex) {
                Console.Error.Write("While building OPC package: {0} at {1}", ex.Message, ex.StackTrace);
                Environment.Exit(-1);
            }
        }
예제 #2
0
        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // decode
            if (e == null || e.Command == null || !(e.Command is RoutedUICommand))
            {
                return;
            }
            var cmd = (e.Command as RoutedUICommand).Text.Trim().ToLower();

            // decide
            if (cmd == "new")
            {
                if ((!Options.UseFlyovers && MessageBoxResult.Yes == MessageBox.Show("Create new Adminshell environment? This operation can not be reverted!", "AASX", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                    ||
                    (Options.UseFlyovers && MessageBoxResult.Yes == MessageBoxFlyoutShow("Create new Adminshell environment? This operation can not be reverted!", "AASX", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                    )
                {
                    try
                    {
                        // create new AASX package
                        thePackageEnv = new AdminShell.PackageEnv();
                        // redraw everything
                        RedrawAllAasxElements();
                        RedrawElementView();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "When creating new AASX, an error occurred");
                        return;
                    }
                }
            }
            if (cmd == "open" || cmd == "openaux")
            {
                var dlg = new Microsoft.Win32.OpenFileDialog();
                try
                {
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(thePackageEnv.Filename);
                }
                catch { }
                dlg.Filter = "AASX package files (*.aasx)|*.aasx|AAS XML file (*.xml)|*.xml|All files (*.*)|*.*";
                if (Options.UseFlyovers)
                {
                    this.StartFlyover(new EmptyFlyout());
                }
                var res = dlg.ShowDialog();
                if (Options.UseFlyovers)
                {
                    this.CloseFlyover();
                }
                if (res == true)
                {
                    if (cmd == "open")
                    {
                        UiLoadPackageEnv(dlg.FileName);
                    }
                    if (cmd == "openaux")
                    {
                        UiLoadPackageAux(dlg.FileName);
                    }
                }
            }
            if (cmd == "save")
            {
                try
                {
                    // save
                    thePackageEnv.SaveAs(thePackageEnv.Filename);
                    // as saving changes the structure of pending supplementary files, re-display
                    RedrawAllAasxElements();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "When saving AASX, an error occurred");
                    return;
                }
                Log.Info("AASX saved successfully: {0}", thePackageEnv.Filename);
            }
            if (cmd == "saveas")
            {
                var dlg = new Microsoft.Win32.SaveFileDialog();
                try
                {
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(thePackageEnv.Filename);
                }
                catch { }
                dlg.FileName   = thePackageEnv.Filename;
                dlg.DefaultExt = "*.aasx";
                dlg.Filter     = "AASX package files (*.aasx)|*.aasx|AAS XML file (*.xml)|*.xml|All files (*.*)|*.*";
                if (Options.UseFlyovers)
                {
                    this.StartFlyover(new EmptyFlyout());
                }
                var res = dlg.ShowDialog();
                if (Options.UseFlyovers)
                {
                    this.CloseFlyover();
                }
                if (res == true)
                {
                    try
                    {
                        // save
                        thePackageEnv.SaveAs(dlg.FileName);
                        // as saving changes the structure of pending supplementary files, re-display
                        RedrawAllAasxElements();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "When saving AASX, an error occurred");
                        return;
                    }
                    Log.Info("AASX saved successfully as: {0}", dlg.FileName);
                }
            }
            if (cmd == "close" && thePackageEnv != null)
            {
                if ((!Options.UseFlyovers && MessageBoxResult.Yes == MessageBox.Show(this, "Do you want to close the open package? Please make sure that you have saved before.", "Close Package?", MessageBoxButton.YesNo, MessageBoxImage.Question))
                    ||
                    (Options.UseFlyovers && MessageBoxResult.Yes == MessageBoxFlyoutShow("Do you want to close the open package? Please make sure that you have saved before.", "Close Package?", MessageBoxButton.YesNo, MessageBoxImage.Question))
                    )
                {
                    try
                    {
                        thePackageEnv.Close();
                        RedrawAllAasxElements();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "When closing AASX, an error occurred");
                    }
                }
            }

            if (cmd == "closeaux" && thePackageAux != null)
            {
                try
                {
                    thePackageAux.Close();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "When closing auxiliary AASX, an error occurred");
                }
            }
            if (cmd == "exit")
            {
                /*
                 * if ((!Options.UseFlyovers && MessageBoxResult.Yes == MessageBox.Show(this, "Exit the application? Please make sure that you have saved before.", "Exit Application?", MessageBoxButton.YesNo, MessageBoxImage.Question))
                 ||
                 || (Options.UseFlyovers && MessageBoxResult.Yes == MessageBoxFlyoutShow("Exit the application? Please make sure that you have saved before.", "Exit Application?", MessageBoxButton.YesNo, MessageBoxImage.Question))
                 || )
                 */
                System.Windows.Application.Current.Shutdown();
            }
            if (cmd == "connect")
            {
                if (!Options.UseFlyovers)
                {
                    MessageBox.Show(this, "In future versions, this feature will allow connecting to an online Administration Shell via OPC UA or similar.\n" +
                                    "This feature is scope of the specification 'Details of the Adminstration Shell Part 1 V1.1' and 'Part 2'.", "Connect", MessageBoxButton.OK);
                }
                else
                {
                    MessageBoxFlyoutShow("In future versions, this feature will allow connecting to an online Administration Shell via OPC UA or similar.", "Connect", MessageBoxButton.OK, MessageBoxImage.Hand);
                }
            }
            if (cmd == "about")
            {
                var ab = new AboutBox();
                ab.ShowDialog();
            }
            if (cmd == "helpgithub")
            {
                theBrowser.Address = @"https://github.com/admin-shell/aasx-package-explorer/blob/master/help/index.md";
                Dispatcher.BeginInvoke((Action)(() => ElementTabControl.SelectedIndex = 1));
            }
            if (cmd == "editkey")
            {
                MenuItemWorkspaceEdit.IsChecked = !MenuItemWorkspaceEdit.IsChecked;
            }
            if (cmd == "hintskey")
            {
                MenuItemWorkspaceHints.IsChecked = !MenuItemWorkspaceHints.IsChecked;
            }
            if (cmd == "editmenu" || cmd == "editkey" || cmd == "hintsmenu" || cmd == "hintskey")
            {
                // edit mode affects the total element view
                RedrawAllAasxElements();
                // fake selection
                RedrawElementView();
            }
            if (cmd == "test")
            {
                /*
                 * string err = null;
                 * Log.Append(err + "");
                 * var p1 = new AdminShell.Property();
                 * p1.value = "42";
                 */
                /*
                 * var w1 = new AdminShell.SubmodelElementWrapper();
                 * w1.submodelElement = p1;
                 * var w2 = new AdminShell.SubmodelElementWrapper(w1);
                 */
                // var w2 = new AdminShell.SubmodelElementWrapper(p1);
                var uc = new MessageBoxFlyout("My very long message text!", "Caption", MessageBoxButton.OK, MessageBoxImage.Error);
                uc.ControlClosed += () =>
                {
                    Log.Info("Yes!");
                };
                this.StartFlyover(uc);
            }
            if (cmd == "queryrepo")
            {
                var uc = new SelectFromRepositoryFlyout();
                uc.Margin = new Thickness(10);
                if (uc.LoadAasxRepoFile(Options.AasxRepositoryFn))
                {
                    uc.ControlClosed += () =>
                    {
                        var fn = uc.ResultFilename;
                        if (fn != null && fn != "")
                        {
                            Log.Info("Switching to {0} ..", fn);
                            UiLoadPackageEnv(fn);
                        }
                    };
                    this.StartFlyover(uc);
                }
            }
        }