예제 #1
0
        protected override void ExecuteAction(IFileActionInfo fileActionInfo)
        {
            SourceDestFileInfo info = (SourceDestFileInfo)fileActionInfo;

            Check(info);
            File.Move(info.SourceFileName, info.DestinationFileName);
        }
예제 #2
0
        protected override void RollbackAction(IFileActionInfo fileActionInfo)
        {
            SourceDestFileInfo info = (SourceDestFileInfo)fileActionInfo;

            if (File.Exists(info.DestinationFileName))
            {
                File.Delete(info.DestinationFileName);
            }
        }
예제 #3
0
        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
        }
예제 #4
0
        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);
                //}
            }
        }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
 public MoveFileAction(string sourceFilePath, string destFilePath)
 {
     _fileActionInfo = new SourceDestFileInfo(sourceFilePath, destFilePath);
     //_overwrite = overwrite;
 }
예제 #7
0
 public CopyFileAction(string sourceFilePath, string destFilePath, bool overwrite)
 {
     _fileActionInfo = new SourceDestFileInfo(sourceFilePath, destFilePath);
     _overwrite      = overwrite;
 }