public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var photosetId = _flickrClient.PhotosetsGetList().FirstOrDefault(x => x.Title == request.PhotosetName)?.PhotosetId; // create photoset if not exists // this adds already photoToPhotoset -> no additional photo addtion needed if (string.IsNullOrEmpty(photosetId)) { photosetId = await _mediator.Execute(new CreatePhotoset.Command(request.PhotosetName, request.PhotoId)); _mediator.Publish(new PhotoAddedAsMainToPhotosetEvent() { Id = request.PhotoId, PhotosetId = photosetId }); return(Unit.Value); } if (string.IsNullOrEmpty(photosetId)) { throw new UnableToCreatePhotoSetException($"Unable to retreive {request.PhotosetName} photoset."); } _flickrClient.AddPhotoToPhotoset(request.PhotoId, photosetId); _mediator.Publish(new PhotoAddedToPhotosetEvent() { Id = request.PhotoId, PhotosetId = photosetId }); return(Unit.Value); }
public async Task Run() { // 1) Authenticate // 2) Init - upload all photos not in photosets already // 3) Watch - upload any newly added photos while app is running - TODO await _mediator.Execute(new AuthenticateUser.Command()); Log.Information("Starting image upload from {Folder} folder.", ApplicationSettings.PhotoPath); await _mediator.Execute(new UploadFolder.Command() { Path = ApplicationSettings.PhotoPath }); Log.Information("All done! Pres any key to end the application :)"); System.Console.ReadKey(); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var dirInfo = _fileSystem.DirectoryInfo.FromDirectoryName(request.FolderPath); var photosetName = dirInfo.Name; if (!dirInfo.Exists) { Log.Error("Folder {FolderName} does not exist!", request.FolderPath); return(Unit.Value); } var photosToUpload = dirInfo.EnumerateFiles("*.jpg").ToList(); if (!photosToUpload.Any()) { Log.Debug("No photos found in {PhotoFolder}", request.FolderPath); return(Unit.Value); } // remove any already already uploaded photos - checking by photo title at the moment var photosetId = _flickrClient.PhotosetsGetList().FirstOrDefault(x => x.Title == photosetName)?.PhotosetId; if (photosetId != null) { var photosInPhotoset = _flickrClient.GetPhotoNamesInPhotoset(photosetId); Log.Information("Album already exists in Flickr with {Photos}. These are not being uploaded again.", photosInPhotoset); photosToUpload.RemoveAll(x => photosInPhotoset.Contains(Path.GetFileNameWithoutExtension(x.FullName))); if (!photosToUpload.Any()) { Log.Information("All photos from {PhotoFolder} has been uploaded already.", request.FolderPath); return(Unit.Value); } } _mediator.Publish(new UploadOfPhotosStarted(request.FolderPath, photosToUpload.Count)); // upload photos one by one Log.Information("Uploading {PhotoCount} photos located in {Folder} folder. {Photos}", photosToUpload.Count, request.FolderPath, photosToUpload.Select(x => x.Name)); foreach (var photo in photosToUpload) { await _mediator.Execute(new UploadPhoto.Command() { Path = photo.FullName, PhotosetName = photosetName }); } _mediator.Publish(new PhotosFromFolderUploadedEvent() { Id = request.FolderPath }); return(Unit.Value); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var dirInfo = _fileSystem.DirectoryInfo.FromDirectoryName(request.Path); if (!dirInfo.Exists) { Log.Error("Folder {FolderName} does not exist!", request.Path); return(Unit.Value); } if (!dirInfo.HasWritePermisssion()) { Log.Error("Missing write rights to folder {FolderName}!", request.Path); return(Unit.Value); } // upload photos from all sub-folders foreach (var directory in dirInfo.EnumerateDirectories()) { await _mediator.Execute(new UploadFolder.Command() { Path = directory.FullName }); } // Upload all photos in folder await _mediator.Execute(new UploadPhotosFromFolder.Command() { FolderPath = request.Path }); _mediator.Publish(new FolderUploadedEvent() { Id = request.Path }); Log.Information("Upload of all photos within folder {FolderPath} is finished!", request.Path); return(Unit.Value); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { // upload photo var id = _flickrClient.UploadPicture(request.Path, Path.GetFileNameWithoutExtension(request.Path)); // add photo to photoset await _mediator.Execute(new AddPhotoToPhotoset.Command() { PhotoId = id, PhotosetName = request.PhotosetName }); _mediator.Publish(new PhotoUploadedEvent() { Id = id, PhotoSet = request.PhotosetName }); return(Unit.Value); }