protected override void ExecuteAction(IFileActionInfo fileActionInfo) { SourceDestFileInfo info = (SourceDestFileInfo)fileActionInfo; Check(info); File.Move(info.SourceFileName, info.DestinationFileName); }
protected override void RollbackAction(IFileActionInfo fileActionInfo) { SourceDestFileInfo info = (SourceDestFileInfo)fileActionInfo; if (File.Exists(info.DestinationFileName)) { File.Delete(info.DestinationFileName); } }
protected override void RollbackAction(IFileActionInfo fileActionInfo) { SourceDestFileInfo info = (SourceDestFileInfo)fileActionInfo; if (File.Exists(info.DestinationFileName)) { File.Move(info.DestinationFileName, info.SourceFileName); } //Warning: Hm, what we will do if destenation file already exists }
private void Check(SourceDestFileInfo info) { if (Locker.IsLocked(info.DestinationFileName)) { throw new FileIsLockedException(info.DestinationFileName); } // TODO: write normal checking if (!File.Exists(info.SourceFileName)) { throw new FileNotFoundException(info.SourceFileName); } UserFileAccessRightsChecker sourceChecker = new UserFileAccessRightsChecker(info.SourceFileName); if (!sourceChecker.CanRead()) { throw new AccessDeniedException(info.SourceFileName); } if (!sourceChecker.CanDelete()) { throw new AccessDeniedException(info.SourceFileName); } UserFileAccessRightsChecker destDirChecker = new UserFileAccessRightsChecker(Path.GetDirectoryName(info.DestinationFileName)); if (!destDirChecker.CanCreateFiles()) { throw new AccessDeniedException(info.DestinationFileName); } if (File.Exists(info.DestinationFileName)) { /*if (_overwrite) * { * UserFileAccessRightsChecker destFileChecker = new UserFileAccessRightsChecker(info.DestinationFileName ); * if (!destFileChecker.CanDelete()) * throw new AccessDeniedException(info.DestinationFileName ); * } * else * {*/ throw new FileAlreadyExistException(info.DestinationFileName); //} } }
private void Check(SourceDestFileInfo info, bool overwrite) { if (Locker.IsLocked(info.DestinationFileName)) { throw new FileIsLockedException(info.DestinationFileName); } // TODO: write normal checking if (!File.Exists(info.SourceFileName)) { throw new FileNotFoundException(info.SourceFileName); } UserFileAccessRightsChecker sourceChecker = new UserFileAccessRightsChecker(info.SourceFileName); if (!sourceChecker.CanRead()) { throw new AccessDeniedException(info.SourceFileName); } UserFileAccessRightsChecker destChecker = new UserFileAccessRightsChecker(Path.GetDirectoryName(info.DestinationFileName)); if (!destChecker.CanCreateFiles()) { throw new AccessDeniedException(info.DestinationFileName); } if (File.Exists(info.DestinationFileName)) { if (overwrite) { UserFileAccessRightsChecker destFileChecker = new UserFileAccessRightsChecker(info.DestinationFileName); if (!destFileChecker.CanModify()) { throw new AccessDeniedException(info.DestinationFileName); } } else { throw new FileAlreadyExistException(info.DestinationFileName); } } }
public MoveFileAction(string sourceFilePath, string destFilePath) { _fileActionInfo = new SourceDestFileInfo(sourceFilePath, destFilePath); //_overwrite = overwrite; }
public CopyFileAction(string sourceFilePath, string destFilePath, bool overwrite) { _fileActionInfo = new SourceDestFileInfo(sourceFilePath, destFilePath); _overwrite = overwrite; }