Browse Source

云文档 - 添加Google Drive 云文档的核心功能

chenrongqian 2 years ago
parent
commit
361a18bf74

+ 51 - 0
PDF Office/Model/CloudDrive/CloudDiskItem.cs

@@ -0,0 +1,51 @@
+using Google.Apis.Auth.OAuth2;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.CloudDrive
+{
+    //云盘信息
+    public enum CloudType
+    {
+        Box,
+        DropBox,
+        GoogleDrive,
+        OneDrive
+    }
+    public class CloudDiskItem
+    {
+        public CloudType CloudDiskType { get; set; }
+        public List<UserCredential> UserCredentials { get; set; }
+        public string UsersInfoPath { get; set; }
+        public int Id { get; set; }
+        public string DriveName { get; private set; }
+        public CloudDiskItem(CloudType cloudDiskType)
+        {
+            CloudDiskType = cloudDiskType;
+            GetName(CloudDiskType);
+        }
+
+        private void GetName(CloudType cloudDiskType)
+        {
+            switch (cloudDiskType)
+            {
+                case CloudType.Box:
+                    DriveName = "Box";
+                    break;
+                case CloudType.DropBox:
+                    DriveName = "DropBox";
+                    break;
+                case CloudType.GoogleDrive:
+                    DriveName = "Google Drive";
+                    break;
+                case CloudType.OneDrive:
+                    DriveName = "OneDrive";
+                    break;
+
+            }
+        }
+    }
+}

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

@@ -0,0 +1,37 @@
+using Google.Apis.Auth.OAuth2;
+using Google.Apis.Drive.v3;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.CloudDrive
+{
+    //某用户云盘的文件
+    internal class CloudFiles
+    {
+    }
+
+    public class GoogleDriveUser
+    {
+        public string Name { get; set; }
+        public int Id { get; set; }
+
+        public string UserAccount { get; set; }
+
+        public UserCredential CurrentCredential { get; set; }
+        public GoogleDriveFiles DriveFiles { get; set; }
+    }
+
+    //谷歌云盘的文件
+    public class GoogleDriveFiles
+    {
+        public string Id { get; set; }
+        public string Name { get; set; }
+        public long? Size { get; set; }
+        public long? Version { get; set; }
+        public DateTime? CreatedTime { get; set; }
+    }
+
+}

+ 25 - 0
PDF Office/PDF Office.csproj

@@ -67,6 +67,24 @@
     <Reference Include="DryIoc, Version=4.7.7.0, Culture=neutral, PublicKeyToken=dfbf2bd50fcf7768, processorArchitecture=MSIL">
     <Reference Include="DryIoc, Version=4.7.7.0, Culture=neutral, PublicKeyToken=dfbf2bd50fcf7768, processorArchitecture=MSIL">
       <HintPath>packages\DryIoc.dll.4.7.7\lib\net45\DryIoc.dll</HintPath>
       <HintPath>packages\DryIoc.dll.4.7.7\lib\net45\DryIoc.dll</HintPath>
     </Reference>
     </Reference>
+    <Reference Include="Google.Apis, Version=1.57.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.1.57.0\lib\net45\Google.Apis.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.Auth, Version=1.57.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.Auth.1.57.0\lib\net461\Google.Apis.Auth.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.57.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.Auth.1.57.0\lib\net461\Google.Apis.Auth.PlatformServices.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.Core, Version=1.57.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.Core.1.57.0\lib\net45\Google.Apis.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.Drive.v3, Version=1.57.0.2859, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.Drive.v3.1.57.0.2859\lib\net45\Google.Apis.Drive.v3.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.PlatformServices, Version=1.57.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+      <HintPath>packages\Google.Apis.1.57.0\lib\net45\Google.Apis.PlatformServices.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.AppCenter, Version=0.0.0.0, Culture=neutral, PublicKeyToken=8a600e2fee7ba272, processorArchitecture=MSIL">
     <Reference Include="Microsoft.AppCenter, Version=0.0.0.0, Culture=neutral, PublicKeyToken=8a600e2fee7ba272, processorArchitecture=MSIL">
       <HintPath>packages\Microsoft.AppCenter.4.5.0\lib\net461\Microsoft.AppCenter.dll</HintPath>
       <HintPath>packages\Microsoft.AppCenter.4.5.0\lib\net461\Microsoft.AppCenter.dll</HintPath>
     </Reference>
     </Reference>
