123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using PDF_Master.Helper;
- using PDF_Master.Model.CloudDrive;
- using PDF_Master.Properties;
- using PDF_Master.ViewModels.HomePanel.CloudDrive.CloudDriveType;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PDF_Master.ViewModels.HomePanel.CloudDrive
- {
-
- //各云盘的管理类
- //单实例化
- public class CloudDriveManager
- {
- #region 云盘类型
- public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
- public DropbBoxManager DropbBox => DropbBoxManager.DropbBox;
-
- #endregion
- public CloudType cloudType;
- private static CloudDriveManager instance;
- public static CloudDriveManager CloudManager => instance ?? (instance = new CloudDriveManager());
- private CloudDriveManager()
- {
- }
- #region 用户帐号
- /// <summary>
- /// 登录
- /// </summary>
- public async Task<bool> LoginUser(CloudType cloudType)
- {
- switch(cloudType)
- {
- case CloudType.GoogleDrive:
- return await GoogleDrive.LoginUserCount();
- case CloudType.DropBox:
- return await DropbBox.LoginUser();
- }
- return false;
- }
- public async Task<ObservableCollection<FilesBaseItem>> OpenFolder(FileOperation fileOperation)
- {
- ObservableCollection<FilesBaseItem> FilesList = null;
- switch (fileOperation.User.cloudType)
- {
- case CloudType.GoogleDrive:
- {
- var list = GoogleDrive.GetFolder(fileOperation);
- FilesList = new ObservableCollection<FilesBaseItem>();
- foreach (var item in list)
- {
- FilesList.Add(item);
- }
- }
- break;
- case CloudType.DropBox:
- {
- var list = await DropbBox.GetFolder(fileOperation);
- FilesList = new ObservableCollection<FilesBaseItem>();
- foreach (var item in list)
- {
- FilesList.Add(item);
- }
- }
- break;
- }
- return FilesList;
- }
- public async Task<bool> OpenFile(FileOperation fileOperation)
- {
- string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- string tempPath = "";
- switch (fileOperation.User.cloudType)
- {
- case CloudType.GoogleDrive:
- tempPath = GoogleDrive.DownloadGoogleFile(fileOperation, docPath);
- break;
- case CloudType.DropBox:
- tempPath = await DropbBox.DownloadFile(fileOperation, docPath);
- break;
- }
- if(string.IsNullOrEmpty(tempPath) == false)
- {
- string[] filePaths = { tempPath };
- await Task.Delay(3);
- LoadPdfViewer(filePaths);
- }
- return false;
- }
- public void LoadPdfViewer(string[] filePaths)
- {
- var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
- if (filePaths.Count() == 1)
- {
- if (App.OpenedFileList.Contains(filePaths[0]))
- {
- App.mainWindowViewModel.SelectItem(filePaths[0]);
- }
- else
- {
- content.OpenFile(filePaths[0]);
- }
- ToolMethod.SetFileThumbImg(filePaths[0]);
- }
- else
- {
- var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
- if (fileList.Count <= 0)
- return;
- content.OpenFile(filePaths[0]);
- for (int i = 1; i < fileList.Count(); i++)
- {
- if (!App.OpenedFileList.Contains(fileList[i]))
- {
- App.mainWindowViewModel.AddTabItem(fileList[i]);
- }
- ToolMethod.SetFileThumbImg(fileList[i]);
- }
- }
- Settings.Default.Save();
- }
- public bool LoadedUsers()
- {
- bool isUsers = false;
- if (Cloud.CloudLists.Count > 0)
- isUsers = true;
- return isUsers;
- }
- /// <summary>
- /// 移除用户
- /// </summary>
- public async Task<bool> RemoveUser(UserBaseItem user)
- {
- bool result = false;
- switch (user.cloudType)
- {
- case CloudType.GoogleDrive:
- {
- var googleUser = user as GoogleDriveUserItem;
- if(googleUser != null)
- {
- result = await GoogleDrive.RemoveUser(googleUser);
- }
- }
- break;
-
- case CloudType.DropBox:
- {
- var dropBoxUser = user as DropbBoxUserItem;
- if (dropBoxUser != null)
- {
- result = DropbBox.RemoveUser(dropBoxUser);
- }
- }
- break;
- }
- return result;
- }
- #endregion
- #region 文件
- public async Task<bool> UpLoadFile(FileOperation fileOperation)
- {
- bool result = false;
- switch (fileOperation.User.cloudType)
- {
- case CloudType.GoogleDrive:
- {
- var googleUser = fileOperation.User as GoogleDriveUserItem;
- if (googleUser != null)
- {
- result = GoogleDrive.UpLoadFile(fileOperation);
- }
- }
- break;
- case CloudType.DropBox:
- {
- var dropBoxUser = fileOperation.User as DropbBoxUserItem;
- if (dropBoxUser != null)
- {
- result = await DropbBox.UpLoadFile(fileOperation);
- }
- }
- break;
- }
- return result;
- }
-
- #endregion
- }
- }
|