Ejemplo n.º 1
0
        //
        // DataSpecificationIEC61360
        //

        public void DisplayOrEditEntityDataSpecificationIEC61360(StackPanel stack,
                                                                 AdminShell.DataSpecificationIEC61360 dsiec)
        {
            // access
            if (stack == null || dsiec == null)
            {
                return;
            }

            // members
            this.AddGroup(
                stack, "Data Specification Content IEC61360:", levelColors[1][0], levelColors[1][1]);

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(dsiec.preferredName == null || dsiec.preferredName.Count < 1); },
                    "Please add a preferred name, which could be used on user interfaces " +
                    "to identify the concept to a human person.",
                    breakIfTrue: true),
                new HintCheck(
                    () => { return(dsiec.preferredName.Count < 2); },
                    "Please add multiple languanges.")
            });
            if (this.SafeguardAccess(
                    stack, repo, dsiec.preferredName, "preferredName:", "Create data element!",
                    v =>
            {
                dsiec.preferredName = new AdminShell.LangStringSetIEC61360();
                return(new ModifyRepo.LambdaActionRedrawEntity());
            }))
            {
                this.AddKeyListLangStr(stack, "preferredName", dsiec.preferredName, repo);
            }

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(dsiec.shortName == null || dsiec.shortName.Count < 1); },
                    "Please check if you can add a short name, which is a reduced, even symbolic version of " +
                    "the preferred name. IEC 61360 defines some symbolic rules " +
                    "(e.g. greek characters) for this name.",
                    severityLevel: HintCheck.Severity.Notice,
                    breakIfTrue: true),
                new HintCheck(
                    () => { return(dsiec.shortName.Count < 2); },
                    "Please add multiple languanges.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            if (this.SafeguardAccess(
                    stack, repo, dsiec.shortName, "shortName:", "Create data element!",
                    v =>
            {
                dsiec.shortName = new AdminShell.LangStringSetIEC61360();
                return(new ModifyRepo.LambdaActionRedrawEntity());
            }))
            {
                this.AddKeyListLangStr(stack, "shortName", dsiec.shortName, repo);
            }

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => {
                    return((dsiec.unitId == null || dsiec.unitId.Count < 1) &&
                           (dsiec.unit == null || dsiec.unit.Trim().Length < 1));
                },
                    "Please check, if you can provide a unit or a unitId, " +
                    "in which the concept is being measured. " +
                    "Usage of SI-based units is encouraged.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            this.AddKeyValueRef(
                stack, "unit", dsiec, ref dsiec.unit, null, repo,
                v => { dsiec.unit = v as string; return(new ModifyRepo.LambdaActionNone()); });

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => {
                    return((dsiec.unit == null || dsiec.unit.Trim().Length < 1) &&
                           (dsiec.unitId == null || dsiec.unitId.Count < 1));
                },
                    "Please check, if you can provide a unit or a unitId, " +
                    "in which the concept is being measured. " +
                    "Usage of SI-based units is encouraged.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            if (this.SafeguardAccess(
                    stack, repo, dsiec.unitId, "unitId:", "Create data element!",
                    v =>
            {
                dsiec.unitId = new AdminShell.UnitId();
                return(new ModifyRepo.LambdaActionRedrawEntity());
            }))
            {
                this.AddKeyListKeys(
                    stack, "unitId", dsiec.unitId.Keys, repo,
                    packages, PackageCentral.Selector.MainAux,
                    AdminShell.Key.GlobalReference, addEclassIrdi: true);
            }

            this.AddKeyValueRef(
                stack, "valueFormat", dsiec, ref dsiec.valueFormat, null, repo,
                v => { dsiec.valueFormat = v as string; return(new ModifyRepo.LambdaActionNone()); });

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () =>
                {
                    return(dsiec.sourceOfDefinition == null || dsiec.sourceOfDefinition.Length < 1);
                },
                    "Please check, if you can provide a source of definition for the concepts. " +
                    "This could be an informal link to a document, glossary item etc.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            this.AddKeyValueRef(
                stack, "sourceOfDef.", dsiec, ref dsiec.sourceOfDefinition, null, repo,
                v =>
            {
                dsiec.sourceOfDefinition = v as string;
                return(new ModifyRepo.LambdaActionNone());
            });

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(dsiec.symbol == null || dsiec.symbol.Trim().Length < 1); },
                    "Please check, if you can provide formulaic character for the concept.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            this.AddKeyValueRef(
                stack, "symbol", dsiec, ref dsiec.symbol, null, repo,
                v => { dsiec.symbol = v as string; return(new ModifyRepo.LambdaActionNone()); });

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(dsiec.dataType == null || dsiec.dataType.Trim().Length < 1); },
                    "Please provide data type for the concept. " +
                    "Data types are provided by the IEC 61360.")
            });
            this.AddKeyValueRef(
                stack, "dataType", dsiec, ref dsiec.dataType, null, repo,
                v => { dsiec.dataType = v as string; return(new ModifyRepo.LambdaActionNone()); },
                comboBoxIsEditable: true,
                comboBoxItems: AdminShell.DataSpecificationIEC61360.DataTypeNames);

            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(dsiec.definition == null || dsiec.definition.Count < 1); },
                    "Please check, if you can add a definition, which could be used to describe exactly, " +
                    "how to establish a value/ measurement for the concept.",
                    severityLevel: HintCheck.Severity.Notice,
                    breakIfTrue: true),
                new HintCheck(
                    () => { return(dsiec.definition.Count < 2); },
                    "Please add multiple languanges.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            if (this.SafeguardAccess(
                    stack, repo, dsiec.definition, "definition:", "Create data element!",
                    v =>
            {
                dsiec.definition = new AdminShell.LangStringSetIEC61360();
                return(new ModifyRepo.LambdaActionRedrawEntity());
            }))
            {
                this.AddKeyListLangStr(stack, "definition", dsiec.definition, repo);
            }
        }