@@ -167,6 +185,8 @@
     <Compile Include="Helper\PasswordBoxHelper.cs" />
     <Compile Include="Helper\PasswordBoxHelper.cs" />
     <Compile Include="Helper\SettingHelper.cs" />
     <Compile Include="Helper\SettingHelper.cs" />
     <Compile Include="Helper\ToolMethod.cs" />
     <Compile Include="Helper\ToolMethod.cs" />
+    <Compile Include="Model\CloudDrive\CloudDiskItem.cs" />
+    <Compile Include="Model\CloudDrive\CloudFiles.cs" />
     <Compile Include="Model\DialogNames.cs" />
     <Compile Include="Model\DialogNames.cs" />
     <Compile Include="CustomControl\SystemControl\InterTabClient.cs" />
     <Compile Include="CustomControl\SystemControl\InterTabClient.cs" />
     <Compile Include="CustomControl\LoadingControl.xaml.cs">
     <Compile Include="CustomControl\LoadingControl.xaml.cs">
@@ -201,6 +221,8 @@
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\VerifyPassWordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\VerifyPassWordDialogViewModel.cs" />
+    <Compile Include="ViewModels\HomePanel\CloudDrive\GoogleDriveUserItem.cs" />
+    <Compile Include="ViewModels\HomePanel\CloudDrive\GoogleDriveViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeCloudContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeCloudContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeGuidContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeGuidContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeToolsContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeToolsContentViewModel.cs" />
@@ -504,6 +526,9 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
     </EmbeddedResource>
+    <None Include="credentials.json">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <None Include="packages.config" />
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <Generator>SettingsSingleFileGenerator</Generator>

+ 307 - 0
PDF Office/ViewModels/HomePanel/CloudDrive/GoogleDriveUserItem.cs

