Exemplo n.º 1
0
        private void SignIn_Click(object sender, RoutedEventArgs e)
        {
            credential = DriveHandler.LoadCredentials(Scopes);
            service    = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });
            Username.Content         = DriveHandler.PrintUsername(service);
            ChooseFolder.ItemsSource = DriveHandler.FolderList(service);
            var userLogo = DriveHandler.UserLogo(service);

            if (userLogo == "" || userLogo == null)
            {
                Logo.Source = ImageHandler.TextImage(
                    Username.Content.ToString(),
                    new System.Drawing.Font("arial", 12),
                    System.Drawing.Color.Black,
                    System.Drawing.Color.Aquamarine);
            }
            else
            {
                Logo.Source = ImageHandler.LoadImage(userLogo);
            }
        }
Exemplo n.º 2
0
        public async void UploadScreenshot(string filename, string folderName)
        {
            var fileMetadata = new File()
            {
                Name = filename
            };

            if (folderName != "Root folder")
            {
                var parents = new List <string>();
                parents.Add(DriveHandler.FolderId(folderName, service));
                fileMetadata.Parents = parents;
            }
            Debug.WriteLine(filename);
            FilesResource.CreateMediaUpload request;

            using (var stream = new System.IO.FileStream(filename,
                                                         System.IO.FileMode.Open))
            {
                Debug.WriteLine(stream.Name);
                request = service.Files.Create(
                    fileMetadata, stream, "image/png");
                request.Fields = "id";
                await request.UploadAsync();
            }
            var file = request.ResponseBody;

            Log($"Screenshot {filename} uploaded to Google Drive folder {folderName}");
            Debug.WriteLine(filename);
            Debug.WriteLine("File ID: " + file.Id);
            System.IO.File.Delete(filename);
        }
Exemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            // Login to Google account
            credential = DriveHandler.LoadCredentials(Scopes);

            // Create Drive API service.
            if (credential != null)
            {
                service = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                Username.Content         = DriveHandler.PrintUsername(service);
                Logo.Source              = ImageHandler.LoadImage(DriveHandler.UserLogo(service));
                ChooseFolder.ItemsSource = DriveHandler.FolderList(service);
            }

            //Instance of global keyboard hook to
            SetupKeyboardHooks();
        }
Exemplo n.º 4
0
 private void LogOut_Click(object sender, RoutedEventArgs e)
 {
     Username.Content         = DriveHandler.ChangeAccount(credential);
     Logo.Source              = ImageHandler.LoadImage("https://firebasestorage.googleapis.com/v0/b/drive-assets.google.com.a.appspot.com/o/Asset%20-%20Drive%20Icon512.png?alt=media");
     ChooseFolder.ItemsSource = null;
 }