Beispiel #1
0
        // UPDATE PROGRESS
        //------------------------------------------------------------------------------------------------------------
        private static void Request_ProgressChanged(Google.Apis.Upload.IUploadProgress progress, Membros.frmMembro parent)
        {
            long totalSize = 100000;

            switch (progress.Status)
            {
            case Google.Apis.Upload.UploadStatus.Uploading:
            {
                parent.updateStatusBar((progress.BytesSent * 100) / totalSize, "Enviando...");
                break;
            }

            case Google.Apis.Upload.UploadStatus.Completed:
            {
                parent.updateStatusBar(100, "Envio Completo.");
                break;
            }

            case Google.Apis.Upload.UploadStatus.Failed:
            {
                parent.updateStatusBar(0, "Falha no Envio.");
                Gtools.writeToFile(frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + "Falha no Envio.\n");
                break;
            }
            }
        }
Beispiel #2
0
        // EXECUTE FILE DOWNLOAD
        //------------------------------------------------------------------------------------------------------------
        public async static Task DownloadFromDrive(string filename, string fileId, string savePath)
        {
            try
            {
                var request = driveService.Files.Get(fileId);
                var stream  = new System.IO.MemoryStream();
                System.Diagnostics.Debug.WriteLine(fileId);
                await request.DownloadAsync(stream);

                ConvertMemoryStreamToFileStream(stream, savePath + @"\" + @filename);
                stream.Dispose();
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.Message + " Download From Drive Error");
                Gtools.writeToFile(frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Download From Drive.\n");
            }
        }
Beispiel #3
0
        // CONVERT MEMORY STREAM TO FILE STREAM
        //------------------------------------------------------------------------------------------------------------
        private static void ConvertMemoryStreamToFileStream(MemoryStream stream, string savePath)
        {
            FileStream fileStream;

            using (fileStream = new System.IO.FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                try
                {
                    // System.IO.File.Create(saveFile)
                    stream.WriteTo(fileStream);
                    fileStream.Close();
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Debug.WriteLine(exc.Message + " Convert Memory stream Error");
                    Gtools.writeToFile(frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                       Environment.NewLine + exc.Message + " Convert Memory stream Error.\n");
                }
            }
        }
 private void btnLogON_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (txtPassword.Password.Length >= 8)
         {
             password = Gtools.encodeMix(txtPassword.Password, txtPassword.Password);
             parentWindow.changePage(page.Main);
         }
         else
         {
             MessageBox.Show("The Password must contain at least 8 characters",
                             "Log in Error.", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #5
0
        // OBTER CREDENTIAL
        //------------------------------------------------------------------------------------------------------------
        private static bool GetCredential(string clientSecretPath, string userName)
        {
            if (credential != null)
            {
                return(true);
            }

            string savePath = Path.Combine(appDataSavePath, Path.GetFileName(clientSecretPath));

            if (System.IO.File.Exists(savePath))
            {
                try
                {
                    using (var stream = new FileStream(savePath, FileMode.Open, FileAccess.Read))
                    {
                        string credPath = Path.Combine(appDataSavePath, ".credentials");

                        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                            GoogleClientSecrets.FromStream(stream).Secrets,
                            Scopes,
                            "Drive-" + userName,
                            CancellationToken.None,
                            new FileDataStore(credPath, true)).Result;
                    }
                    return(true);
                }
                catch (Exception exc)
                {
                    //--- Write LOG FILE
                    Gtools.writeToFile(frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                       Environment.NewLine + exc.Message + " Get Credential Error.\n");
                    //--- return
                    return(false);
                }
            }
            else
            {
                System.IO.File.Copy(clientSecretPath, Path.Combine(appDataSavePath, Path.GetFileName(clientSecretPath)));
                return(GetCredential(clientSecretPath, userName));
            }
        }
Beispiel #6
0
        // INICIALIZA O SERVICO GOOGLE DRIVE
        //------------------------------------------------------------------------------------------------------------
        private static bool CreateDriveService()
        {
            if (driveService != null)
            {
                return(true);
            }

            try
            {
                // Create Drive API service.
                driveService = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = _ApplicationName,
                });
                return(true);
            }
            catch (Exception exc)
            {
                Gtools.writeToFile(frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Create Drive Service Error.\n");
                return(false);
            }
        }
Beispiel #7
0
        // GET ALL FILES FROM GOOGLE DRIVE AND RETURN LIST
        //------------------------------------------------------------------------------------------------------------
        public static IList <Google.Apis.Drive.v3.Data.File> ListDriveFilesOriginal(string fileName = null, string fileType = null, string parentID = null)
        {
            IList <Google.Apis.Drive.v3.Data.File> filesList = new List <Google.Apis.Drive.v3.Data.File>();

            try
            {
                if (!GoogleDriveConnection())
                {
                    throw new Exception("Não conectado");
                }

                if (fileName == null && fileType == null && parentID == null)
                {
                    FilesResource.ListRequest listRequest = driveService.Files.List();
                    listRequest.PageSize = 1000;
                    listRequest.Fields   = "nextPageToken, files(mimeType, id, name, parents, size, modifiedTime, md5Checksum, webViewLink)";
                    //listRequest.OrderBy = "mimeType";

                    // List files.
                    IList <Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
                    filesList.Clear();

                    foreach (var item in files)
                    {
                        filesList.Add(item);
                    }

                    return(filesList);
                }
                else
                {
                    string pageToken = null;
                    do
                    {
                        FilesResource.ListRequest request = driveService.Files.List();
                        request.PageSize = 1000;
                        //request.Q = "mimeType='image/jpeg'";
                        request.Q = "name contains '" + fileName + "'";

                        if (fileType != null)
                        {
                            request.Q += $"and (mimeType contains '{fileType}')";
                        }

                        if (!string.IsNullOrEmpty(parentID))
                        {
                            request.Q += $" and ('{parentID}' in parents)";
                        }

                        request.Q += " and trashed = false";

                        request.Spaces    = "drive";
                        request.Fields    = "nextPageToken, files(mimeType, id, name, parents, size, modifiedTime, md5Checksum, webViewLink)";
                        request.PageToken = pageToken;
                        var result = request.Execute();

                        foreach (var file in result.Files)
                        {
                            filesList.Add(file);
                        }

                        pageToken = result.NextPageToken;
                    } while (pageToken != null);

                    return(filesList);
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.Message + " Drivefile list Error");
                Gtools.writeToFile(CamadaUI.Main.frmPrincipal.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Drivefile list Error.\n");
            }

            return(filesList);
        }