@@ -0,0 +1,307 @@
+using Google.Apis.Auth.OAuth2;
+using Google.Apis.Download;
+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.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace PDF_Office.ViewModels.HomePanel.CloudDrive
+{
+
+    //对单用户账号处理核心功能
+    public class GoogleDriveUserItem
+    {
+        public GoogleDriveUser User { get; private set; }
+        public static string[] Scopes = { DriveService.Scope.Drive };
+        public  DriveService Service { get; private set; }
+        private List<GoogleDriveFiles> GoogleDriveFilesList = new List<GoogleDriveFiles>();
+
+        public GoogleDriveUserItem()
+        {
+            User = new GoogleDriveUser();
+            
+        }
+
+        #region   请求身份验证
+
+        /// <summary>
+        /// 获取登录过的账号
+        /// </summary>
+        /// <returns>历史账号</returns>
+        public  async Task<List<DriveService>> GetHistoryService()
+        {
+            DirectoryInfo TheFolder = new DirectoryInfo(GoogleDriveViewModel.FilesPathTemp);
+            List<DriveService> DriveServices = new List<DriveService>();
+
+            foreach (var directorieItem in TheFolder.GetDirectories())
+            {
+                var driveServiceItem = await GetServiceAsync(directorieItem.Name);
+
+                if (driveServiceItem != null)
+                {
+                    DriveServices.Add(driveServiceItem);
+                }
+            }
+            return DriveServices;
+        }
+
+        /// <summary>
+        ///  异步获取Google服务的包信息,避免UI线程卡死
+        /// </summary>
+        /// <param name="userInfoFile"></param>
+        [Obsolete]
+        public async Task<DriveService> GetServiceAsync(string userInfoFile = "")
+        {
+            DriveService service = null;
+
+            await Task.Run(() =>
+            {
+
+                service = GetService(userInfoFile);
+            });
+
+            if (userInfoFile == "")
+            {
+                if (service != null)
+                    Service = service;
+            }
+
+            return service;
+        }
+
+        /// <summary>
+        /// 获取Google服务的包信息(包含访问令牌,App Key密钥等)
+        /// </summary>
+        /// <param name="FilePath">登录过的用户文件;若为空,则为新用户登录</param>
+        /// <returns></returns>
+        [Obsolete]
+        private  DriveService GetService(string FilePath = "")
+        {
+            UserCredential credential;
+
+            if (FilePath == "")
+            {
+                var time = DateTime.Now.ToString("yyyyMMddHHmmss");
+                FilePath = System.IO.Path.Combine(GoogleDriveViewModel.FilesPathTemp, time + ".json");
+            }
+
+
+            using (var stream = new FileStream(GoogleDriveViewModel.CredentialsPath, FileMode.Open, FileAccess.Read))
+            {
+                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
+                    GoogleClientSecrets.Load(stream).Secrets,
+                    Scopes,
+                    "user",
+                    CancellationToken.None,
+                    new FileDataStore(FilePath, true)).Result;
+                User.CurrentCredential = credential;
+            }
+
+            //create Drive API service.
+            DriveService service = new DriveService(new BaseClientService.Initializer()
+            {
+                HttpClientInitializer = credential,
+                ApplicationName = "PDF Office",
+            });
+
+            return service;
+        }
+
+
+        #endregion
+
+        #region   对用户账号处理
+
+        public async Task<bool> RemoveUser()
+        {
+            bool result = false;
+            if (User.CurrentCredential != null)
+            {
+                result = await User.CurrentCredential.RevokeTokenAsync(CancellationToken.None);
+            }
+            if (result == true)
+                User.CurrentCredential = null;
+
+            return result;
+        }
+
+        /// <summary>
+        /// 获取帐号
+        /// </summary>
+        /// <returns>返回用户帐号地址</returns>
+        public string GetUserAcount()
+        {
+            string userAcount = "";
+            if (Service != null)
+            {
+                var about = Service.About.Get();
+                about.Fields = "user";
+                userAcount = about.Execute().User.EmailAddress;
+            }
+
+            return userAcount;
+        }
+
+        #endregion
+
+
+        #region   文件夹
+
+
+
+        #endregion
+
+
+
+        #region  文件
+
+        /// <summary>
+        /// 对单个用户,获取文件列表
+        /// </summary>
+        public  async Task<List<GoogleDriveFiles>> GetDriveFiles(DriveService service = null)
+        {
+            if (service == null)
+                service = await GetServiceAsync();
+
+            // define parameters of request.
+            FilesResource.ListRequest FileListRequest = service.Files.List();
+
+            //listRequest.PageSize = 10;
+            //listRequest.PageToken = 10;
+            FileListRequest.Fields = "nextPageToken, files(id, name, size, version, createdTime)";
+
+            //get file list.
+            IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
+            List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();
+
+            if (files != null && files.Count > 0)
+            {
+                foreach (var file in files)
+                {
+                    GoogleDriveFiles File = new GoogleDriveFiles
+                    {
+                        Id = file.Id,
+                        Name = file.Name,
+                        Size = file.Size,
+                        Version = file.Version,
+                        CreatedTime = file.CreatedTime
+                    };
+                    FileList.Add(File);
+                }
+            }
+            return FileList;
+        }
+
+        /// <summary>
+        /// 上传文件
+        /// </summary>
+        /// <param name="filepath">本地文件路径</param>
+        public  async Task<bool> FileUpload(string filepath)
+        {
+            if (Service == null)
+                Service = await GetServiceAsync();
+
+            var FileMetaData = new Google.Apis.Drive.v3.Data.File();
+            var str = filepath.LastIndexOf("\\");
+            var str2 = filepath.Substring(str + 1, filepath.Length - str - 1);
+
+            FileMetaData.Name = str2;
+            FileMetaData.MimeType = "";
+
+            FilesResource.CreateMediaUpload request;
+            try
+            {
+                using (var stream = new System.IO.FileStream(filepath, System.IO.FileMode.Open))
+                {
+                    request = Service.Files.Create(FileMetaData, stream, FileMetaData.MimeType);
+                    request.Fields = "id";
+                    request.Upload();
+                }
+
+                return true;
+            }
+            catch
+            {
+               return false;
+            }
+
+        }
+
+
+        /// <summary>
+        /// Download file from Google Drive by fileId.
+        /// </summary>
+        /// <param name="googleDriveFiles"></param>
+        /// <param name="savePath"></param>
+        /// <returns></returns>
+        //
+        public  async Task<string> DownloadGoogleFile(GoogleDriveFiles googleDriveFiles, string savePath)
+        {
+            if (Service == null)
+                Service = await GetServiceAsync();
+
+            string fileId = googleDriveFiles.Id;
+            if (string.IsNullOrEmpty(fileId))
+                return "";
+
+            //fileId = DriveFiles[0].Id;
+
+            FilesResource.GetRequest request = Service.Files.Get(fileId);
+
+            string FileName = request.Execute().Name;
+            string FilePath = System.IO.Path.Combine(savePath, FileName);
+
+            MemoryStream stream = new MemoryStream();
+
+            // Add a handler which will be notified on progress changes.
+            // It will notify on each chunk download and when the
+            // download is completed or failed.
+            request.MediaDownloader.ProgressChanged += (Google.Apis.Download.IDownloadProgress progress) =>
+            {
+                switch (progress.Status)
+                {
+                    case DownloadStatus.Downloading:
+                        {
+                            Console.WriteLine(progress.BytesDownloaded);
+                            break;
+                        }
+                    case DownloadStatus.Completed:
+                        {
+                            Console.WriteLine("Download complete.");
+                            SaveStream(stream, FilePath);
+                            break;
+                        }
+                    case DownloadStatus.Failed:
+                        {
+                            Console.WriteLine("Download failed.");
+                            break;
+                        }
+                }
+            };
+            request.Download(stream);
+
+            if (string.IsNullOrEmpty(savePath) == false)
+            {
+
+            }
+            return FilePath;
+        }
+
+        private static void SaveStream(MemoryStream stream, string FilePath)
+        {
+            using (System.IO.FileStream file = new FileStream(FilePath, FileMode.Create, FileAccess.ReadWrite))
+            {
+                stream.WriteTo(file);
+            }
+        }
+
+        #endregion
+    }
+}

