/// <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; } } }
public void CopyDirectoryTest() { FileInfo[] except = { new FileInfo(@".\FileSystemCopyTest\File1.txt"), new FileInfo(@".\FileSystemCopyTest\File2.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\File1.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\File2.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File1.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File2.txt") }; try { Directory.Delete(@".\FileSystemCopyTest", true); } catch (System.IO.DirectoryNotFoundException) { Console.WriteLine("copy target not found, pass"); } RecursiveDirectoryIterator actual = FSUtil.CopyDirectory(new DirectoryInfo(@".\FileSystemTest\"), new DirectoryInfo(@".\FileSystemCopyTest\")); for (int i = 0; i < 6; i++) { string except_fullpath = except[i].FullName; string actual_fullpath = actual[i].FullName; Assert.AreEqual(except_fullpath, actual_fullpath, "\nexcxept:{0}\nActual{1}", except_fullpath, actual_fullpath); } }
/// <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, "")); } }
public bool Authenticate(NVIdentity identity) { if (string.IsNullOrEmpty(identity.Name) || string.IsNullOrEmpty(identity.Password)) { return(false); } return(FSUtil.Authenticate(identity)); }
/// <summary> /// 此方法暂时放弃 xiecongwen 20150102 /// </summary> private void StartSync() { /** * * 依次扫描监控路径,并判断数据库中是否存在 * */ try { bool isOk = false; foreach (var ms in new DBService.MonitorServerService().GetMonitorServerListWithAttached()) { if (Signal.IsSystemStoping) { break; } DirectoryInfo targetDirInfo = new DirectoryInfo(ms.monitorLocalPath); foreach (FileInfo fi in targetDirInfo.EnumerateFiles("*", SearchOption.AllDirectories)) { if (Signal.IsSystemStoping) { break; } //过滤不必要文件 if (UnnecessaryList.Contains(fi.Name)) { continue; } //判断数据库是否存在 string fullPath = FSUtil.GetFullPath(fi); //if (!IsExistsInDB(fullPath, ms)) //{ // isOk = false; //again: isOk = msQueue.Enqueue(new FileArgs() //{ // MonitorServer = ms, // FileSystemEventArgs = new FileSystemEventArgs(WatcherChangeTypes.Created, ms.monitorLocalPath, fullPath.Substring(ms.monitorLocalPath.Length + 1)) //}); // if (!isOk) // { // //由于文件过多,需要等待一下 // System.Threading.Thread.Sleep(2000); // goto again; // } //} } } } catch (Exception ex) { Common.LogManager.WriteLog(Common.LogFile.Error, MessageUtil.GetExceptionMsg(ex, "")); } }
/// <summary> /// Create a project and return a <c>ProjectInfo</c> object repersent it /// </summary> /// <param name="Name">Project Name</param> /// <param name="ProjectLocation">Where the new project locates</param> /// <returns><c>ProjectInfo</c> represent the created project</returns> virtual public ProjectInfo CreateFormThis(string Name, DirectoryInfo ProjectLocation) { RecursiveDirectoryIterator iter = FSUtil.CopyFilesToDirectory(files, Location, ProjectLocation); ProcessFiles(Name, ref iter); var ret_value = new ProjectInfo(Name, iter.OriginalDirectoryInfo, iter); ret_value.Save(); return(ret_value); }
/// <summary> /// 备份路径 /// </summary> private void BackupPath() { try { //删除原有备份 进行初始化 TruncatePathBk(); //获取路径,并插入 bool isOk = false; foreach (var ms in new DBService.MonitorServerService().GetMonitorServerListWithAttached()) { if (Signal.IsSystemStoping) { break; } DirectoryInfo targetDirInfo = new DirectoryInfo(ms.monitorLocalPath); /** * 此处应当使用 Directory.EnumerateFiles 直接返回路径,这样就不需要用 * FSUtil.GetFullPath 多此一举了 */ foreach (FileInfo fi in targetDirInfo.EnumerateFiles("*", SearchOption.AllDirectories)) { if (Signal.IsSystemStoping) { break; } //过滤不必要文件 由于当文件夹下没有文件时 客户扔希望下载,顾不再过滤 xiecongwen 20150111 //if (UnnecessaryList.Contains(fi.Name)) continue; //将路径放入队列 string fullPath = FSUtil.GetFullPath(fi); PathDesc pd = new PathDesc() { msID = ms.id, relativePath = fullPath.Substring(ms.monitorLocalPath.Length) }; again : isOk = pathQueue.Enqueue(pd); if (!isOk) { //由于文件过多,需要等待一下 System.Threading.Thread.Sleep(200); goto again; } } } } catch (Exception ex) { Common.LogManager.WriteLog(Common.LogFile.Error, MessageUtil.GetExceptionMsg(ex, "")); } }
/// <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); }
/// <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); }
public void RelativeTest() { string _base = "\\dir\\base"; string path1 = "\\dir\\base\\file"; string path2 = "\\dir\\file"; string path3 = "\\file"; string path4 = "\\dir\\base\\sub\\directory\\file"; //common relative Assert.AreEqual("\\file", FSUtil.Relative(_base, path1), "base->path1"); Assert.AreEqual("\\sub\\directory\\file", FSUtil.Relative(_base, path4), "base->path4"); //a little rare? Assert.AreEqual("\\..", FSUtil.Relative(path1, _base), "path1->base"); Assert.AreEqual("\\..\\..\\..", FSUtil.Relative(path4, _base), "path4->base"); //more rare Assert.AreEqual("..\\file", FSUtil.Relative(_base, path2), "base->path2"); Assert.AreEqual("..\\..\\file", FSUtil.Relative(_base, path3), "base->path3"); }
public void CopyDirectoryTest() { FileInfo[] except = { new FileInfo(@".\FileSystemCopyTest\File1.txt"), new FileInfo(@".\FileSystemCopyTest\File2.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\File1.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\File2.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File1.txt"), new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File2.txt") }; Directory.Delete(@".\FileSystemCopyTest", true); RecursiveDirectoryIterator actual = FSUtil.CopyDirectory(new DirectoryInfo(@".\FileSystemTest\"), new DirectoryInfo(@".\FileSystemCopyTest\")); for (int i = 0; i < 6; i++) { string except_fullpath = except[i].FullName; string actual_fullpath = actual[i].FullName; Assert.AreEqual(except_fullpath, actual_fullpath, "\nexcxept:{0}\nActual{1}", except_fullpath, actual_fullpath); } }
protected NVReadRepository(IFSRepository <TFSEntity> rep, IMapper mapper, FSUtil util) : base(rep, mapper, util) { }
public NVArticleQueryBuilder(INVSelectRepository <NVArticle> rep, IMapper mapper, FSUtil fsUtil) : base(rep, mapper, fsUtil) { }
protected NVBaseRepository(IFSRepository <TFSEntity> rep, IMapper mapper, FSUtil fsUtil) { Repository = rep; Mapper = mapper; FSUtil = fsUtil; }
public NVArticleRepository(IFSRepository <IcdArticle> rep, IMapper mapper, FSUtil util) : base(rep, mapper, util) { }
protected NVQueryBuilderBase(INVSelectRepository <TNVEntity> rep, IMapper mapper, FSUtil fsUtil) : base(rep, mapper, fsUtil) { }