private static void StartAsAzureJob() { try { cmdLineOptions = new CommandLineOptions(); cmdLineOptions.ItemsToProcessDirectory = Environment.GetEnvironmentVariable("AZURE_IMAGE_OPTIMIZER_PATH") ?? @"D:\home\site\wwwroot\"; cmdLineOptions.FileExtensionsToCompress = new string[] { "*.png", "*.jpg", "*.jpeg", "*.gif" }; cmdLineOptions.OptimizerCacheFile = Path.Combine(cmdLineOptions.ItemsToProcessDirectory, @"app_data\ImageOptimizerHashTable.xml"); //cmdLineOptions.ItemsToProcessDirectory = @"C:\Users\madsk\Documents\GitHub\AzureJobs\Azurejobs.Web\ImageOptimization\img"; var imgCompressorMgr = new ImageCompressorManager(cmdLineOptions); imgCompressorMgr.Run(); Timer timer = new Timer((o) => imgCompressorMgr.ProcessQueue()); timer.Change(1000, 5000); while (true) { Thread.Sleep(2000); } } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.ToString()); throw ex; } }
/// <summary> /// Runs the image compressor (gathering imgs, compressing, writing to log). Optionally will /// listen for file system changes on the directory via cmd line options StartListener. /// </summary> private static void RunCompressor() { Console.WriteLine("Monitoring dir " + cmdLineOptions.ItemsToProcessDirectory); var imgCompressorMgr = new ImageCompressorManager(cmdLineOptions); imgCompressorMgr.Run(); if (cmdLineOptions.StartListener) { Console.WriteLine("Press Enter to quit at any time."); do { while (Console.KeyAvailable) { System.Threading.Thread.Sleep(1000); imgCompressorMgr.ProcessQueue(); } } while (Console.ReadKey(true).Key != ConsoleKey.Enter); } }