Пример #1
0
        //
        // special Submodel References
        //

        public void DisplayOrEditEntitySubmodelRef(StackPanel stack,
                                                   AdminShell.SubmodelRef smref,
                                                   Action <AdminShell.SubmodelRef> setOutput,
                                                   string entityName)
        {
            // access
            if (stack == null)
            {
                return;
            }

            // members
            this.AddHintBubble(stack, hintMode, new[] {
                new HintCheck(
                    () => { return(smref == null); },
                    $"No {entityName}. Please consider adding a reference " +
                    "to an adequate Submodel."),
            });
            if (this.SafeguardAccess(
                    stack, repo, smref, $"{entityName}:",
                    "Create data element!",
                    v =>
            {
                setOutput?.Invoke(new AdminShell.SubmodelRef());
                return(new ModifyRepo.LambdaActionRedrawEntity());
            }))
            {
                this.AddGroup(
                    stack, $"{entityName} - Reference to describing Submodel:",
                    levelColors[1][0], levelColors[1][1]);
                this.AddKeyListKeys(
                    stack, $"{entityName}:", smref.Keys,
                    repo, packages, PackageCentral.Selector.Main, "Submodel");
            }
        }
Пример #2
0
 public void TryFixSmRefIfNull()
 {
     if (smref == null && sm?.identification != null)
     {
         smref = new AdminShell.SubmodelRef(new AdminShell.Reference(new AdminShell.Key(
                                                                         AdminShell.Key.Submodel, true, sm.identification.idType, sm.identification.id)));
     }
 }
Пример #3
0
 public CopyPasteItemSubmodel(
     object parentContainer,
     object entity,
     AdminShell.SubmodelRef smref,
     AdminShell.Submodel sm)
 {
     this.parentContainer = parentContainer;
     this.smref           = smref;
     this.sm = sm;
     TryFixSmRefIfNull();
 }
 public CopyPasteItemSubmodel(
     object parentContainer,
     object entity,
     AdminShell.SubmodelRef smref,
     AdminShell.Submodel sm)
 {
     this.parentContainer = parentContainer;
     this.entity          = entity;
     this.smref           = smref;
     this.sm = sm;
 }
Пример #5
0
        public static void createSubmodelElements(
            UaNode n, AdminShell.AdministrationShellEnv env, AdminShell.SubmodelElementCollection smec,
            AdminShell.SubmodelRef smref, string path, AdminShell.SubmodelElementCollection concepts)
        {
            String name = n.BrowseName;

            if (n.SymbolicName != null && n.SymbolicName != "")
            {
                name = n.SymbolicName;
            }
            var semanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", path + name);

            if ((n.children != null && n.children.Count != 0) ||
                (n.fields != null && n.fields.Count != 0))
            {
                var sme = AdminShell.SubmodelElementCollection.CreateNew(name, null, semanticID);
                sme.semanticId.Keys.Add(AdminShell.Key.CreateNew("UATypeName", false, "OPC", n.UAObjectTypeName));
                smec.Add(sme);
                if (n.Value != "")
                {
                    var p = createSE(n, path);
                    sme.Add(p);
                    addLeaf(concepts, p);
                }
                foreach (field f in n.fields)
                {
                    sme.semanticId.Keys.Add(
                        AdminShell.Key.CreateNew(
                            "UAField", false, "OPC", f.name + " = " + f.value + " : " + f.description));
                    semanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", path + name + "/" + f.name);
                    var p = AdminShell.Property.CreateNew(f.name, null, semanticID);
                    p.valueType = "string";
                    p.value     = f.value;
                    sme.Add(p);
                    addLeaf(concepts, p);
                }
                if (n.children != null)
                {
                    foreach (UaNode c in n.children)
                    {
                        createSubmodelElements(c, env, sme, smref, path + name + "/", concepts);
                    }
                }
            }
            else
            {
                var se = createSE(n, path);
                smec.Add(se);
                addLeaf(concepts, se);
            }
        }
