callm 3 роки тому
батько
коміт
4ad96e5897

+ 2 - 2
FileWatcher/DataHelper.cs

@@ -9,9 +9,9 @@ namespace FileWatcher
     class DataHelper
     {
         //系统默认的的连接字符串
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=SZSI_P;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.0.22)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.0.82)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=SZSI_P;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.0.22)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.0.82)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         public static OracleConnection connection = null;
         OracleCommand command = null;
         int ReconnectTime = 0;

+ 10 - 0
FileWatcher/FileWatcher.csproj

@@ -49,6 +49,13 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="DataHelper.cs" />
+    <Compile Include="ftpOperater.cs" />
+    <Compile Include="测试记录解析.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="测试记录解析.Designer.cs">
+      <DependentUpon>测试记录解析.cs</DependentUpon>
+    </Compile>
     <Compile Include="Form1.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -57,6 +64,9 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="测试记录解析.resx">
+      <DependentUpon>测试记录解析.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Form1.resx">
       <DependentUpon>Form1.cs</DependentUpon>
     </EmbeddedResource>

+ 1 - 1
FileWatcher/Program.cs

@@ -15,7 +15,7 @@ namespace FileWatcher
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new Form1());
+            Application.Run(new 测试记录解析());
         }
     }
 }

+ 399 - 0
FileWatcher/ftpOperater.cs