+ 59 - 0
PDF Office/ViewModels/HomePanel/CloudDrive/GoogleDriveViewModel.cs

@@ -0,0 +1,59 @@
+using Google.Apis.Auth.OAuth2;
+using Google.Apis.Download;
+using Google.Apis.Drive.v3;
+using Google.Apis.Services;
+using Google.Apis.Util.Store;
+using PDF_Office.Model.CloudDrive;
+using Prism.Commands;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace PDF_Office.ViewModels.HomePanel.CloudDrive
+{
+    //多用户UX交互
+    public class GoogleDriveViewModel
+    {
+
+        public List<GoogleDriveUserItem> GoogleDriveUsers = new List<GoogleDriveUserItem>();
+        public static string FilesPathTemp { get; private set; }
+        public static string CredentialsPath { get; private set; }
+
+        public GoogleDriveViewModel()
+        {
+            GetFilesPathTemp();
+            GetCredentialsPath();
+        }
+
+        /// <summary>
+        /// 获取或创建缓存登录帐户信息
+        /// </summary>
+        public void GetFilesPathTemp()
+        {
+            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
+            String FolderPath = str_1 + "GoogleDriveUsers";
+
+            if (Directory.Exists(FolderPath) == false)
+                Directory.CreateDirectory(FolderPath);
+
+            FilesPathTemp = FolderPath;
+        }
+
+        /// <summary>
+        /// 获取本地身份验证文件
+        /// </summary>
+        public void GetCredentialsPath()
+        {
+            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
+            String filePath = str_1 + @"\credentials.json";
+            CredentialsPath = filePath;
+        }
+
+    }
+
+}

+ 32 - 1
PDF Office/ViewModels/HomePanel/HomeCloudContentViewModel.cs

