Example #1
0
            public static double GetNumericValue(IStruct structure, string name)
            {
                if (structure == null)
                {
                    throw new ArgumentNullException("structure");
                }

                ISymbol symbol = structure.Child(name);

                if (symbol == null)
                {
                    throw new InvalidOperationException("Could not find the property " + name + " in structure " + structure.Name);
                }

                INumericProperty property = symbol as INumericProperty;

                if (property == null)
                {
                    throw new InvalidOperationException("Symbol " + symbol.Name + " type " + symbol.GetType().FullName + " is not the expected " + typeof(INumericProperty).FullName);
                }

                double result = property.Value.GetValueOrDefault();

                return(result);
            }
Example #2
0
        private static void DemoCode(IEditorPlugIn plugIn, IPage page)
        {
            IList <ISymbol> deviceNodes = plugIn.Symbol.SelectSymbols("//Device[Properties[@Name='ModelNo' and @Value='Pump']]");

            IStruct temperatureSrut    = Util.Properties.GetStruct(page, "Temperature");
            double  temperatureNominal = Util.Properties.GetNumericValue(temperatureSrut, "Nominal");
            double  temperatureValue   = Util.Properties.GetNumericValue(temperatureSrut, "Value");
            double  temperatureMin     = Util.Properties.GetNumericValue(temperatureSrut, "LowerLimit");
            double  temperatureMax     = Util.Properties.GetNumericValue(temperatureSrut, "UpperLimit");

            bool ready = Util.Properties.GetBoolValue(page, "Ready");

            foreach (ISymbol symbol in deviceNodes)
            {
                ISymbol symbolFlowStruct = symbol.Child("Flow");
                if (symbolFlowStruct != null)
                {
                    IStruct structure = symbolFlowStruct as IStruct;
                    if (structure == null)
                    {
                        string errText = "Symbol " + symbolFlowStruct.Name + " must always be of type " + typeof(IStruct).FullName + ", but is " + symbolFlowStruct.GetType().FullName;
                        throw new InvalidCastException(errText);
                    }

                    ISymbol symbolFlow = structure.Child("Value");
                    if (symbolFlow == null)
                    {
                        throw new InvalidOperationException("Could not find the property Value in structure " + symbolFlowStruct.Name);
                    }

                    double flow = (symbolFlow as INumericProperty).Value.GetValueOrDefault();
                    //              Pump_Name            Flow                          Value
                    Trace.WriteLine(symbol.Name + "." + symbolFlowStruct.Name + "." + plugIn.Symbol.Name + " = " + flow.ToString());
                }

                ISymbol symbolReady = symbol.Child(SymbolName.Ready);
                if (symbolReady != null)
                {
                    INumericProperty propertyReady = symbolReady as INumericProperty;
                    if (propertyReady != null)
                    {
                        ready = Util.GetBool(propertyReady);
                        Trace.WriteLine(propertyReady.Name + " = " + ready.ToString());
                        if (propertyReady.Writeable)
                        {
                            //              Pump_Name           Ready
                            Trace.WriteLine(symbol.Name + "." + propertyReady.Name + " is Writable");
                        }
                    }
                }
            }
        }