private void StartMonit_Click(object sender, EventArgs e) { this.MonitFolder = this.textBox1.Text; try { if (!new DirectoryInfo(this.MonitFolder).Exists) { MessageBox.Show("检测文件不存在,请核实"); } else { this.notifyIcon1.Text = "文件夹检测中"; this.MsgListBox.Items.Add("文件夹监测中......"); this.MsgListBox.SetSelected(this.MsgListBox.Items.Count - 1, true); //Form1.watcher.Path = this.MonitFolder; //Form1.watcher.EnableRaisingEvents = true; this.StopMonit.Enabled = true; this.StartMonit.Enabled = false; this.button1.Enabled = false; this.textBox1.Enabled = false; } } catch (Exception ex) { MessageBox.Show("发生异常:" + ex.Message); } IDirectoryMonitor iDM = new DirectoryMonitor(MonitFolder, textBox2.Text, this); iDM.Start(); }
protected async override Task ExecuteAsync() { if (Watch && FromFile != null) { var filename = Path.GetFullPath(FromFile); Console.WriteLine($"filename: {filename}"); await Root.Connection.ConcurrencyRetryBlock(Handler.SetMetadata); using (var watcher = new DirectoryMonitor(System.IO.Path.GetFileName(filename))) { watcher.Change += (string changedFilePath) => { Task.Run(async() => { Console.WriteLine("Updating metadata"); await Root.Connection.ConcurrencyRetryBlock(Handler.SetMetadata); }); }; watcher.Start(); while (true) { Console.WriteLine("watching"); Console.ReadLine(); } } } else { await Root.Connection.ConcurrencyRetryBlock(Handler.SetMetadata); } }
public static IApplicationBuilder UseGrpcMonitorProtoFileEnable(this IApplicationBuilder app) { DirectoryMonitor monitor = new DirectoryMonitor(GrpcServiceMethodFactory.ProtoPath, "*.proto"); monitor.Change += (string filePath) => { InnerLogger.Log(LoggerLevel.Debug, filePath); GrpcServiceMethodFactory.ProtoQueue.Enqueue(filePath); }; monitor.Start(); return(app); }
/// <summary> /// 开启监控 /// </summary> private void MonitorStart() { if (!Directory.Exists(PluginPath)) { Directory.CreateDirectory(PluginPath); } monitor = new DirectoryMonitor(PluginPath, "*.dll"); monitor.Change += (string filePath) => { LoadAsync(filePath); }; monitor.Start(); }
/// <summary> /// 开启监控 /// </summary> private void MonitorStart() { if (!Directory.Exists(ProtoPath)) { Directory.CreateDirectory(ProtoPath); } monitor = new DirectoryMonitor(ProtoPath, "*.proto"); monitor.Change += (string filePath) => { protoQueue.Enqueue(filePath); }; monitor.Start(); }
public void TestFileChanged() { string file1, file2; monitor.Start(); file1 = Path.Combine(tmpDir, "test1"); file2 = Path.Combine(tmpDir, "test2"); File.OpenWrite(file1).Close(); // Ugly as hell... System.Threading.Thread.Sleep(100); Assert.AreEqual(1, addedChanged); Assert.AreEqual(0, deletedChanged); File.Move(file1, file2); System.Threading.Thread.Sleep(100); Assert.AreEqual(2, addedChanged); Assert.AreEqual(1, deletedChanged); File.Delete(file2); System.Threading.Thread.Sleep(100); Assert.AreEqual(2, addedChanged); Assert.AreEqual(2, deletedChanged); monitor.Stop(); }
public void Identifies_changed_services_to_pipeline() { long count = 0; string baseDir = AppDomain.CurrentDomain.BaseDirectory; using (var manualResetEvent = new ManualResetEvent(false)) using (var dm = new DirectoryMonitor(".", _coordinator)) { var myChannel = new ChannelAdapter(); dm.Start(); myChannel.Connect(sc => sc.AddConsumerOf <ServiceFolderChanged>() .UsingConsumer(fsc => { if (fsc.ServiceName.Equals("bottle", StringComparison.OrdinalIgnoreCase)) { return; // gotta skip the bottle directory } long localCount = Interlocked.Increment(ref count); //Console.WriteLine(fsc.ShelfName); if (localCount % 2 == 0) { manualResetEvent.Set(); } })); //Console.WriteLine(baseDir); //Console.WriteLine("-- Directories"); Directory.CreateDirectory(Path.Combine(baseDir, "Service1")); Directory.CreateDirectory(Path.Combine(baseDir, "Service2")); manualResetEvent.WaitOne(15.Seconds()); count.ShouldEqual(2); manualResetEvent.Reset(); //Console.WriteLine("-- Files"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service2", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test2.out")), "Testing stuff"); manualResetEvent.WaitOne(10.Seconds()); //Console.WriteLine("-- Done"); count.ShouldEqual(4); } }
protected override Task ExecuteAsync() { var organizationIdentifier = GetOrganizationIdentifier(Key); using (var watcher = new DirectoryMonitor(System.IO.Path.GetDirectoryName(Path))) { watcher.Change += Watcher_Change; watcher.Start(); while (true) { Console.WriteLine("watching"); Console.ReadLine(); } } }
public void Identifies_changed_services_to_pipeline() { long count = 0; string baseDir = AppDomain.CurrentDomain.BaseDirectory; using (var manualResetEvent = new ManualResetEvent(false)) using (var dm = new DirectoryMonitor(".")) { var myChannel = new ChannelAdapter(); using (AddressRegistry.GetInboundServiceCoordinatorChannel(x => { })) { dm.Start(); myChannel.Connect(sc => sc.AddConsumerOf<ServiceFolderChanged>() .UsingConsumer(fsc => { if (fsc.ServiceName.Equals("bottle", StringComparison.OrdinalIgnoreCase)) return; // gotta skip the bottle directory long localCount = Interlocked.Increment(ref count); //Console.WriteLine(fsc.ShelfName); if (localCount % 2 == 0) manualResetEvent.Set(); })); //Console.WriteLine(baseDir); //Console.WriteLine("-- Directories"); Directory.CreateDirectory(Path.Combine(baseDir, "Service1")); Directory.CreateDirectory(Path.Combine(baseDir, "Service2")); manualResetEvent.WaitOne(15.Seconds()); count.ShouldEqual(2); manualResetEvent.Reset(); //Console.WriteLine("-- Files"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service2", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test2.out")), "Testing stuff"); manualResetEvent.WaitOne(10.Seconds()); //Console.WriteLine("-- Done"); count.ShouldEqual(4); } } }
private void buttonStart_Click(object sender, EventArgs e) { _process = this.checkBoxProcess.Checked; _monitor.Config.SourcePath = this.textBoxPath.Text; _monitor.Start(); }
public void Identifies_changed_services_to_pipeline() { long count = 0; string baseDir = AppDomain.CurrentDomain.BaseDirectory; using (var manualResetEvent = new ManualResetEvent(false)) using (var dm = new DirectoryMonitor(".")) { var myChannel = new ChannelAdapter(); using (WellknownAddresses.GetHostHost(myChannel)) { dm.Start(); myChannel.Connect(sc => sc.AddConsumerOf<FileSystemChange>() .UsingConsumer(fsc => { long localCount = Interlocked.Increment(ref count); Console.WriteLine(fsc.ShelfName); if (localCount%2 == 0) manualResetEvent.Set(); })); Console.WriteLine(baseDir); Console.WriteLine("-- Directories"); Directory.CreateDirectory(Path.Combine(baseDir, "Service1")); Directory.CreateDirectory(Path.Combine(baseDir, "Service2")); manualResetEvent.WaitOne(15.Seconds()); count.ShouldEqual(2); manualResetEvent.Reset(); Console.WriteLine("-- Files"); File.AppendAllText(Path.Combine(baseDir, "Service1", "test.out"), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, "Service2", "test.out"), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, "Service1", "test2.out"), "Testing stuff"); manualResetEvent.WaitOne(10.Seconds()); Console.WriteLine("-- Done"); count.ShouldEqual(4); } } }