Esempio n. 1
0
        /// <summary>
        /// 封装MFL对象 并压入队列
        /// </summary>
        /// <param name="file"></param>
        private void InsertMFL(monitorServer ms, FileSystemEventArgs item)
        {
            try
            {
                //根据不同事件类型,封装信息多少有所不同
                switch (item.ChangeType)
                {
                case WatcherChangeTypes.Deleted: { var mfl = GetWhenDeletedType(ms, item); if (mfl != null)
                                                   {
                                                       rqueue.Enqueue(mfl);
                                                   }
                                                   break; }

                case WatcherChangeTypes.Created: { var mfl = GetWhenCreatedType(ms, item); if (mfl != null)
                                                   {
                                                       rqueue.Enqueue(mfl);
                                                   }
                                                   break; }

                case WatcherChangeTypes.Changed: { var mfl = GetWhenChangedType(ms, item); if (mfl != null)
                                                   {
                                                       rqueue.Enqueue(mfl);
                                                   }
                                                   break; }
                }
            }
            catch (Exception ex)
            {
                logger.Error("MFLTableManager" + Environment.NewLine + item.FullPath + Environment.NewLine + MessageUtil.GetExceptionMsg(ex, ""));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 将文件系统信息插入到数据库
        /// </summary>
        public static void BackupFSWithoutCheck(monitorServer ms, FileListenResolver flr)
        {
            DirectoryInfo targetDirInfo = new DirectoryInfo(ms.monitorLocalPath);



            //遍历文件列表
            foreach (var targetFileInfo in targetDirInfo.EnumerateFiles("*", SearchOption.AllDirectories))
            {
                bool isOk = false;

                /*此处向flr发送自制消息
                 *
                 * targetFileInfo.FullName.Substring(0, targetFileInfo.FullName.LastIndexOf('\\')) 是为了保留完整路径信息
                 * 默认情况下.net将怪异的路径修正,造成文件找不到
                 */
                string fullPath = FSUtil.GetFullPath(targetDirInfo);
                again : isOk = flr.OnProcess(new FileSystemEventArgs(WatcherChangeTypes.Created, ms.monitorLocalPath, fullPath.Substring(ms.monitorLocalPath.Length + 1)));
                if (!isOk)
                {
                    //由于文件过多,需要等待一下
                    System.Threading.Thread.Sleep(2000);
                    goto again;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 封装log对象 并压入队列
        /// </summary>
        /// <param name="file"></param>
        private void InsertLog(monitorServer ms, FileSystemEventArgs item)
        {
            //insert log
            try
            {
                FileInfoStruct fi = FSUtil.FindSpecialFileInfo(item.FullPath);

                log logInfo = new log();
                logInfo.monitorServerID   = ms.id;
                logInfo.monitorFileName   = fi.Name;
                logInfo.monitorFileStatus = "正常完了";

                if (item.Name.Contains('\\'))
                {
                    logInfo.monitorFilePath = ms.monitorDrive + "\\" + item.Name.Substring(0, item.Name.LastIndexOf('\\'));
                }
                else
                {
                    logInfo.monitorFilePath = ms.monitorDrive;
                }
                logInfo.monitorFileType = fi.Extension;
                logInfo.monitorFileSize = fi.Length.ToString();
                logInfo.monitorTime     = DateTime.Now;
                logInfo.transferFlg     = (short)1;
                //根据monitorServer 查询backupServerGroup表monitorServerID 获取其id
                logInfo.backupServerGroupID = ms.backupServerGroupID;

                //根据backupServerGroupID 查询backupServerGroupDetail表 获取backupServerID
                logInfo.backupServerID       = ms.backupServerID;
                logInfo.backupServerFileName = fi.Name;

                logInfo.backupServerFilePath = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.backupServerFileType = fi.Extension;
                logInfo.backupServerFileSize = fi.Length.ToString();
                logInfo.backupStartTime      = DateTime.Now;
                logInfo.backupEndTime        = DateTime.Now;
                logInfo.backupTime           = (logInfo.backupEndTime - logInfo.backupStartTime).TotalMilliseconds.ToString() + "ms";
                logInfo.backupFlg            = (short)1;
                logInfo.copyStartTime        = logInfo.backupStartTime;
                logInfo.copyEndTime          = logInfo.backupEndTime;
                logInfo.copyTime             = logInfo.backupTime;

                logInfo.copyFlg = 2;

                logInfo.deleteFlg   = DefaultValue.DEFAULTINT_VALUE;
                logInfo.deleter     = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.deleteDate  = DefaultValue.DEFAULTDATETIME_VALUE;
                logInfo.creater     = "exe";
                logInfo.createDate  = DateTime.Now;
                logInfo.updater     = "exe";
                logInfo.updateDate  = DateTime.Now;
                logInfo.restorer    = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.restoreDate = DefaultValue.DEFAULTDATETIME_VALUE;
                rqueue.Enqueue(logInfo);
            }
            catch (Exception e)
            {
                logger.Error("LogTableManager" + Environment.NewLine + item.FullPath + Environment.NewLine + MessageUtil.GetExceptionMsg(e, ""));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 監視リスト取得
        /// </summary>
        /// <returns></returns>
        public List <monitorServer> GetMonitorServerList()
        {
            List <monitorServer> monitorServerList = new List <monitorServer>();

            try
            {
                string sql = @"select * from monitorServer where deleteFlg = 0 order by id asc";
                using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString,
                                                                      CommandType.Text, sql, null))
                {
                    while (reader.Read())
                    {
                        monitorServer _monitorServer = new monitorServer();
                        _monitorServer.id = int.Parse(reader["id"].ToString());
                        _monitorServer.monitorServerName = reader["monitorServerName"].ToString();
                        _monitorServer.monitorServerIP   = reader["monitorServerIP"].ToString();
                        _monitorServer.monitorSystem     = short.Parse(reader["monitorSystem"].ToString());
                        _monitorServer.account           = reader["account"].ToString();
                        _monitorServer.password          = reader["password"].ToString();
                        _monitorServer.startFile         = reader["startFile"].ToString();
                        _monitorServer.monitorDrive      = reader["monitorDrive"].ToString();
                        _monitorServer.monitorMacPath    = reader["monitorMacPath"].ToString();
                        _monitorServer.monitorLocalPath  = reader["monitorLocalPath"].ToString();
                        monitorServerList.Add(_monitorServer);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            return(monitorServerList);
        }
Esempio n. 5
0
        /// <summary>
        /// 判断文件是否存在
        /// 如果出错,则连续判断三次
        ///
        /// 此方法暂时放弃 xiecongwen 20150102
        /// </summary>
        /// <param name="path"></param>
        /// <param name="ms"></param>
        /// <returns></returns>
        private bool IsExistsInDB(string path, monitorServer ms)
        {
            bool isExists = false;
            int  i        = 2;
            bool isOk     = true;

            do
            {
                try
                {
                    DBService.MonitorFileListenService mflservice = new DBService.MonitorFileListenService();
                    string relativeFullPath = path.Substring(ms.monitorLocalPath.Length);
                    isExists = mflservice.IsPathExists(ms.id, relativeFullPath);
                    isOk     = true;
                }
                catch (Exception ex)
                {
                    Common.LogManager.WriteLog(Common.LogFile.Error, "Path:" + path + Environment.NewLine + MessageUtil.GetExceptionMsg(ex, ""));
                    isExists = false;
                    isOk     = false;
                }
            } while (!isOk && i-- > 0);

            return(isExists);
        }
Esempio n. 6
0
 private void BudBackupCopy_Load(object sender, EventArgs e)
 {
     try
     {
         timer1.Interval = 10000;
         timer1.Elapsed += new System.Timers.ElapsedEventHandler(CheckStart);
         //
         monitorServerList = monitorServerManager.GetMonitorServerList();
         // 対象Binding
         List <ComboBoxItem> cbiList = new List <ComboBoxItem>();
         foreach (monitorServer ms in monitorServerList)
         {
             cbiList.Add(new ComboBoxItem(ms.id.ToString(), ms.monitorServerName));
             monitorServerHashList.Add(ms.id.ToString(), ms);
         }
         this.comboBoxObject.DisplayMember = "Text";
         this.comboBoxObject.ValueMember   = "Value";
         this.comboBoxObject.DataSource    = cbiList;
         // ディフォルトの場合
         monitorServer defaultMonitorServer = (monitorServer)monitorServerHashList[this.comboBoxObject.SelectedValue];
         textBoxJobPath.Text   = @"\\" + defaultMonitorServer.monitorServerIP + @"\" + defaultMonitorServer.startFile.TrimStart('\\');
         textBoxLocalPath.Text = defaultMonitorServer.monitorLocalPath;
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
Esempio n. 7
0
        private void comboBoxObject_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 選択の場合
            monitorServer defaultMonitorServer = (monitorServer)monitorServerHashList[this.comboBoxObject.SelectedValue];

            textBoxJobPath.Text   = @"\\" + defaultMonitorServer.monitorServerIP + @"\" + defaultMonitorServer.startFile.TrimStart('\\');
            textBoxLocalPath.Text = defaultMonitorServer.monitorLocalPath;
        }
Esempio n. 8
0
 /// <summary>
 /// 维护到数据库
 /// </summary>
 public void Handle(monitorServer ms, FileSystemEventArgs item)
 {
     //忽略更新事件
     if (item.ChangeType != WatcherChangeTypes.Changed)
     {
         //封装MFL对象 并压入队列
         InsertMFL(ms, item);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 识别消息,插入到数据库
        /// </summary>
        public void Handle(monitorServer ms, FileSystemEventArgs item)
        {
            if (item.ChangeType == WatcherChangeTypes.Deleted)
            {
                return;
            }

            //封装log对象 并压入队列
            InsertLog(ms, item);
        }
Esempio n. 10
0
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenDeletedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();

            mflinfo.monitorServerID             = ms.id;
            mflinfo.monitorType                 = "削除";
            mflinfo.monitorStatus               = "削除済";
            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;
            mflinfo.deleteDate = DateTime.Now;
            mflinfo.deleteFlg  = 1;
            return(mflinfo);
        }
Esempio n. 11
0
 /// <summary>
 /// 识别消息,插入到数据库
 /// </summary>
 public void Handle(monitorServer ms, FileSystemEventArgs item)
 {
     if (item.ChangeType == WatcherChangeTypes.Changed)
     {
         //判断消息是否有价值
         if (!FileListenHelper.IsMessageValuable(item))
         {
             return;
         }
         //封装log对象 并压入队列
         InsertLog(ms, item);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// 更新事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenChangedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();
            FileInfoStruct    fi      = FSUtil.FindSpecialFileInfo(item.FullPath);

            mflinfo.monitorServerID             = ms.id;
            mflinfo.monitorType                 = "更新";
            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;
            mflinfo.monitorFileSize             = fi.Length.ToString();
            mflinfo.updateDate = DateTime.Now;

            return(mflinfo);
        }
Esempio n. 13
0
        /// <summary>
        /// 顺带获取关联信息
        /// </summary>
        /// <returns></returns>
        public List <monitorServer> GetMonitorServerListWithAttached()
        {
            List <monitorServer> monitorServerList = new List <monitorServer>();

            try
            {
                //此处sql语句保证每个monitorserver只有一条信息
                string sql = @"select *
from(
select ms.*,bsg.id as backupServerGroupID,bsgd.backupServerID,'\\'+backupServer.backupServerIP+'\'+backupServer.startFile as remotePath,ROW_NUMBER() over (PARTITION by ms.id order by ms.id) rowno
from 
	monitorServer ms
left join backupServerGroup bsg on bsg.deleteFlg=0 and ms.id=bsg.monitorServerID 
left join backupServerGroupDetail bsgd on bsgd.deleteFlg=0 and bsgd.backupServerGroupID=bsg.id
inner join backupServer on backupServer.id=bsgd.backupServerID

where ms.deleteFlg=0 
) tmp
where tmp.rowno = 1";

                using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString,
                                                                      CommandType.Text, sql, null))
                {
                    while (reader.Read())
                    {
                        monitorServer _monitorServer = new monitorServer();
                        _monitorServer.id = int.Parse(reader["id"].ToString());
                        _monitorServer.monitorServerName = reader["monitorServerName"].ToString();
                        _monitorServer.monitorServerIP   = reader["monitorServerIP"].ToString();
                        _monitorServer.monitorSystem     = short.Parse(reader["monitorSystem"].ToString());
                        _monitorServer.account           = reader["account"].ToString();
                        _monitorServer.password          = reader["password"].ToString();
                        _monitorServer.startFile         = reader["startFile"].ToString();
                        _monitorServer.monitorDrive      = reader["monitorDrive"].ToString();
                        _monitorServer.monitorMacPath    = reader["monitorMacPath"].ToString();
                        //此处改为远端服务器的UNC路径 201412162316 xiecongwen
                        _monitorServer.monitorLocalPath    = reader["remotePath"].ToString();
                        _monitorServer.backupServerGroupID = Convert.ToInt32(reader["backupServerGroupID"]);
                        _monitorServer.backupServerID      = Convert.ToInt32(reader["backupServerID"]);
                        monitorServerList.Add(_monitorServer);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            return(monitorServerList);
        }
Esempio n. 14
0
        /// <summary>
        /// 更新事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenChangedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();

            Alphaleonis.Win32.Filesystem.FileInfo fi = new Alphaleonis.Win32.Filesystem.FileInfo(item.FullPath);

            if (fi == null)
            {
                return(null);
            }
            mflinfo.monitorServerID             = ms.id;
            mflinfo.monitorType                 = "更新";
            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;
            mflinfo.monitorFileSize             = fi.Length.ToString();
            mflinfo.updateDate = DateTime.Now;

            return(mflinfo);
        }
Esempio n. 15
0
 private void buttonCopyStart_Click(object sender, EventArgs e)
 {
     try
     {
         // 同期のTIMER起動
         timer1.Enabled = true;
         processIDList.Clear();
         EXEDoStartTime = DateTime.Now;
         string datenowDir = DateTime.Now.ToString("yyyy-MM-dd");
         // 今のログフォルダーパス
         string logDirPath = System.AppDomain.CurrentDomain.BaseDirectory + datenowDir;
         if (!Directory.Exists(logDirPath))
         {
             Directory.CreateDirectory(logDirPath);
         }
         // ログクリア
         DeleteFile(logDirPath);
         // BATフォルダーパス
         string batDir     = DateTime.Now.ToString("yyyy-MM-dd") + "Bat";
         string batDirPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir;
         if (!Directory.Exists(batDirPath))
         {
             Directory.CreateDirectory(batDirPath);
         }
         // ログクリア
         DeleteFile(batDirPath);
         // 選択の場合
         monitorServer selectMonitorServer = (monitorServer)monitorServerHashList[this.comboBoxObject.SelectedValue];
         // コピー元
         DirectoryInfo CopySrcDir = new DirectoryInfo(selectMonitorServer.monitorLocalPath);
         // コピー先
         string        targetDirPath = @"\\" + textBoxIP.Text.Trim() + @"\" + textBoxSavePath.Text.Trim().TrimStart('\\');
         DirectoryInfo CopyTargetDir = new DirectoryInfo(targetDirPath);
         if (CopySrcDir.Exists && CopyTargetDir.Exists)
         {
             CopyListen(CopySrcDir.FullName.TrimEnd('\\'), CopyTargetDir.FullName.TrimEnd('\\'), copyListenTime, MTNum, RNum, WNum);
             //XCopy(CopySrcDir.FullName.TrimEnd('\\'), CopyTargetDir.FullName.TrimEnd('\\'));
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
Esempio n. 16
0
        /// <summary>
        /// 创建事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenCreatedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();
            FileInfoStruct    fi      = FSUtil.FindSpecialFileInfo(item.FullPath);

            mflinfo.monitorServerID  = ms.id;
            mflinfo.monitorFileName  = fi.Name;
            mflinfo.monitorType      = "新規";
            mflinfo.monitorServerIP  = ms.monitorServerIP;
            mflinfo.sharePoint       = ms.startFile;
            mflinfo.monitorLocalPath = ms.monitorLocalPath;
            if (item.Name.Contains('\\'))
            {
                mflinfo.monitorFileRelativeDirectory = "\\" + item.Name.Substring(0, item.Name.LastIndexOf('\\'));
            }
            else
            {
                mflinfo.monitorFileRelativeDirectory = "";
            }

            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;

            mflinfo.monitorFileLastWriteTime = fi.LastWriteTime;
            mflinfo.monitorFileSize          = fi.Length.ToString();
            mflinfo.monitorFileExtension     = fi.Extension;

            mflinfo.monitorFileCreateTime     = fi.CreationTime;
            mflinfo.monitorFileLastAccessTime = fi.LastAccessTime;
            mflinfo.monitorStatus             = "転送済";
            mflinfo.monitorFileStartTime      = DateTime.Now;
            mflinfo.monitorFileEndTime        = DateTime.Now;
            mflinfo.deleteFlg  = DefaultValue.DEFAULTINT_VALUE;
            mflinfo.deleter    = DefaultValue.DEFAULTCHAR_VALUE;
            mflinfo.deleteDate = DefaultValue.DEFAULTDATETIME_VALUE;
            mflinfo.creater    = "admin";
            mflinfo.createDate = DateTime.Now;
            mflinfo.updater    = "admin";
            mflinfo.updateDate = DateTime.Now;

            return(mflinfo);
        }
Esempio n. 17
0
 /// <summary>
 /// 放弃此 处理
 /// </summary>
 private void FileCheck(monitorServer ms, FileListenResolver flr)
 {
     try
     {
         #region 维护文件列表数据
         try
         {
             //判断数据库中对应monitorServer是否为空,如果为空 则不进行比较,直接插入
             FileListenService fls = new FileListenService();
             if (fls.IsDBCleared(ms.id))
             {
                 FileListenHelper.BackupFSWithoutCheck(ms, flr);
             }
             else
             {
                 /**
                  * 数据库数据正确性及完整性维护逻辑 20140706 xiecongwen
                  * 进行比较 此处将不使用自制消息,即数据完整性交由数据库实现
                  * 为了提高效率:特将比较逻辑移到内存,即从数据库中取一部分数据
                  *          与文件系统进行比较 看是否存在
                  *
                  * 两边数据相同:1.文件系统没有的,数据库要删除;文件系统有的,数据库要添加
                  *
                  * 难点:查找文件是否在数据库中存在 原因:数据量大,且聚集为id
                  *    从根目录开始:  1.目录下文件2.子目录 依次递归
                  */
             }
         }
         catch (Exception ex)
         {
             logger.Error(MessageUtil.GetExceptionMsg(ex, ""));
         }
         #endregion
     }
     catch (Exception ex)
     {
         logger.Error(MessageUtil.GetExceptionMsg(ex, ""));
     }
 }
Esempio n. 18
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="monitorServerFolder"></param>
 public void Edit(monitorServer monitorServer)
 {
     this.monitorServerService.Edit(monitorServer);
 }
Esempio n. 19
0
 /// <summary>
 /// 维护到数据库
 /// </summary>
 public void Handle(monitorServer ms, FileSystemEventArgs item)
 {
     //封装MFL对象 并压入队列
     InsertMFL(ms, item);
 }
Esempio n. 20
0
 /// <summary>
 /// 创建
 /// </summary>
 /// <param name="ms">监控的服务器</param>
 public FileListenResolver(monitorServer ms)
 {
     this.ms = ms;
 }