Ejemplo n.º 1
0
        public static void AddMetric(Metrics metric, string valueAsString, double?valueAsNumber, DateTime?valueAsDateTime)
        {
            string cdmProcessingConnectionStrings = null;

            if (ConfigurationManager.ConnectionStrings["CDM_Processing"] != null)
            {
                cdmProcessingConnectionStrings = ConfigurationManager.ConnectionStrings["CDM_Processing"].ConnectionString;
            }

            if (Settings.Current.Building.LoadId <= 0 || string.IsNullOrEmpty(cdmProcessingConnectionStrings))
            {
                return;
            }

            var dbProcessing = new DBProcessing(cdmProcessingConnectionStrings);

            dbProcessing.InsertMetric(Settings.Current.Building.LoadId, metric, valueAsString, valueAsNumber, valueAsDateTime);
        }
Ejemplo n.º 2
0
        private static void AddMetric(Metrics metric, DateTime?start, DateTime?end, double?valueAsNumber)
        {
            var    loadId = Settings.Current.Building.LoadId;
            string cdmProcessingConnectionStrings = null;

            if (ConfigurationManager.ConnectionStrings["CDM_Processing"] != null)
            {
                cdmProcessingConnectionStrings = ConfigurationManager.ConnectionStrings["CDM_Processing"].ConnectionString;
            }

            if (loadId <= 0 || string.IsNullOrEmpty(cdmProcessingConnectionStrings))
            {
                return;
            }

            var dbProcessing = new DBProcessing(cdmProcessingConnectionStrings);

            if (start.HasValue && end.HasValue)
            {
                var elapsedTime   = end.Value.Subtract(start.Value);
                var valueAsString = string.Format("{0}:{1}:{2}", (int)elapsedTime.TotalHours,
                                                  elapsedTime.Minutes > 9
                  ? elapsedTime.Minutes.ToString(CultureInfo.InvariantCulture)
                  : "0" + elapsedTime.Minutes,
                                                  elapsedTime.Seconds > 9
                  ? elapsedTime.Seconds.ToString(CultureInfo.InvariantCulture)
                  : "0" + elapsedTime.Seconds);

                dbProcessing.AddMetric(loadId, metric, valueAsString, null, DateTime.Now);
            }

            if (valueAsNumber.HasValue)
            {
                dbProcessing.AddMetric(loadId, metric, "", valueAsNumber, DateTime.Now);
            }
        }