示例#1
0
        private void CopyIfDifferent(string sourcePath, IEnumerable <string> destinationDirs)
        {
            Debug.Assert(fileWrapper.Exists(sourcePath),
                         string.Format(CultureInfo.InvariantCulture, "Could not find the loader .targets file at {0}", sourcePath));

            var sourceContent = fileWrapper.ReadAllText(sourcePath);
            var fileName      = Path.GetFileName(sourcePath);

            foreach (var destinationDir in destinationDirs)
            {
                var destinationPath = Path.Combine(destinationDir, fileName);

                if (!fileWrapper.Exists(destinationPath))
                {
                    directoryWrapper.CreateDirectory(destinationDir); // creates all the directories in the path if needed
                    fileWrapper.Copy(sourcePath, destinationPath, overwrite: false);
                    logger.LogDebug(Resources.MSG_InstallTargets_Copy, fileName, destinationDir);
                }
                else
                {
                    var destinationContent = fileWrapper.ReadAllText(destinationPath);

                    if (!string.Equals(sourceContent, destinationContent, StringComparison.Ordinal))
                    {
                        fileWrapper.Copy(sourcePath, destinationPath, overwrite: true);
                        logger.LogDebug(Resources.MSG_InstallTargets_Overwrite, fileName, destinationDir);
                    }
                    else
                    {
                        logger.LogDebug(Resources.MSG_InstallTargets_UpToDate, fileName, destinationDir);
                    }
                }
            }
        }
示例#2
0
        public string SafeWriteFile(byte[] content, string sourceFileName, string path)
        {
            _directoryWrapper.CreateDirectory(path);
            var outputFile = Path.Combine(path, sourceFileName);

            _fileWrapper.WriteAllBytes(outputFile, content);
            return(outputFile);
        }
示例#3
0
        public void Init()
        {
            _mockFileInfo = Substitute.For <IFileInfoWrapper>();
            _mockFileInfo.Name.Returns("fileInfoName");
            _mockFileInfo.FullName.Returns("fullFileName");
            _mockFileInfo.CreationTime.Returns(new DateTime(2020, 12, 31));
            _mockFileInfo.Extension.Returns(".txt");

            _mockConsole = Substitute.For <IConsoleWrapper>();

            _mockFile = Substitute.For <IFileWrapper>();
            _mockFile.ReadAllText(_mockFileInfo.Name).Returns("5545");

            _mockDirectory = Substitute.For <IDirectoryWrapper>();
            _mockDirectory.CreateDirectory(_mockFileInfo.Name);
            _mockDirectory.GetCreationTime(_mockFileInfo.CreationTime.ToString(CultureInfo.InvariantCulture));

            _target = new TxtHandler(_mockFile, _mockFileInfo, _mockConsole, _mockDirectory);
        }
示例#4
0
        public HttpResponseMessage Move([FromBody] MovePhotosViewModel viewModel)
        {
            if (viewModel == null || string.IsNullOrEmpty(viewModel.AlbumName) || !viewModel.PhotosId.Any())
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Uknown error"));
            }

            var uploadFileInfos = new List <UploadResultViewModel>();

            try
            {
                int albumId;

                try
                {
                    albumId = _albumService.GetAlbumId(User.Id, viewModel.AlbumName);
                }
                catch (AlbumNotFoundException)
                {
                    albumId = _albumService.CreateAlbum(User.Id, viewModel.AlbumName).Id;
                }

                // Get temporary album Id
                int tempAlbumId = _albumService.GetAlbumId(User.Id, "Temporary");

                // Get path to the temporary album folder
                string pathToTempAlbum = _pathUtil.BuildAbsoluteAlbumPath(User.Id, tempAlbumId);

                // Get path to the destination album folder
                string pathToDestAlbum = _pathUtil.BuildAbsoluteAlbumPath(User.Id, albumId);

                if (!_directoryWrapper.Exists(pathToDestAlbum))
                {
                    _directoryWrapper.CreateDirectory(pathToDestAlbum);
                }

                foreach (int photoId in viewModel.PhotosId)
                {
                    PhotoModel photoModel = _photoService.GetPhoto(User.Id, photoId);

                    string fileInTempAlbum = string.Format("{0}\\{1}.{2}", pathToTempAlbum, photoModel.Id,
                                                           photoModel.Format);

                    string fileInDestAlbum = string.Format("{0}\\{1}.{2}", pathToDestAlbum, photoModel.Id,
                                                           photoModel.Format);

                    bool fileExist = _fileWrapper.Exists(fileInTempAlbum);

                    if (fileExist)
                    {
                        try
                        {
                            _fileWrapper.Move(fileInTempAlbum, fileInDestAlbum);
                        }
                        catch (Exception)
                        {
                            uploadFileInfos.Add(new UploadResultViewModel
                            {
                                Id         = photoId,
                                IsAccepted = false,
                                Error      = "Can't save photo to selected album"
                            });

                            continue;
                        }

                        photoModel.AlbumId = albumId;

                        _photoService.UpdatePhoto(photoModel);

                        // Create thumbnails for photo
                        _photoProcessor.CreateThumbnails(User.Id, albumId, photoModel.Id, photoModel.Format);

                        uploadFileInfos.Add(new UploadResultViewModel
                        {
                            Id         = photoId,
                            IsAccepted = true
                        });
                    }
                    else
                    {
                        uploadFileInfos.Add(new UploadResultViewModel
                        {
                            Id         = photoId,
                            IsAccepted = false,
                            Error      = "Photo is not found in temporary album"
                        });
                    }
                }

                // Create collage for album
                _collageProcessor.CreateCollage(User.Id, albumId);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, uploadFileInfos, new JsonMediaTypeFormatter()));
        }
示例#5
0
 public override void Create(string path)
 {
     _directory.CreateDirectory(path);
     _console.WriteLine($"The directory was created successfully at {_directory.GetCreationTime(path)}.");
 }
示例#6
0
 private void CreateDirectoryIfNotExists(string path)
 {
     _directoryWrapper.CreateDirectory(_pathWrapper.GetDirectoryName(path));
 }