private void Dispose(bool isDisposing) { try { if (isDisposing) { System.IO.Directory.Delete(Directory.FullName, true); } } catch { try { var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(Directory.FullName, Alphaleonis.Win32.Filesystem.PathFormat.FullPath); if (dirInfo.Exists) { dirInfo.Delete(true, true); } } catch (Exception ex) { Console.WriteLine("TemporaryDirectory delete failure. Error: {0}", ex.Message.Replace(Environment.NewLine, string.Empty)); } } }
private void Dispose(bool isDisposing) { try { if (isDisposing) { System.IO.Directory.Delete(Directory.FullName, true); } } catch (Exception ex) { Console.WriteLine("\n\nDelete TemporaryDirectory: [{0}]. Error: [{1}]", Directory.FullName, ex.Message.Replace(Environment.NewLine, string.Empty)); Console.Write("Retry using AlphaFS... "); try { var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(Directory.FullName, Alphaleonis.Win32.Filesystem.PathFormat.FullPath); if (dirInfo.Exists) { dirInfo.Delete(true, true); Console.WriteLine("Success."); } else { Console.WriteLine("TemporaryDirectory was already removed."); } } catch (Exception ex2) { Console.WriteLine("Delete failure TemporaryDirectory. Error: {0}", ex2.Message.Replace(Environment.NewLine, string.Empty)); } } }
static void DeleteDirectory(string dir) { Alphaleonis.Win32.Filesystem.DirectoryInfo di = new Alphaleonis.Win32.Filesystem.DirectoryInfo(dir); RemoveReadonlyAttribute(di); di.Delete(true); return; }
private void DirectoryInfo_Refresh(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.RandomDirectoryFullPath; var diSysIo = new System.IO.DirectoryInfo(folder + "-System.IO"); var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS"); Console.WriteLine("System.IO Input Directory Path: [{0}]", diSysIo.FullName); Console.WriteLine("AlphaFS Input Directory Path: [{0}]", diAlphaFS.FullName); var existsSysIo = diSysIo.Exists; var exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Create(); diAlphaFS.Create(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Delete(); diAlphaFS.Delete(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); } Console.WriteLine(); }
public void DeleteDir(string path) { try { Alphaleonis.Win32.Filesystem.DirectoryInfo di = new Alphaleonis.Win32.Filesystem.DirectoryInfo(path); if (di.Exists) { di.Delete(true); } } catch (System.Exception ex) { LogManager.WriteLog(LogFile.System, MessageUtil.GetExceptionMsg(ex, "")); } }
public override void Delete() { instance.Delete(); }
private void DirectoryInfo_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, "DirectoryInfo.Refresh")) { var folder = rootDir.RandomFileFullPath; var diSysIo = new System.IO.DirectoryInfo(folder + "-System.IO"); var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS"); Console.WriteLine("\nSystem.IO Input Directory Path: [{0}]", diSysIo.FullName); Console.WriteLine("AlphaFS Input Directory Path: [{0}]", diAlphaFS.FullName); var existsSysIo = diSysIo.Exists; var exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Create(); diAlphaFS.Create(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Delete(); diAlphaFS.Delete(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); } Console.WriteLine(); }
public static async Task RemoveGivenFilesAsync(IEnumerable <string> FileList, List <string> DirectoryList = null, Definitions.List.TaskInfo CurrentTask = null) { try { if (CurrentTask != null) { await Task.Delay(5000); } Parallel.ForEach(FileList, currentFile => { FileInfo File = new FileInfo(currentFile); if (File.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingFile)), new { FileName = File.Name, FormattedFileSize = FormatBytes(File.Length) }); } Alphaleonis.Win32.Filesystem.File.SetAttributes(File.FullName, System.IO.FileAttributes.Normal); File.Delete(); } }); if (DirectoryList != null) { Parallel.ForEach(DirectoryList, currentDirectory => { DirectoryInfo Directory = new DirectoryInfo(currentDirectory); if (Directory.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingDirectory)), new { DirectoryName = Directory.Name }); } Directory.Delete(); } }); } if (CurrentTask != null) { CurrentTask.TaskStatusInfo = ""; } } catch (DirectoryNotFoundException ex) { logger.Error(ex); } catch (IOException ex) { logger.Error(ex); } catch (AggregateException ex) { logger.Error(ex); } catch (UnauthorizedAccessException ex) { logger.Error(ex); } catch (Exception ex) { logger.Fatal(ex); } }
protected virtual void Dispose(bool disposing) { if (_isDisposed) { return; } int waitCounter = 1; while (!_processId.HasValue) { Thread.Sleep(TimeSpan.FromMilliseconds(50)); Console.WriteLine("Waiting {0} milliseconds", 50*waitCounter); waitCounter++; } Console.WriteLine("Disposing IIS Express process"); if (disposing) { int? pid; if (_process != null) { pid = _process.Id; Console.WriteLine("Closed IIS Express"); if (!_process.HasExited) { _process.Kill(); } using (_process) Console.WriteLine("Disposed IIS Express"); { } } else { pid = _processId; Console.WriteLine("Process is null"); } if (pid != null) { try { Process process = Process.GetProcessById(pid.Value); using (process) { Console.WriteLine("Killing IIS Express"); if (!process.HasExited) { process.Kill(); } } } catch (Exception ex) { Console.Error.WriteLine("Could not kill process with id {0}, {1}", pid, ex); } } else { Console.WriteLine("Could not find any process id to kill"); } } if (_removeSiteOnExit) { try { if (WebsitePath.Exists) { var directoryInfo = new DirectoryInfo(WebsitePath.FullName); directoryInfo.Delete(true); } } catch (IOException ex) { throw new IOException("Could not delete the website path '" + WebsitePath.FullName + "'", ex); } } _process = null; _processId = null; _isDisposed = true; }