@@ -1,4 +1,7 @@
-using Prism.Mvvm;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.ViewModels.HomePanel.CloudDrive;
+using Prism.Commands;
+using Prism.Mvvm;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
@@ -9,8 +12,36 @@ namespace PDF_Office.ViewModels.HomePanel
 {
 {
     public class HomeCloudContentViewModel:BindableBase
     public class HomeCloudContentViewModel:BindableBase
     {
     {
+        public GoogleDriveViewModel googleDriveViewModel;
+        
+        public DelegateCommand<CloudDiskItem> OpenCloudDriveCommand { get; set; }
         public HomeCloudContentViewModel()
         public HomeCloudContentViewModel()
         {
         {
+            googleDriveViewModel = new GoogleDriveViewModel();
+            OpenCloudDriveCommand = new DelegateCommand<CloudDiskItem>(OpenCloudDrive_Click);
+        }
+
+        public void OpenCloudDrive_Click(CloudDiskItem cloudDiskItem)
+        {
+            if (cloudDiskItem != null)
+            {
+
+                switch (cloudDiskItem.CloudDiskType)
+                {
+                    case CloudType.Box:
+                        break;
+                    case CloudType.DropBox:
+                        break;
+                    case CloudType.GoogleDrive:
+                        //    isSccuess = await googleDriveViewModel.LoginUser();
+                        break;
+                    case CloudType.OneDrive:
+                        break;
+                    default:
+                        break;
+                }
+
+            }
 
 
         }
         }
     }
     }

+ 18 - 2
PDF Office/Views/HomePanel/CloudDocs/CloudDiskContent.xaml

@@ -14,7 +14,15 @@
 
 
         <Grid HorizontalAlignment="Stretch">
         <Grid HorizontalAlignment="Stretch">
             <TextBlock Text="Cloud disk" HorizontalAlignment="Left"/>
             <TextBlock Text="Cloud disk" HorizontalAlignment="Left"/>
-            <ComboBox x:Name="combCloudDisk" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right"/>
+            <ComboBox x:Name="combCloudDisk" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right">
+                <ComboBox.ItemTemplate>
+                    <DataTemplate>
+                        <Border Background="#DBDBDB">
+                            <TextBlock Text="{Binding DriveName}"/>
+                        </Border>
+                    </DataTemplate>
+                </ComboBox.ItemTemplate>
+            </ComboBox>
         </Grid>
         </Grid>
         <ListBox x:Name="ListCloudDisk" Grid.Row="1">
         <ListBox x:Name="ListCloudDisk" Grid.Row="1">
              
              
@@ -27,11 +35,19 @@
             <ListBox.ItemTemplate>
             <ListBox.ItemTemplate>
                 <DataTemplate>
                 <DataTemplate>
                     <Border Background="#DBDBDB" Width="218" Height="172">
                     <Border Background="#DBDBDB" Width="218" Height="172">
-                        <TextBlock Text="{Binding}"/>
+                        <TextBlock Text="{Binding DriveName}"/>
                     </Border>
                     </Border>
                 </DataTemplate>
                 </DataTemplate>
             </ListBox.ItemTemplate>
             </ListBox.ItemTemplate>
 
 
+            <ListBox.ItemContainerStyle>
+                <Style TargetType="{x:Type ListBoxItem}">
+                    <EventSetter Event="PreviewMouseLeftButtonUp" 
+                                 Handler="SelectCloudDrive_Click"
+                                 />
+                </Style>
+            </ListBox.ItemContainerStyle>
+
         </ListBox>
         </ListBox>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 43 - 9
PDF Office/Views/HomePanel/CloudDocs/CloudDiskContent.xaml.cs

@@ -1,4 +1,8 @@
-using System;
+using Google.Apis.Auth.OAuth2;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.ViewModels.HomePanel;
+using PDF_Office.ViewModels.HomePanel.CloudDrive;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
@@ -15,22 +19,52 @@ using System.Windows.Shapes;
 
 
 namespace PDF_Office.Views.HomePanel.CloudDocs
 namespace PDF_Office.Views.HomePanel.CloudDocs
 {
 {
+
     /// <summary>
     /// <summary>
     /// CloudDiskContent.xaml 的交互逻辑
     /// CloudDiskContent.xaml 的交互逻辑
     /// </summary>
     /// </summary>
     public partial class CloudDiskContent : UserControl
     public partial class CloudDiskContent : UserControl
     {
     {
-
-        private List<string> list = new List<string>();
+        private List<CloudDiskItem> CloudeDisks = new List<CloudDiskItem>();
+        public event EventHandler<bool> OpenCloudDriveHandler;
         public CloudDiskContent()
         public CloudDiskContent()
         {
         {
             InitializeComponent();
             InitializeComponent();
-            list.Add("Box");
-            list.Add("DropBox");
-            list.Add("GoogleDrive");
-            list.Add("OneDrive");
-            ListCloudDisk.ItemsSource = list; 
-            combCloudDisk.ItemsSource = list;
+            InitCloudDisk();
+           
+        }
+
+        private void InitCloudDisk()
+        {
+            var cloudDiskItem = new CloudDiskItem(CloudType.Box);
+            CloudeDisks.Add(cloudDiskItem);
+
+            cloudDiskItem = new CloudDiskItem(CloudType.DropBox);
+            CloudeDisks.Add(cloudDiskItem);
+
+            cloudDiskItem = new CloudDiskItem(CloudType.GoogleDrive);
+            CloudeDisks.Add(cloudDiskItem);
+
+            cloudDiskItem = new CloudDiskItem(CloudType.OneDrive);
+            CloudeDisks.Add(cloudDiskItem);
+
+            ListCloudDisk.ItemsSource = CloudeDisks;
+            combCloudDisk.ItemsSource = CloudeDisks;
+            combCloudDisk.SelectedIndex = 0;
+        }
+
+        private void SelectCloudDrive_Click(object sender, MouseButtonEventArgs e)
+        {
+         
+            var cloudDiskItem = (sender as FrameworkElement).DataContext as CloudDiskItem;
+            var cloudContentViewModel = this.DataContext as HomeCloudContentViewModel;
+            if (cloudDiskItem != null && cloudContentViewModel != null)
+            {
+                cloudContentViewModel.OpenCloudDriveCommand.Execute(cloudDiskItem);
+                OpenCloudDriveHandler.Invoke(sender, true);
+            }
+
+
         }
         }
     }
     }
 }
 }

+ 29 - 3
PDF Office/Views/HomePanel/CloudDocs/CloudFilesContent.xaml

@@ -23,7 +23,11 @@
                     </ItemsPanelTemplate>
                     </ItemsPanelTemplate>
                 </ListBox.ItemsPanel>
                 </ListBox.ItemsPanel>
             </ListBox>
             </ListBox>
-            <ComboBox x:Name="combCloudDisk" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right"/>
+            <StackPanel 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 Grid.Row="1">
         <Grid Grid.Row="1">
@@ -32,8 +36,30 @@
                 <ColumnDefinition/>
                 <ColumnDefinition/>
             </Grid.ColumnDefinitions>
             </Grid.ColumnDefinitions>
 
 
-            <ListBox x:Name="Listusers" Width="170"/>
-            <ListView x:Name="ListvmFiles" Grid.Column="1" />
+            <ListBox x:Name="Listusers" Width="170">
+                <ListBox.ItemTemplate>
+                    <DataTemplate>
+                        <TextBlock Text="{Binding Name}"/>
+                    </DataTemplate>
+                </ListBox.ItemTemplate>
+            </ListBox>
+            
+            <ListView x:Name="ListvmFiles" Grid.Column="1" >
+                <ListView.ItemTemplate>
+                    <DataTemplate>
+                        <StackPanel Margin="0,5,0,5">
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Text="Id:"/>
+                                <TextBlock Text="{Binding Id}"/>
+                            </StackPanel>
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Text="文件名:"/>
+                                <TextBlock Text="{Binding Name}"/>
+                            </StackPanel>
+                        </StackPanel>
+                    </DataTemplate>
+                </ListView.ItemTemplate>
+            </ListView>
         </Grid>
         </Grid>
 
 
        
        

+ 24 - 4
PDF Office/Views/HomePanel/CloudDocs/CloudFilesContent.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.ViewModels.HomePanel.CloudDrive;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
@@ -21,6 +23,9 @@ namespace PDF_Office.Views.HomePanel.CloudDocs
     public partial class CloudFilesContent : UserControl
     public partial class CloudFilesContent : UserControl
     {
     {
         private List<string> list = new List<string>();
         private List<string> list = new List<string>();
+        private GoogleDriveViewModel GoogleDrive = new GoogleDriveViewModel();
+
+        private CloudType cloudType;
         public CloudFilesContent()
         public CloudFilesContent()
         {
         {
             InitializeComponent();
             InitializeComponent();
@@ -29,9 +34,24 @@ namespace PDF_Office.Views.HomePanel.CloudDocs
             list.Add("GoogleDrive");
             list.Add("GoogleDrive");
             list.Add("OneDrive");
             list.Add("OneDrive");
             ListFolder.ItemsSource = list;
             ListFolder.ItemsSource = list;
-            Listusers.ItemsSource = list;
-            combCloudDisk.ItemsSource = list;
-            ListvmFiles.ItemsSource = list;
+           // Listusers.ItemsSource = list;
+          //  combCloudDisk.ItemsSource = list;
+           // ListvmFiles.ItemsSource = list;
+        }
+
+        public void SelectCloudTye(CloudType cloudType)
+        {
+            switch (cloudType)
+            {
+                case CloudType.GoogleDrive:
+                    cloudType = CloudType.GoogleDrive;
+                    break;
+            }
+        }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            SelectCloudTye(CloudType.GoogleDrive);
         }
         }
     }
     }
 }
 }

