예제 #1
0
        public async Task DoDownload(string FileName, string PathForDownload = null, string FileID = "")
        {
            GoogleServiceController GSC = new GoogleServiceController();
            DriveService            DS  = GSC.GetDriveService();
            DriveController         dc  = new DriveController(DS);
            string OnlyFileName         = AuxFileCommCenter.GetFileNameOnlyWithFormat(FileName)[0];

            if (string.IsNullOrEmpty(FileID))
            {
                //Find the file
                Dictionary <string, string> FilesInDrive = dc.FindFiles(false);
                FileID = FilesInDrive.Where(x => x.Value == OnlyFileName).First().Key;
            }

            if (!string.IsNullOrEmpty(FileID))
            {
                if (string.IsNullOrEmpty(PathForDownload))
                {
                    await dc.DownloadFile(FileID, FileName);
                }
                else
                {
                    await dc.DownloadFile(FileID, FileName, PathForDownload);
                }
            }
            else
            {
                Console.WriteLine("O Arquivo não foi localizado, abortando a operação.");
            }
        }
        public void DownloadFileMode(string Folder, string FileName, string GoogleDir = "")
        {
            DriveAPIAccess DAA = new DriveAPIAccess();

            DAA = new DriveAPIAccess();
            Console.WriteLine("Iniciando Download Automata");
            string FullPath = AuxFileCommCenter.AdjustPath(Folder, FileName);

            DAA.DoDownload(FullPath).Wait();
        }
        public void UploadFileMode(string Folder, string FileName, string GoogleDir = "")
        {
            DriveAPIAccess DAA = new DriveAPIAccess();

            Console.WriteLine("Iniciando Upload Automata");
            string FullPath = AuxFileCommCenter.AdjustPath(Folder, FileName);

            if (string.IsNullOrEmpty(GoogleDir))
            {
                GoogleDir = null;
            }

            DAA.DoUpload(FullPath, GoogleDir).Wait();
        }
예제 #4
0
        public async Task DeleteFile(string FileName = "", string FileID = "")
        {
            GoogleServiceController GSC = new GoogleServiceController();
            DriveService            DS  = GSC.GetDriveService();
            DriveController         dc  = new DriveController(DS);

            string OnlyFileName = AuxFileCommCenter.GetFileNameOnlyWithFormat(FileName)[0];

            if (string.IsNullOrEmpty(FileID) && string.IsNullOrEmpty(FileName))
            {
                //Find the file
                Dictionary <string, string> FilesInDrive = dc.FindFiles(false);
                FileID = FilesInDrive.Where(x => x.Value == OnlyFileName).First().Key;
            }
            else if (string.IsNullOrEmpty(FileID))
            {
                dc.DeleteFile(DS, FileID);
            }
            else
            {
                Console.WriteLine("Nomes em branco, abortando operação");
            }
        }
        public void HumanControl()
        {
            bool ExecMode = true;

            Console.WriteLine("Bem vindo Humano, como posso te servir?");
            while (ExecMode)
            {
                Console.WriteLine("Selecione com um número uma opção abaixo");
                Console.WriteLine("1 - Listar Arquivos\n2 - Criar Diretorio \n3 - Upload de Arquivo\n4 - Download de Arquivo\n5 - Exclusão de Arquivo\n6 - Sair");

                string op    = Console.ReadLine();
                int    opNum = 0;
                if (int.TryParse(op, out opNum))
                {
                    DriveAPIAccess DAA;
                    bool           continuity = true;
                    switch (opNum)
                    {
                    case 1:
                        Console.Clear();
                        DAA = new DriveAPIAccess();
                        DAA.ShowFiles().Wait();
                        break;

                    case 2:
                        Console.Clear();
                        Console.WriteLine("Bem, dê um nome para o diretório que deseja criar, caso ele já exista ele não será criado!");
                        string newGDriveDir = Console.ReadLine();
                        DAA = new DriveAPIAccess();
                        DAA.CreateGDriveDir(newGDriveDir).Wait();
                        break;

                    case 3:
                        Console.Clear();
                        while (continuity)
                        {
                            Console.WriteLine("Digite o caminho completo do arquivo que deseja subir, incluindo o formato!\nDica: Se você estiver com preguiça, utilize ctrl+c shit+insert para inserir os dados no console");
                            string path = Console.ReadLine();
                            if (AuxFileCommCenter.Exists(path))
                            {
                                Console.WriteLine("Muito bem Humano! Excelente escrita de caminho, Antes de continuar tenho que perguntar, deseja adicionar em algum diretório esse arquivo? Se não quiser apenas pressione Enter.");
                                Console.WriteLine("Lembrando que caso o diretório não exista, ele será criado.");
                                string dir = Console.ReadLine();

                                Console.WriteLine("Ótimo! Seu Arquivo será enviado em breve");

                                if (string.IsNullOrEmpty(dir))
                                {
                                    dir = null;
                                }

                                Thread.Sleep(5000);
                                Console.Clear();
                                DAA = new DriveAPIAccess();
                                DAA.DoUpload(path, dir).Wait();
                                continuity = false;
                                ExecMode   = false;
                            }
                            else
                            {
                                Console.WriteLine("É... o caminho não existe ou o nome do arquivo está incorreto, de qualquer forma, tente novamente!");
                            }
                        }
                        break;

                    case 4:
                        Console.Clear();
                        while (continuity)
                        {
                            Console.WriteLine("Digite o caminho completo do arquivo que deseja baixar, incluindo o formato!\nDica: Se você estiver com preguiça, utilize ctrl+c shit+insert para inserir os dados no console");
                            Console.WriteLine("Lembre-se que para o download, você deve digitar o nome do arquivo igual ao qual você deseja do google drive!\n");
                            string path = Console.ReadLine();
                            if (!string.IsNullOrEmpty(path))
                            {
                                Console.WriteLine("Muito bem Humano! Excelente escrita de caminho, vamos baixar o seu arquivo agora, você deve visualizar o progresso na sua tela em breve!");

                                Thread.Sleep(5000);
                                Console.Clear();
                                DAA = new DriveAPIAccess();
                                DAA.DoDownload(path).Wait();
                                continuity = false;
                                ExecMode   = false;
                            }
                            else
                            {
                                Console.WriteLine("É... o caminho não existe ou o nome do arquivo está incorreto, de qualquer forma, tente novamente!");
                            }
                        }
                        break;

                    case 5:
                        Console.Clear();
                        while (continuity)
                        {
                            Console.WriteLine("Digite o nome do arquivo que deseja excluir, incluindo o formato!\nDica: Se você estiver com preguiça, utilize ctrl+c shit+insert para inserir os dados no console");
                            Console.WriteLine("Lembre-se que você deve digitar o nome do arquivo igual ao qual você deseja excluir do google drive!\n");
                            string path = Console.ReadLine();
                            if (!string.IsNullOrEmpty(path))
                            {
                                Console.WriteLine("Muito bem Humano! Vamos excluir o seu arquivo agora!");
                                Thread.Sleep(1000);
                                Console.Clear();
                                DAA = new DriveAPIAccess();
                                DAA.DeleteFile(path).Wait();
                                continuity = false;
                                ExecMode   = false;
                            }
                            else
                            {
                                Console.WriteLine("É... o nome do arquivo está incorreto, de qualquer forma, tente novamente!");
                            }
                        }
                        break;

                    case 6:
                        Console.WriteLine("Adeus Humano, em breve nos veremos...");
                        ExecMode = false;
                        Environment.Exit(0);
                        break;

                    default:
                        Console.WriteLine("Selecione uma opção válida!");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Selecione uma opção válida!");
                }
            }
        }