private static IEnumerable<TaskOption> LoadDocument()
 {
     const string fileName = "watcherTasks.xml";
     EnvDTE.DTE dte = GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
     string solutionPath = Path.GetDirectoryName(dte.Solution.FullName);
     string filePath = Path.Combine(solutionPath, fileName);
     var options = new List<TaskOption>();
     if (File.Exists(filePath))
     {
         XDocument document = XDocument.Load(filePath);
         foreach (XElement element in document.Root.Element("component").Elements("TaskOptions"))
         {
             var option = new TaskOption();
             option.IsEnabled = Convert.ToBoolean(element.Attribute("isEnabled").Value);
             option.Description = element.Elements().FirstOrDefault(n => n.Attribute("name").Value == "description")
                                         .IfNotNull(n => n.Attribute("value").Value);
             option.WorkingDir = element.Elements().FirstOrDefault(n => n.Attribute("name").Value == "workingDir")
                                         .IfNotNull(n => n.Attribute("value").Value);
             option.FileExtension = element.Elements().FirstOrDefault(n => n.Attribute("name").Value == "fileExtension")
                                           .IfNotNull(n => n.Attribute("value").Value);
             option.Arguments = element.Elements().FirstOrDefault(n => n.Attribute("name").Value == "arguments")
                                       .IfNotNull(n => n.Attribute("value").Value);
             option.Program = element.Elements().FirstOrDefault(n => n.Attribute("name").Value == "program")
                                     .IfNotNull(n => n.Attribute("value").Value);
             options.Add(option);
         }
     }
     return options;
 }
Example #2
0
        public Watcher(TaskOption option)
        {
            _option = option;

            _watcher = new FileSystemWatcher(option.WorkingDir, "*." + option.FileExtension);
            _watcher.IncludeSubdirectories = true;
            _watcher.Changed += FileChanged;
            _watcher.EnableRaisingEvents = true;
        }