فهرست منبع

云文档 - 下载打开云文档

chenrongqian 2 سال پیش
والد
کامیت
bb6dc70cbe

+ 13 - 0
PDF Office/Model/CloudDrive/CloudFiles.cs

@@ -15,14 +15,27 @@ namespace PDF_Office.Model.CloudDrive
 
     #region GooglrDrive
 
+    public class CloudFileUser
+    {
+        public User user { get; set; }
+        public UserBaseItem driveItem{ get; set; }
+    }
+
     public class User
     {
+        public CloudType cloudType { get; set; }
         public string Name { get; set; }
         public int Id { get; set; }
 
         public string UserAccount { get; set; }
     }
 
+    public class UserBaseItem
+    {
+      
+    }
+
+
     //谷歌云盘的文件
     public class GoogleDriveFiles
     {

+ 2 - 8
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveContentViewModel.cs

@@ -18,18 +18,12 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
 
         private CloudDriveManager Manager =>CloudDriveManager.GetInstance();
         public event EventHandler<bool> IshowContentHandler;
-        ///   public DelegateCommand CheckDriveCommand { get; set; }
-        // public DelegateCommand OpenCloudDriveCommand { get; set; }
+      
         public CloudDriveContentViewModel()
         {
-           
             CheckDriveCommand = new DelegateCommand<CloudDriveItem>(CheckDrive);
-
             CheckDriveLoginUserCommand = new DelegateCommand<CloudDriveItem>(CheckDriveLoginUser);
-
-
-            //    OpenCloudDriveCommand = new DelegateCommand(OpenCloudDrive_Click);
-
+          
         }
 
         public void LoadUsers()

+ 6 - 6
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveManager.cs

@@ -8,12 +8,13 @@ using System.Threading.Tasks;
 
 namespace PDF_Office.ViewModels.HomePanel.CloudDrive
 {
+   
     //各云盘的管理类
     //单实例化
     public class CloudDriveManager
     {
-        public GoogleDriveManager GoogleDrive;
-        public DropbBoxManager DropbBox;
+       public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
+       // public DropbBoxManager DropbBox;
         public CloudType cloudType;
 
         private static CloudDriveManager instance;
@@ -27,8 +28,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         }
         private CloudDriveManager()
         {
-            GoogleDrive = new GoogleDriveManager();
-            DropbBox = new DropbBoxManager();
+         //   DropbBox = new DropbBoxManager();
         }
 
 
@@ -42,7 +42,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
             switch(cloudType)
             {
                 case CloudType.GoogleDrive:
-                   return await GoogleDrive.LoginUderCount();
+                   return await GoogleDrive.LoginUserCount();
             }
             return false;
         }
@@ -50,7 +50,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         public bool LoadedUsers()
         {
             bool isUsers = false;
-            if(GoogleDrive.GoogleDriveUsers.Count > 0)
+            if (CloudFilesContentViewModel.CloudFileUserLists.Count > 0)
                 isUsers = true;
 
             return isUsers;

+ 3 - 0
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/DropbBoxManager.cs

@@ -12,6 +12,9 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
     public class DropbBoxManager
     {
+        private static DropbBoxManager instance;
+        public static DropbBoxManager DropbBox => instance ?? (instance = new DropbBoxManager());
+
         public DropbBoxManager()
         {
         }

+ 52 - 19
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/GoogleDriveManager.cs

@@ -2,8 +2,10 @@
 using Google.Apis.Drive.v3;
 using Google.Apis.Services;
 using Google.Apis.Util.Store;
+using PDF_Office.Model.CloudDrive;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.IO;
 using System.Linq;
 using System.Text;
@@ -15,12 +17,12 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
     //多用户UX交互
     public class GoogleDriveManager
     {
-
         //已登录的所有用户
-        public List<GoogleDriveUserItem> GoogleDriveUsers = new List<GoogleDriveUserItem>();
-
+     //   public ObservableCollection<CloudFileUser> GoogleDriveUsers = new ObservableCollection<CloudFileUser>();
 
-        public GoogleDriveManager()
+        private static GoogleDriveManager instance;
+        public static GoogleDriveManager GoogleDrive => instance ?? (instance = new GoogleDriveManager());
+        private GoogleDriveManager()
         {
              GoogleDriveStatic.GetFilesPathTemp();
              GoogleDriveStatic.GetCredentialsPath();
@@ -34,7 +36,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         public async Task<bool> GetHistoryUsers()
         {
             var tuples = await GoogleDriveStatic.GetHistoryService();
-            GoogleDriveUsers.Clear();
+            CloudFilesContentViewModel.CloudFileUserLists.Clear();
             foreach (var tuple in tuples)
             {
 
@@ -44,7 +46,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                 }
             }
 
-            if (GoogleDriveUsers.Count > 0)
+            if (CloudFilesContentViewModel.CloudFileUserLists.Count > 0)
             {
                 return true;
             }
@@ -53,28 +55,59 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
         public async void AddGoogleDriveUser(Tuple<DriveService, UserCredential> tuple)
         {
-            GoogleDriveUserItem userItem = new GoogleDriveUserItem();
+            CloudFileUser cloudFileUser = new CloudFileUser();
+           GoogleDriveUserItem userItem = new GoogleDriveUserItem();
             userItem.Service = tuple.Item1;
             userItem.CurrentCredential = tuple.Item2;
-            userItem.User.UserAccount = await userItem.GetUserAcountAsync();
-            GoogleDriveUsers.Add(userItem);
+            cloudFileUser.driveItem = userItem;
+          
+            User user = new User();
+            user.UserAccount = await userItem.GetUserAcountAsync();
+            user.cloudType = CloudType.GoogleDrive;
+            cloudFileUser.user = user;
+
+            CloudFilesContentViewModel.CloudFileUserLists.Add(cloudFileUser);
         }
 
-        public async Task<bool> LoginUderCount()
+        public async Task<bool> LoginUserCount()
         {
-           var tuple = await GoogleDriveStatic.GetServiceAsync();
-
+            var tuple = await GoogleDriveStatic.GetServiceAsync();
+            bool result = false;
             if (tuple != null)
             {
+                result = true;
+
+           //     Task.Run(async () =>
+           //     {
+
+                    await GetUserInfo(tuple);
+           //     });
 
-                GoogleDriveUserItem userItem = new GoogleDriveUserItem();
-                userItem.Service = tuple.Item1;
-                userItem.CurrentCredential = tuple.Item2;
-                userItem.User.UserAccount = await userItem.GetUserAcountAsync();
-                GoogleDriveUsers.Add(userItem);
-                return true;
             }
-            return false;
+
+            return result;
+        }
+
+        public async Task<bool> GetUserInfo(Tuple<DriveService, UserCredential> tuple)
+        {
+            CloudFileUser cloudFileUser = new CloudFileUser();
+            GoogleDriveUserItem userItem = new GoogleDriveUserItem();
+            userItem.Service = tuple.Item1;
+            userItem.CurrentCredential = tuple.Item2;
+            cloudFileUser.driveItem = userItem;
+
+            User user = new User();
+            user.UserAccount = await userItem.GetUserAcountAsync();
+            user.cloudType = CloudType.GoogleDrive;
+            cloudFileUser.user = user;
+
+            CloudFilesContentViewModel.CloudFileUserLists.Add(cloudFileUser);
+            //GoogleDriveUserItem userItem = new GoogleDriveUserItem();
+            //userItem.Service = tuple.Item1;
+            //userItem.CurrentCredential = tuple.Item2;
+            //userItem.User.UserAccount = await userItem.GetUserAcountAsync();
+            //CloudFilesContentViewModel.CloudFileUserLists.Add(userItem);
+            return true;
         }
 
         public async Task<bool> RemoveUser(GoogleDriveUserItem userIttem)

+ 6 - 6
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/GoogleDriveUserItem.cs

@@ -18,9 +18,9 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
     /// <summary>
     /// 对单账号处理的核心功能类
     /// </summary>
-    public class GoogleDriveUserItem
+    public class GoogleDriveUserItem: UserBaseItem
     {
-        public User User { get;  set; }
+       
         public  DriveService Service { get; set; }//Google提供服务
         private List<GoogleDriveFiles> FilesList = new List<GoogleDriveFiles>();//文件
 
@@ -28,7 +28,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
         public GoogleDriveUserItem()
         {
-            User = new User();
+         //   User = new User();
             
         }
       
@@ -99,7 +99,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                 return null;
 
             // define parameters of request.
-            FilesResource.ListRequest FileListRequest = service.Files.List();
+            FilesResource.ListRequest FileListRequest = service.Files.List(); 
 
             //listRequest.PageSize = 10;
             //listRequest.PageToken = 10;
@@ -113,7 +113,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
             {
                 foreach (var file in files)
                 {
-                    GoogleDriveFiles File = new GoogleDriveFiles
+                       GoogleDriveFiles File = new GoogleDriveFiles
                     {
                         Id = file.Id,
                         Name = file.Name,
@@ -238,7 +238,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
     {
         public static string[] Scopes = { DriveService.Scope.Drive };
         //Google Drive应用名称
-        private static readonly string GoogleDriveAppName = "PDF Office";
+        private static readonly string GoogleDriveAppName = "PDF Office848";
         //请求应用进行身份验证的信息
         public static string CredentialsPath { get; private set; }
 

+ 7 - 4
PDF Office/ViewModels/HomePanel/CloudDrive/CloudFilesContentViewModel.cs

@@ -1,8 +1,10 @@
-using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
 using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -12,8 +14,9 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
     //各云盘事件
     public class CloudFilesContentViewModel : BindableBase
     {
-     //   public GoogleDriveManager GoogleDrive;
-        public GoogleDriveManager Manager;
+        public static ObservableCollection<CloudFileUser> CloudFileUserLists = new ObservableCollection<CloudFileUser>();
+        public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
+        public DropbBoxManager DropbBox => DropbBoxManager.DropbBox;
         public DelegateCommand OpenCloudDriveCommand { get; set; }
         public DelegateCommand CheckDriveUsersCommand { get; set; }
 
@@ -21,7 +24,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
       //  public event EventHandler<bool> isFoundUserHandler;
         public CloudFilesContentViewModel()
         {
-            Manager = new GoogleDriveManager(); 
+          //  Manager = new GoogleDriveManager(); 
          //   GoogleDrive = new GoogleDriveManager();
 
             OpenCloudDriveCommand = new DelegateCommand(OpenCloudDrive_Click);

+ 2 - 2
PDF Office/ViewModels/HomePanel/HomeCloudContentViewModel.cs

@@ -13,12 +13,12 @@ namespace PDF_Office.ViewModels.HomePanel
 {
     public class HomeCloudContentViewModel:BindableBase
     {
-        public GoogleDriveManager googleDriveManager;
+     //   public GoogleDriveManager googleDriveManager;
         
         public DelegateCommand<CloudDriveItem> OpenCloudDriveCommand { get; set; }
         public HomeCloudContentViewModel()
         {
-            googleDriveManager = new GoogleDriveManager();
+         //   googleDriveManager = new GoogleDriveManager();
             OpenCloudDriveCommand = new DelegateCommand<CloudDriveItem>(OpenCloudDrive_Click);
         }
 

+ 39 - 11
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml

@@ -8,10 +8,36 @@
              xmlns:local="clr-namespace:PDF_Office.Views.HomePanel.CloudDrive"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
+    <UserControl.Resources>
+        <ContextMenu x:Key="FlyoutMenu" FontSize="14"
+                         >
+            <ContextMenu.ItemContainerStyle>
+                <Style TargetType="MenuItem">
+                    <Setter Property="Padding" Value="0,7,0,7"/>
+                    <Setter Property="VerticalContentAlignment" Value="Center"/>
+                </Style>
+            </ContextMenu.ItemContainerStyle>
+            <MenuItem Name="OpenDocMenuItem" Header="打开文件" IsEnabled="True" Click="OpenDocMenuItem_Click">
+                <MenuItem.Icon>
+                    <Path Fill="Black" Data="M9 0H3V2H0V3H1V14H11V3H12V2H9V0ZM2 13V3H3H4H8H9H10V13H2ZM8 2V1H4V2H8ZM4 12V4H3V12H4ZM6.5 4V12H5.5V4H6.5ZM9 12V4H8V12H9Z">
+                        <Path.RenderTransform>
+                            <TranslateTransform X="5.0000" Y="0"/>
+                        </Path.RenderTransform>
+                    </Path>
+                </MenuItem.Icon>
+            </MenuItem>
+   
+
+        </ContextMenu>
+
+        <Style x:Key="itemstyle" TargetType="{x:Type ListViewItem}">
+            <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"></Setter>
+        </Style>
+    </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="auto"/>
-            <RowDefinition Height="auto"/>
+            <RowDefinition/>
         </Grid.RowDefinitions>
         <Grid HorizontalAlignment="Stretch">
             <Grid.ColumnDefinitions>
@@ -25,29 +51,31 @@
                     </ItemsPanelTemplate>
                 </ListBox.ItemsPanel>
             </ListBox>
-            <StackPanel Orientation="Horizontal">
+            <StackPanel Grid.Column="1" Orientation="Horizontal">
                 <ComboBox x:Name="combCloudDisk" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right"/>
                 <Button Content="Test" Click="Button_Click"/>
             </StackPanel>
            
         </Grid>
 
-        <Grid Grid.Row="1">
+        <Grid Grid.Row="1" >
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="Auto"/>
                 <ColumnDefinition/>
             </Grid.ColumnDefinitions>
 
-            <ListBox x:Name="Listusers" Width="170">
-                <ListBox.ItemTemplate>
+            <ListView x:Name="Listusers" Width="220"  SelectionChanged="Listusers_SelectionChanged" VerticalAlignment="Top">
+                <ListView.ItemTemplate>
                     <DataTemplate>
-                        <TextBlock Text="{Binding UserAccount}"/>
-                        
+                        <Grid Height="50" >
+                            <TextBlock VerticalAlignment="Center" Text="{Binding user.UserAccount}"/>
+                        </Grid>
+                       
                     </DataTemplate>
-                </ListBox.ItemTemplate>
-            </ListBox>
-            
-            <ListView x:Name="ListvmFiles" Grid.Column="1" >
+                </ListView.ItemTemplate>
+            </ListView>
+
+            <ListView x:Name="ListvmFiles" Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource itemstyle}">
                 <ListView.ItemTemplate>
                     <DataTemplate>
                         <StackPanel Margin="0,5,0,5">

+ 58 - 11
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml.cs

@@ -1,7 +1,10 @@
-using PDF_Office.Model.CloudDrive;
+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;
@@ -22,10 +25,8 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
     /// </summary>
     public partial class CloudFilesContent : UserControl
     {
-        private List<string> list = new List<string>();
-      //  private GoogleDriveViewModel GoogleDrive = new GoogleDriveViewModel();
-
-        private CloudFilesContentViewModel CloudFilesDrive=>DataContext as CloudFilesContentViewModel;
+     
+        private CloudFilesContentViewModel ViewModel => DataContext as CloudFilesContentViewModel;
 
         private List<CloudDriveItem> CloudeDrives = new List<CloudDriveItem>();
 
@@ -33,7 +34,7 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
         public CloudFilesContent()
         {
             InitializeComponent();
-
+            InitCloudDrive();
             this.Loaded += usercontrol_Loaded;
         }
 
@@ -51,15 +52,17 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
             cloudDriveItem = new CloudDriveItem(CloudType.OneDrive);
             CloudeDrives.Add(cloudDriveItem);
 
-            ListFolder.ItemsSource = CloudeDrives;
-            ListFolder.SelectedIndex = 0;
+            combCloudDisk.ItemsSource = CloudeDrives;
+            combCloudDisk.SelectedIndex = 0;
         }
 
         private void usercontrol_Loaded(object sender, RoutedEventArgs e)
         {
-          if(CloudFilesDrive != null)
+          if(ViewModel != null)
             {
-                CloudFilesDrive.CheckDriveUsers();
+                ViewModel.CheckDriveUsers();
+                if (Listusers.ItemsSource == null)
+                    Listusers.ItemsSource = CloudFilesContentViewModel.CloudFileUserLists;
             }
         }
 
@@ -75,8 +78,52 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
 
         private void Button_Click(object sender, RoutedEventArgs e)
         {
-            SelectCloudTye(CloudType.GoogleDrive);
+
+         //  SelectCloudTye(CloudType.GoogleDrive);
         }
 
+        private CloudFileUser CurrentUser;
+        
+
+        private async void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            var cloudFileUser = Listusers.SelectedItem as CloudFileUser;
+            if(cloudFileUser != null)
+            {
+                CurrentUser = cloudFileUser;
+                if ((CurrentUser.driveItem as GoogleDriveUserItem) != null)
+                {
+                    var item = CurrentUser.driveItem 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;
+                }
+            }
+        }
+
+        private async void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
+        {
+            var menuItem = sender as MenuItem;
+           var item = menuItem.DataContext as GoogleDriveFiles;
+
+            var googleItem = CurrentUser.driveItem as GoogleDriveUserItem;
+            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+
+            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);
+            }
+        }
     }
 }

+ 0 - 25
PDF Office/Views/HomePanel/HomeCloudContent.xaml.cs

@@ -24,32 +24,7 @@ namespace PDF_Office.Views.HomePanel
         public HomeCloudContent()
         {
             InitializeComponent();
-            this.Loaded += HomeCloudContent_Loaded;
-            CloudDriveManager.GetInstance();
         }
 
-        private void HomeCloudContent_Loaded(object sender, RoutedEventArgs e)
-        {
-            //var cloudDrives = cloudFilesContent.DataContext as CloudFilesContentViewModel;
-            //if (cloudDrives != null)
-            //{
-            //    cloudDrives.CheckDriveUsersCommand?.Execute();
-            //}
-        }
-
-
-        private void cloudDiskContent_OpenCloudDriveHandler(object sender, bool e)
-        {
-            if(e)
-            {
-                cloudDriveContent.Visibility = Visibility.Collapsed;
-                cloudFilesContent.Visibility = Visibility.Visible;
-            }
-        }
-
-        private void LoadCloudDrive()
-        {
-
-        }
     }
 }