Ejemplo n.º 2
0
        private AdminShell.ConceptDescription GenerateConceptDescription(List <SelectItem> input)
        {
            // access
            if (input == null || input.Count < 1)
            {
                return(null);
            }

            // new cd
            var res = new AdminShell.ConceptDescription();

            var ds = new AdminShell.DataSpecificationIEC61360();

            res.embeddedDataSpecification.dataSpecificationContent.dataSpecificationIEC61360 = ds;

            // over all, first is significant
            for (int i = 0; i < input.Count; i++)
            {
                var node = input[i].ContentNode;
                if (node == null)
                {
                    continue;
                }

                XmlNode n1;

                // first is significant
                if (i == 0)
                {
                    res.identification.idType = "IRDI";
                    res.identification.id     = input[i].IRDI;

                    res.AddIsCaseOf(AdminShell.Reference.CreateIrdiReference(input[i].IRDI));

                    res.administration = new AdminShell.Administration();
                    n1 = node.SelectSingleNode("revision");
                    if (n1 != null)
                    {
                        res.administration.revision = "" + n1.InnerText;
                    }

                    FildChildLangStrings(node, "short_name", "label", "language_code", (ls) =>
                    {
                        ds.shortName = ls.str;
                        res.idShort  = ls.str;
                    });
                }

                // all have language texts
                FildChildLangStrings(node, "preferred_name", "label", "language_code", (ls) =>
                {
                    if (ds.preferredName == null)
                    {
                        ds.preferredName = new AdminShell.LangStringIEC61360();
                    }
                    ds.preferredName.langString.Add(ls);
                });

                FildChildLangStrings(node, "definition", "text", "language_code", (ls) =>
                {
                    if (ds.definition == null)
                    {
                        ds.definition = new AdminShell.LangStringIEC61360();
                    }
                    ds.definition.langString.Add(ls);
                });
            }

            // ok
            return(res);
        }
