Browse Source

文件变更坚监测

yuzhengyang 8 years ago
parent
commit
acaa9a48d2

+ 17 - 15
Fork.Net/Oreo.Plugins/Oreo.FaultLog/Partials/FaultLogInputPartial.cs

@@ -23,13 +23,7 @@ namespace Oreo.FaultLog.Partials
 
         private void FaultLogInputPartial_Load(object sender, EventArgs e)
         {
-            TbIp.Text = "";
-            TbPhone.Text = "";
-            TbAddress.Text = "";
-            TbProblem.Text = "";
-            TbSolution.Text = "";
-            TbPostscript.Text = "";
-            DgvData.Rows.Clear();
+            UICleanInput();
 
             Task.Factory.StartNew(() =>
             {
@@ -106,13 +100,7 @@ namespace Oreo.FaultLog.Partials
                 CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
             };
 
-            TbIp.Text = "";
-            TbPhone.Text = "";
-            TbAddress.Text = "";
-            TbProblem.Text = "";
-            TbSolution.Text = "";
-            TbPostscript.Text = "";
-            DgvData.Rows.Clear();
+            UICleanInput();
 
             Task.Factory.StartNew(() =>
             {
@@ -217,7 +205,21 @@ namespace Oreo.FaultLog.Partials
                 BtAdd.Enabled = enable;
             }));
         }
-
+        void UICleanInput()
+        {
+            BeginInvoke(new Action(() =>
+            {
+                TbIp.Text = "";
+                TbPhone.Text = "";
+                TbAddress.Text = "";
+                TbProblem.Text = "";
+                TbSolution.Text = "";
+                TbPostscript.Text = "";
+                CbIsFinish.Checked = false;
+                CbSystem.Text = "";
+                DgvData.Rows.Clear();
+            }));
+        }
 
     }
 }

+ 11 - 4
Fork.Net/Oreo.Plugins/Oreo.FileMan/DatabaseEngine/Mapping.cs

@@ -10,16 +10,16 @@ using System.Threading.Tasks;
 
 namespace Oreo.FileMan.DatabaseEngine
 {
-    public class FilesMap : EntityTypeConfiguration<Files>
+    public class UsnFilesMap : EntityTypeConfiguration<UsnFiles>
     {
-        public FilesMap()
+        public UsnFilesMap()
         {
             this.Property(o => o.Id).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = true }));
         }
     }
-    public class DrivesMap : EntityTypeConfiguration<Drives>
+    public class UsnDrivesMap : EntityTypeConfiguration<UsnDrives>
     {
-        public DrivesMap()
+        public UsnDrivesMap()
         {
             this.Property(o => o.Id).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = true }));
         }
@@ -38,4 +38,11 @@ namespace Oreo.FileMan.DatabaseEngine
             this.Property(o => o.Id).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = true }));
         }
     }
+    public class WatcherFilesMap : EntityTypeConfiguration<WatcherFiles>
+    {
+        public WatcherFilesMap()
+        {
+            this.Property(o => o.Id).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = true }));
+        }
+    }
 }