+ 2 - 2
PDF Office/Views/HomePanel/HomeCloudContent.xaml

@@ -11,7 +11,7 @@
              mc:Ignorable="d" 
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
              d:DesignHeight="450" d:DesignWidth="800">
     <Grid>
     <Grid>
-        <Cloud:CloudDiskContent/>
-        <Cloud:CloudFilesContent  Visibility="Collapsed"/>
+        <Cloud:CloudDiskContent x:Name="cloudDiskContent" Visibility="Collapsed" OpenCloudDriveHandler ="cloudDiskContent_OpenCloudDriveHandler"/>
+        <Cloud:CloudFilesContent x:Name="cloudFilesContent"  Visibility="Visible"/>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

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

@@ -24,5 +24,19 @@ namespace PDF_Office.Views.HomePanel
         {
         {
             InitializeComponent();
             InitializeComponent();
         }
         }
+
+        private void cloudDiskContent_OpenCloudDriveHandler(object sender, bool e)
+        {
+            if(e)
+            {
+                cloudDiskContent.Visibility = Visibility.Collapsed;
+                cloudFilesContent.Visibility = Visibility.Visible;
+            }
+        }
+
+        private void LoadCloudDrive()
+        {
+
+        }
     }
     }
 }
 }

+ 1 - 0
PDF Office/credentials.json