Ejemplo n.º 3
0
        public static AdminShell.ConceptDescription GenerateConceptDescription(
            List <EclassUtils.SearchItem> input, string targetIrdi)
        {
            // access
            if (input == null || input.Count < 1)
            {
                return(null);
            }

            // new cd
            var res = new AdminShell.ConceptDescription();

            var ds = new AdminShell.DataSpecificationIEC61360();

            res.embeddedDataSpecification.IEC61360Content = ds;

            // over all, first is significant
            for (int i = 0; i < input.Count; i++)
            {
                // only accept property nodes, which are targetIrdi
                var si = input[i];
                if (si.Entity != "prop" || si.IRDI.ToLower().Trim() != targetIrdi.ToLower().Trim())
                {
                    continue;
                }
                var node = si.ContentNode;
                if (node == null)
                {
                    continue;
                }

                // first is significant
                if (i == 0)
                {
                    // identification
                    res.identification.idType = AdminShell.Identification.IRDI;
                    res.identification.id     = input[i].IRDI;

                    // isCase of
                    res.AddIsCaseOf(AdminShell.Reference.CreateIrdiReference(input[i].IRDI));

                    // administration
                    res.administration = new AdminShell.Administration();
                    var n1 = node.SelectSingleNode("revision");
                    if (n1 != null)
                    {
                        res.administration.revision = "" + n1.InnerText;
                    }

                    // short name -> TBD in future
                    FindChildLangStrings(node, "short_name", "label", "language_code", (ls) =>
                    {
                        ds.shortName = new AdminShellV20.LangStringSetIEC61360("EN?", ls.str);
                        res.idShort  = ls.str;
                    });

                    // guess data type
                    var nd = node.SelectSingleNode("domain");
                    if (nd != null)
                    {
                        var ndt = GetAttributeByName(nd, "xsi:type");
                        if (ndt != null)
                        {
                            // try find a match
                            foreach (var dtn in AdminShell.DataSpecificationIEC61360.DataTypeNames)
                            {
                                if (ndt.ToLower().Trim().Contains(dtn.ToLower().Trim()))
                                {
                                    ds.dataType = dtn;
                                }
                            }
                        }
                    }

                    // unit
                    var ndu = node.SelectSingleNode("domain/unit");
                    if (ndu != null)
                    {
                        var urefIrdi = GetAttributeByName(ndu, "unit_ref");
                        if (urefIrdi != null)
                        {
                            foreach (var xi in input)
                            {
                                if (xi.IRDI.ToLower().Trim() == urefIrdi.ToLower().Trim() && xi.ContentNode != null)
                                {
                                    foreach (var xiun in GetChildNodesByName(xi.ContentNode, "unitsml:UnitName"))
                                    {
                                        if (xiun != null)
                                        {
                                            ds.unitId = AdminShell.UnitId.CreateNew(
                                                "GlobalReference", false,
                                                AdminShell.Identification.IRDI, urefIrdi.Trim());
                                            ds.unit = xiun.InnerText.Trim();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // all have language texts
                FindChildLangStrings(node, "preferred_name", "label", "language_code", (ls) =>
                {
                    if (ds.preferredName == null)
                    {
                        ds.preferredName = new AdminShell.LangStringSetIEC61360();
                    }
                    ds.preferredName.Add(ls);
                });

                FindChildLangStrings(node, "definition", "text", "language_code", (ls) =>
                {
                    if (ds.definition == null)
                    {
                        ds.definition = new AdminShell.LangStringSetIEC61360();
                    }
                    ds.definition.Add(ls);
                });

                // <domain xsi:type="ontoml:REAL_MEASURE_TYPE_Type">
                //   <unit unit_ref="0173-1#05-AAA351#002"/>
                // </domain >
                // <unitsml:Unit dimensionURL="0173-1#Z2-AAA173#001" xml:id="id0173-1x05-AAA351x002">
                //   <unitsml:UnitName xml:lang="de-DE">Hz</unitsml:UnitName>
                //   <unitsml:UnitName xml:lang="en-US">Hz</unitsml:UnitName>
                //   <unitsml:UnitSymbol type="ASCII">Hz</unitsml:UnitSymbol>
                //   <unitsml:CodeListValue codeListName="IRDI" unitCodeValue="0173-1#05-AAA351#002" />
                // <unitsml:Quantity dimensionURL="0173-1#Z2-AAA173#001" xml:id="id0173-1xZ4-BAJ257x001">
                //   <unitsml:QuantityName xml:lang="de-DE">Frequenz</unitsml:QuantityName>
                //   <unitsml:QuantityName xml:lang="en-US">frequency</unitsml:QuantityName>
                //   <unitsml:QuantitySymbol type="IRDI">0173-1#Z4-BAJ257#001</unitsml:QuantitySymbol>
                //   <unitsml:UnitReference xml:lang="en-US" name="hertz" url="0173-1#05-AAA351#002" />
                //   <unitsml:UnitReference xml:lang="en-US" name="megahertz" url="0173-1#05-AAA581#002" />
                //   <unitsml:UnitReference xml:lang="en-US" name="terahertz" url="0173-1#05-AAA190#002" />
                //   <unitsml:UnitReference xml:lang="en-US" name="gigahertz" url="0173-1#05-AAA505#002" />
                //   <unitsml:UnitReference xml:lang="en-US" name="kilohertz" url="0173-1#05-AAA033#002" />
            }

            // Phase 2: fix some shortcomings
            //

            // ReSharper disable EmptyGeneralCatchClause
            try
            {
                if (ds.shortName == null || ds.shortName.Count < 1) // TBD: multi-language short name?!
                {
                    if (ds.preferredName != null && !ds.preferredName.IsEmpty)
                    {
                        var found = false;
                        foreach (var pn in ds.preferredName)
                        {
                            // let have "en" always have precedence!
                            if (found && !pn.lang.ToLower().Trim().Contains("en"))
                            {
                                continue;
                            }
                            // ok
                            found = true;
                            // Array of words
                            var words = pn.str.Split(
                                new[] { ' ', '\t', '-', '_' },
                                StringSplitOptions.RemoveEmptyEntries);
                            var sn = "";
                            foreach (var w in words)
                            {
                                var part = w.ToLower().Trim();
                                if (part.Length > 3)
                                {
                                    part = part.Substring(0, 3);
                                }
                                if (part.Length > 0)
                                {
                                    part = Char.ToUpperInvariant(part[0]) + part.Substring(1);
                                }
                                sn += part;
                            }
                            // set it
                            ds.shortName = new AdminShellV20.LangStringSetIEC61360("EN?", sn);
                        }
                    }
                }
            }
            catch { }
            // ReSharper enable EmptyGeneralCatchClause

            // ok
            return(res);
        }