@@ -0,0 +1,399 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+using System.Text;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace FileWatcher
+{
+    class ftpOperater
+    {
+        //从配置文件读取FTP信息
+        public static string FTPAddress = Properties.Settings.Default.Properties["FTPAddress"].DefaultValue.ToString().Split('|')[0];
+
+        public static string DownLoadTo = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":\" + @"打印标签\";
+
+        private string FTPInf;
+        private string ftpServerIP;
+        private string ftpUser;
+        private string ftpPwd;
+        bool status = false;
+
+        public ftpOperater()
+        {
+            string[] FTPInf = "ftp://10.8.0.82|vsftpd|vsftpd".Split('|');
+            this.ftpServerIP = FTPInf[0];
+            this.ftpUser = FTPInf[1];
+            this.ftpPwd = FTPInf[2];
+            //string FTPInf = Properties.Settings.Default.Properties["FTPAddress"].DefaultValue.ToString();
+
+            //连接共享文件夹
+            //status = BaseUtil.connectState(FTPInf);
+        }
+
+        #region
+        public void UpLoadFile(string filepath, string filename, string UploadFolder)
+        {
+            //上传之前判断文件是否存在
+            string[] filelist = GetFileList();
+            if (filelist != null)
+                for (int i = 0; i < filelist.Length; i++)
+                {
+                    if (filelist[i] == filename)
+                    {
+                        string upload = MessageBox.Show("已存在同名文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                        if (upload.ToString() != "Yes")
+                        {
+                            return;
+                        }
+                    }
+                }
+            FtpWebRequest reqFTP;
+            FtpCheckDirectoryExist(UploadFolder);
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + UploadFolder + filename));
+            reqFTP.UseBinary = true;
+            reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
+            FileInfo file = new FileInfo(filepath + "/" + filename);
+            const int BufferSize = 2048;
+            byte[] content = new byte[BufferSize - 1 + 1];
+            int dataRead;
+            using (FileStream fs = file.OpenRead())
+            {
+                //把上传的文件写入流
+                using (Stream rs = reqFTP.GetRequestStream())
+                {
+                    do
+                    {
+                        //每次读文件流的2KB
+                        dataRead = fs.Read(content, 0, BufferSize);
+                        rs.Write(content, 0, dataRead);
+                    } while (!(dataRead < BufferSize));
+                    rs.Close();
+                }
+                fs.Close();
+            }
+            Thread.Sleep(1000);
+            File.Delete(filepath + "/" + filename);
+        }
+
+        private static void BeginWriteCallBack(IAsyncResult ar)
+        {
+            MemoryStream stream = ar.AsyncState as MemoryStream;
+            if (stream == null) return;
+            byte[] bytes = stream.ToArray();
+            stream.EndWrite(ar);
+            string str = Encoding.UTF8.GetString(bytes);
+            Console.WriteLine(str);
+
+        }
+        #endregion
+
+        public delegate string AsyncMethodCaller(int callDuration, out int threadId);
+
+        private void UploadFileContent() {
+
+
+        }
+
+
+
+        //public void UpLoadFile(string filepath, string filename, string savepath)
+        //{
+        //    if (status)
+        //    {
+        //        //目标路径
+        //        string targetPath = savepath;
+        //        //var file = Directory.GetFiles(targetPath);
+        //        string sourceFile = Path.Combine(filepath + @"\", filename);
+        //        string destFile = Path.Combine(targetPath + @"\", filename);
+        //        //获取指定路径下的全部文件名
+        //        var file = Directory.GetFiles(targetPath);
+        //        string overwrite = "";
+        //        for (int i = 0; i < file.Length; i++)
+        //        {
+        //            if (file[i].Substring(file[i].LastIndexOf(@"\") + 1) == filename)
+        //            {
+        //                overwrite = MessageBox.Show("已存在名为" + filename + "的文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+        //                break;
+        //            }
+        //        }
+        //        if (overwrite == "Yes" || overwrite == "")
+        //        {
+        //            //不存在文件的话进行创建
+        //            if (!Directory.Exists(targetPath))
+        //                Directory.CreateDirectory(targetPath);
+        //            //将文件复制到指定位置
+        //            File.Copy(sourceFile, destFile, true);
+        //        }
+        //        //string sourceFile = Path.Combine(filepath+@"\", filename);
+        //        ////共享文件夹的目录
+        //        //DirectoryInfo theFolder = new DirectoryInfo(savepath);
+        //        ////获取保存文件的路径
+        //        //string fielpath = theFolder.ToString() + @"\";
+        //        ////执行方法
+        //        //BaseUtil.Transport(sourceFile, fielpath, filename);
+        //    }
+        //    else
+        //    {
+        //        //ListBox1.Items.Add("未能连接!");
+        //        MessageBox.Show("共享文件连接错误");
+        //    }
+
+        //}
+
+        /// <summary>
+        /// 获取ftp服务器上的文件信息
+        /// </summary>
+        /// <returns>存储了所有文件信息的字符串数组</returns>
+        public string[] GetFileList()
+        {
+            string[] downloadFiles;
+            StringBuilder result = new StringBuilder();
+            FtpWebRequest reqFTP;
+            try
+            {
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/"));
+                reqFTP.UseBinary = true;
+                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
+                WebResponse response = reqFTP.GetResponse();
+                StreamReader reader = new StreamReader(response.GetResponseStream());
+
+                string line = reader.ReadLine();
+                while (line != null)
+                {
+                    result.Append(line);
+                    result.Append("\n");
+                    line = reader.ReadLine();
+                }
+                result.Remove(result.ToString().LastIndexOf('\n'), 1);
+                reader.Close();
+                response.Close();
+                return result.ToString().Split('\n');
+            }
+            catch (Exception ex)
+            {
+                System.Windows.Forms.MessageBox.Show("获取文件信息失败:" + ex.Message, "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                downloadFiles = null;
+                return downloadFiles;
+            }
+        }
+
+        //获取指定的文件的内容
+        public string GetFileContent(string filename)
+        {
+            FtpWebRequest reqFTP;
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + filename));
+            reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+
+            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+
+            Stream ftpStream = response.GetResponseStream();
+
+            int bufferSize = GetFileContentLength(filename);
+            byte[] buffer = new byte[bufferSize];
+            ftpStream.Read(buffer, 0, bufferSize);
+            ftpStream.Close();
+            return Encoding.Default.GetString(buffer);
+        }
+
+        //获取指定文件的内容的字节长度
+        public int GetFileContentLength(string filename)
+        {
+            FtpWebRequest reqFTP;
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + filename));
+            reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+
+            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+
+            Stream ftpStream = response.GetResponseStream();
+
+            List<byte> buf = new List<byte>();
+            while (ftpStream.ReadByte() != -1)
+            {
+                buf.Add((byte)ftpStream.ReadByte());
+            }
+            ftpStream.Close();
+            return buf.ToArray().Length * 2;
+        }
+
+        /// <summary>
+        /// 获取FTP上指定文件的大小
+        /// </summary>
+        /// <param name="filename">文件名</param>
+        /// <returns>文件大小</returns>
+        public long GetFileSize(string filename)
+        {
+            FtpWebRequest reqFTP;
+            long fileSize = 0;
+            try
+            {
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + filename));
+                reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
+                reqFTP.UseBinary = true;
+                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+                fileSize = response.ContentLength;
+
+                ftpStream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("获取文件大小时,出现异常:\n" + ex.Message, "获取文件大小失败!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            return fileSize;
+        }
+
+        public void FtpCheckDirectoryExist(string destFilePath)
+        {
+            string fullDir = FtpParseDirectory(destFilePath);
+            string[] dirs = fullDir.Split('/');
+            string curDir = "/";
+            for (int i = 0; i < dirs.Length; i++)
+            {
+                string dir = dirs[i];
+                //如果是以/开始的路径,第一个为空    
+                if (dir != null && dir.Length > 0)
+                {
+                    try
+                    {
+                        curDir += dir + "/";
+                        FtpMakeDir(curDir);
+                    }
+                    catch (Exception)
+                    { }
+                }
+            }
+        }
+
+        public string FtpParseDirectory(string destFilePath)
+        {
+            return destFilePath.Substring(0, destFilePath.LastIndexOf("/"));
+        }
+
+        //创建目录  
+        public Boolean FtpMakeDir(string localFile)
+        {
+            FtpWebRequest req = (FtpWebRequest)WebRequest.Create(ftpServerIP + localFile);
+            req.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+            req.Method = WebRequestMethods.Ftp.MakeDirectory;
+            try
+            {
+                FtpWebResponse response = (FtpWebResponse)req.GetResponse();
+                response.Close();
+            }
+            catch (Exception)
+            {
+                req.Abort();
+                return false;
+            }
+            req.Abort();
+            return true;
+        }
+
+
+        /// <summary>
+        /// 实现ftp下载操作
+        /// </summary>
+        /// <param name="fileName">远程文件名</param>
+        public string Download(string fileName)
+        {
+            FtpWebRequest reqFTP;
+            try
+            {
+                FileStream outputStream = new FileStream(DownLoadTo + @"\" + fileName, FileMode.Create);
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + fileName));
+                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+                reqFTP.UseBinary = true;
+                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                reqFTP.UsePassive = true;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+                long cl = response.ContentLength;
+                int bufferSize = 2048;
+                int readCount;
+                byte[] buffer = new byte[bufferSize];
+
+                readCount = ftpStream.Read(buffer, 0, bufferSize);
+                while (readCount > 0)
+                {
+                    outputStream.Write(buffer, 0, readCount);
+                    readCount = ftpStream.Read(buffer, 0, bufferSize);
+                }
+                ftpStream.Close();
+                outputStream.Close();
+                response.Close();
+                return DownLoadTo + @"\" + fileName;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+                return "";
+            }
+        }
+
+
+        public string DownLoadFromSharePath(string URL, string fileName)
+        {
+            //目标路径
+            string targetPath = FTPInf;
+            //var file = Directory.GetFiles(targetPath);
+            string sourceFile = Path.Combine(URL);
+            string destFile = Path.Combine(DownLoadTo, fileName);
+            //不存在文件的话进行创建
+            if (!Directory.Exists(DownLoadTo))
+                Directory.CreateDirectory(DownLoadTo);
+            //将文件复制到指定位置
+            try
+            {
+                File.Copy(sourceFile, destFile, true);
+            }
+            catch
+            {
+                MessageBox.Show("标签文件更新失败,不在指定维护路径" + URL + "中或已被占用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+            }
+            return destFile;
+        }
+
+        /// <summary>
+        /// 删除文件
+        /// </summary>
+        /// <param name="fileName"></param>
+        public void Delete(string fileName)
+        {
+            try
+            {
+                FtpWebRequest reqFTP;
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + fileName));
+                reqFTP.KeepAlive = false;
+                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
+                reqFTP.UseBinary = true;
+                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                reqFTP.UsePassive = true;
+                string result = String.Empty;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                long size = response.ContentLength;
+                Stream datastream = response.GetResponseStream();
+                StreamReader sr = new StreamReader(datastream);
+                result = sr.ReadToEnd();
+                sr.Close();
+                datastream.Close();
+                response.Close();
+                //Buffer.Log(string.Format("Ftp文件{1}删除成功!", DateTime.Now.ToString(), fileName));
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+    }
+}

