static void Main(string[] args) { ConnectsToGC.Setup(); dbHelper = new DBHelper(); downloadMonitor = new DownloadMonitor(dbHelper.db); downloadMonitor.rootDir = "C:\\test"; downloadTimer = new System.Threading.Timer(DownloadCheck, null, 4000, Timeout.Infinite); consumerTimer = new System.Threading.Timer(ConsumerProcess, null, 4000, Timeout.Infinite); diskMonitor = new DiskMonitor(downloadMonitor.rootDir, dbHelper.db); consumer = new GCActionConsumer(dbHelper.db); consumer.rootDir = downloadMonitor.rootDir; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (NotifyIcon icon = new NotifyIcon()) { icon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath); icon.ContextMenu = new ContextMenu(new MenuItem[] { new MenuItem("About", (s, e) => {new MainForm().Show();}), new MenuItem("Exit", (s, e) => { Application.Exit(); }), }); icon.Visible = true; Application.Run(); icon.Visible = false; } }
public static IEnumerator<object> MonitorForChanges() { Scheduler.Start( PeriodicGC(), TaskExecutionPolicy.RunAsBackgroundTask ); string[] filters; TagDatabase.Folder[] folders = null; { Future<string[]> f; yield return Database.GetFilterPatterns().Run(out f); filters = f.Result; } { var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders()); yield return Scheduler.Start(iter.GetArray()) .Bind( () => folders ); } var exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray(); DiskMonitor monitor = new DiskMonitor( (from folder in folders select folder.Path).ToArray(), filters, new string[] { System.Text.RegularExpressions.Regex.Escape(@"\.svn\"), System.Text.RegularExpressions.Regex.Escape(@"\.git\"), System.Text.RegularExpressions.Regex.Escape(@"\.hg\") } ); monitor.Monitoring = true; var changedFiles = new List<string>(); var deletedFiles = new List<string>(); long lastDiskChange = 0; long updateInterval = TimeSpan.FromSeconds(10).Ticks; while (true) { long now = DateTime.Now.Ticks; if ((changedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) { var filenames = changedFiles.ToArray(); changedFiles.Clear(); yield return UpdateIndex(filenames); } if ((deletedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) { using (new ActiveWorker(String.Format("Pruning {0} item(s) from index", deletedFiles.Count))) { string[] filenames = deletedFiles.ToArray(); deletedFiles.Clear(); yield return DeleteSourceFiles(filenames); } } using (new ActiveWorker(String.Format("Reading disk change history"))) { now = DateTime.Now.Ticks; foreach (string filename in monitor.GetChangedFiles().Distinct()) { lastDiskChange = now; bool excluded = false; foreach (var exclusion in exclusionList) { if (filename.StartsWith(exclusion)) { excluded = true; break; } } if (!excluded) changedFiles.Add(filename); } foreach (string filename in monitor.GetDeletedFiles().Distinct()) { lastDiskChange = now; bool excluded = false; foreach (var exclusion in exclusionList) { if (filename.StartsWith(exclusion)) { excluded = true; break; } } if (!excluded) deletedFiles.Add(filename); } } yield return new Sleep(2.5); } }