+ 1 - 1
Fork.Net/Oreo.Plugins/Oreo.FileMan/Models/Drives.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace Oreo.FileMan.Models
 {
-    public class Drives
+    public class UsnDrives
     {
         public int Id { get; set; }
         public string Name { get; set; }

+ 2 - 1
Fork.Net/Oreo.Plugins/Oreo.FileMan/Models/Files.cs

@@ -8,7 +8,7 @@ using Y.Utils.IOUtils.FileUtils;
 
 namespace Oreo.FileMan.Models
 {
-    public class Files
+    public class UsnFiles
     {
         public int Id { get; set; }
         public string Name { get; set; }
@@ -17,5 +17,6 @@ namespace Oreo.FileMan.Models
         public string ParentNumber { get; set; }
         public string Drive { get; set; }
         public long Usn { get; set; }
+        public string  CreateTime { get; set; }
     }
 }

+ 13 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Models/WatcherFiles.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Oreo.FileMan.Models
+{
+    public class WatcherFiles
+    {
+        public int Id { get; set; }
+        public string FullPath { get; set; }
+    }
+}

+ 3 - 2
Fork.Net/Oreo.Plugins/Oreo.FileMan/Oreo.FileMan.csproj

@@ -94,8 +94,9 @@
     <Compile Include="DatabaseEngine\SuperDb.cs" />
     <Compile Include="Models\BackupFiles.cs" />
     <Compile Include="Models\BackupPaths.cs" />
-    <Compile Include="Models\Drives.cs" />
-    <Compile Include="Models\Files.cs" />
+    <Compile Include="Models\UsnDrives.cs" />
+    <Compile Include="Models\UsnFiles.cs" />
+    <Compile Include="Models\WatcherFiles.cs" />
     <Compile Include="Partials\FileBackupPartial.cs">
       <SubType>UserControl</SubType>
     </Compile>

+ 24 - 33
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.Designer.cs

@@ -38,10 +38,9 @@
             this.DgvFileSize = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvFileVersionHistory = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvFileLastBackupTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.button1 = new System.Windows.Forms.Button();
-            this.textBox1 = new System.Windows.Forms.TextBox();
-            this.button2 = new System.Windows.Forms.Button();
+            this.BtStart = new System.Windows.Forms.Button();
             this.BtDelPath = new System.Windows.Forms.Button();
+            this.BtStop = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.DgvPath)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvFile)).BeginInit();
             this.SuspendLayout();
@@ -143,30 +142,15 @@
             this.DgvFileLastBackupTime.ReadOnly = true;
             this.DgvFileLastBackupTime.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
-            // button1
+            // BtStart
             // 
-            this.button1.Location = new System.Drawing.Point(562, 6);
-            this.button1.Name = "button1";
-            this.button1.Size = new System.Drawing.Size(75, 23);
-            this.button1.TabIndex = 3;
-            this.button1.Text = "button1";
-            this.button1.UseVisualStyleBackColor = true;
-            // 
-            // textBox1
-            // 
-            this.textBox1.Location = new System.Drawing.Point(356, 297);
-            this.textBox1.Name = "textBox1";
-            this.textBox1.Size = new System.Drawing.Size(281, 21);
-            this.textBox1.TabIndex = 4;
-            // 
-            // button2
-            // 
-            this.button2.Location = new System.Drawing.Point(252, 295);
-            this.button2.Name = "button2";
-            this.button2.Size = new System.Drawing.Size(98, 23);
-            this.button2.TabIndex = 5;
-            this.button2.Text = "设置备份目录";
-            this.button2.UseVisualStyleBackColor = true;
+            this.BtStart.Location = new System.Drawing.Point(481, 6);
+            this.BtStart.Name = "BtStart";
+            this.BtStart.Size = new System.Drawing.Size(75, 23);
+            this.BtStart.TabIndex = 3;
+            this.BtStart.Text = "启动";
+            this.BtStart.UseVisualStyleBackColor = true;
+            this.BtStart.Click += new System.EventHandler(this.BtStart_Click);
             // 
             // BtDelPath
             // 
@@ -178,14 +162,23 @@
             this.BtDelPath.UseVisualStyleBackColor = true;
             this.BtDelPath.Click += new System.EventHandler(this.BtDelPath_Click);
             // 
+            // BtStop
+            // 
+            this.BtStop.Location = new System.Drawing.Point(562, 6);
+            this.BtStop.Name = "BtStop";
+            this.BtStop.Size = new System.Drawing.Size(75, 23);
+            this.BtStop.TabIndex = 7;
+            this.BtStop.Text = "停止";
+            this.BtStop.UseVisualStyleBackColor = true;
+            this.BtStop.Click += new System.EventHandler(this.BtStop_Click);
+            // 
             // FileBackupPartial
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.Controls.Add(this.BtStop);
             this.Controls.Add(this.BtDelPath);
-            this.Controls.Add(this.button2);
-            this.Controls.Add(this.textBox1);
-            this.Controls.Add(this.button1);
+            this.Controls.Add(this.BtStart);
             this.Controls.Add(this.DgvFile);
             this.Controls.Add(this.BtAddPath);
             this.Controls.Add(this.DgvPath);
