예제 #1
0
 static void client_OnMeasurementDelta(object sender, Delta d)
 {
     Console.WriteLine("{0}: {1:" + d.MetaData.Format + "} {2}", d.Path, d.Value, d.MetaData.Units);
 }
예제 #2
0
        /// <summary>
        /// Writes out all measurements in a given object recursively.
        /// </summary>
        /// <param name="target"></param>
        private void WriteOutMeasurements(object target, string path)
        {
            PropertyInfo[] infos;
            Measurement measurement;
            Group group;

            infos = target.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            // For each propery on the target
            foreach (PropertyInfo info in infos)
            {
                if (null != (measurement = (Measurement)info.GetCustomAttribute(typeof(Measurement))))
                {
                    Delta d = new Delta();
                    d.Path = path + measurement.Name;
                    d.Value = info.GetValue(target);
                    d.Timestamp = (long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;
                    d.MetaData = measurement;

                    if (null != OnMeasurementDelta)
                    {
                        OnMeasurementDelta(this, d);
                    }
                }

                if (null != (group = (Group)info.GetCustomAttribute(typeof(Group))))
                {
                    WriteOutMeasurements(info.GetValue(target), path + group.Name + "/");
                }
            }
        }