+ 175 - 0
FileWatcher/测试记录解析.Designer.cs

@@ -0,0 +1,175 @@
+namespace FileWatcher
+{
+    partial class 测试记录解析
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.OperateResult = new System.Windows.Forms.RichTextBox();
+            this.timer1 = new System.Windows.Forms.Timer(this.components);
+            this.Start = new System.Windows.Forms.Button();
+            this.ChooseBackUpFolder = new System.Windows.Forms.Button();
+            this.BackUpFolderPath = new System.Windows.Forms.TextBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.ChooseFolder = new System.Windows.Forms.Button();
+            this.FolderPath = new System.Windows.Forms.TextBox();
+            this.label1 = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.OperateResult.Location = new System.Drawing.Point(38, 15);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(6);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(1336, 580);
+            this.OperateResult.TabIndex = 0;
+            this.OperateResult.Text = "";
+            // 
+            // timer1
+            // 
+            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
+            // 
+            // Start
+            // 
+            this.Start.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.Start.Location = new System.Drawing.Point(631, 800);
+            this.Start.Name = "Start";
+            this.Start.Size = new System.Drawing.Size(141, 40);
+            this.Start.TabIndex = 1;
+            this.Start.Text = "开始监控";
+            this.Start.UseVisualStyleBackColor = true;
+            this.Start.Click += new System.EventHandler(this.Start_Click);
+            // 
+            // ChooseBackUpFolder
+            // 
+            this.ChooseBackUpFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.ChooseBackUpFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ChooseBackUpFolder.Location = new System.Drawing.Point(680, 708);
+            this.ChooseBackUpFolder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.ChooseBackUpFolder.Name = "ChooseBackUpFolder";
+            this.ChooseBackUpFolder.Size = new System.Drawing.Size(156, 48);
+            this.ChooseBackUpFolder.TabIndex = 17;
+            this.ChooseBackUpFolder.Text = "选择文件夹";
+            this.ChooseBackUpFolder.UseVisualStyleBackColor = true;
+            this.ChooseBackUpFolder.Click += new System.EventHandler(this.ChooseBackUpFolder_Click);
+            // 
+            // BackUpFolderPath
+            // 
+            this.BackUpFolderPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.BackUpFolderPath.Enabled = false;
+            this.BackUpFolderPath.Location = new System.Drawing.Point(212, 715);
+            this.BackUpFolderPath.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.BackUpFolderPath.Name = "BackUpFolderPath";
+            this.BackUpFolderPath.Size = new System.Drawing.Size(436, 35);
+            this.BackUpFolderPath.TabIndex = 16;
+            // 
+            // label2
+            // 
+            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label2.Location = new System.Drawing.Point(42, 712);
+            this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(162, 38);
+            this.label2.TabIndex = 15;
+            this.label2.Text = "备份文件夹";
+            // 
+            // ChooseFolder
+            // 
+            this.ChooseFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.ChooseFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ChooseFolder.Location = new System.Drawing.Point(680, 626);
+            this.ChooseFolder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.ChooseFolder.Name = "ChooseFolder";
+            this.ChooseFolder.Size = new System.Drawing.Size(156, 48);
+            this.ChooseFolder.TabIndex = 14;
+            this.ChooseFolder.Text = "选择文件夹";
+            this.ChooseFolder.UseVisualStyleBackColor = true;
+            this.ChooseFolder.Click += new System.EventHandler(this.ChooseFolder_Click);
+            // 
+            // FolderPath
+            // 
+            this.FolderPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.FolderPath.Enabled = false;
+            this.FolderPath.Location = new System.Drawing.Point(212, 632);
+            this.FolderPath.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.FolderPath.Name = "FolderPath";
+            this.FolderPath.Size = new System.Drawing.Size(436, 35);
+            this.FolderPath.TabIndex = 13;
+            // 
+            // label1
+            // 
+            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(42, 626);
+            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(162, 38);
+            this.label1.TabIndex = 12;
+            this.label1.Text = "监控文件夹";
+            // 
+            // 测试记录解析
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1402, 856);
+            this.Controls.Add(this.ChooseBackUpFolder);
+            this.Controls.Add(this.BackUpFolderPath);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.ChooseFolder);
+            this.Controls.Add(this.FolderPath);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.Start);
+            this.Controls.Add(this.OperateResult);
+            this.Margin = new System.Windows.Forms.Padding(6);
+            this.Name = "测试记录解析";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "测试文件监控";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.RichTextBox OperateResult;
+        private System.Windows.Forms.Timer timer1;
+        private System.Windows.Forms.Button Start;
+        private System.Windows.Forms.Button ChooseBackUpFolder;
+        private System.Windows.Forms.TextBox BackUpFolderPath;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Button ChooseFolder;
+        private System.Windows.Forms.TextBox FolderPath;
+        private System.Windows.Forms.Label label1;
+    }
+}
+

