private static (bool uploadResult, string uploadResultText) ProcessAlbumDirectory(string path)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    throw new ArgumentException($"The path '{path}' was not found.");
                }

                DirectoryInfo dirInfo    = new DirectoryInfo(path);
                string        albumtitle = dirInfo.Name;

                Console.WriteLine();
                Console.WriteLine($"Uploading Album: {albumtitle}");

                MyAlbum album = new MyAlbum(_logger, service, albumtitle, dirInfo);


                //Does the album already exist?
                if (!album.IsAlbumNew)
                {
                    if (!album.IsAlbumWritable)
                    {
                        return(false, "Album not updated. For safety reasons then album created outside this utility is not updated.");
                    }
                    else
                    {
                        Console.Write("The album already exists, do you want to add any missing images to it? (y/n) ");

                        try
                        {
                            char key = Console.ReadKey().KeyChar;

                            if (key != 'y')
                            {
                                Console.WriteLine();
                                album.UploadStatus = UploadStatusEnum.UploadAborted;
                                return(false, album.ToStringUploadResult());
                            }
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e, "An error occured when evaluating user input");
                            Console.WriteLine();
                            return(false, "An unexpected error occured, check the log");
                        }

                        Console.WriteLine();
                    }
                }


                //Upload the album and images to Google Photos
                bool albumuploadresult = album.UploadAlbum();


                //Upload complete, share the result
                return(true, album.ToStringUploadResult());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An exception occured");

                return(false, $"{path}: An exception occured during Album upload");
            }
        }
示例#2
0
        private (bool uploadResult, string uploadResultText) ProcessAlbumDirectoryUpload(string path, bool?addifalbumexists)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    throw new ArgumentException($"The path '{path}' was not found.");
                }

                DirectoryInfo dirInfo = new DirectoryInfo(path);


                //Verify there is sufficient disk space
                if (!SpaceAvailableForMediaFolder(dirInfo))
                {
                    return(false, "Album not uploaded. Not sufficient storage space in Google Photos.");
                }



                string albumtitle = dirInfo.Name;

                Console.WriteLine();
                Console.WriteLine($"Uploading Album: {albumtitle}");

                MyAlbum album = new MyAlbum(logger, service, albumtitle, dirInfo);


                //Verify the Album has not been cretaed outside this tool
                if (!album.IsAlbumNew && !album.IsAlbumWritable)
                {
                    return(false, "Albums created outside this tool cannot be updated, for safety reasons.");
                }

                //Get User consent to update existing Album
                if (!album.IsAlbumNew)
                {
                    //Ask user if existing Album should be updated, if answer not provided through program args
                    if (addifalbumexists == null)
                    {
                        addifalbumexists = UserGrantedAlbumUpdate();
                    }

                    if (addifalbumexists != true)
                    {
                        album.UploadStatus = UploadStatus.UploadAborted;
                        logger.LogInformation("The album already exists and is not updated.");
                        return(false, album.ToStringUploadResult());
                    }
                }


                //Upload the album and images to Google Photos
                album.UploadAlbum();


                //Upload complete, share the result
                return(true, album.ToStringUploadResult());
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"An exception occured during processing of '{path}'");

                return(false, $"{path}: An exception occured during Album upload");
            }
        }