public override string ToString()
 {
     if (Meal is null)
     {
         return($"{TimeOfDay.ToLocalTime().ToShortDateString()}, {ReadingType.ToString()} Meal");
     }
     else
     {
         return($"{TimeOfDay.ToLocalTime().ToShortDateString()}, {Meal.FoodName}, {ReadingType.ToString()} {Meal.MealTime}");
     }
 }
Beispiel #2
0
        public static void StartReading(ReadingType rType)
        {
            foreach (Task task in tasks)
            {
                //Start the thread
                task.Start();
                try
                {
                    task.Wait();
                }
                catch { }
                Thread.Sleep(100);
            }

            Task t = Task.WhenAll(tasks);

            try
            {
                t.Wait();
            }
            catch { }

            //TODO Move this code to higher level
            if (t.IsCompleted)
            {
                string query = "";
                switch (rType)
                {
                case ReadingType.Hourly:
                {
                    query += DBManager.AssembleTableQuery("tblwatermeters1h");
                }
                break;

                case ReadingType.Daily:
                {
                    query += DBManager.AssembleTableQuery("tblwatermeters1h");
                    query += DBManager.AssembleTableQuery("tblwatermeters");
                }
                break;

                default:
                    throw new NotImplementedException($"Type '{rType.ToString()}' not implemented.");
                }

                //Execute the query
                DBManager db = new DBManager();
                db.Execute(query);
                Output.Report("Database updated.");

                //TODO Add database cleanup
                db.Disconnect();

                //Release resources
                foreach (Task task in tasks)
                {
                    task.Dispose();
                }
                t.Dispose();
            }
        }