예제 #1
0
        /// <summary>
        /// Removes older values to keep DB size within configured size limit.
        /// </summary>
        /// <param name="daysToKeep">Records older than this number of days are removed.</param>
        private void CleanOldValuesFromStatisticsDatabase(int daysToKeep)
        {
            if (daysToKeep <= 0)
            {
                return;
            }

            var thresholdDate = _dateTime.UtcNow.Date.AddDays(-daysToKeep);

            try
            {
                _statisticsRepository.CleanOldValues(thresholdDate);

                HomeGenieService.LogDebug(
                    Domains.HomeAutomation_HomeGenie,
                    "Service.StatisticsLogger",
                    "Cleaned old values from database.",
                    "DayThreshold",
                    thresholdDate.ToString("O")
                    );
            }
            catch (Exception ex)
            {
                HomeGenieService.LogError(
                    Domains.HomeAutomation_HomeGenie,
                    "Service.StatisticsLogger",
                    "Error cleaning old stats from the database",
                    "Exception.StackTrace",
                    $"{ex.Message}: {ex.StackTrace}"
                    );
            }
        }
예제 #2
0
        private static void StopExecute(Stopwatch sw, string caller)
        {
            sw.Stop();
            if (sw.ElapsedMilliseconds <= LongRequestThresholdMs)
            {
                return;
            }

            //Console.WriteLine($"[Long request] Method = {caller}, Elapsed = {sw.ElapsedMilliseconds} ms.");
            HomeGenieService.LogDebug(
                Domains.HomeAutomation_HomeGenie,
                "LongRequestLogger",
                $"[Long request] Method = {caller}, Elapsed = {sw.ElapsedMilliseconds} ms.",
                null, null
                );
        }
예제 #3
0
        /// <summary>
        /// Removes older values to keep DB size within configured size limit.
        /// </summary>
        /// <param name="numberOfDays">Records older than this number of days are removed.</param>
        private void CleanOldValuesFromStatisticsDatabase(int numberOfDays)
        {
            if (numberOfDays > 0)
            {
                var dbCommand = dbConnection.CreateCommand();
                dbCommand.CommandText = "DELETE FROM ValuesHist WHERE TimeStart < DATEADD(dd,-" + numberOfDays + ",GETDATE());";
                dbCommand.ExecuteNonQuery();
                dbCommand.CommandText = "VACUUM";
                dbCommand.ExecuteNonQuery();

                HomeGenieService.LogDebug(
                    Domains.HomeAutomation_HomeGenie,
                    "Service.StatisticsLogger",
                    "Cleaned old values from database.",
                    "DayThreshold",
                    numberOfDays.ToString()
                    );
            }
        }