/// <summary> /// Froms the text reader. /// </summary> /// <returns>The text reader.</returns> /// <param name="reader"></param> /// <param name="path">Base path, location of rules file</param> static Rules FromTextReader(TextReader reader, string path) { var rules = new Rules(); var list = rules.List; Rule r = null; string line; while (true) { line = reader.ReadLine(); if (line == null) //EOF return rules; if (line.StartsWith("#!")) //to ignore first #!/... in autoex script file continue; //Ignore comments if (line.StartsWith("#runall")) { rules.RunAllAtStart = true; continue; //Ignore comments } string lineTrim = line.Trim(' ', '\t'); if (lineTrim.StartsWith("//")) continue; //Ignore comments if (lineTrim == "") continue; if (r == null) { r = new Rule(); list.Add(r); } if (line[0] == '\t') //Commands are indented ParseCommand(r, line); else { //Skip comments if (line[0] == '#') continue; if (r.Commands.Count != 0) { r = new Rule(); list.Add(r); } ParsePath(r, line, path); } } }
void LoadRules() { ColorConsole.WriteLine("Loading rules: " + rulesPath, ConsoleColor.DarkGray); try { rules = RulesLoader.FromFile(rulesPath); rulesPathExitCode = 0; } catch (Exception e) { Console.Error.WriteLine(e.Message); rulesPathExitCode = -1; rules = new Rules(); } //Stop previous watchers foreach (var w in watchers) w.Dispose(); if (rules.RunAllAtStart) lastRun = DateTime.MinValue; //Set new filewatchers List<string> watched = new List<string>(); foreach (var r in rules.List) { foreach (var f in r.Files) { if (watched.Contains(f.Path)) continue; if (Directory.Exists(f.Path) == false) { ColorConsole.WriteLine("Directory not found: " + f.Path, ConsoleColor.Red); continue; } var w = new FileSystemWatcher(f.Path); w.IncludeSubdirectories = f.IncludeSubdirectories; w.Changed += FileSystemEvent; w.Created += FileSystemEvent; w.Deleted += FileSystemEvent; w.Renamed += FileRenamed; w.EnableRaisingEvents = true; watchers.Add(w); } } }