@@ -195,7 +188,6 @@
             ((System.ComponentModel.ISupportInitialize)(this.DgvPath)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvFile)).EndInit();
             this.ResumeLayout(false);
-            this.PerformLayout();
 
         }
 
@@ -204,9 +196,7 @@
         private System.Windows.Forms.DataGridView DgvPath;
         private System.Windows.Forms.Button BtAddPath;
         private System.Windows.Forms.DataGridView DgvFile;
-        private System.Windows.Forms.Button button1;
-        private System.Windows.Forms.TextBox textBox1;
-        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Button BtStart;
         private System.Windows.Forms.Button BtDelPath;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvPathName;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvPathSize;
@@ -215,5 +205,6 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileSize;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileVersionHistory;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvFileLastBackupTime;
+        private System.Windows.Forms.Button BtStop;
     }
 }

+ 34 - 17
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.cs

@@ -19,21 +19,26 @@ namespace Oreo.FileMan.Partials
 {
     public partial class FileBackupPartial : UserControl
     {
-        List<BackupPaths> BackupPath = new List<BackupPaths>();
+        FileWatcher Watcher = new FileWatcher();
+        string FileManBackup = @"D:\FileManBackup\";
+        List<BackupPaths> Paths = new List<BackupPaths>();
+
         public FileBackupPartial()
         {
             InitializeComponent();
         }
         private void FileBackupPartial_Load(object sender, EventArgs e)
         {
+            Watcher. += WatcherChangedEvent;
+            //读取要备份的文件路径列表
             Task.Factory.StartNew(() =>
             {
                 using (var db = new Muse())
                 {
-                    BackupPath = db.GetAll<BackupPaths>(null, false).ToList();
-                    if (ListTool.HasElements(BackupPath))
+                    Paths = db.GetAll<BackupPaths>(null, false).ToList();
+                    if (ListTool.HasElements(Paths))
                     {
-                        foreach (var b in BackupPath)
+                        foreach (var b in Paths)
                         {
                             UIDgvPathAdd(b.Name);
                         }
@@ -41,7 +46,7 @@ namespace Oreo.FileMan.Partials
                 }
             });
         }
-        #region 目录操作
+
         private void BtAddPath_Click(object sender, EventArgs e)
         {
             FolderBrowserDialog dialog = new FolderBrowserDialog();
@@ -49,7 +54,7 @@ namespace Oreo.FileMan.Partials
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 string selPath = dialog.SelectedPath;//格式化选中的目录
-                List<BackupPaths> clashPath = BackupPath.Where(x => x.Path.Contains(selPath + "\\") || (selPath + "\\").Contains(x.Path)).ToList();//查询冲突项
+                List<BackupPaths> clashPath = Paths.Where(x => x.Path.Contains(selPath + "\\") || (selPath + "\\").Contains(x.Path)).ToList();//查询冲突项
                 if (ListTool.HasElements(clashPath))
                 {
                     string cp = "";
@@ -62,7 +67,7 @@ namespace Oreo.FileMan.Partials
                     long size = 0;//目录下的文件大小
                     int row = DgvPath.Rows.Count;//当前目录列表总数
                     BackupPaths bp = new BackupPaths() { Name = Path.GetFileName(selPath), Path = selPath + "\\", };
-                    BackupPath.Add(bp);//添加到列表
+                    Paths.Add(bp);//添加到列表
                     UIDgvPathAdd(Path.GetFileName(selPath));//添加到列表UI
 
                     UIEnableButton(false);
@@ -91,14 +96,14 @@ namespace Oreo.FileMan.Partials
             if (DgvPath.CurrentRow != null)
             {
                 int row = DgvPath.CurrentRow.Index;
-                string path = BackupPath[row].Path;
+                string path = Paths[row].Path;
                 if (row >= 0)
                 {
                     using (var db = new Muse())
                     {
                         BackupPaths bp = db.Get<BackupPaths>(x => x.Path == path, null);
                         if (bp != null) db.Del(bp, true);
-                        BackupPath.RemoveAt(row);
+                        Paths.RemoveAt(row);
                     }
                     UIDgvPathDel(row);
                 }
@@ -108,7 +113,7 @@ namespace Oreo.FileMan.Partials
         {
             if (e.RowIndex >= 0)
             {
-                string path = BackupPath[e.RowIndex].Path;
+                string path = Paths[e.RowIndex].Path;
                 UIEnableButton(false);
                 DgvFile.Rows.Clear();
                 Task.Factory.StartNew(() =>
@@ -125,7 +130,19 @@ namespace Oreo.FileMan.Partials
                 });
             }
         }
-        #endregion
+
+        private void BtStart_Click(object sender, EventArgs e)
+        {
+            Watcher.Start();
+        }
+        private void BtStop_Click(object sender, EventArgs e)
+        {
+            Watcher.Stop();
+        }
+        private void WatcherChangedEvent(object sender, FileSystemEventArgs e)
+        {
+            UIDgvFileAdd(e.Name, e.FullPath, "Changed");
+        }
 
         /// <summary>
         /// 停用或启用所有按钮
@@ -138,7 +155,6 @@ namespace Oreo.FileMan.Partials
                 BtAddPath.Enabled = enable;
             }));
         }
-        #region 路径列表UI操作
         /// <summary>
         /// 添加到路径列表
         /// </summary>
@@ -173,8 +189,12 @@ namespace Oreo.FileMan.Partials
                 DgvPath.Rows[row].SetValues(new object[] { Path.GetFileName(path), size });
             }));
         }
