123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using Microsoft.Win32;
- using PDF_Office.Model.CloudDrive;
- using PDF_Office.ViewModels.HomePanel.CloudDrive;
- using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace PDF_Office.Views.HomePanel.CloudDrive
- {
- /// <summary>
- /// CloudFilesContent.xaml 的交互逻辑
- /// </summary>
- public partial class CloudFilesContent : UserControl
- {
-
- private CloudFilesContentViewModel ViewModel => DataContext as CloudFilesContentViewModel;
- private List<CloudBoxItem> CloudeDrives = new List<CloudBoxItem>();
- private CloudType cloudType;
- public CloudFilesContent()
- {
- InitializeComponent();
- InitCloudDrive();
- this.Loaded += usercontrol_Loaded;
- }
- private void InitCloudDrive()
- {
- CloudeDrives = Cloud.InitCloudBoxs();
- combCloudDrive.ItemsSource = CloudeDrives;
- combCloudDrive.SelectedIndex = 0;
- }
- private void usercontrol_Loaded(object sender, RoutedEventArgs e)
- {
- if(ViewModel != null)
- {
- ViewModel.CheckDriveUsers();
- if (Listusers.ItemsSource == null)
- Listusers.ItemsSource = Cloud.CloudLists;
- }
- }
- private void combCloudDrive_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var cloudDriveItem = combCloudDrive.SelectedItem as CloudBoxItem;
- if (cloudDriveItem != null)
- {
- ViewModel.CheckDriveCommand.Execute(cloudDriveItem);
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- }
- private UserBaseItem CurrentUser;
- private async void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
- if(cloudFileUser != null)
- {
- CurrentUser = cloudFileUser;
- switch(cloudFileUser.cloudType)
- {
- case CloudType.GoogleDrive:
- if ((CurrentUser as GoogleDriveUserItem) != null)
- {
- var item = CurrentUser as GoogleDriveUserItem;
- var files = await item.GetDriveFiles(item.Service);
- ObservableCollection<GoogleDriveFiles> filesList = new ObservableCollection<GoogleDriveFiles>();
- foreach (var file in files)
- {
- if (file.Name.EndsWith(".pdf") == true)
- {
- filesList.Add(file);
- }
- }
- ListvmFiles.ItemsSource = filesList;
- }
- break;
- case CloudType.DropBox:
- if ((CurrentUser as DropbBoxUserItem) != null)
- {
- var item = CurrentUser as DropbBoxUserItem;
- var files = await item.RefreshList();
- ObservableCollection<DropbBoxFiles> filesList = new ObservableCollection<DropbBoxFiles>();
- foreach (var file in files)
- {
- if (file.Name.EndsWith(".pdf") == true)
- {
- filesList.Add(file);
- }
- }
- ListvmFiles.ItemsSource = filesList;
- }
- break;
- }
-
- }
- }
- private async void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
- {
- var menuItem = sender as MenuItem;
- if (menuItem == null)
- return;
- string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- switch (CurrentUser.cloudType)
- {
- case CloudType.GoogleDrive:
-
- var item = menuItem.DataContext as GoogleDriveFiles;
- if (menuItem == null || item == null)
- return;
- var googleItem = CurrentUser as GoogleDriveUserItem;
- var filename = await googleItem.DownloadGoogleFile(item, docPath);
- if (filename != null)
- {
- string[] filePaths = { filename };
- await Task.Delay(3);
- MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
- parentWindow.LoadPdfViewer(filePaths);
- }
- break;
- case CloudType.DropBox:
- var file = menuItem.DataContext as DropbBoxFiles;
- var dropBoxItem = CurrentUser as DropbBoxUserItem;
- var dropBoxFileName = await dropBoxItem.Download(file.Name, docPath);
- if (dropBoxFileName != null)
- {
- string[] filePaths = { dropBoxFileName };
- await Task.Delay(3);
- MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
- parentWindow.LoadPdfViewer(filePaths);
- }
- break;
- }
-
- }
-
- }
- }
|