public static void Main(string[] args) { var config = Config.Load(); var carIdentificationService = new CarIdentificationService(config); var currentFileName = ""; var inputDir = new DirectoryInfo(config.ConvertedFolder); while (true) { try { var files = inputDir.GetFiles(); if (files.Length > 0) { var stopwatch = Stopwatch.StartNew(); var file = files.OrderBy(f => f.Name).First(); if (args.Length > 0 && args[0] == "b") { file = files.OrderByDescending(f => f.Name).First(); } if (args.Length > 0 && args[0] == "m") { file = files.Skip(files.Length / 2).Take(1).First(); } if (args.Length > 0 && args[0] == "logan") { file = files.Skip(files.Length / 3).Take(1).First(); } currentFileName = file.Name; //file = new FileInfo(@"C:\users\andy\videos\speedcam\20180715150000_20180715153000.mp4"); Console.WriteLine($"{DateTime.Now.ToString("hh:mm")}: Analyzing {file.Name} {files.Length} files left"); carIdentificationService.AnalyzeVideo(file.FullName, false); File.Move(file.FullName, Path.Combine(config.AnalyzedFolder, file.Name)); } else { Console.WriteLine($"{DateTime.Now.ToString("hh:mm")}: Not enough files, sleeping for 60 seconds"); } } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); var database = new SqlDatabase(config.DbConnectionString); database.LogInsert(new Log { DateAdded = DateTime.Now, Message = $"File: {currentFileName} - Message: {ex.Message}", StackTrace = ex.StackTrace }); Console.ReadLine(); } } }
static async Task Main(string[] args) { try { Config = Config.Load(); CarIdentificationService = new CarIdentificationService(Config); ExportService = new AmcrestNVRClient(Config); Database = new SqlDatabase(Config.DbConnectionString); IsDebug = args.Any(a => a == "-debug"); var specificFlagIndex = Array.IndexOf(args, "-s"); VideoOnly = args.Any(a => a == "-v"); var idleFlagIndex = Array.IndexOf(args, "-shutdown"); ShutdownTime = idleFlagIndex != -1 ? TimeSpan.FromMinutes(Convert.ToDouble(args[idleFlagIndex + 1])) : TimeSpan.MinValue; //process normally if (specificFlagIndex == -1) { //if the last chunk was not completed, delete it so it can start over var latestChunk = Database.GetLatestDateChunk(); if (ShouldDeleteLatestChunk(latestChunk)) { Database.DeleteDateChunk(latestChunk); } LastActiveTime = DateTime.Now; while (true) { try { var makeUp = Database.GetNextMakeUp(); if (makeUp != null) { await ProcessMakeUp(makeUp); } else { var workDone = await ProcessNextChunk(); if (workDone) { LastActiveTime = DateTime.Now; } } } catch (Exception ex) { Database.LogInsert(new Log { DateAdded = DateTime.Now, Message = $"Error in main loop: {ex.Message}", StackTrace = ex.StackTrace }); Console.WriteLine($"ERROR: {ex.Message}"); } DrawSleepyDots(5); Console.WriteLine(""); if (ShutdownTime != TimeSpan.MinValue && (DateTime.Now - LastActiveTime).TotalMinutes > ShutdownTime.TotalMinutes) { return; } } } else //process a specific datetime { if (args.Length < specificFlagIndex + 3) { Console.WriteLine("The Specific flag requires a datetime and length"); return; } else { var startDate = DateTime.Parse(args[specificFlagIndex + 1]); var chunkTime = int.Parse(args[specificFlagIndex + 2]); await ProcessFootage(startDate, chunkTime, () => { return; }); } } } catch (Exception ex) { Database.LogInsert(new Log { DateAdded = DateTime.Now, Message = $"Error analyzing footage: {ex.Message}", StackTrace = ex.StackTrace }); } }