/// <summary>
        /// Creates and adds to grid a single row corresponding to a single property. Can be called recursively for embedded
        /// objects.
        /// </summary>
        /// <param name="prop"> </param>
        /// <param name="namePrefix">This is used for embedded objects, so that the propertyof an embedded object
        /// appears to have name of form "Parent.Child" </param>
        private DataRow CreatePropertyRow(Property prop, string namePrefix)
        {
            if (prop == null)
            {
                return(null);
            }

            if (propFilters.HideInherited && !prop.IsLocal)
            {
                return(null);                   //skip this property
            }


            DataRow propRow = NewRow();

            propRow[propNameColumn] = namePrefix + prop.Name;

            propRow[propTypeColumn] = CimTypeMapper.ToString(prop.Type);

            if (showOperators)
            {
                //TODO: initialize drop-down. How: in Beta2, a DataGridColumnStyle derived class
                //can be added, DataGridComboBoxColumn. Ask urtuser if they are planning to
                //to add one themselves

                propRow[operatorColumn] = string.Empty;
            }

            if (prop.Type == CimType.Object)
            {
                if ((showValues || showEmbeddedObjValue) &&
                    prop.Value is ManagementBaseObject)
                {
                    if (showOperators)
                    {
                        propRow[operatorColumn] = "ISA";
                    }
                    propRow[propValueColumn] = ((ManagementBaseObject)prop.Value).SystemProperties["__CLASS"].Value.ToString();
                }
                else
                {
                    propRow[propValueColumn] = string.Empty;
                }
            }
            else
            {
                if (showValues)
                {
                    propRow[propValueColumn] = prop.Value;
                }
                else
                {
                    propRow[propValueColumn] = string.Empty;
                }
            }
            //propRow[propDescrColumn] = WmiHelper.GetPropertyDescription(prop, wmiObj);


            //set property origin column

            if (showOrigin)
            {
                if (prop.IsLocal)
                {
                    propRow[propOrigin] = true;
                }
                else
                {
                    propRow[propOrigin] = false;
                }
            }

            if (showKeys)
            {
                propRow[propIsKey] = WmiHelper.IsKeyProperty(prop);
            }

            //grey selectionBoxColumn for expanded embedded object properties:
            if (propRow[propNameColumn].ToString().IndexOf(".") > 0)
            {
                //NOTE: this doesn't work!!! is there a way to disable input on an individual cell?
                propRow.SetUnspecified(selectionBoxColumn);
            }


            Rows.Add(propRow);

            if (prop.Type == CimType.Object && expandEmbedded)
            {
                if (prop.Value != null && prop.Value is ManagementBaseObject)
                {
                    ManagementBaseObject embeddedObj = (ManagementBaseObject)prop.Value;
                    foreach (Property embeddedProp in embeddedObj.Properties)
                    {
                        CreatePropertyRow(embeddedProp, prop.Name + ".");
                    }
                }
            }

            rowPropertyMap.Add(propRow, prop);

            return(propRow);
        }
Exemplo n.º 2
0
        public override Object GetValue(Object component)
        {
            CimType CimType = prop.Type;

            if (prop == null)
            {
                return(null);
            }


            //handle embedded objects and array of embedded objects
            if (CimType == CimType.Object)
            {
                return(null);                   //disabled for Beta1: too many problems
                //throw new Exception("Displaying embedded objects is not supported in Beta1");
            }


            if (prop.Value == null)
            {
                if (prop.IsArray)
                {
                    return(Array.CreateInstance(CimTypeMapper.ToType(CimType, false, prop), 0));
                }
                return(null);
            }

            //handle datetimes, intervals and arrays of datetimes and intervals
            if (CimType == CimType.DateTime)
            {
                if (WmiHelper.IsInterval(prop))
                {
                    if (prop.IsArray)
                    {
                        string[]   strAr = (string[])prop.Value;
                        TimeSpan[] retAr = new TimeSpan[strAr.Length];
                        for (int i = 0; i < strAr.Length; i++)
                        {
                            retAr[i] = WmiHelper.ToTimeSpan(strAr[i]);
                        }
                        return(retAr);
                    }
                    else
                    {
                        return(WmiHelper.ToTimeSpan(prop.Value.ToString()));
                    }
                }
                else
                {
                    if (prop.IsArray)
                    {
                        string[]   strAr = (string[])prop.Value;
                        DateTime[] retAr = new DateTime[strAr.Length];
                        for (int i = 0; i < strAr.Length; i++)
                        {
                            retAr[i] = WmiHelper.ToDateTime(strAr[i]);
                        }
                        return(retAr);
                    }
                    else
                    {
                        return(WmiHelper.ToDateTime(prop.Value.ToString()));
                    }
                }
            }

            return(prop.Value);
        }