Пример #6
0
 public VisualElementSubmodelRef(VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.SubmodelRef smr, AdminShell.Submodel sm)
     : base()
 {
     this.Parent         = parent;
     this.Cache          = cache;
     this.theEnv         = env;
     this.theSubmodelRef = smr;
     this.theSubmodel    = sm;
     this.Background     = (SolidColorBrush)(new BrushConverter().ConvertFrom("#CBD8EB"));
     this.Border         = (SolidColorBrush)(new BrushConverter().ConvertFrom("#4370B3"));
     this.TagString      = "Sub";
     this.TagBg          = this.Border;
     this.TagFg          = Brushes.White;
     RefreshFromMainData();
     RestoreFromCache();
 }
        public VisualElementSubmodelRef(
            VisualElementGeneric parent, TreeViewLineCache cache, AdminShell.AdministrationShellEnv env,
            AdminShell.SubmodelRef smr, AdminShell.Submodel sm)
            : base()
        {
            this.Parent         = parent;
            this.Cache          = cache;
            this.theEnv         = env;
            this.theSubmodelRef = smr;
            this.theSubmodel    = sm;

            this.Background = (SolidColorBrush)System.Windows.Application.Current.Resources["LightAccentColor"];
            this.Border     = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkestAccentColor"];
            this.TagBg      = (SolidColorBrush)System.Windows.Application.Current.Resources["DarkestAccentColor"];
            this.TagFg      = Brushes.White;

            this.TagString = "SM";
            RefreshFromMainData();
            RestoreFromCache();
        }
        public static void ImportBMEcatToSubModel(
            string inputFn, AdminShell.AdministrationShellEnv env, AdminShell.Submodel sm,
            AdminShell.SubmodelRef smref)
        {
            // Select between BMEcat and XML publication
            // Tag "<BMECAT" for BMEcat File
            // Tag "<Publication" for XML from GWIS
            Boolean isBMEcat      = false;
            Boolean isPublication = false;

            XmlTextReader reader = new XmlTextReader(inputFn);
            StreamWriter  sw     = File.CreateText(inputFn + ".log.txt");

            // BMEcat or Publication?
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:     // The node is an element.
                    if (reader.Name == "BMECAT")
                    {
                        isBMEcat = true;
                    }
                    if (reader.Name == "Publication")
                    {
                        isPublication = true;
                    }
                    break;
                }
                if (isBMEcat || isPublication)
                {
                    break;
                }
            }

            // BMEcat
            String FT_ID   = "";
            String FT_NAME = "";

            String[] FVALUE        = new string[] { "", "", "", "", "", "", "", "", "", "" };
            int      i_FVALUE      = 0;
            String   FUNIT         = "";
            String   FID           = "";
            String   FPARENT_ID    = "";
            Boolean  is_FT_ID      = false;
            Boolean  is_FT_NAME    = false;
            Boolean  is_FVALUE     = false;
            Boolean  is_FUNIT      = false;
            Boolean  is_FID        = false;
            Boolean  is_FPARENT_ID = false;

            String[] Stack_FID        = new string[10];
            int      StackPointer_FID = 0;
            // GWIS XML Publication
            String  attribute_label_id = "";
            String  attribute_value    = "";
            String  subheadline        = "";
            Boolean is_technical_data  = false;
            Boolean is_attribute_list  = false;
            Boolean is_subheadline     = false;
            Boolean is_attribute       = false;
            Boolean is_attribute_label = false;
            Boolean is_attribute_value = false;

            AdminShell.SubmodelElementCollection[] propGroup = new AdminShell.SubmodelElementCollection[10];

            // GWIS XML Publication
            if (isPublication)
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:     // The node is an element.
                        if (reader.Name == "technical_data")
                        {
                            is_technical_data = true;
                        }
                        if (reader.Name == "attribute_list")
                        {
                            is_attribute_list = true;
                        }
                        if (reader.Name == "subheadline")
                        {
                            is_subheadline = true;
                        }
                        if (reader.Name == "attribute")
                        {
                            is_attribute = true;
                        }
                        if (reader.Name == "label")
                        {
                            is_attribute_label = true;
                        }
                        if (reader.Name == "value")
                        {
                            is_attribute_value = true;
                        }
                        break;

                    case XmlNodeType.Text:     //Display the text in each element.
                        if (is_technical_data && is_attribute_list && is_attribute && is_attribute_label)
                        {
                            attribute_label_id = reader.Value;
                            is_attribute_label = false;
                        }
                        if (is_technical_data && is_attribute_list && is_attribute && is_attribute_value)
                        {
                            attribute_value    = reader.Value;
                            is_attribute_value = false;
                        }
                        if (is_technical_data && is_attribute_list && is_subheadline)
                        {
                            subheadline = reader.Value;
                        }
                        break;

                    case XmlNodeType.EndElement:     //Display the end of the element.
                        if (reader.Name == "subheadline")
                        {
                            if (subheadline != "")
                            {
                                propGroup[0] = AdminShell.SubmodelElementCollection.CreateNew(subheadline);
                                sm.Add(propGroup[0]);
                            }
                        }
                        if (reader.Name == "attribute")
                        {
                            if (attribute_label_id != "" && attribute_value != "")
                            {
                                sw.WriteLine(attribute_label_id + " | " + attribute_value);
                                using (var cd = AdminShell.ConceptDescription.CreateNew(
                                           "" + attribute_label_id, AdminShell.Identification.IRDI, FT_ID))
                                {
                                    env.ConceptDescriptions.Add(cd);
                                    cd.SetIEC61360Spec(
                                        preferredNames: new[] { "EN", attribute_label_id },
                                        shortName: attribute_label_id,
                                        unit: "string",
                                        valueFormat: "STRING",
                                        definition: new[] { "EN", attribute_label_id }
                                        );

                                    var p = AdminShell.Property.CreateNew(
                                        cd.GetDefaultShortName(), "PARAMETER",
                                        AdminShell.Key.GetFromRef(cd.GetCdReference()));
                                    if (is_subheadline)
                                    {
                                        propGroup[0].Add(p);
                                    }
                                    else
                                    {
                                        sm.Add(p);
                                    }
                                    p.valueType = "string";
                                    p.value     = attribute_value;
                                }
                            }
                            is_attribute       = false;
                            attribute_value    = "";
                            attribute_label_id = "";
                        }
                        if (reader.Name == "attribute_list")
                        {
                            is_attribute_list = false;
                            is_subheadline    = false;
                            subheadline       = "";
                        }
                        break;
                    }
                }
                sw.Close();
                return;
            }

            // BMEcat
            if (isBMEcat)
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:     // The node is an element.
                        if (reader.Name == "FT_ID")
                        {
                            is_FT_ID = true;
                        }
                        if (reader.Name == "FT_NAME")
                        {
                            is_FT_NAME = true;
                        }
                        if (reader.Name == "FVALUE")
                        {
                            var rString = reader.GetAttribute("lang");
                            // only no language or English values
                            if (rString == null || rString == "" || rString == "eng")
                            {
                                is_FVALUE = true;
                            }
                        }
                        if (reader.Name == "FUNIT")
                        {
                            is_FUNIT = true;
                        }
                        if (reader.Name == "FID")
                        {
                            is_FID = true;
                        }
                        if (reader.Name == "FPARENT_ID")
                        {
                            is_FPARENT_ID = true;
                        }
                        break;

                    case XmlNodeType.Text:     //Display the text in each element.
                        // BMEcat
                        if (is_FT_ID)
                        {
                            FT_ID    = reader.Value;
                            is_FT_ID = false;
                        }
                        if (is_FT_NAME)
                        {
                            FT_NAME    = reader.Value;
                            is_FT_NAME = false;
                        }
                        if (is_FVALUE)
                        {
                            FVALUE[i_FVALUE++] = reader.Value;
                            is_FVALUE          = false;
                        }
                        if (is_FUNIT)
                        {
                            FUNIT    = reader.Value;
                            is_FUNIT = false;
                        }
                        if (is_FUNIT)
                        {
                            FUNIT    = reader.Value;
                            is_FUNIT = false;
                        }
                        if (is_FID)
                        {
                            FID    = reader.Value;
                            is_FID = false;
                        }
                        if (is_FPARENT_ID)
                        {
                            FPARENT_ID    = reader.Value;
                            is_FPARENT_ID = false;
                        }
                        break;

                    case XmlNodeType.EndElement:     //Display the end of the element.
                        // BMEcat
                        if (reader.Name == "FEATURE")
                        {
                            Boolean is_AXIS1D = (i_FVALUE == 6);
                            int     k;

                            for (k = 0; k < i_FVALUE; k++)
                            {
                                sw.WriteLine(FT_ID + " | " + FT_NAME + " | " + FVALUE[k] + " | " + FUNIT +
                                             " | " + FID + " | " + FPARENT_ID);
                            }

                            if (FT_ID != "" && FT_NAME != "")     // korrekter Eintrag
                            {
                                if (FPARENT_ID == "-1")
                                {
                                    StackPointer_FID = 0;
                                }
                                if (i_FVALUE > 0)     // Property
                                {
                                    for (k = 0; k < i_FVALUE; k++)
                                    {
                                        if (FUNIT != "")
                                        {
                                            if (FUNIT == "0173-1#05-AAA480#002")
                                            {
                                                FUNIT = "mm | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA731#002")
                                            {
                                                FUNIT = "kg | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA153#002")
                                            {
                                                FUNIT = "V | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA295#002")
                                            {
                                                FUNIT = "mm² | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA723#002")
                                            {
                                                FUNIT = "mA | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA114#002")
                                            {
                                                FUNIT = "ms | " + FUNIT;
                                            }
                                            else if (FUNIT == "0173-1#05-AAA220#002")
                                            {
                                                FUNIT = "A | " + FUNIT;
                                            }
                                        }

                                        string extendedname = FT_NAME;
                                        if (is_AXIS1D)     // checked by IRDIs
                                        {
                                            extendedname += " " + names_AXIS1D[k];
                                        }
                                        else if (i_FVALUE > 1 && i_FVALUE <= 4)
                                        {
                                            extendedname += " " + names_LEVELTYPE[k];     // MIN, MAX, ...
                                        }

                                        using (var cd = AdminShell.ConceptDescription.CreateNew(
                                                   "" + extendedname, AdminShell.Identification.IRDI, FT_ID))
                                        {
                                            env.ConceptDescriptions.Add(cd);
                                            cd.SetIEC61360Spec(
                                                preferredNames: new[] { "DE", extendedname, "EN", extendedname },
                                                shortName: extendedname,
                                                unit: FUNIT,
                                                valueFormat: "REAL_MEASURE",
                                                definition: new[] { "DE", extendedname, "EN", extendedname }
                                                );

                                            var p = AdminShell.Property.CreateNew(
                                                cd.GetDefaultShortName(), "PARAMETER",
                                                AdminShell.Key.GetFromRef(cd.GetCdReference()));
                                            p.valueType = "double";
                                            p.value     = FVALUE[k];

                                            if (StackPointer_FID == 0)     // am Submodell
                                            {
                                                sm.Add(p);
                                            }
                                            else     // an Collection
                                            {
                                                for (int j = 0; j < StackPointer_FID; j++)
                                                {
                                                    if (Stack_FID[j] == FPARENT_ID)     // Vater gefunden
                                                    {
                                                        propGroup[j].Add(p);
                                                        StackPointer_FID = j + 1;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else                           // Collection
                                {
                                    if (StackPointer_FID == 0) // oberste Collection
                                    {
                                        Stack_FID[0] = FID;
                                        propGroup[0] = AdminShell.SubmodelElementCollection.CreateNew(FT_NAME);
                                        sm.Add(propGroup[0]);
                                        StackPointer_FID++; // nächste Ebene
                                    }
                                    else                    // Collection suchen
                                    {
                                        for (int j = 0; j < StackPointer_FID; j++)
                                        {
                                            if (Stack_FID[j] == FPARENT_ID)     // Vater gefunden
                                            {
                                                StackPointer_FID            = j + 1;
                                                Stack_FID[StackPointer_FID] = FID;
                                                propGroup[StackPointer_FID] =
                                                    AdminShell.SubmodelElementCollection.CreateNew(FT_NAME);
                                                propGroup[StackPointer_FID - 1].Add(propGroup[StackPointer_FID]);
                                                StackPointer_FID++;     // nächste Ebene
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            FT_ID      = "";
                            FT_NAME    = "";
                            i_FVALUE   = 0;
                            FUNIT      = "";
                            FID        = "";
                            FPARENT_ID = "";
                        }
                        break;
                    }
                }
            }
            sw.Close();
            // OZ end
        }
Пример #9
0
        public static void ImportCSVtoSubModel(
            string inputFn, AdminShell.AdministrationShellEnv env, AdminShell.Submodel sm, AdminShell.SubmodelRef smref)
        {
            AdminShell.SubmodelElementCollection[] propGroup = new AdminShell.SubmodelElementCollection[10];
            int i_propGroup = 0;

            var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(inputFn);

            parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
            parser.SetDelimiters(";");

            string[] rows = parser.ReadFields();
            if (rows == null)
            {
                throw new InvalidOperationException(
                          $"There were no fields read from the inputFn: {inputFn}");
            }

            if ((rows[0] != "typeName" ||
                 rows[1] != "idShort" ||
                 rows[2] != "value") ||
                (rows.Length > 3 &&
                 (
                     rows[3] != "valueType" ||
                     rows[4] != "category" ||
                     rows[5] != "descriptionEN" ||
                     rows[6] != "descriptionDE"
                 )))
            {
                return;
            }

            sm.idShort = inputFn.Split('\\').Last().Replace(".csv", "");

            while (!parser.EndOfData)
            {
                rows = parser.ReadFields();

                if (rows == null)
                {
                    throw new InvalidOperationException(
                              $"There were no fields read from inputFn: {inputFn}");
                }

                switch (rows[0])
                {
                case "SubmodelElementCollection":
                    propGroup[i_propGroup] = AdminShell.SubmodelElementCollection.CreateNew(rows[1]);
                    if (i_propGroup == 0)
                    {
                        sm.Add(propGroup[0]);
                        if (rows.Length > 3)
                        {
                            if (rows[7] != "")
                            {
                                propGroup[0].semanticId = new AdminShellV20.SemanticId(
                                    AdminShell.Reference.CreateNew(
                                        "ConceptDescription", false, "IRI", rows[7]));
                            }
                        }
                        propGroup[0].kind = AdminShellV20.ModelingKind.CreateAsInstance();
                    }
                    else
                    {
                        propGroup[i_propGroup - 1].Add(propGroup[i_propGroup]);
                    }
                    i_propGroup++;
                    break;

                case "End-SubmodelElementCollection":
                    if (i_propGroup != 0)
                    {
                        i_propGroup--;
                    }
                    break;

                case "Property":
                    var p = AdminShell.Property.CreateNew(rows[1].Replace("-", "_"));
                    p.value = rows[2];
                    if (rows.Length > 3)
                    {
                        p.valueType = rows[3];
                        p.category  = rows[4];
                        if (rows[5] != "")
                        {
                            p.AddDescription("en", rows[5]);
                        }
                        if (rows[6] != "")
                        {
                            p.AddDescription("de", rows[6]);
                        }
                        p.kind = AdminShellV20.ModelingKind.CreateAsInstance();
                        if (rows[7] != "")
                        {
                            p.semanticId = new AdminShell.SemanticId(
                                AdminShell.Reference.CreateNew(
                                    "ConceptDescription", false, "IRI", rows[7]));
                        }
                    }
                    if (i_propGroup == 0)
                    {
                        sm.Add(p);
                    }
                    else
                    {
                        propGroup[i_propGroup - 1].Add(p);
                    }
                    break;
                }
            }
        }
Пример #10
0
        public static void ImportNodeSetToSubModel(
            string inputFn, AdminShell.AdministrationShellEnv env, AdminShell.Submodel sm,
            AdminShell.SubmodelRef smref)
        {
            XmlTextReader reader = new XmlTextReader(inputFn);
            StreamWriter  sw     = File.CreateText(inputFn + ".log.txt");

            string elementName   = "";
            bool   tagDefinition = false;
            string referenceType = "";

            roots          = new List <UaNode>();
            nodes          = new List <UaNode>();
            parentNodes    = new Dictionary <string, UaNode>();
            semanticIDPool = new Dictionary <string, Int16>();
            UaNode currentNode = null;

            // global model data
            string ModelUri                        = "";
            string ModelUriVersion                 = "";
            string ModelUriPublicationDate         = "";
            string RequiredModelUri                = "";
            string RequiredModelUriVersion         = "";
            string RequiredModelUriPublicationDate = "";


            // scan nodeset and store node data in nodes
            // store also roots, i.e. no parent in node
            // store also new ParentNodeIds in parentNodes with value null
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    elementName = reader.Name;
                    switch (elementName)
                    {
                    case "Model":
                        ModelUri                = reader.GetAttribute("ModelUri");
                        ModelUriVersion         = reader.GetAttribute("Version");
                        ModelUriPublicationDate = reader.GetAttribute("PublicationDate");
                        break;

                    case "RequiredModel":
                        RequiredModelUri                = reader.GetAttribute("ModelUri");
                        RequiredModelUriVersion         = reader.GetAttribute("Version");
                        RequiredModelUriPublicationDate = reader.GetAttribute("PublicationDate");
                        break;

                    case "UADataType":
                    case "UAVariable":
                    case "UAObject":
                    case "UAMethod":
                    case "UAReferenceType":
                    case "UAObjectType":
                    case "UAVariableType":
                        string parentNodeId = reader.GetAttribute("ParentNodeId");
                        currentNode = new UaNode();
                        currentNode.UAObjectTypeName = elementName;
                        currentNode.NodeId           = reader.GetAttribute("NodeId");
                        currentNode.ParentNodeId     = parentNodeId;
                        currentNode.BrowseName       = reader.GetAttribute("BrowseName");
                        var split = currentNode.BrowseName.Split(':');
                        if (split.Length > 1)
                        {
                            currentNode.NameSpace = split[0];
                            if (split.Length == 2)
                            {
                                currentNode.BrowseName = split[1];
                            }
                        }
                        currentNode.SymbolicName = reader.GetAttribute("SymbolicName");
                        currentNode.DataType     = reader.GetAttribute("DataType");
                        break;

                    case "Reference":
                        referenceType = reader.GetAttribute("ReferenceType");
                        break;

                    case "Definition":
                        tagDefinition = true;
                        currentNode.DefinitionName = reader.GetAttribute("Name");
                        var splitd = currentNode.DefinitionName.Split(':');
                        if (splitd.Length > 1)
                        {
                            currentNode.DefinitionNameSpace = splitd[0];
                            if (splitd.Length == 2)
                            {
                                currentNode.DefinitionName = splitd[1];
                            }
                        }
                        break;

                    case "Field":
                        field f = new field();
                        f.name  = reader.GetAttribute("Name");
                        f.value = reader.GetAttribute("Value");
                        currentNode.fields.Add(f);
                        break;

                    case "Description":
                        break;
                    }
                    break;

                case XmlNodeType.Text:
                    switch (elementName)
                    {
                    case "String":
                    case "DateTime":
                    case "Boolean":
                    case "Int32":
                    case "ByteString":
                    case "uax:String":
                    case "uax:DateTime":
                    case "uax:Boolean":
                    case "uax:Int32":
                    case "uax:Int16":
                    case "uax:ByteString":
                    case "uax:Float":
                        currentNode.Value = reader.Value;
                        break;

                    case "Description":
                        if (tagDefinition)
                        {
                            int count = currentNode.fields.Count;
                            if (count > 0)
                            {
                                currentNode.fields[count - 1].description = reader.Value;
                            }
                        }
                        else
                        {
                            currentNode.Description = reader.Value;
                        }
                        break;

                    case "Reference":
                        string reference = referenceType + " " + reader.Value;
                        currentNode.references.Add(reference);
                        break;

                    case "DisplayName":
                        currentNode.DisplayName = reader.Value;
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:     //Display the end of the element.
                    switch (reader.Name)
                    {
                    case "Definition":
                        tagDefinition = false;
                        break;
                    }
                    if (currentNode == null || currentNode.UAObjectTypeName == null)
                    {
                        break;
                    }
                    if (reader.Name == currentNode.UAObjectTypeName)
                    {
                        switch (currentNode.UAObjectTypeName)
                        {
                        case "UADataType":
                        case "UAVariable":
                        case "UAObject":
                        case "UAMethod":
                        case "UAReferenceType":
                        case "UAObjectType":
                        case "UAVariableType":
                            nodes.Add(currentNode);
                            if (currentNode.ParentNodeId == null || currentNode.ParentNodeId == "")
                            {
                                roots.Add(currentNode);
                            }
                            else
                            {
                                // collect different parentNodeIDs to set corresponding node in dictionary later
                                if (!parentNodes.ContainsKey(currentNode.ParentNodeId))
                                {
                                    parentNodes.Add(currentNode.ParentNodeId, null);
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }

            sw.Close();

            // scan nodes and store parent node in parentNodes value
            foreach (UaNode n in nodes)
            {
                if (parentNodes.TryGetValue(n.NodeId, out UaNode unused))
                {
                    parentNodes[n.NodeId] = n;
                }
            }

            // scan nodes and set parent and children for node
            foreach (UaNode n in nodes)
            {
                if (n.ParentNodeId != null && n.ParentNodeId != "")
                {
                    if (parentNodes.TryGetValue(n.ParentNodeId, out UaNode p))
                    {
                        if (p != null)
                        {
                            n.parent = p;
                            p.children.Add(n);
                        }
                        else
                        {
                            roots.Add(n);
                        }
                    }
                }
            }

            var outerSme = AdminShell.SubmodelElementCollection.CreateNew("OuterCollection");

            sm.Add(outerSme);
            var innerSme = AdminShell.SubmodelElementCollection.CreateNew("InnerCollection");

            sm.Add(innerSme);
            var conceptSme = AdminShell.SubmodelElementCollection.CreateNew("ConceptDescriptionCollection");

            sm.Add(conceptSme);

            // store models information
            var msemanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", ModelUri + "models");
            var msme        = AdminShell.SubmodelElementCollection.CreateNew("Models", null, msemanticID);

            msme.semanticId.Keys.Add(AdminShell.Key.CreateNew("UATypeName", false, "OPC", "Models"));
            innerSme.Add(msme);
            // modeluri
            msemanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", ModelUri + "models/modeluri");
            var mp = AdminShell.Property.CreateNew("ModelUri", null, msemanticID);

            mp.valueType = "string";
            mp.value     = ModelUri;
            msme.Add(mp);
            addLeaf(conceptSme, mp);
            // modeluriversion
            msemanticID = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "models/modeluriversion");
            mp           = AdminShell.Property.CreateNew("ModelUriVersion", null, msemanticID);
            mp.valueType = "string";
            mp.value     = ModelUriVersion;
            msme.Add(mp);
            addLeaf(conceptSme, mp);
            // modeluripublicationdate
            msemanticID = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "models/modeluripublicationdate");
            mp           = AdminShell.Property.CreateNew("ModelUriPublicationDate", null, msemanticID);
            mp.valueType = "string";
            mp.value     = ModelUriPublicationDate;
            msme.Add(mp);
            addLeaf(conceptSme, mp);
            // requiredmodeluri
            msemanticID = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "models/requiredmodeluri");
            mp           = AdminShell.Property.CreateNew("RequiredModelUri", null, msemanticID);
            mp.valueType = "string";
            mp.value     = RequiredModelUri;
            msme.Add(mp);
            addLeaf(conceptSme, mp);
            // modeluriversion
            msemanticID = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "models/requiredmodeluriversion");
            mp           = AdminShell.Property.CreateNew("RequiredModelUriVersion", null, msemanticID);
            mp.valueType = "string";
            mp.value     = RequiredModelUriVersion;
            msme.Add(mp);
            addLeaf(conceptSme, mp);
            // modeluripublicationdate
            msemanticID = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "models/requiredmodeluripublicationdate");
            mp           = AdminShell.Property.CreateNew("RequiredModelUriPublicationDate", null, msemanticID);
            mp.valueType = "string";
            mp.value     = RequiredModelUriPublicationDate;
            msme.Add(mp);
            addLeaf(conceptSme, mp);

            // iterate through independent root trees
            // store UADataType to UADataTypeCollection in the end
            var semanticIDDataTypes = AdminShell.Key.CreateNew(
                "GlobalReference", false, "IRI", ModelUri + "UADataTypeCollection");
            var smeDataTypes = AdminShell.SubmodelElementCollection.CreateNew(
                "UADataTypeCollection", null, semanticIDDataTypes);

            foreach (UaNode n in roots)
            {
                String name = n.BrowseName;
                if (n.SymbolicName != null && n.SymbolicName != "")
                {
                    name = n.SymbolicName;
                }
                var semanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", ModelUri + name);
                if ((n.children != null && n.children.Count != 0) ||
                    (n.fields != null && n.fields.Count != 0))
                {
                    var sme = AdminShell.SubmodelElementCollection.CreateNew(name, null, semanticID);
                    sme.semanticId.Keys.Add(AdminShell.Key.CreateNew("UATypeName", false, "OPC", n.UAObjectTypeName));
                    switch (n.UAObjectTypeName)
                    {
                    case "UADataType":
                    case "UAObjectType":
                        smeDataTypes.Add(sme);
                        break;

                    default:
                        innerSme.Add(sme);
                        break;
                    }
                    if (n.Value != null && n.Value != "")
                    {
                        var p = createSE(n, ModelUri);
                        sme.Add(p);
                        addLeaf(conceptSme, p);
                    }
                    foreach (field f in n.fields)
                    {
                        sme.semanticId.Keys.Add(
                            AdminShell.Key.CreateNew(
                                "UAField", false, "OPC", f.name + " = " + f.value + " : " + f.description));

                        semanticID = AdminShell.Key.CreateNew(
                            "GlobalReference", false, "IRI", ModelUri + name + "/" + f.name);

                        var p = AdminShell.Property.CreateNew(f.name, null, semanticID);
                        p.valueType = "string";
                        p.value     = f.value;
                        sme.Add(p);
                        addLeaf(conceptSme, p);
                    }
                    foreach (UaNode c in n.children)
                    {
                        createSubmodelElements(c, env, sme, smref, ModelUri + name + "/", conceptSme);
                    }
                }
                else
                {
                    var se = createSE(n, ModelUri);
                    switch (n.UAObjectTypeName)
                    {
                    case "UADataType":
                    case "UAObjectType":
                        smeDataTypes.Add(se);
                        addLeaf(conceptSme, se);
                        break;

                    default:
                        innerSme.Add(se);
                        addLeaf(conceptSme, se);
                        break;
                    }
                }
            }

            // Add datatypes in the end
            innerSme.Add(smeDataTypes);
        }
Пример #11
0
        public static void ImportCSVtoSubModel(
            string inputFn, AdminShell.AdministrationShellEnv env, AdminShell.Submodel sm,
            AdminShell.SubmodelRef smref)
        {
            AdminShell.SubmodelElementCollection[] propGroup = new AdminShell.SubmodelElementCollection[10];
            int i_propGroup = 0;

            var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(inputFn);

            parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
            parser.SetDelimiters(";");

            string[] rows = parser.ReadFields();
            if (rows == null || rows.Length < 3 ||
                rows[0] != "typeName" ||
                rows[1] != "idShort" ||
                rows[2] != "value")
            {
                return;
            }

            while (!parser.EndOfData)
            {
                rows = parser.ReadFields();
                if (rows == null || rows.Length < 1)
                {
                    continue;
                }

                switch (rows[0])
                {
                case "SubmodelElementCollection":
                    propGroup[i_propGroup] = AdminShell.SubmodelElementCollection.CreateNew(rows[1]);
                    if (i_propGroup == 0)
                    {
                        sm.Add(propGroup[0]);
                    }
                    else
                    {
                        propGroup[i_propGroup - 1].Add(propGroup[i_propGroup]);
                    }
                    i_propGroup++;
                    break;

                case "End-SubmodelElementCollection":
                    if (i_propGroup != 0)
                    {
                        i_propGroup--;
                    }
                    break;

                case "Property":
                    var p = AdminShell.Property.CreateNew(rows[1]);
                    p.valueType = "string";
                    p.value     = rows[2];

                    if (i_propGroup == 0)
                    {
                        sm.Add(p);
                    }
                    else
                    {
                        propGroup[i_propGroup - 1].Add(p);
                    }
                    break;
                }
            }
        }
        //Annotations
        //  Procedure:
        //  1. find submodel node
        //  2. create submodel node as submodel
        //  3. find children of submodel node
        //  4. create children of submodel node -> a (SubmodelElement)
        //      4.1. find children of a
        //      4.2. create children of a -> b (SubmodelElement)
        //          4.2.1. find children of b
        //          ...
        //      4.3. set a as SubmodelElement of submodel
        //  5. add Submodel
        //
        //
        //  most Methods are built the same way:
        //  1. iterate through all References of the node
        //  2. check that the ReferenceType is not HasTypeDefinition
        //  3. check for the Type or BrowseName

        public static AdminShellNS.AdminShellPackageEnv Import(UANodeSet model)
        {
            thePackageEnv    = new AdminShellNS.AdminShellPackageEnv();
            InformationModel = model;

            //Initialize everything needed
            AdminShell.AdministrationShellEnv env = thePackageEnv.AasEnv;
            var aas = new AdminShell.AdministrationShell();

            aas.views       = new Views();
            aas.views.views = new List <View>();
            env.AdministrationShells.Add(aas);

            //search for the root Node
            var root = getRoot();

            //see Annotations
            if (root != null)
            {
                foreach (Reference _ref in root.References)
                {
                    if (_ref.ReferenceType == "HasComponent")
                    {
                        var node = findNode(_ref.Value);
                        //create Submodel
                        if (getTypeDefinition(node) == "1:AASSubmodelType")
                        {
                            var submodel = createSubmodel((UAObject)node);

                            if (submodel != null)
                            {
                                //add Submodel and its SubmodelRef
                                env.Submodels.Add(submodel);
                                var smr = new AdminShell.SubmodelRef();
                                smr.Keys.Add(
                                    new AdminShell.Key(
                                        "Submodel", true, submodel.identification.idType, submodel.identification.id));
                                aas.submodelRefs.Add(smr);
                            }
                        }
                        //create ConceptDictionary
                        else if (getTypeDefinition(node) == "1:AASConceptDictionaryType")
                        {
                            createConceptDictionary((UAObject)node);
                        }
                        //create Asset
                        else if (getTypeDefinition(node) == "1:AASAssetType")
                        {
                            Asset ass = createAsset(node);
                            thePackageEnv.AasEnv.Assets.Add(ass);
                        }
                        //create Views
                        else if (getTypeDefinition(node) == "1:AASViewType")
                        {
                            aas.views.views.Add(createView(node));
                        }
                        //set DerivedFrom
                        else if (node.BrowseName == "1:DerivedFrom")
                        {
                            List <Key> keys = addSemanticID(node);
                            if (keys.Count > 0)
                            {
                                aas.derivedFrom = new AssetAdministrationShellRef(keys[0]);
                            }
                        }
                        //create HasDataSpecification
                        else if (node.BrowseName == "1:DataSpecification")
                        {
                            aas.hasDataSpecification = CreateHasDataSpecification(node);
                        }
                        //create AssetRef
                        else if (node.BrowseName == "1:AssetRef")
                        {
                            aas.assetRef = createAssetRef(node);
                        }
                        else if (node.BrowseName == "1:Identification" &&
                                 getTypeDefinition(node) == "1:AASIdentifierType")
                        {
                            aas.identification = createIdentification(node);
                        }
                    }
                    else if (_ref.ReferenceType == "HasProperty")
                    {
                        var node = findNode(_ref.Value);
                        if (node.BrowseName == "1:idShort")
                        {
                            var vari = (UAVariable)node;
                            aas.idShort = vari.Value.InnerText;
                        }
                    }
                }
            }

            return(thePackageEnv);
        }