コード例 #1
0
        public static bool GenerateRepositoryFromFileNames(string[] inputFns, string outputFn)
        {
            var res = true;

            // new repo
            var repo = new AasxFileRepository();

            // make records
            foreach (var ifn in inputFns)
            {
                // get one or multiple asset ids
                var assetIds = new List <string>();
                try
                {
                    var pkg = new AdminShellPackageEnv();
                    pkg.Load(ifn);
                    if (pkg.AasEnv != null && pkg.AasEnv.Assets != null)
                    {
                        foreach (var asset in pkg.AasEnv.Assets)
                        {
                            if (asset.identification != null)
                            {
                                assetIds.Add(asset.identification.id);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    res = false;
                }

                // make the record(s)
                foreach (var assetid in assetIds)
                {
                    var fmi = new AasxFileRepository.FileItem();
                    fmi.Filename    = ifn;
                    fmi.CodeType2D  = "DMC";
                    fmi.AssetId     = assetid;
                    fmi.Description = "TODO";
                    fmi.Tag         = "TODO";

                    // add it
                    repo.FileMap.Add(fmi);
                }
            }

            // save
            using (var s = new StreamWriter(outputFn))
            {
                var json = JsonConvert.SerializeObject(repo, Formatting.Indented);
                s.WriteLine(json);
            }

            return(res);
        }
コード例 #2
0
        public bool LoadAasxRepoFile(string fn = null, AasxFileRepository repo = null)
        {
            try
            {
                this.TheAasxRepo = null;

                if (fn != null)
                {
                    // from file
                    this.TheAasxRepo = AasxFileRepository.Load(fn);
                }

                if (repo != null)
                {
                    // from RAM
                    this.TheAasxRepo = repo;
                }

                if (this.TheAasxRepo == null)
                {
                    return(false);
                }

                // rework buttons
                this.StackPanelTags.Children.Clear();
                foreach (var fm in this.TheAasxRepo.FileMap)
                {
                    var tag = fm.Tag.Trim();
                    if (tag != "")
                    {
                        var b = new Button();
                        b.Style      = (Style)FindResource("TranspRoundCorner");
                        b.Content    = "" + tag;
                        b.Height     = 40;
                        b.Width      = 40;
                        b.Margin     = new Thickness(5, 0, 5, 0);
                        b.Foreground = Brushes.White;
                        b.Click     += TagButton_Click;
                        this.StackPanelTags.Children.Add(b);
                        b.Tag = fm;
                    }
                }
            }
            catch (Exception ex)
            {
                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                this.TheAasxRepo = null;
                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static bool PrintRepositoryCodeSheet(
            string repoFn = null, AasxFileRepository repoDirect = null, string title = "Asset repository")
        {
            List <CodeSheetItem> codeSheetItems = new List <CodeSheetItem>();

            try
            {
                AasxFileRepository repo = null;

                // load the data
                if (repoFn != null)
                {
                    // from file
                    repo = AasxFileRepository.Load(repoFn);
                }

                if (repoDirect != null)
                {
                    // from RAM
                    repo = repoDirect;
                }

                // got something
                if (repo == null)
                {
                    return(false);
                }

                // all assets
                foreach (var fmi in repo.FileMap)
                {
                    var csi = new CodeSheetItem();
                    csi.id          = fmi.AssetId;
                    csi.code        = fmi.CodeType2D;
                    csi.description = fmi.Description;
                    csi.normSize    = 1.0; // do not vary
                    codeSheetItems.Add(csi);
                }

                // print
                PrintCodeSheet(codeSheetItems.ToArray(), title);
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.Message, "Print AASX file repository");
                return(false);
            }
            return(true);
        }
コード例 #4
0
        // Generators

        public static AasxFileRepository CreateDemoData()
        {
            var tr = new AasxFileRepository();

            tr.Add(new AasxFileRepository.FileItem("http://pk.festo.com/111111111111", "1.aasx"));
            tr.Add(new AasxFileRepository.FileItem("http://pk.festo.com/222222222222", "2.aasx"));
            tr.Add(new AasxFileRepository.FileItem("http://pk.festo.com/333333333333", "3.aasx"));

            tr.FileMap[0].Description = "Additional info";
            tr.FileMap[0].AasId       = "http://smart.festo.com/cdscsdbdsbchjdsbjhcbdshjcbhjdsbchjsdbhjcsdbhjcdsbhjcsbdhj";
            tr.FileMap[0].VisualState = AasxFileRepository.FileItem.VisualStateEnum.Activated;
            tr.FileMap[0].VisualTime  = 6.0;

            tr.FileMap[1].Description = "Additional info";
            tr.FileMap[1].VisualState = AasxFileRepository.FileItem.VisualStateEnum.ReadFrom;
            tr.FileMap[1].VisualTime  = 3.0;

            tr.FileMap[2].VisualState = AasxFileRepository.FileItem.VisualStateEnum.WriteTo;
            tr.FileMap[2].VisualTime  = 4.5;

            return(tr);
        }
        public bool LoadAasxRepoFile(string fn = null)
        {
            try
            {
                // load the data
                if (fn == null)
                {
                    // Static example
                    var init =
                        @"{
  'filemaps': [
    {
      'assetid': 'http://pk.festo.com/3s7plfdrs35',
      'tag': 'F',
      'fn': 'C:\\Users\\miho\\Desktop\\AasxPackageExplorer\\Sample_AAS\\Festo-USB-stick-sample-admin-shell.aasx'
    },
    {
      'assetid': 'http://pk.pf.com/40000039198163',
      'tag': 'PF',
      'fn': 'C:\\Users\\miho\\Desktop\\AasxPackageExplorer\\Sample_AAS\\pf_232769_40000039198163.aasx'
    },
    {
      'assetid': 'www.phoenixcontact.com/asset/product/2404267',
      'tag': 'PC',
      'fn': 'C:\\Users\\miho\\Desktop\\AasxPackageExplorer\\Sample_AAS\\Phoenix Contact AXC F 2152 - 11.aasx'
    }
  ]
}";
                    this.TheAasxRepo = JsonConvert.DeserializeObject <AasxFileRepository>(init);
                }
                else
                {
                    // from file
                    if (!File.Exists(fn))
                    {
                        return(false);
                    }
                    var init = File.ReadAllText(fn);
                    this.TheAasxRepo = JsonConvert.DeserializeObject <AasxFileRepository>(init);
                }

                // rework buttons
                this.StackPanelTags.Children.Clear();
                foreach (var fm in this.TheAasxRepo.filemaps)
                {
                    var tag = fm.tag.Trim();
                    if (tag != "")
                    {
                        var b = new Button();
                        b.Style      = (Style)FindResource("TranspRoundCorner");
                        b.Content    = "" + tag;
                        b.Height     = 40;
                        b.Width      = 40;
                        b.Margin     = new Thickness(5, 0, 5, 0);
                        b.Foreground = Brushes.White;
                        b.Click     += TagButton_Click;
                        this.StackPanelTags.Children.Add(b);
                        fm.link = b;
                    }
                }
            }
            catch
            {
                this.TheAasxRepo = null;
                return(false);
            }

            return(true);
        }