/// <summary> /// Render the list of form elements into a list of SubmodelElements. /// </summary> public AdminShell.SubmodelElementWrapperCollection AddOrUpdateDifferentElementsToCollection( AdminShell.SubmodelElementWrapperCollection elements, AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false) { // will be a list of newly added elements (for tracing) var res = new AdminShell.SubmodelElementWrapperCollection(); // each description / instance pair foreach (var pair in this) { // ok, perform the actual add or update procedure var lst = pair.instances.AddOrUpdateSameElementsToCollection(elements, packageEnv, addFilesToPackage); // for newly added elements, shaping of idSHort might be required if (lst != null) { foreach (var smw in lst) { // access if (smw?.submodelElement?.idShort == null) { continue; } // check, if to make idShort unique? FormInstanceHelper.MakeIdShortUnique(elements, smw.submodelElement); // add to tracing res.Add(smw); } } } return(res); }
public void TestLoadSaveLoadAssertEqual(string extension) { List <string> aasxPaths = SamplesAasxDir.ListAasxPaths(); using (var tmpDir = new TemporaryDirectory()) { foreach (string aasxPath in aasxPaths) { /* * The chain is as follows: * - First load from AASX (package A) * - Convert package 1 to `extension` format and save as path 1 * - Load from the path 1 in `extension` format (package B) * - Save package B in `extension` format to path 2 * * We expect the content of the two files (path 1 and path 2, respectively) to be equal. */ using (var packageA = new AdminShellPackageEnv(aasxPath)) { string path1 = System.IO.Path.Combine(tmpDir.Path, $"first{extension}"); string path2 = System.IO.Path.Combine(tmpDir.Path, $"second{extension}"); packageA.SaveAs(path1, writeFreshly: true); using (var packageB = new AdminShellPackageEnv(path1)) { packageB.SaveAs(path2, writeFreshly: true); AssertFilesEqual(path1, path2, aasxPath); } } } } }
/// <summary> /// Render the list of form elements into a list of SubmodelElements. /// </summary> public AdminShell.SubmodelElementWrapperCollection AddOrUpdateDifferentElementsToCollection( AdminShell.SubmodelElementWrapperCollection elements, AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false, bool editSource = false) { // SM itself? if (this.sm != null && Touched && this.sourceSM != null && editSource) { if (this.sm.idShort != null) { this.sourceSM.idShort = "" + this.sm.idShort; } if (this.sm.description != null) { this.sourceSM.description = new AdminShell.Description(this.sm.description); } } // SM as a set of elements if (this.PairInstances != null) { return(this.PairInstances.AddOrUpdateDifferentElementsToCollection( elements, packageEnv, addFilesToPackage)); } return(null); }
public static BitmapImage LoadBitmapImageFromPackage(AdminShellPackageEnv package, string path) { if (package == null || path == null) { return(null); } // ReSharper disable EmptyGeneralCatchClause try { var thumbStream = package.GetLocalStreamFromPackage(path); if (thumbStream == null) { return(null); } // load image var bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.StreamSource = thumbStream; bi.EndInit(); // note: no closing required! // give this back return(bi); } catch { } // ReSharper enable EmptyGeneralCatchClause return(null); }
public void SetContents( AdminShellPackageEnv package, ConceptModelZveiTechnicalData theDefs, string defaultLang, AdminShell.Submodel sm) { // access if (sm == null) { return; } // section General var smcFurther = sm.submodelElements.FindFirstSemanticIdAs <AdminShell.SubmodelElementCollection>( theDefs.CD_FurtherInformation.GetSingleKey()); if (smcFurther != null) { // single items TextBoxValidDate.Text = "" + smcFurther.value.FindFirstSemanticIdAs <AdminShell.Property>( theDefs.CD_ValidDate.GetSingleKey())?.value; // Lines var tsl = new List <string>(); foreach (var smw in smcFurther.value.FindAllSemanticId( theDefs.CD_TextStatement.GetSingleKey(), allowedTypes: AdminShell.SubmodelElement.PROP_MLP)) { tsl.Add("" + smw?.submodelElement?.ValueAsText(defaultLang)); } ItemsControlStatements.ItemsSource = tsl; } }
public static BitmapImage LoadBitmapImageFromPackage(AdminShellPackageEnv package, string path) { if (package == null || path == null) { return(null); } try { var thumbStream = package.GetLocalStreamFromPackage(path); if (thumbStream == null) { return(null); } // load image var bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.StreamSource = thumbStream; bi.EndInit(); // note: no closing required! // give this back return(bi); } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); } return(null); }
public VisualElementPluginExtension( VisualElementGeneric parent, TreeViewLineCache cache, AdminShellPackageEnv package, AdminShell.Referable referable, Plugins.PluginInstance plugin, AasxIntegrationBase.AasxPluginResultVisualExtension ext) : base() { this.Parent = parent; this.Cache = cache; this.thePackage = package; this.theReferable = referable; this.thePlugin = plugin; this.theExt = ext; this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#A0A0A0")); this.Border = (SolidColorBrush)(new BrushConverter().ConvertFrom("#707070")); this.TagBg = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkestAccentColor"]; this.TagFg = Brushes.White; this.TagString = "" + ext?.Tag; RefreshFromMainData(); RestoreFromCache(); }
public VisualElementEnvironmentItem( VisualElementGeneric parent, TreeViewLineCache cache, AdminShellPackageEnv package, AdminShell.AdministrationShellEnv env, ItemType itemType) : base() { this.Parent = parent; this.Cache = cache; this.thePackage = package; this.theEnv = env; this.theItemType = itemType; this.Background = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkAccentColor"]; this.Border = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkestAccentColor"]; this.TagBg = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkestAccentColor"]; this.TagFg = Brushes.White; this.Caption = $"\"{ItemTypeNames[(int)itemType]}\""; this.Info = ""; this.IsTopLevel = true; this.TagString = "Env"; if (theItemType == ItemType.EmptySet) { this.TagString = "\u2205"; this.Caption = "No information available"; } if (theItemType == ItemType.Package && thePackage != null) { this.TagString = "\u25a2"; this.Info += "" + thePackage.Filename; } RestoreFromCache(); }
/// <summary> /// Render the instance into a list (right now, exactly one!) of SubmodelElements. /// Might be overridden in subclasses. /// </summary> public virtual AdminShell.SubmodelElementWrapperCollection AddOrUpdateSmeToCollection( AdminShell.SubmodelElementWrapperCollection collectionNewElements, AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false) { // typically, there will be only one SME var res = new AdminShell.SubmodelElementWrapperCollection(); // SME present? if (sme != null) { // process (will update existing elements) var doAdd = ProcessSmeForRender(packageEnv, addFilesToPackage, editSource: true); // still add? if (doAdd) { // add to elements (this is the real transaction) collectionNewElements.Add(AdminShell.SubmodelElementWrapper.CreateFor(sme)); // add to the tracing information for new elements res.Add(AdminShell.SubmodelElementWrapper.CreateFor(sme)); } } // OK return(res); }
public override async Task LoadFromSourceAsync( string fullItemLocation, PackCntRuntimeOptions runtimeOptions = null) { // buffer to temp file try { await DownloadFromSource(new Uri(fullItemLocation), runtimeOptions); } catch (Exception ex) { throw new PackageContainerException( $"While buffering aasx from {Location} full-location {fullItemLocation} via HttpClient " + $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}"); } // open try { Env = new AdminShellPackageEnv(TempFn, indirectLoadSave: false); runtimeOptions?.Log?.Info($".. successfully opened as AASX environment: {Env?.AasEnv?.ToString()}"); } catch (Exception ex) { throw new PackageContainerException( $"While opening buffered aasx {TempFn} from source {this.ToString()} " + $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}"); } }
/// <summary> /// Before rendering the SME into a list of new elements, process the SME. /// If <c>Touched</c>, <c>sourceSme</c> and <c>editSource</c> is set, /// this function shall write back the new values instead of /// producing a new element. Returns True, if a new element shall be rendered. /// </summary> public override bool ProcessSmeForRender( AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false, bool editSource = false) { // refer to base (SME) function, but not caring about result base.ProcessSmeForRender(packageEnv, addFilesToPackage, editSource); // access var file = this.sme as AdminShell.File; var fileSource = this.sourceSme as AdminShell.File; // need to do more than the base implementation! if (file != null) { if (packageEnv != null) { // source path as given by the user var sourcePath = this.FileToLoad?.Trim(); if (sourcePath != null && sourcePath.Length > 0) { // target path challenge: shall be unqiue try { var onlyFn = System.IO.Path.GetFileNameWithoutExtension(sourcePath); var onlyExt = System.IO.Path.GetExtension(sourcePath); var salt = Guid.NewGuid().ToString().Substring(0, 8); var targetPath = "/aasx/files/"; var targetFn = String.Format("{0}_{1}{2}", onlyFn, salt, onlyExt); // have package to adopt the file name packageEnv.PrepareSupplementaryFileParameters(ref targetPath, ref targetFn); // save file.value = targetPath + targetFn; if (addFilesToPackage) { packageEnv.AddSupplementaryFileToStore( sourcePath, targetPath, targetFn, embedAsThumb: false); } } catch (Exception ex) { throw new Exception( $"FormInstanceFile.RenderAasSmeCollection failed while " + $"writing package for {sourcePath}", ex); } } } } // now, may be edit instead of new if (file != null && Touched && fileSource != null && editSource) { fileSource.value = file.value; return(false); } return(true); }
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); }
public virtual void Close() { if (!IsOpen) { return; } Env.Close(); Env = null; }
public AasEntityBuilder(AasModeManager nodeMgr, AdminShellPackageEnv package, IDictionary <NodeId, IList <IReference> > externalReferences, AasxUaServerOptions options) { AasEntityBuilder.nodeMgr = nodeMgr; this.package = package; this.nodeMgrExternalReferences = externalReferences; this.aasTypes = new AasTypeEntities(); this.theServerOptions = options; this.aasTypes.BuildEntites(this); }
public UaServerWrapper( bool _autoAccept, int _stopTimeout, AdminShellPackageEnv _aasxEnv, LogInstance logger = null, AasxUaServerOptions _serverOptions = null) { autoAccept = _autoAccept; aasxEnv = _aasxEnv; aasxServerOptions = _serverOptions; serverRunTime = _stopTimeout == 0 ? Timeout.Infinite : _stopTimeout * 1000; this.Log = logger; }
private Microsoft.Msagl.Drawing.Graph CreateGraph( AdminShellPackageEnv env, AdminShell.Submodel sm, GenericBomCreatorOptions options) { // access if (env == null || sm == null || options == null) { return(null); } //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("BOM-graph"); #if FALSE //create the graph content graph.AddEdge("A", "B"); var e1 = graph.AddEdge("B", "C"); // e1.LabelText = "Dumpf!"; e1.LabelText = "hbhbjhbjhb"; // e1.Label = new Microsoft.Msagl.Drawing.Label("Dumpf!!"); graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); graph.FindNode("B").LabelText = "HalliHallo"; c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; c.Label.FontSize = 28; #else var creator = new GenericBomCreator( env?.AasEnv, _bomRecords, options); using (var tw = new StreamWriter("bomgraph.log")) { creator.RecurseOnLayout(1, graph, null, sm.submodelElements, 1, tw); creator.RecurseOnLayout(2, graph, null, sm.submodelElements, 1, tw); creator.RecurseOnLayout(3, graph, null, sm.submodelElements, 1, tw); } // make default or (already) preferred settings var settings = GivePresetSettings(options.LayoutIndex); if (this.preferredPresetIndex != null && this.preferredPresetIndex.ContainsKey(sm)) { settings = GivePresetSettings(this.preferredPresetIndex[sm]); } if (settings != null) { graph.LayoutAlgorithmSettings = settings; } #endif return(graph); }
/// <summary> /// Render the list of form elements into a list of SubmodelElements. /// </summary> public AdminShell.SubmodelElementWrapperCollection AddOrUpdateDifferentElementsToCollection( AdminShell.SubmodelElementWrapperCollection elements, AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false) { if (this.PairInstances != null) { return(this.PairInstances.AddOrUpdateDifferentElementsToCollection( elements, packageEnv, addFilesToPackage)); } return(null); }
public void Start( AdminShellPackageEnv thePackage, AdminShell.Submodel theSubmodel, AasxPluginMtpViewer.MtpViewerOptions theOptions, PluginEventStack eventStack) { this.thePackage = thePackage; this.theSubmodel = theSubmodel; this.theOptions = theOptions; this.theEventStack = eventStack; }
public SelectAasEntityFlyout( AdminShell.AdministrationShellEnv env, string filter = null, AdminShellPackageEnv package = null, AdminShellPackageEnv[] auxPackages = null) { InitializeComponent(); thePackage = package; theAuxPackages = auxPackages; theEnv = env; theFilter = filter; }
public void TestThatSupplementaryMaterialIsLoaded() { var packaging = new AasCore.Aas3.Package.Packaging(); using var tmpDir = new TemporaryDirectory(); var pth = System.IO.Path.Combine(tmpDir.Path, "dummy.aasx"); var supplUri = new Uri( "/aasx-suppl/some-company/some-manual.pdf", UriKind.Relative); var supplContent = Encoding.UTF8.GetBytes("some content"); // Create a package { using var pkg = packaging.Create(pth); var spec = pkg.MakeSpec( pkg.PutPart( new Uri("/aasx/some-company/data.xml", UriKind.Relative), "text/xml", Get01FestoAasxXmlBytes())); pkg.RelateSupplementaryToSpec( pkg.PutPart( supplUri, "application/pdf", supplContent), spec); pkg.Flush(); } // Load the AASX using AasxCsharpLibrary { using var package = new AdminShellPackageEnv(pth); Assert.IsTrue(package.IsOpen); var lst = package.GetListOfSupplementaryFiles(); Assert.AreEqual(1, lst.Count); var suppl = lst.First(); Assert.AreEqual(supplUri, suppl.Uri); Assert.AreEqual( Encoding.UTF8.GetString(supplContent), Encoding.UTF8.GetString( package.GetByteArrayFromUriOrLocalPackage( suppl.Uri.ToString())) ); } }
public static void loadAasx(string value) { aasxFileSelected = value; if (env != null) { env.Dispose(); } env = new AdminShellPackageEnv(Program.aasxFileSelected); editMode = false; thumbNail = null; signalNewData(3); // build new tree, all nodes closed }
public void Start( LogInstance log, AdminShellPackageEnv thePackage, AdminShell.Submodel theSubmodel, KnownSubmodelsOptions theOptions, PluginEventStack eventStack) { _log = log; _package = thePackage; _submodel = theSubmodel; _options = theOptions; _eventStack = eventStack; }
public void Start( LogInstance log, AdminShellPackageEnv thePackage, AdminShell.Submodel theSubmodel, AasxPluginDocumentShelf.DocumentShelfOptions theOptions, PluginEventStack eventStack) { this.Log = log; this.thePackage = thePackage; this.theSubmodel = theSubmodel; this.theOptions = theOptions; this.theEventStack = eventStack; }
public void Start( AdminShellPackageEnv thePackage, AdminShell.Submodel theSubmodel, AasxPluginMtpViewer.MtpViewerOptions theOptions, PluginEventStack eventStack) { this.thePackage = thePackage; this.theSubmodel = theSubmodel; this.theOptions = theOptions; this.theEventStack = eventStack; this.theDefs = new DefinitionsMTP.ModuleTypePackage(new DefinitionsMTP()); }
/* * TODO (mristin, 2020-10-05): This test has been temporary disabled so that we can merge in the branch * MIHO/EnhanceDocumentShelf. The test should be fixed in a future pull request and we will then re-enable it * again. * * Please do not forget to remove the Resharper directive at the top of this class. * * [Test] * * dead-csharp ignore this comment */ public void TestLoadSaveXmlValidate() { var validator = AasSchemaValidation.NewXmlValidator(); List <string> aasxPaths = SamplesAasxDir.ListAasxPaths(); using (var tmpDir = new TemporaryDirectory()) { string tmpDirPath = tmpDir.Path; foreach (string aasxPath in aasxPaths) { using (var package = new AdminShellPackageEnv(aasxPath)) { /* * TODO (mristin, 2020-09-17): Remove autofix once XSD and Aasx library in sync * * Package has been loaded, now we need to do an automatic check & fix. * * This is necessary as Aasx library is still not conform with the XSD AASX schema and breaks * certain constraints (*e.g.*, the cardinality of langString = 1..*). */ var recs = package.AasEnv.ValidateAll(); if (recs != null) { package.AasEnv.AutoFix(recs); } // Save as XML string name = Path.GetFileName(aasxPath); string outPath = System.IO.Path.Combine(tmpDirPath, $"{name}.converted.xml"); package.SaveAs(outPath, writeFreshly: true); using (var fileStream = System.IO.File.OpenRead(outPath)) { var records = new AasValidationRecordList(); validator.Validate(records, fileStream); if (records.Count != 0) { var parts = new List <string> { $"Failed to validate XML file exported from {aasxPath} to {outPath}:" }; parts.AddRange(records.Select((r) => r.Message)); throw new AssertionException(string.Join(Environment.NewLine, parts)); } } } } } }
public override async Task LoadFromSourceAsync( string fullItemLocation, PackCntRuntimeOptions runtimeOptions = null) { // check extension if (IsFormat == Format.Unknown) { throw new PackageContainerException( "While loading aasx, unknown file format/ extension was encountered!"); } // buffer var fn = fullItemLocation; try { if (IndirectLoadSave) { TempFn = CreateNewTempFn(fullItemLocation, IsFormat); fn = TempFn; System.IO.File.Copy(fullItemLocation, fn); } else { TempFn = null; } } catch (Exception ex) { throw new PackageContainerException( $"While buffering aasx from {this.ToString()} full-location {fullItemLocation} " + $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}"); } // open try { // TODO (MIHO, 2020-12-15): consider removing "indirectLoadSave" from AdminShellPackageEnv Env = new AdminShellPackageEnv(fn, indirectLoadSave: false); } catch (Exception ex) { throw new PackageContainerException( $"While opening aasx {fn} from source {this.ToString()} " + $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}"); } await Task.Yield(); }
static void Main(string[] args) { Console.Error.WriteLine( "AAS Console Server. (c) 2019 Michael Hoffmeister, Festo AG & Co. KG. See LICENSE.TXT."); // default command line options var fn = "usb-stick-REST-demo.aasx"; var host = "localhost"; var port = "1111"; // parse int i = 0; while (i < args.Length) { var x = args[i].Trim().ToLower(); // real option? if (i < args.Length - 1) { if (x == "-host") { host = args[i + 1]; i += 2; continue; } if (x == "-port") { port = args[i + 1]; i += 2; continue; } } // last?? fn = args[i]; i += 1; } // load? var package = new AdminShellPackageEnv(fn); AasxRestServer.Start(package, host, port, new GrapevineLoggerToConsole()); // wait for RETURN Console.ReadLine(); AasxRestServer.Stop(); }
public void Start( AdminShellPackageEnv package, AdminShell.Submodel sm, PlottingOptions options, PluginEventStack eventStack) { // set the context this.thePackage = package; this.theSubmodel = sm; this.theOptions = options; this.theEventStack = eventStack; // ok, directly set contents SetContents(); }
/// <summary> /// Before rendering the SME into a list of new elements, process the SME. /// If <c>Touched</c>, <c>sourceSme</c> and <c>editSource</c> is set, this function shall write back /// the new values instead of producing a new element. /// </summary> /// <returns>True, if a new element shall be rendered from the instance <c>sme</c>.</returns> public virtual bool ProcessSmeForRender( AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false, bool editSource = false) { if (this.sme != null && Touched && this.sourceSme != null && editSource) { if (this.sme.idShort != null) { this.sourceSme.idShort = "" + this.sme.idShort; } if (this.sme.description != null) { this.sourceSme.description = new AdminShell.Description(this.sme.description); } } return(false); }
/// <summary> /// Build a new instance, based on the description data /// </summary> public override AdminShell.SubmodelElementWrapperCollection AddOrUpdateSmeToCollection( AdminShell.SubmodelElementWrapperCollection elements, AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false) { // SMEC as Refrable this.ProcessSmeForRender(packageEnv: null, addFilesToPackage: false, editSource: true); // SMEC as list of items if (this.PairInstances != null) { return(this.PairInstances.AddOrUpdateDifferentElementsToCollection( elements, packageEnv, addFilesToPackage)); } return(null); }