private void FileInfo_Refresh(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.RandomTxtFileFullPath; var fiSysIo = new System.IO.FileInfo(file + "-System.IO.txt"); var fiAlphaFS = new Alphaleonis.Win32.Filesystem.FileInfo(file + "-AlphaFS.txt"); Console.WriteLine("System.IO Input File Path: [{0}]", fiSysIo.FullName); Console.WriteLine("AlphaFS Input File Path: [{0}]", fiAlphaFS.FullName); var existsSysIo = fiSysIo.Exists; var exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); var fsSysIo = fiSysIo.Create(); var fsAlphaFS = fiAlphaFS.Create(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); fiSysIo.Refresh(); fiAlphaFS.Refresh(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The file does not exists, but is expected to."); fsSysIo.Close(); fsAlphaFS.Close(); fiSysIo.Delete(); fiAlphaFS.Delete(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The file does not exists, but is expected to."); fiSysIo.Refresh(); fiAlphaFS.Refresh(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); } Console.WriteLine(); }
private void FileInfo_Refresh(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, "FileInfo.Refresh")) { var file = rootDir.RandomFileFullPath; var fiSysIo = new System.IO.FileInfo(file + "-System.IO.txt"); var fiAlphaFS = new Alphaleonis.Win32.Filesystem.FileInfo(file + "-AlphaFS.txt"); Console.WriteLine("\nSystem.IO Input File Path: [{0}]", fiSysIo.FullName); Console.WriteLine("AlphaFS Input File Path: [{0}]", fiAlphaFS.FullName); var existsSysIo = fiSysIo.Exists; var exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); var fsSysIo = fiSysIo.Create(); var fsAlphaFS = fiAlphaFS.Create(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); fiSysIo.Refresh(); fiAlphaFS.Refresh(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The file does not exists, but is expected to."); fsSysIo.Close(); fsAlphaFS.Close(); fiSysIo.Delete(); fiAlphaFS.Delete(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The file does not exists, but is expected to."); fiSysIo.Refresh(); fiAlphaFS.Refresh(); existsSysIo = fiSysIo.Exists; exists = fiAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The file exists, but is expected not to."); } Console.WriteLine(); }
public override void Refresh() { instance.Refresh(); }
private void DumpRefresh(bool isLocal) { #region Setup Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string tempPathSysIo = Path.GetTempPath("FileInfo.Refresh()-file-SysIo-" + Path.GetRandomFileName()); string tempPath = Path.GetTempPath("FileInfo.Refresh()-file-AlphaFS-" + Path.GetRandomFileName()); if (!isLocal) { tempPathSysIo = Path.LocalToUnc(tempPathSysIo); } if (!isLocal) { tempPath = Path.LocalToUnc(tempPath); } Console.WriteLine("\nInput File Path: [{0}]", tempPath); #endregion // Setup #region Refresh try { System.IO.FileInfo fiSysIo = new System.IO.FileInfo(tempPathSysIo); FileInfo fi = new FileInfo(tempPath); bool existsSysIo = fiSysIo.Exists; bool exists = fi.Exists; Console.WriteLine("\nnew FileInfo(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false Assert.AreEqual(existsSysIo, exists); FileStream fsSysIo = fiSysIo.Create(); FileStream fs = fi.Create(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Create(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false Assert.AreEqual(existsSysIo, exists); fiSysIo.Refresh(); fi.Refresh(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Refresh(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fsSysIo.Close(); fs.Close(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Close(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fiSysIo.Delete(); fi.Delete(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Delete(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fiSysIo.Refresh(); fi.Refresh(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Refresh(): Exists (Should be False): [{0}]", exists); // false Assert.AreEqual(existsSysIo, exists); } finally { File.Delete(tempPath); Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed."); File.Delete(tempPathSysIo); Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed."); Console.WriteLine(); } #endregion // Refresh }
private void DumpRefresh(bool isLocal) { #region Setup Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string tempPathSysIo = Path.GetTempPath("FileInfo.Refresh()-file-SysIo-" + Path.GetRandomFileName()); string tempPath = Path.GetTempPath("FileInfo.Refresh()-file-AlphaFS-" + Path.GetRandomFileName()); if (!isLocal) tempPathSysIo = Path.LocalToUnc(tempPathSysIo); if (!isLocal) tempPath = Path.LocalToUnc(tempPath); Console.WriteLine("\nInput File Path: [{0}]", tempPath); #endregion // Setup #region Refresh try { System.IO.FileInfo fiSysIo = new System.IO.FileInfo(tempPathSysIo); FileInfo fi = new FileInfo(tempPath); bool existsSysIo = fiSysIo.Exists; bool exists = fi.Exists; Console.WriteLine("\nnew FileInfo(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false Assert.AreEqual(existsSysIo, exists); FileStream fsSysIo = fiSysIo.Create(); FileStream fs = fi.Create(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Create(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false Assert.AreEqual(existsSysIo, exists); fiSysIo.Refresh(); fi.Refresh(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Refresh(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fsSysIo.Close(); fs.Close(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Close(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fiSysIo.Delete(); fi.Delete(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Delete(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true Assert.AreEqual(existsSysIo, exists); fiSysIo.Refresh(); fi.Refresh(); existsSysIo = fiSysIo.Exists; exists = fi.Exists; Console.WriteLine("\nfi.Refresh(): Exists (Should be False): [{0}]", exists); // false Assert.AreEqual(existsSysIo, exists); } finally { File.Delete(tempPath); Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed."); File.Delete(tempPathSysIo); Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed."); Console.WriteLine(); } #endregion // Refresh }
/// <summary> /// 复制文件 /// </summary> /// <param name="sf"></param> /// <param name="ms"></param> /// <param name="sshOP">SSH output path</param> /// <param name="sftpProxy"></param> private void SSHCopyFile(SftpFile sf, MonitorServer ms, string sshOP, SFTPProxy sftpProxy) { var sshlog = new Common.Util.SSHLogManager(); //获取本地合法路径 string localPath = GetValidLocalPath(sf.FullName, ms.monitorMacPath, ms.monitorLocalPath); //获取SSH输出路径 暂时不支持网络位置 if (string.IsNullOrWhiteSpace(sshOP.Trim())) { localPath = localPath.Substring(0, localPath.IndexOf(':') + 1) + "\\SSH\\" + ms.monitorServerName + "-SSH"; } else { sshOP.TrimEnd('\\'); localPath = localPath.Replace(ms.monitorLocalPath.TrimEnd('\\'), sshOP + "\\" + ms.monitorServerName + "-SSH"); } #region 制 DateTime dateM = sf.Attributes.LastWriteTime; DateTime dateA = sf.Attributes.LastAccessTime; #region try { Alphaleonis.Win32.Filesystem.FileInfo targetFile = new Alphaleonis.Win32.Filesystem.FileInfo(localPath); //如果文件没有发生改变,则不进行下载 if (targetFile.Exists) { if (targetFile.LastWriteTime == dateM) { return; } } if (!Directory.Exists(targetFile.DirectoryName)) { try { Directory.CreateDirectory(targetFile.DirectoryName); } catch (System.Exception) { } if (!Directory.Exists(targetFile.DirectoryName)) { LongPath.CreateDirectory(targetFile.DirectoryName); } } sftpProxy.GetFile(sf.FullName, targetFile.FullName, true); targetFile.Refresh(); if (targetFile.Exists) { targetFile.CreationTime = dateM; targetFile.LastWriteTime = dateM; targetFile.LastAccessTime = dateA; } else { #region string errorDirToFileNameExtension = ""; if (sf.Name.IndexOf(".") > -1) { errorDirToFileNameExtension = sf.Name.Substring(sf.Name.IndexOf(@".") + 1); } Thread.Sleep(2000); bool copyconfirm = true; int confirmCoount = 0; while (copyconfirm) { #region if (confirmCoount < 3) { targetFile.Refresh(); if (targetFile.Exists) { DateTime fileFirstTime = targetFile.LastWriteTime; Thread.Sleep(2000); DateTime fileSecondTime = targetFile.LastWriteTime; if (fileFirstTime.Equals(fileSecondTime)) { targetFile.CreationTime = dateM; targetFile.LastWriteTime = dateM; targetFile.LastAccessTime = dateA; copyconfirm = false; } } else { Thread.Sleep(2000); } confirmCoount++; } else { break; } #endregion } #endregion } sshlog.WriteLog(new Common.Util.SSHLog() { DateTime = DateTime.Now, LogType = Common.Util.SSHLogType.Success, Message = targetFile.FullName }); } catch (ArgumentException ae) { logger.Error("localpath:" + localPath + Environment.NewLine + MessageUtil.GetExceptionMsg(ae, "")); sshlog.WriteLog(new Common.Util.SSHLog() { DateTime = DateTime.Now, LogType = Common.Util.SSHLogType.Failure, Message = ms.monitorServerIP + ", " + sf.FullName }); } catch (System.Exception ex) { logger.Error("localpath:" + localPath + Environment.NewLine + MessageUtil.GetExceptionMsg(ex, "")); sshlog.WriteLog(new Common.Util.SSHLog() { DateTime = DateTime.Now, LogType = Common.Util.SSHLogType.Failure, Message = ms.monitorServerIP + ", " + sf.FullName }); } #endregion #endregion }