Пример #1
0
        public static MapValue ReadComponentDN1(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "DN1";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                if (br.RealName() == "BØJN KDLR v2")
                {
                    prdDbg(br.GetDynamicPropertyByName(valueToReturn).Value.ToString());
                }

                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    return(new MapValue(br.GetDynamicPropertyByName(valueToReturn).Value.ToString() ?? ""));
                }
            }
            return(new MapValue(valueToReturn ?? ""));
        }
        public static double ReadComponentDN2KodDouble(BlockReference br, System.Data.DataTable fjvTable)
        {
            string system = ReadComponentSystem(br, fjvTable);

            if (system.IsNoE())
            {
                throw new System.Exception($"{br.RealName()} failed to read system!");
            }
            int dn = ReadComponentDN2Int(br, fjvTable);

            if (dn == 0 || dn == 999)
            {
                throw new System.Exception($"{br.RealName()} failed to read DN1!");
            }
            if (system == "Twin")
            {
                return(PipeSchedule.GetTwinPipeKOd(dn));
            }
            else if (system == "Enkelt")
            {
                return(PipeSchedule.GetBondedPipeKOd(dn));
            }
            else
            {
                throw new System.Exception($"{br.RealName()} returned non-standard \"System\": {system}!");
            }
        }
Пример #3
0
        private static string GetValueByRegex(BlockReference br, string propertyToExtractName, string valueToProcess)
        {
            //Extract property name
            Regex  regex    = new Regex(@"(?<Name>^[\w\s]+)");
            string propName = "";

            if (!regex.IsMatch(valueToProcess))
            {
                throw new System.Exception("Property name not found!");
            }
            propName = regex.Match(valueToProcess).Groups["Name"].Value;
            //Read raw data from block
            //Debug
            if (br.RealName() == "BØJN KDLR v2")
            {
                prdDbg(br.GetDynamicPropertyByName(propName).UnitsType.ToString());
            }

            string rawContents = br.GetDynamicPropertyByName(propName).Value as string;

            //Safeguard against value not being set -> CUSTOM
            if (rawContents == "Custom" || rawContents == "ÆNDR MIG")
            {
                throw new System.Exception($"Parameter {propName} is not set for block handle {br.Handle}!");
            }
            //Extract regex def from the table
            Regex regxExtract = new Regex(@"{(?<Regx>[^}]+)}");

            if (!regxExtract.IsMatch(valueToProcess))
            {
                throw new System.Exception("Regex definition is incorrect!");
            }
            string extractedRegx = regxExtract.Match(valueToProcess).Groups["Regx"].Value;
            //extract needed value from the rawContents by using the extracted regex
            Regex finalValueRegex = new Regex(extractedRegx);

            if (!finalValueRegex.IsMatch(rawContents))
            {
                prdDbg($"Extracted Regex failed to match Raw Value for block {br.RealName()}, handle {br.Handle}!");
                prdDbg($"Returning instead: {finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value}");
                return(finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value);
            }
            return(finalValueRegex.Match(rawContents).Groups[propertyToExtractName].Value);
        }
        public static string ReadComponentSystem(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "System";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    return(br.GetDynamicPropertyByName(valueToReturn).Value as string ?? "");
                }
            }
            return(valueToReturn ?? "");
        }
Пример #5
0
        public static string ReadComponentVinkel(BlockReference br, System.Data.DataTable fjvTable)
        {
            string propertyToExtractName = "Vinkel";

            string valueToReturn = ReadStringParameterFromDataTable(br.RealName(), fjvTable, propertyToExtractName, 0);

            if (valueToReturn.StartsWith("$"))
            {
                valueToReturn = valueToReturn.Substring(1);
                //If the value is a pattern to extract from string
                if (valueToReturn.Contains("{"))
                {
                    valueToReturn = GetValueByRegex(br, propertyToExtractName, valueToReturn);
                }
                //Else the value is parameter literal to read
                else
                {
                    double value = Convert.ToDouble(br.GetDynamicPropertyByName(valueToReturn).Value);
                    return((value * (180 / Math.PI)).ToString("0.##"));
                }
            }
            return(valueToReturn ?? "");
        }
Пример #6
0
 public static string ReadBlockName(BlockReference br, System.Data.DataTable fjvTable) => br.RealName();