예제 #1
0
        public void LogExpiredUserConsumption(Int32 sinceMinutes)
        {
            Dictionary <string, double> persons = new Dictionary <string, double>();

            try
            {
                using (SqliteConnection db =
                           new SqliteConnection(SqliteConnectionString))
                {
                    db.Open();
                    //select VisitedDateTime, datetime('now', 'localtime'), strftime('%s', VisitedDateTime), strftime('%s', datetime(VisitedDateTime,'1 hour')), strftime('%s', datetime('now', 'localtime')) FROM Test  WHERE strftime('%s', datetime(VisitedDateTime,'1 hour')) < strftime('%s', datetime('now', 'localtime'))
                    //string sql = $"SELECT VisitorId, SUM(Ounces) FROM Keg_Visitor WHERE strftime('%s', datetime(VisitedDateTime,'{sinceHours} hour')) < strftime('%s', datetime('now', 'localtime')) Group By VisitorId Having Sum(Ounces)> 0.0;";
                    string sql = $"SELECT VisitorId, SUM(Ounces) FROM Keg_Visitor WHERE strftime('%s', datetime(VisitedDateTime,'{sinceMinutes} minutes')) < strftime('%s', datetime('now', 'localtime')) Group By VisitorId Having Sum(Ounces)> 0.0;";

                    // Commit results.
                    using (SqliteCommand command = new SqliteCommand(sql, db))
                    {
                        var reader = command.ExecuteReader();
                        while (reader.HasRows && reader.Read())
                        {
                            if (!reader.IsDBNull(0))
                            {
                                persons.Add(
                                    reader[0].ToString(), reader.IsDBNull(1) ? 0.0 : double.Parse(reader[1].ToString()));

                                //Log Metrics
                                MetricTelemetry metricTelemetry = new MetricTelemetry();
                                metricTelemetry.Name = reader[0].ToString();
                                metricTelemetry.Sum  = reader.IsDBNull(1) ? 0.0 : double.Parse(reader[1].ToString());
                                metricTelemetry.Context.Operation.Name = "EventComplete";

                                KegLogger.KegLogMetrics("Event Complete or timeout", "EventComplete", metricTelemetry);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                KegLogger.KegLogTrace(ex.Message, "SqLiteHelper:DeleteExpiredUserConsumption", SeverityLevel.Error,
                                      new Dictionary <string, string>()
                {
                    { "Con", SqliteConnectionString }
                });
                //throw;
            }
        }