-        #endregion
-        #region 文件列表UI操作
+        /// <summary>
+        /// 添加文件到列表
+        /// </summary>
+        /// <param name="file"></param>
+        /// <param name="path"></param>
+        /// <param name="size"></param>
         void UIDgvFileAdd(string file, string path, string size)
         {
             BeginInvoke(new Action(() =>
@@ -182,8 +202,5 @@ namespace Oreo.FileMan.Partials
                 DgvFile.Rows.Add(new object[] { file, path, size });
             }));
         }
-        #endregion
-
-
     }
 }

+ 21 - 0
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileBackupPartial.resx

@@ -123,6 +123,27 @@
   <metadata name="DgvPathSize.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="DgvPathName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvPathSize.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFilePath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFileSize.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFileVersionHistory.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="DgvFileLastBackupTime.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
   <metadata name="DgvFileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>

+ 17 - 15
Fork.Net/Oreo.Plugins/Oreo.FileMan/Partials/FileTypePartial.cs

@@ -15,6 +15,7 @@ using Y.Utils.IOUtils.DriveUtils;
 using System.Data.SqlClient;
 using System.Data.Entity.Infrastructure;
 using Y.Utils.AppUtils;
+using Y.Utils.DataUtils.DateTimeUtils;
 
 namespace Oreo.FileMan.Partials
 {
@@ -75,15 +76,15 @@ namespace Oreo.FileMan.Partials
                         {
                             //检测磁盘是否格式化,如果格式化则清空USN记录
                             DateTime dt1 = DriveTool.GetLastFormatTime(drive.Name);
-                            var ds = db.Get<Drives>(x => x.Name == drive.Name, null);
+                            var ds = db.Get<UsnDrives>(x => x.Name == drive.Name, null);
                             if ((ds == null) || (ds != null && ds.LastFormatTime != dt1.ToString()))
                             {
-                                var fs = db.Gets<Files>(x => x.Drive == drive.Name, null);
+                                var fs = db.Gets<UsnFiles>(x => x.Drive == drive.Name, null);
                                 if (ListTool.HasElements(fs)) db.Dels(fs);
 
                                 if (ds == null)
                                 {
-                                    db.Add(new Drives() { Name = drive.Name, LastFormatTime = dt1.ToString() });
+                                    db.Add(new UsnDrives() { Name = drive.Name, LastFormatTime = dt1.ToString() });
                                 }
                                 else
                                 {
@@ -93,9 +94,9 @@ namespace Oreo.FileMan.Partials
                             }
 
                             //查询上次读取到的位置并读取USN
-                            if (db.Any<Files>(x => x.Drive == drive.Name, null))
+                            if (db.Any<UsnFiles>(x => x.Drive == drive.Name, null))
                             {
-                                long currentUsn = db.Do<Files>().Where(x => x.Drive == drive.Name).Max(x => x.Usn);
+                                long currentUsn = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Usn);
                                 usnList = usnList.Where(x => x.Usn > currentUsn).ToList();
                             }
                             //将记录存储到数据库中
@@ -121,7 +122,7 @@ namespace Oreo.FileMan.Partials
                                     //    temp = new List<Files>();
                                     //    Thread.Sleep(100);
                                     //}
-                                    db.Add(new Files()
+                                    db.Add(new UsnFiles()
                                     {
                                         Name = usnList[i].FileName,
                                         IsFolder = usnList[i].IsFolder,
@@ -148,20 +149,20 @@ namespace Oreo.FileMan.Partials
                     NewFileCount = 0;
                     if (drive.Name.Contains("C")) continue;//测试时跳过C盘
                     //if (drive.Name.Contains("D")) continue;//测试时跳过D盘
-                    if (drive.Name.Contains("F")) continue;//测试时跳过F盘
+                    //if (drive.Name.Contains("F")) continue;//测试时跳过F盘
 
                     using (var db = new Muse())
                     {
                         //检测磁盘是否格式化,如果格式化则清空USN记录
                         DateTime dt1 = DriveTool.GetLastFormatTime(drive.Name);
-                        var ds = db.Get<Drives>(x => x.Name == drive.Name, null);
+                        var ds = db.Get<UsnDrives>(x => x.Name == drive.Name, null);
                         if ((ds == null) || (ds != null && ds.LastFormatTime != dt1.ToString()))
                         {
-                            var deleteSql = db.Context.Database.ExecuteSqlCommand("DELETE FROM files WHERE drive = @p0;", drive.Name);
+                            var deleteSql = db.Context.Database.ExecuteSqlCommand("DELETE FROM usnfiles WHERE drive = @p0;", drive.Name);
 
                             if (ds == null)
                             {
-                                db.Add(new Drives() { Name = drive.Name, LastFormatTime = dt1.ToString() });
+                                db.Add(new UsnDrives() { Name = drive.Name, LastFormatTime = dt1.ToString() });
                             }
                             else
                             {
@@ -172,9 +173,9 @@ namespace Oreo.FileMan.Partials
 
                         //查询上次读取到的位置
                         long currentUsn = 0;
-                        if (db.Any<Files>(x => x.Drive == drive.Name, null))
+                        if (db.Any<UsnFiles>(x => x.Drive == drive.Name, null))
                         {
-                            currentUsn = db.Do<Files>().Where(x => x.Drive == drive.Name).Max(x => x.Usn);
+                            currentUsn = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Usn);
                         }
                         //从上次Usn记录开始读取
                         var usnOperator = new UsnOperator(drive);
@@ -185,12 +186,12 @@ namespace Oreo.FileMan.Partials
         }
         private void GetFileToDatabaseEvent(DriveInfo drive, List<UsnEntry> data)
         {
-            List<Files> temp = new List<Files>();
+            List<UsnFiles> temp = new List<UsnFiles>();
             if (ListTool.HasElements(data))
             {
                 for (int i = 0; i < data.Count; i++)
                 {
-                    temp.Add(new Files()
+                    temp.Add(new UsnFiles()
                     {
                         Name = data[i].FileName,
                         IsFolder = data[i].IsFolder,
@@ -198,6 +199,7 @@ namespace Oreo.FileMan.Partials
                         ParentNumber = data[i].ParentFileReferenceNumber.ToString(),
                         Drive = drive.Name,
                         Usn = data[i].Usn,
+                        CreateTime = DateTimeConvert.ToStandardString(DateTime.Now)
                     });
                     NewFileCount++;
                 }
@@ -254,7 +256,7 @@ namespace Oreo.FileMan.Partials
                     {
                         foreach (var t in type)
                         {
-                            var count = db.Do<Files>().Count(x => !x.IsFolder && x.Name.EndsWith(t));
+                            var count = db.Do<UsnFiles>().Count(x => !x.IsFolder && x.Name.EndsWith(t));
                             result += count;
                             //foreach (var l in list)
                             //{

+ 82 - 0
Fork.Net/Y.Utils/IOUtils/FileManUtils/FileWatcher.cs

@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Y.Utils.DataUtils.Collections;
+
+namespace Y.Utils.IOUtils.FileManUtils
+{
+    /// <summary>
+    /// 文件更改通知
+    /// </summary>
+    public class FileWatcher
+    {
+        private bool _IsStart = false;
+        private List<FileSystemWatcher> Watchers = new List<FileSystemWatcher>();
+
+        /// <summary>
+        /// 当前运行状态
+        /// </summary>
+        public bool IsStart { get { return _IsStart; } }
+        public delegate void FileWatcherEventHandler(object sender, FileWatcherEventArgs args);
+        public FileWatcher()
+        {
+            DriveInfo[] drives = DriveInfo.GetDrives().Where(x => x.IsReady && (x.DriveType == DriveType.Fixed || x.DriveType == DriveType.Removable)).ToArray();
+            if (ListTool.HasElements(drives))
+            {
+                foreach (var d in drives)
+                {
+                    FileSystemWatcher fsw = new FileSystemWatcher(d.Name);
+                    fsw.Created += CreatedEvent;//创建文件或目录
+                    fsw.Changed += ChangedEvent;//更改文件或目录
+                    fsw.Deleted += DeletedEvent;//删除文件或目录
+                    fsw.Renamed += RenamedEvent;//重命名文件或目录
+                    fsw.IncludeSubdirectories = true;
+                    fsw.NotifyFilter = (NotifyFilters)383;
+                    Watchers.Add(fsw);
+                }
+            }
+        }
+        public void Start()
+        {
+            _IsStart = true;
+            if (ListTool.HasElements(Watchers))
+            {
+                foreach (var w in Watchers)
+                {
+                    w.EnableRaisingEvents = true;
+                }
+            }
+        }
+        public void Stop()
+        {
+            _IsStart = false;
+            if (ListTool.HasElements(Watchers))
+            {
+                foreach (var w in Watchers)
+                {
+                    w.EnableRaisingEvents = false;
+                }
+            }
+        }
+
+
+        private void CreatedEvent(object sender, FileSystemEventArgs e)
+        {
+
+        }
+        private void ChangedEvent(object sender, FileSystemEventArgs e)
+        {
+
+        }
+        private void DeletedEvent(object sender, FileSystemEventArgs e)
+        {
+
+        }
+        private void RenamedEvent(object sender, RenamedEventArgs e)
+        {
+
+        }
+    } 
+}

+ 17 - 0
Fork.Net/Y.Utils/IOUtils/FileManUtils/FileWatcherEventArgs.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Y.Utils.IOUtils.FileManUtils
+{
+    public class FileWatcherEventArgs
+    {
+        public WatcherChangeTypes ChangeType { get; }
+        public string FullPath { get; }
+        public string Name { get; }
+        public string OldFullPath { get; }
+        public string OldName { get; }
+    }
+}

+ 3 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -55,9 +55,11 @@
     <Compile Include="DelegateUtils\ProgressDelegate.cs" />
     <Compile Include="DelegateUtils\ProgressEventArgs.cs" />
     <Compile Include="IOUtils\DriveUtils\DriveTool.cs" />
+    <Compile Include="IOUtils\FileManUtils\FileWatcherEventArgs.cs" />
     <Compile Include="IOUtils\FileUtils\FileCompressTool.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageModel.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageTool.cs" />
+    <Compile Include="IOUtils\FileManUtils\FileWatcher.cs" />
     <Compile Include="IOUtils\TxtUtils\ConfigTool.cs" />
     <Compile Include="NetUtils\NetManUtils\NetConnectionInfo.cs" />
     <Compile Include="NetUtils\NetManUtils\NetFlowService.cs" />
@@ -147,6 +149,7 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.