+ 180 - 0
FileWatcher/测试记录解析.cs

@@ -0,0 +1,180 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Diagnostics;
+using System.IO;
+using System.Text;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace FileWatcher
+{
+    public partial class 测试记录解析 : Form
+    {
+
+        DataHelper dh = new DataHelper();
+
+        public 测试记录解析()
+        {
+            InitializeComponent();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            timer1.Interval = 1000 * 10;
+            timer1.Start();
+        }
+
+        public void DoLog(string Message)
+        {
+            try
+            {
+                StreamWriter sw = File.AppendText(DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Message + "\n");
+                sw.Close();
+            }
+            catch (Exception) { }
+        }
+
+        /// <summary>
+        /// 私有变量
+        /// </summary>
+        private List<FileInfo> lst = new List<FileInfo>();
+        /// <summary>
+        /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
+        /// </summary>
+        /// <param name="path">文件夹路径</param>
+        /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
+        /// <returns>List<FileInfo></returns>
+        public List<FileInfo> getFile(string path, string extName)
+        {
+            getdir(path, extName);
+            return lst;
+        }
+
+        /// <summary>
+        /// 私有方法,递归获取指定类型文件,包含子文件夹
+        /// </summary>
+        /// <param name="path"></param>
+        /// <param name="extName"></param>
+        private void getdir(string path, string extName)
+        {
+            try
+            {
+                string[] dir = Directory.GetDirectories(path); //文件夹列表   
+                DirectoryInfo fdir = new DirectoryInfo(path);
+                FileInfo[] file = fdir.GetFiles();
+                //FileInfo[] file = Directory.GetFiles(path); //文件列表   
+                if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空                   
+                {
+                    foreach (FileInfo f in file) //显示当前目录所有文件   
+                    {
+                        if (f.FullName.Contains("SN_"))
+                        {
+                          
+                            Console.WriteLine(f.FullName);
+                            StreamReader sr = new StreamReader(f.FullName);
+                            while (!sr.EndOfStream)
+                            {
+                                string val = sr.ReadLine();
+                                string type = val.Split(':')[0].Trim();
+                                string value = val.Split(':')[1].Trim();
+                                dh.ExecuteSql("insert into windowsninfo(ws_id,ws_sncode,ws_type,ws_value)values(windowsninfo_seq.nextval,'" + f.Name + "','"+type+"','"+value+"')", "insert");
+                            }
+                            sr.Close();
+                        }
+                        //if (f.Attributes.ToString().IndexOf("Hidden") > -1 && f.Attributes.ToString().IndexOf("System") > -1)
+                        //{
+
+                        //}
+                        //else
+                        //{
+                        //    if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
+                        //    {
+                        //        lst.Add(f);
+                        //    }
+                        //}
+                    }
+                    foreach (string d in dir)
+                    {
+                        Console.WriteLine(d);
+                        getdir(d, extName);//递归   
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            getFile(FolderPath.Text, ".log");
+        }
+
+        /// <summary>
+        /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
+        /// </summary>
+        /// <param name="path">文件夹路径</param>
+        /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
+        /// <returns>List<FileInfo></returns>
+        public static List<FileInfo> getFile(string path, string extName, List<FileInfo> lst)
+        {
+            try
+            {
+                string[] dir = Directory.GetDirectories(path); //文件夹列表  
+                DirectoryInfo fdir = new DirectoryInfo(path);
+                FileInfo[] file = fdir.GetFiles();
+                //FileInfo[] file = Directory.GetFiles(path); //文件列表  
+                if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空          
+                {
+                    foreach (FileInfo f in file) //显示当前目录所有文件  
+                    {
+                        if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
+                        {
+                            lst.Add(f);
+                        }
+                    }
+                    foreach (string d in dir)
+                    {
+                        getFile(d, extName, lst);//递归  
+                    }
+                }
+                return lst;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        private void ChooseFolder_Click(object sender, EventArgs e)
+        {
+            FolderBrowserDialog folder = new FolderBrowserDialog();
+            folder.Description = "选择监控文件夹";
+            DialogResult result = folder.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                FolderPath.Text = folder.SelectedPath;
+            }
+        }
+
+        private void ChooseBackUpFolder_Click(object sender, EventArgs e)
+        {
+            FolderBrowserDialog folder = new FolderBrowserDialog();
+            folder.Description = "选择备份文件夹";
+            DialogResult result = folder.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                BackUpFolderPath.Text = folder.SelectedPath;
+            }
+        }
+
+        private void Start_Click(object sender, EventArgs e)
+        {
+            timer1.Start();
+        }
+    }
+}

+ 123 - 0
FileWatcher/测试记录解析.resx

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>228, 17</value>
+  </metadata>
+</root>