public FormInstanceFile( FormInstanceListOfSame parentInstance, FormDescFile parentDesc, AdminShell.SubmodelElement source = null, bool deepCopy = false) { // way back to description this.parentInstance = parentInstance; this.desc = parentDesc; // initialize Refwrable var file = new AdminShell.File(); this.sme = file; InitReferable(parentDesc, source); // check, if a source is present this.sourceSme = source; var fileSource = this.sourceSme as AdminShell.File; if (fileSource != null) { // take over file.value = fileSource.value; } // create user control this.subControl = new FormSubControlFile(); this.subControl.DataContext = this; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { // init library activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib(); activeVisualObjectLib.LoadStatic(null); // find file, remember Submodel element for it, find filename // (ConceptDescription)(no-local)[IRI]http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage var simIdFn = new AdminShell.Key("ConceptDescription", false, "IRI", "http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage"); this.activeMtpFileElem = theSubmodel?.submodelElements?.FindFirstSemanticIdAs <AdminShell.File>(simIdFn); var inputFn = this.activeMtpFileElem?.value; if (inputFn == null) { return; } // access file if (CheckIfPackageFile(inputFn)) { inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn); } // load file LoadFile(inputFn); // fit it this.mtpVisu.ZoomToFitCanvas(); // double click handler this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick; }
public AdminShell.File GenerateDefault() { var res = new AdminShell.File(); this.InitSme(res); if (this.presetMimeType != null) { res.mimeType = this.presetMimeType; } return(res); }
/// <summary> /// Checks, if a FileType node is advisable for representing an AASX file .. /// Shall be TRUE for local, existing files .. /// </summary> /// <returns></returns> public bool CheckSuitablity(AdminShellPackageEnv package, AdminShell.File file) { // trivial if (package == null || file == null) { return(false); } // try get a stream .. Stream s = null; try { s = package.GetLocalStreamFromPackage(file.value); } catch { return(false); } // ok? return(s != null); }
/// <summary> /// Checks, if a FileType node is advisable for representing an AASX file .. /// Shall be TRUE for local, existing files .. /// </summary> /// <returns></returns> public bool CheckSuitablity(AdminShellPackageEnv package, AdminShell.File file) { // trivial if (package == null || file == null) { return(false); } // try get a stream .. Stream s = null; try { s = package.GetLocalStreamFromPackage(file.value); } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); return(false); } // ok? return(s != null); }
public FileInfo(AdminShell.File file) { Path = file?.value; MimeType = file?.mimeType; }
private bool GatherMtpInfos() { // clear mappings this.activeEndpointMapping = new Dictionary <string, string>(); // access var env = this.thePackage?.AasEnv; if (this.theSubmodel?.semanticId == null || this.theSubmodel.submodelElements == null || this.theDefs == null || env?.AdministrationShells == null || this.thePackage.AasEnv.Submodels == null) { return(false); } // need to find the type Submodel AdminShell.Submodel mtpTypeSm = null; // check, if the user pointed to the instance submodel if (this.theSubmodel.semanticId.Matches(this.theDefs.SEM_MtpInstanceSubmodel)) { // gather infos foreach (var srcLst in this.theSubmodel.submodelElements .FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( this.theDefs.CD_SourceList?.GetReference(), AdminShell.Key.MatchMode.Relaxed)) { // found a source list, might contain sources if (srcLst?.value == null) { continue; } // UA Server? foreach (var src in srcLst.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( this.theDefs.CD_SourceOpcUaServer?.GetReference(), AdminShell.Key.MatchMode.Relaxed)) { if (src?.value != null) { // UA server var ep = src.value.FindFirstSemanticIdAs <AdminShell.Property>( this.theDefs.CD_Endpoint.GetReference(), AdminShell.Key.MatchMode.Relaxed)?.value; // add this.activeEndpointMapping[("" + src.idShort).Trim()] = "" + ep; } } } // according spec from Sten Gruener, the AAS.derivedFrom relationship shall be exploited. // How to get from subModel to AAS? var instanceAas = env.FindAASwithSubmodel(this.theSubmodel.identification); var typeAas = env.FindReferableByReference(instanceAas?.derivedFrom) as AdminShell.AdministrationShell; if (instanceAas?.derivedFrom != null && typeAas != null) { foreach (var msm in env.FindAllSubmodelGroupedByAAS((aas, sm) => { return(aas == typeAas && true == sm?.semanticId?.Matches(this.theDefs.SEM_MtpSubmodel)); })) { mtpTypeSm = msm; break; } } // another possibility: direct reference var dirLink = this.theSubmodel.submodelElements .FindFirstSemanticIdAs <AdminShell.ReferenceElement>( this.theDefs.CD_MtpTypeSubmodel?.GetReference(), AdminShell.Key.MatchMode.Relaxed); var dirLinkSm = env.FindReferableByReference(dirLink?.value) as AdminShell.Submodel; if (mtpTypeSm == null) { mtpTypeSm = dirLinkSm; } } // other (not intended) case: user points to type submodel directly if (mtpTypeSm == null && this.theSubmodel.semanticId.Matches(this.theDefs.SEM_MtpSubmodel)) { mtpTypeSm = this.theSubmodel; } // ok, is there a type submodel? if (mtpTypeSm == null) { return(false); } // find file, remember Submodel element for it, find filename // (ConceptDescription)(no-local)[IRI]http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage this.activeMtpFileElem = mtpTypeSm.submodelElements? .FindFirstSemanticIdAs <AdminShell.File>(this.theDefs.CD_MtpFile.GetReference(), AdminShell.Key.MatchMode.Relaxed); var inputFn = this.activeMtpFileElem?.value; if (inputFn == null) { return(false); } this.activeMtpFileFn = inputFn; return(true); }
public AasUaPackageFileHandler(AdminShellPackageEnv package, AdminShell.File file) { this.package = package; this.file = file; }
public NodeState CreateAddElements(NodeState parent, CreateMode mode, AdminShellPackageEnv package = null, AdminShell.File file = null) { // access if (parent == null) { return(null); } // for sake of complexity, differentiate early if (mode == CreateMode.Type) { var o = this.entityBuilder.CreateAddObject( parent, mode, "File", ReferenceTypeIds.HasComponent, ObjectTypeIds.FileType); return(o); } else { if (package == null || file == null) { return(null); } var instData = new InstanceData(); instData.packHandler = new AasUaPackageFileHandler(package, file); // containing element var o = this.entityBuilder.CreateAddObject( parent, mode, "File", ReferenceTypeIds.HasComponent, ObjectTypeIds.FileType); // this first information is to provide a "off-the-shelf" size information; a Open() will re-new this var fileLen = Convert.ToUInt64(package.GetStreamSizeFromPackage(file.value)); // populate attributes from the spec this.entityBuilder.CreateAddPropertyState <string>(o, mode, "MimeType", DataTypeIds.String, file.mimeType, ReferenceTypeIds.HasProperty, VariableTypeIds.PropertyType); instData.nodeOpenCount = this.entityBuilder.CreateAddPropertyState <UInt16>(o, mode, "OpenCount", DataTypeIds.UInt16, 0, ReferenceTypeIds.HasProperty, VariableTypeIds.PropertyType); instData.nodeSize = this.entityBuilder.CreateAddPropertyState <UInt64>(o, mode, "Size", DataTypeIds.UInt64, fileLen, ReferenceTypeIds.HasProperty, VariableTypeIds.PropertyType, valueRank: -1); this.entityBuilder.CreateAddPropertyState <bool>(o, mode, "UserWritable", DataTypeIds.Boolean, true, ReferenceTypeIds.HasProperty, VariableTypeIds.PropertyType); this.entityBuilder.CreateAddPropertyState <bool>(o, mode, "Writable", DataTypeIds.Boolean, true, ReferenceTypeIds.HasProperty, VariableTypeIds.PropertyType); // Open instData.mOpen = this.entityBuilder.CreateAddMethodState(o, mode, "Open", inputArgs: new[] { new Argument("Mode", DataTypeIds.Byte, -1, "") }, outputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, "") }, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_Open, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mOpen, instData); // Close instData.mClose = this.entityBuilder.CreateAddMethodState(o, mode, "Close", inputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, "") }, outputArgs: null, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_Close, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mClose, instData); // Read instData.mRead = this.entityBuilder.CreateAddMethodState(o, mode, "Read", inputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, ""), new Argument("Length", DataTypeIds.Int32, -1, "") }, outputArgs: new[] { new Argument("Data", DataTypeIds.ByteString, -1, "") }, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_Read, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mRead, instData); // Write instData.mWrite = this.entityBuilder.CreateAddMethodState(o, mode, "Write", inputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, ""), new Argument("Data", DataTypeIds.ByteString, -1, "") }, outputArgs: null, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_Write, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mWrite, instData); // GetPosition instData.mGetPosition = this.entityBuilder.CreateAddMethodState(o, mode, "GetPosition", inputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, ""), }, outputArgs: new[] { new Argument("Position", DataTypeIds.UInt64, -1, "") }, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_GetPosition, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mGetPosition, instData); // SetPosition instData.mSetPosition = this.entityBuilder.CreateAddMethodState(o, mode, "SetPosition", inputArgs: new[] { new Argument("FileHandle", DataTypeIds.UInt32, -1, ""), new Argument("Position", DataTypeIds.UInt64, -1, "") }, outputArgs: null, referenceTypeFromParentId: ReferenceTypeIds.HasComponent, methodDeclarationId: MethodIds.FileType_SetPosition, onCalled: this.OnMethodCalled); this.entityBuilder.AddNodeStateAnnotation(instData.mSetPosition, instData); // result return(o); } }