Esempio n. 1
0
        public MonitorTask(string monitorFile, bool verbose)
        {
            string spec;

            using (StreamReader reader = new StreamReader(monitorFile))
            {
                spec = reader.ReadToEnd();
            }
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.MissingMemberHandling = MissingMemberHandling.Error;
            MonitorDescr descr = JsonConvert.DeserializeObject <MonitorDescr>(spec, settings);

            monitor = new Monitor(descr, verbose);

            watcher = new ManagementEventWatcher("Select * From Win32_DeviceChangeEvent Within 1 Where EventType = 2 Or EventType = 3");
        }
Esempio n. 2
0
 public Monitor(MonitorDescr descr, bool verbose)
 {
     this.taskFactory = new TaskFactory(verbose);
     this.query       = "Select * From " + descr.ClassId + " Where DeviceID = \"" + descr.DeviceId.Replace("\\", "\\\\") + "\"";
     DoUpdate();
     if (verbose || descr.ShowEvent)
     {
         string id = descr.DeviceId;
         onAttach.Add(new LogTask("Device " + id + " attached."));
         onDetach.Add(new LogTask("Device " + id + " detached."));
         Console.WriteLine(Attached ? "Device " + id + " initially attached." : "Device " + id + " initally detached.");
     }
     foreach (TaskDescr d in descr.OnAttach)
     {
         onAttach.Add(taskFactory.Create(d));
     }
     foreach (TaskDescr d in descr.OnDetach)
     {
         onDetach.Add(taskFactory.Create(d));
     }
 }