Beispiel #1
0
        /// <summary>
        /// Returns the property IDs and values for all data contained in this data report.
        /// </summary>
        /// <returns>A dictionary mapping property IDs to values.</returns>
        public IDictionary <PropertyKey, object> GetDataFields()
        {
            Dictionary <PropertyKey, object> reportData = new Dictionary <PropertyKey, object>();
            IPortableDeviceValues            valuesCollection;

            _iSensorReport.GetSensorValues(null, out valuesCollection);

            uint nItems = 0;

            valuesCollection.GetCount(ref nItems);
            for (uint i = 0; i < nItems; i++)
            {
                PropertyKey propKey   = new PropertyKey();
                PROPVARIANT propValue = new PROPVARIANT();
                valuesCollection.GetAt(i, ref propKey, out propValue);

                try
                {
                    reportData.Add(propKey, propValue.Value);
                }
                finally
                {
                    propValue.Clear();
                }
            }

            return(reportData);
        }
Beispiel #2
0
        internal static SensorData FromNativeReport(ISensor iSensor, ISensorDataReport iReport)
        {
            SensorData data = new SensorData( );

            IPortableDeviceKeyCollection keyCollection;
            IPortableDeviceValues        valuesCollection;

            iSensor.GetSupportedDataFields(out keyCollection);
            iReport.GetSensorValues(keyCollection, out valuesCollection);

            uint items = 0;

            keyCollection.GetCount(out items);
            for (uint index = 0; index < items; index++)
            {
                PropertyKey key;
                PropVariant propValue;
                keyCollection.GetAt(index, out key);
                valuesCollection.GetValue(ref key, out propValue);
                try
                {
                    if (data.ContainsKey(key.FormatId))
                    {
                        data[key.FormatId].Add(propValue.Value);
                    }
                    else
                    {
                        data.Add(key.FormatId, new List <object> {
                            propValue.Value
                        });
                    }
                }
                finally
                {
                    propValue.Clear( );
                }
            }

            if (keyCollection != null)
            {
                Marshal.ReleaseComObject(keyCollection);
                keyCollection = null;
            }

            if (valuesCollection != null)
            {
                Marshal.ReleaseComObject(valuesCollection);
                valuesCollection = null;
            }


            return(data);
        }