protected override void OnStart(string[] args) { ScanEngine.ScanEngineSetDefault(); messageIn = new Queue <string>(); messageOut = new Queue <string>(); messageOut.Enqueue("\u0000\u0008\u0001"); closing = false; mybase = new Base("c:\\antiv\\avdb.avb"); threads = new List <Thread>(); threads.Add(new Thread(ListenPipe)); threads.Add(new Thread(Base.load)); threads.Add(new Thread(commandParse)); scanner = new Task(ScanEngine.scan); monitoringDirs = new List <FileSystemWatcher>(); planningScan = new List <string[]>(); timer1 = new System.Timers.Timer(1000); timer1.Elapsed += new System.Timers.ElapsedEventHandler(checkTime); timer1.Start(); foreach (var t in threads) { t.Start(); } }
private static void commandParse() { while (!closing) { string str = "\u0000\u0000"; lock (messageIn) if (messageIn.Count > 0) { str = messageIn.Dequeue(); } switch (str[1]) { case '\u0000': break; case '\u0001': //disconnect lock (threads) { threads[0].Abort(); while (threads[0].IsAlive) { } threads[0] = new Thread(ListenPipe); threads[0].Start(); } break; case '\u0002': //scan start lock (messageOut) messageOut.Enqueue("\u0000\u0004"); ScanEngine.closing = 0; scanner.Start(); break; case '\u0003': //scan stop lock (messageOut) messageOut.Enqueue("\u0000\u0005"); ScanEngine.closing = 1; break; case '\u0004': //scan add lock (ScanEngine.toScan) { if (!ScanEngine.toScan.Contains(str.Substring(2).Trim('\0'))) { ScanEngine.toScan.Add(str.Substring(2).Trim('\0')); } } break; case '\u0005': //scan remove lock (ScanEngine.toScan) ScanEngine.toScan.Remove(str.Substring(2).Trim('\0')); break; case '\u0006': //monitor add var fsw = (str.Substring(2).Trim('\0')); if (!monitoringDirs.Contains(monitoringDirs.Find(x => x.Path == fsw))) { monitoringDirs.Add(new FileSystemWatcher(fsw)); monitoringDirs.Last().Created += new FileSystemEventHandler(newMonitor); } break; case '\u0007': //monitor remove var fsw2 = (str.Substring(2).Trim('\0')); monitoringDirs.Remove(monitoringDirs.Find(x => x.Path == fsw2)); break; case '\u0008': //plan add if (!planningScan.Contains( str.Substring(2).Trim('\0').Split('|'))) { planningScan.Add(str.Substring(2).Trim('\0').Split('|')); } break; case '\u0009': //plan remove planningScan.Remove(str.Substring(2).Trim('\0').Split('|')); break; case '\u000A': //received break; case '\u000B': //ask status lock (messageOut) messageOut.Enqueue("\u0000\u0004"); break; case '\u0010': //delete from qarantine ScanEngine.delete(str.Substring(2).Trim('\0')); break; case '\u0011': //restore from qarantin ScanEngine.restore(str.Substring(2).Trim('\0')); break; } } }