@@ -0,0 +1 @@
+{"installed":{"client_id":"133109619517-90ri7o190j44mb0bf5fgotlt79ksv9gl.apps.googleusercontent.com","project_id":"myprojecttestdemo-370006","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"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","redirect_uris":["http://localhost"]}}

+ 4 - 0
PDF Office/packages.config

@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
 <packages>
   <package id="DryIoc.dll" version="4.7.7" targetFramework="net462" />
   <package id="DryIoc.dll" version="4.7.7" targetFramework="net462" />
+  <package id="Google.Apis" version="1.57.0" targetFramework="net462" />
+  <package id="Google.Apis.Auth" version="1.57.0" targetFramework="net462" />
+  <package id="Google.Apis.Core" version="1.57.0" targetFramework="net462" />
+  <package id="Google.Apis.Drive.v3" version="1.57.0.2859" targetFramework="net462" />
   <package id="Microsoft.AppCenter" version="4.5.0" targetFramework="net462" />
   <package id="Microsoft.AppCenter" version="4.5.0" targetFramework="net462" />
   <package id="Microsoft.AppCenter.Analytics" version="4.5.0" targetFramework="net462" />
   <package id="Microsoft.AppCenter.Analytics" version="4.5.0" targetFramework="net462" />
   <package id="Microsoft.AppCenter.Crashes" version="4.5.0" targetFramework="net462" />
   <package id="Microsoft.AppCenter.Crashes" version="4.5.0" targetFramework="net462" />