Esempio n. 1
0
 public PiServerModel Map(PiServer source)
 {
     return(source == null ? null : this.Map(new List <PiServer> {
         source
     }.AsQueryable()).First());
 }
Esempio n. 2
0
        public DailyConsumptionDetail GetTodaysDailyConsumptionDetails(SqlConnection sqlConnection, SqlTransaction sqlTransaction, string powerScout, PiServer piServer)
        {
            var query = "select top(1) Breaker_details, Timestamp, Building, Temperature, PowerScout, Visibility from DailyConsumptionDetails where PowerScout = @param1 and CAST(Timestamp AS DATE) = @param2 and  PiServerName = @PiServerName";

            DailyConsumptionDetail detailConsumptionDetail = null;

            using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection, sqlTransaction))
            {
                sqlCommand.Parameters.AddWithValue("@param1", powerScout);
                sqlCommand.Parameters.AddWithValue("@param2", piServer.PiServerCurrentDateTime.AddDays(-1).Date.ToString("yyyy-MM-dd"));

                sqlCommand.Parameters.AddWithValue("@PiServerName", piServer.PiServerName);

                using (SqlDataReader result = sqlCommand.ExecuteReader())
                {
                    while (result.Read())
                    {
                        detailConsumptionDetail = new DailyConsumptionDetail();

                        detailConsumptionDetail.Breaker_details = SqlTypeConverter.ToString(result["Breaker_details"]);
                        detailConsumptionDetail.Timestamp       = SqlTypeConverter.ToDateTime(result["Timestamp"]);
                        detailConsumptionDetail.Temperature     = SqlTypeConverter.ToDouble(result["Temperature"]);
                        detailConsumptionDetail.Building        = SqlTypeConverter.ToString(result["Building"]);
                        detailConsumptionDetail.PowerScout      = SqlTypeConverter.ToString(result["PowerScout"]);
                        detailConsumptionDetail.Visibility      = SqlTypeConverter.ToDouble(result["Visibility"]);
                    }

                    result.Close();
                }
            }

            return(detailConsumptionDetail);
        }
        private static void GenerateConsumptionAlertAndNotification(SqlConnection sqlConnection, SqlTransaction sqlTransaction, double consumption, PiServer piServer, bool isWeekEndConsumption = true)
        {
            var alertService        = new AlertService();
            var notificationService = new NotificationService();

            double costTobeSaved = consumption * ConfigurationSettings.MeterKwhCost;
            string alertMessage  = string.Format(Constants.RECOMMENDATION_ALERT_MESSAGE, costTobeSaved, isWeekEndConsumption ? "weekend" : "weekday");

            var alert = new Alert
            {
                AlertType    = Constants.ALERT_TYPE_RECOMMENDATION,
                Description  = alertMessage,
                TimeStamp    = piServer.PiServerCurrentDateTime,
                PiServerName = piServer.PiServerName
            };

            alertService.AddNewAlert(sqlConnection, sqlTransaction, alert);
            notificationService.SendNotification(alertMessage, sqlConnection, sqlTransaction);

            Console.WriteLine("ConsumptionAlertJob RowInserted : Created alert and notification for PiServer - {0}.", piServer.PiServerName);
        }