GoogleDriveManager.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Google.Apis.Auth.OAuth2;
  2. using Google.Apis.Drive.v3;
  3. using Google.Apis.Services;
  4. using Google.Apis.Util.Store;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace PDF_Office.ViewModels.HomePanel.CloudDrive
  13. {
  14. //多用户UX交互
  15. public class GoogleDriveManager
  16. {
  17. //已登录的用户们
  18. public List<GoogleDriveUserItem> GoogleDriveUsers = new List<GoogleDriveUserItem>();
  19. public GoogleDriveManager()
  20. {
  21. GoogleDriveStatic.GetFilesPathTemp();
  22. GoogleDriveStatic.GetCredentialsPath();
  23. }
  24. #region 请求身份验证
  25. /// <summary>
  26. /// 获取登录过的用户
  27. /// </summary>
  28. public async Task<bool> GetHistoryUsers()
  29. {
  30. var tuples = await GoogleDriveStatic.GetHistoryService();
  31. GoogleDriveUsers.Clear();
  32. foreach (var tuple in tuples)
  33. {
  34. if (tuple != null && tuple.Item1 != null && tuple.Item2 != null)
  35. {
  36. AddGoogleDriveUser(tuple);
  37. }
  38. }
  39. if (GoogleDriveUsers.Count > 0)
  40. {
  41. return true;
  42. }
  43. return false;
  44. }
  45. public async void AddGoogleDriveUser(Tuple<DriveService, UserCredential> tuple)
  46. {
  47. GoogleDriveUserItem user = new GoogleDriveUserItem();
  48. user.Service = tuple.Item1;
  49. user.User.CurrentCredential = tuple.Item2;
  50. user.User.UserAccount = await user.GetUserAcountAsync();
  51. GoogleDriveUsers.Add(user);
  52. }
  53. #endregion
  54. }
  55. }