Ejemplo n.º 1
0
        private static MongoAggregationResult ToMongoAggregationResult(object mr)
        {
            var jO = (JObject)mr;

            JToken dateTime = jO["UtcDateTime"];
            int    year     = dateTime["year"] != null?Convert.ToInt32(dateTime["year"]) : DateTime.MinValue.Year;

            int month = dateTime["month"] != null?Convert.ToInt32(dateTime["month"]) : 1;

            int day = dateTime["day"] != null?Convert.ToInt32(dateTime["day"]) : 1;

            int hour = dateTime["hour"] != null?Convert.ToInt32(dateTime["hour"]) : 0;

            int minute = dateTime["minute"] != null?Convert.ToInt32(dateTime["minute"]) : 0;

            var measureTime = new DateTime(year, month, day, hour, minute, 0);

            var mongoRecord = new MongoAggregationResult(measureTime);

            foreach (var attr in jO)
            {
                if (attr.Key != "_id" || attr.Key != "UtcDateTime")
                {
                    long value = 0;
                    if (long.TryParse(attr.Value.ToString(), out value))
                    {
                        mongoRecord.MeasurementValues.Add(attr.Key, value);
                    }
                }
            }
            return(mongoRecord);
        }
Ejemplo n.º 2
0
        private static MongoAggregationResult ToMongoAggregationResult(object mr)
        {
            var jO = (JObject)mr;

            JToken dateTime = jO["UtcDateTime"];
            int year = dateTime["year"] != null ? Convert.ToInt32(dateTime["year"]) : DateTime.MinValue.Year;
            int month = dateTime["month"] != null ? Convert.ToInt32(dateTime["month"]) : 1;
            int day = dateTime["day"] != null ? Convert.ToInt32(dateTime["day"]) : 1;
            int hour = dateTime["hour"] != null ? Convert.ToInt32(dateTime["hour"]) : 0;
            int minute = dateTime["minute"] != null ? Convert.ToInt32(dateTime["minute"]) : 0;
            var measureTime = new DateTime(year, month, day, hour, minute, 0);

            var mongoRecord = new MongoAggregationResult(measureTime);

            foreach (var attr in jO)
            {
                if (attr.Key != "_id" || attr.Key != "UtcDateTime")
                {
                    long value = 0;
                    if (long.TryParse(attr.Value.ToString(), out value))
                    {
                        mongoRecord.MeasurementValues.Add(attr.Key, value);
                    }
                }
            }
            return mongoRecord;
        }