Explorar el Código

云文档 - 优化谷歌文档和DropBox下载文件的逻辑

chenrongqian hace 2 años
padre
commit
31f5874507

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

@@ -74,4 +74,21 @@ namespace PDF_Office.Model.CloudDrive
 
     #endregion
 
+
+    #region GooglrDrive
+
+    /// <summary>
+    /// 谷歌云盘的文件
+    /// </summary>
+    public class DropbBoxFiles
+    {
+        public string Id { get; set; }
+        public string Name { get; set; }
+        public long? Size { get; set; }
+        public DateTime? CreatedTime { get; set; }
+    }
+
+    #endregion
+
+
 }

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

@@ -36,25 +36,14 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         public async void CheckDrive(CloudBoxItem cloudDriveItem)
         {
             bool result = false;
-            switch (cloudDriveItem.CloudDiskType)
-            {
-                case CloudType.GoogleDrive:
-                     result = await Manager.LoginUser(cloudDriveItem.CloudDiskType);
-                    break;
-            }
-
+            result = await Manager.LoginUser(cloudDriveItem.CloudDiskType);
             IshowContentHandler?.Invoke(null, !result);
         }
 
         public async void CheckDriveLoginUser(CloudBoxItem cloudDriveItem)
         {
             bool result = false;
-            switch (cloudDriveItem.CloudDiskType)
-            {
-                case CloudType.GoogleDrive:
-                    result = await Manager.LoginUser(cloudDriveItem.CloudDiskType);
-                    break;
-            }
+            result = await Manager.LoginUser(cloudDriveItem.CloudDiskType);
         }
 
 

+ 3 - 1
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveManager.cs

@@ -16,7 +16,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
     {
       
         public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
-       // public DropbBoxManager DropbBox;
+        public DropbBoxManager DropbBox => DropbBoxManager.DropbBox;
         public CloudType cloudType;
 
         private static CloudDriveManager instance;
@@ -44,6 +44,8 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
             {
                 case CloudType.GoogleDrive:
                    return await GoogleDrive.LoginUserCount();
+                case CloudType.DropBox:
+                    return await DropbBox.LoginUser();
             }
             return false;
         }

+ 15 - 2
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/DropbBoxManager.cs

@@ -26,9 +26,22 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         /// <summary>
         /// 登录
         /// </summary>
-        public void LoginUser()
+        public async Task<bool> LoginUser()
         {
-
+            bool result = false;
+            DropbBoxUserItem dropbBoxUserItem = new DropbBoxUserItem();
+            result = await dropbBoxUserItem.LoginUser();
+            if(result)
+            {
+                dropbBoxUserItem.cloudType = CloudType.DropBox;
+                   UserInfo user = new UserInfo();
+                user.Name = "DropBox测试" + (Cloud.CloudLists.Count + 1).ToString();
+                dropbBoxUserItem.userInfo = user;
+
+                Cloud.CloudLists.Add(dropbBoxUserItem);
+
+            }
+            return result;
         }
 
         /// <summary>

+ 169 - 128
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/DropbBoxUserItem.cs

@@ -1,5 +1,6 @@
 using Dropbox.Api;
 using Dropbox.Api.Files;
+using PDF_Office.Model.CloudDrive;
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -11,10 +12,146 @@ using System.Windows;
 
 namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 {
-    
-    public class DropbBoxUserItem
+    /// <summary>
+    /// 单用户
+    /// </summary>
+    public class DropbBoxUserItem : UserBaseItem
     {
         DropboxClient client;
+        private List<DropbBoxFiles> FilesList = new List<DropbBoxFiles>();//文件
+        private List<Metadata> MetadataList = new List<Metadata>();//文件
+        public async Task<bool> LoginUser()
+        {
+            client = await DropbBoxStatic.Connect();
+            if (client == null)
+                return false;
+            else
+                return true;
+        }
+
+        public async Task<List<DropbBoxFiles>> RefreshList(string path = "")
+        {
+            var files = await client.Files.ListFolderAsync(path);
+            DropbBoxFiles dropbBoxFiles = new DropbBoxFiles();
+            List<DropbBoxFiles> FileList = new List<DropbBoxFiles>();
+            foreach (var file in files.Entries)
+            {
+                dropbBoxFiles.Name = file.Name;
+                FileList.Add(dropbBoxFiles);
+            }
+            MetadataList = (List<Metadata>)files.Entries;
+            this.FilesList = FileList;
+            return FileList;
+        }
+
+
+
+        public async Task<string> Download(string name, string savePath)
+        {
+            Metadata metadata = null;
+            foreach(var item in MetadataList)
+            {
+                if (item.IsFolder)
+                    continue;
+
+                if (item.Name == name)
+                {
+                    metadata = item;
+                    break;
+                }
+            }
+
+            if (metadata != null)
+            {
+                savePath = savePath + "\\" + metadata.Name;
+                using (var response = await client.Files.DownloadAsync(metadata.PathDisplay))
+                {
+                    var result = await response.GetContentAsStreamAsync();
+                    var stream = StreamToMemoryStream(result);
+                    using (var fileStream = System.IO.File.Create(savePath))
+                    {
+                        stream.Seek(0, System.IO.SeekOrigin.Begin);
+                        stream.CopyTo(fileStream);
+                    }
+                }
+               // System.Diagnostics.Process.Start(@"explorer.exe", "/select,\"" + savePath + "\"");
+                RefreshList(savePath);
+
+                return savePath;
+            }
+            
+            return "";
+
+        }
+
+        public MemoryStream StreamToMemoryStream(Stream stream)
+        {
+            MemoryStream memoryStream = new MemoryStream();
+
+            //将基础流写入内存流
+            const int bufferLength = 1024;
+            byte[] buffer = new byte[bufferLength];
+            int actual = stream.Read(buffer, 0, bufferLength);
+            while (actual > 0)
+            {
+                // 读、写过程中,流的位置会自动走。
+                memoryStream.Write(buffer, 0, actual);
+                actual = stream.Read(buffer, 0, bufferLength);
+            }
+            memoryStream.Position = 0;
+
+            return memoryStream;
+        }
+
+        private void Upload()
+        {
+            //if (ItemList.SelectedItem != null)
+            //{
+            //    var item = ItemList.SelectedItem as Metadata;
+            //    if (item.IsFolder)
+            //        return;
+
+            //OpenFileDialog openFileDialog = new OpenFileDialog();
+            //if ((bool)openFileDialog.ShowDialog())
+            //{
+            //    string folder = currentFolder; /*= item.PathDisplay.Replace("/" + item.Name, "");*/
+            //    using (var stream = System.IO.File.OpenRead(openFileDialog.FileName))
+            //    {
+            //        await client.Files.UploadAsync(folder + "/" + openFileDialog.SafeFileName, WriteMode.Overwrite.Instance, body: stream);
+            //    }
+            //    MessageBox.Show("上传完成");
+            //    RefreshList(folder);
+            //}
+            //}
+        }
+
+        private void Loaded()
+        {
+            //var text = sender as TextBlock;
+            //if (text == null)
+            //    return;
+            //if (text.DataContext is Metadata)
+            //{
+            //    var data = (text.DataContext as Metadata);
+            //    if (data.IsFile)
+            //    {
+            //        text.Text = "File";
+            //    }
+            //    if (data.IsFolder)
+            //    {
+            //        text.Text = "Folder";
+            //    }
+            //}
+        }
+
+
+    }
+
+
+    #region 身份验证
+
+    public static class DropbBoxStatic
+    {
         // This loopback host is for demo purpose. If this port is not
         // available on your machine you need to update this URL with an unused port.
         public static readonly string LoopbackHost = "http://127.0.0.1:8080/";
@@ -22,15 +159,13 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         public static readonly string ApiKey = "k1hv3601odbsmln";
         // URL to receive OAuth 2 redirect from Dropbox server.
         // You also need to register this redirect URL on https://www.dropbox.com/developers/apps.
-        public readonly Uri RedirectUri = new Uri(LoopbackHost + "authorize");
+        public static readonly Uri RedirectUri = new Uri(LoopbackHost + "authorize");
 
         // URL to receive access token from JS.
-        public readonly Uri JSRedirectUri = new Uri(LoopbackHost + "token");
-
-        private string currentFolder = "";
+        public static readonly Uri JSRedirectUri = new Uri(LoopbackHost + "token");
 
-        HttpListener http = new HttpListener();
-        private async void Connect()
+        private static HttpListener http = new HttpListener();
+        public static async Task<DropboxClient> Connect()
         {
             DropboxCertHelper.InitializeCertPinning();
             var state = Guid.NewGuid().ToString("N");
@@ -49,15 +184,36 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
             var tokenResult = await OAuthflow.ProcessCodeFlowAsync(redirectUri, ApiKey, RedirectUri.ToString(), state);
 
-          //  Window.GetWindow(this).Activate();
+            //  Window.GetWindow(this).Activate();
             DropboxClientConfig dropboxClientConfig = new DropboxClientConfig("ControlTest");
 
+            DropboxClient client;
             client = new DropboxClient(tokenResult.AccessToken, dropboxClientConfig);
+            return client;
+        }
 
-            RefreshList();
+        /// <summary>
+        /// Handle the redirect from JS and process raw redirect URI with fragment to
+        /// complete the authorization flow.
+        /// </summary>
+        /// <param name="http">The http listener.</param>
+        /// <returns>The <see cref="OAuth2Response"/></returns>
+        private static async Task<Uri> HandleJSRedirect(HttpListener http)
+        {
+            var context = await http.GetContextAsync();
+
+            // We only care about request to TokenRedirectUri endpoint.
+            while (context.Request.Url.AbsolutePath != JSRedirectUri.AbsolutePath)
+            {
+                context = await http.GetContextAsync();
+            }
 
+            var redirectUri = new Uri(context.Request.QueryString["url_with_fragment"]);
+
+            return redirectUri;
         }
 
+
         public static void ListenerCallback(IAsyncResult result)
         {
             HttpListener listener = (HttpListener)result.AsyncState;
@@ -77,12 +233,6 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
             output.Close();
         }
 
-        public async void RefreshList(string path = "")
-        {
-            var files = await client.Files.ListFolderAsync(path);
-
-      //      ItemList.ItemsSource = files.Entries;
-        }
 
         /// <summary>
         /// Handles the redirect from Dropbox server. Because we are using token flow, the local
@@ -91,7 +241,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         /// </summary>
         /// <param name="http">The http listener.</param>
         /// <returns>The <see cref="Task"/></returns>
-        private async Task HandleOAuth2Redirect(HttpListener http)
+        private static async Task HandleOAuth2Redirect(HttpListener http)
         {
             var context = await http.GetContextAsync();
 
@@ -113,121 +263,12 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
             context.Response.OutputStream.Close();
         }
 
-        /// <summary>
-        /// Handle the redirect from JS and process raw redirect URI with fragment to
-        /// complete the authorization flow.
-        /// </summary>
-        /// <param name="http">The http listener.</param>
-        /// <returns>The <see cref="OAuth2Response"/></returns>
-        private async Task<Uri> HandleJSRedirect(HttpListener http)
-        {
-            var context = await http.GetContextAsync();
-
-            // We only care about request to TokenRedirectUri endpoint.
-            while (context.Request.Url.AbsolutePath != JSRedirectUri.AbsolutePath)
-            {
-                context = await http.GetContextAsync();
-            }
-
-            var redirectUri = new Uri(context.Request.QueryString["url_with_fragment"]);
 
-            return redirectUri;
-        }
-
-
-
-
-
-        private void Download()
-        {
-            //if (ItemList.SelectedItem != null)
-            //{
-            //    var item = ItemList.SelectedItem as Metadata;
-            //    if (item.IsFolder)
-            //        return;
-
-            //    SaveFileDialog saveFileDialog = new SaveFileDialog();
-            //    saveFileDialog.FileName = item.Name;
-            //    if ((bool)saveFileDialog.ShowDialog())
-            //    {
-            //        string folder = item.PathDisplay.Replace("/" + item.Name, "");
-            //        using (var response = await client.Files.DownloadAsync(item.PathDisplay))
-            //        {
-            //            var result = await response.GetContentAsStreamAsync();
-            //            var stream = StreamToMemoryStream(result);
-            //            using (var fileStream = System.IO.File.Create(saveFileDialog.FileName))
-            //            {
-            //                stream.Seek(0, System.IO.SeekOrigin.Begin);
-            //                stream.CopyTo(fileStream);
-            //            }
-            //        }
-            //        MessageBox.Show("下载完成");
-            //        System.Diagnostics.Process.Start(@"explorer.exe", "/select,\"" + saveFileDialog.FileName + "\"");
-            //        RefreshList(folder);
-            //    }
-            //}
-        }
-
-        public MemoryStream StreamToMemoryStream(Stream stream)
-        {
-            MemoryStream memoryStream = new MemoryStream();
-
-            //将基础流写入内存流
-            const int bufferLength = 1024;
-            byte[] buffer = new byte[bufferLength];
-            int actual = stream.Read(buffer, 0, bufferLength);
-            while (actual > 0)
-            {
-                // 读、写过程中,流的位置会自动走。
-                memoryStream.Write(buffer, 0, actual);
-                actual = stream.Read(buffer, 0, bufferLength);
-            }
-            memoryStream.Position = 0;
+    }
 
-            return memoryStream;
-        }
 
-        private void Upload()
-        {
-            //if (ItemList.SelectedItem != null)
-            //{
-            //    var item = ItemList.SelectedItem as Metadata;
-            //    if (item.IsFolder)
-            //        return;
-
-            //OpenFileDialog openFileDialog = new OpenFileDialog();
-            //if ((bool)openFileDialog.ShowDialog())
-            //{
-            //    string folder = currentFolder; /*= item.PathDisplay.Replace("/" + item.Name, "");*/
-            //    using (var stream = System.IO.File.OpenRead(openFileDialog.FileName))
-            //    {
-            //        await client.Files.UploadAsync(folder + "/" + openFileDialog.SafeFileName, WriteMode.Overwrite.Instance, body: stream);
-            //    }
-            //    MessageBox.Show("上传完成");
-            //    RefreshList(folder);
-            //}
-            //}
-        }
+    #endregion
 
-        private void Loaded()
-        {
-            //var text = sender as TextBlock;
-            //if (text == null)
-            //    return;
-            //if (text.DataContext is Metadata)
-            //{
-            //    var data = (text.DataContext as Metadata);
-            //    if (data.IsFile)
-            //    {
-            //        text.Text = "File";
-            //    }
-            //    if (data.IsFolder)
-            //    {
-            //        text.Text = "Folder";
-            //    }
-            //}
-        }
 
 
-    }
 }

+ 9 - 21
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/GoogleDriveManager.cs

@@ -52,19 +52,16 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
         public async void AddGoogleDriveUser(Tuple<DriveService, UserCredential> tuple)
         {
-            UserBaseItem cloudFileUser = new UserBaseItem();
-           GoogleDriveUserItem userItem = new GoogleDriveUserItem();
+            GoogleDriveUserItem userItem = new GoogleDriveUserItem();
             userItem.Service = tuple.Item1;
             userItem.CurrentCredential = tuple.Item2;
-            cloudFileUser = userItem;
-            cloudFileUser.cloudType = CloudType.GoogleDrive;
-          
+            userItem.cloudType = CloudType.GoogleDrive;
+
             UserInfo user = new UserInfo();
             user = await userItem.GetUserAcountAsync();
-         
-            cloudFileUser.userInfo = user;
+            userItem.userInfo = user;
 
-            Cloud.CloudLists.Add(cloudFileUser);
+            Cloud.CloudLists.Add(userItem);
         }
 
         public async Task<bool> LoginUserCount()
@@ -74,13 +71,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
             if (tuple != null)
             {
                 result = true;
-
-           //     Task.Run(async () =>
-           //     {
-
-                    await GetUserInfo(tuple);
-           //     });
-
+                await GetUserInfo(tuple);//此处不可用异步处理,否则导致的结果是没法刷新集合呈现在UI上
             }
 
             return result;
@@ -88,19 +79,16 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
         public async Task<bool> GetUserInfo(Tuple<DriveService, UserCredential> tuple)
         {
-            UserBaseItem cloudFileUser = new UserBaseItem();
             GoogleDriveUserItem userItem = new GoogleDriveUserItem();
             userItem.Service = tuple.Item1;
             userItem.CurrentCredential = tuple.Item2;
-            cloudFileUser = userItem;
-            cloudFileUser.cloudType = CloudType.GoogleDrive;
+            userItem.cloudType = CloudType.GoogleDrive;
 
             UserInfo user = new UserInfo();
             user = await userItem.GetUserAcountAsync();
+            userItem.userInfo = user;
 
-            cloudFileUser.userInfo = user;
-
-            Cloud.CloudLists.Add(cloudFileUser);
+            Cloud.CloudLists.Add(userItem);
             return true;
         }
 

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

@@ -131,6 +131,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                     };
                     FileList.Add(File);
                 }
+                this.FilesList = FileList;
             }
             return FileList;
         }

+ 15 - 8
PDF Office/ViewModels/HomePanel/CloudDrive/CloudFilesContentViewModel.cs

@@ -20,20 +20,27 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         public DelegateCommand OpenCloudDriveCommand { get; set; }
         public DelegateCommand CheckDriveUsersCommand { get; set; }
 
-        //向外触发
-      //  public event EventHandler<bool> isFoundUserHandler;
+        public DelegateCommand<CloudBoxItem> CheckDriveCommand { get; set; }
+        
         public CloudFilesContentViewModel()
         {
-          //  Manager = new GoogleDriveManager(); 
-         //   GoogleDrive = new GoogleDriveManager();
-
             OpenCloudDriveCommand = new DelegateCommand(OpenCloudDrive_Click);
             OpenCloudDriveCommand = new DelegateCommand(CheckDriveUsers);
 
-          //  CheckDriveUsersCommand = new DelegateCommand(CheckDriveUsers);
-
+            CheckDriveCommand = new DelegateCommand<CloudBoxItem>(CheckDrive);
+        }
 
-         
+        public async void CheckDrive(CloudBoxItem cloudDriveItem)
+        {
+            switch (cloudDriveItem.CloudDiskType)
+            {
+                case CloudType.GoogleDrive:
+                     await GoogleDrive.LoginUserCount();
+                    break;
+                case CloudType.DropBox:
+                     await DropbBox.LoginUser();
+                    break;
+            }
         }
 
         #region 云盘公用接口

+ 9 - 1
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml

@@ -52,7 +52,15 @@
                 </ListBox.ItemsPanel>
             </ListBox>
             <StackPanel Grid.Column="1" Orientation="Horizontal">
-                <ComboBox x:Name="combCloudDisk" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right"/>
+                <ComboBox x:Name="combCloudDrive" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right" SelectionChanged="combCloudDrive_SelectionChanged">
+                    <ComboBox.ItemTemplate>
+                        <DataTemplate>
+                            <Border Background="#DBDBDB">
+                                <TextBlock Text="{Binding DriveName}"/>
+                            </Border>
+                        </DataTemplate>
+                    </ComboBox.ItemTemplate>
+                </ComboBox>
                 <Button Content="Test" Click="Button_Click"/>
             </StackPanel>
            

+ 87 - 20
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml.cs

@@ -41,8 +41,8 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
         private void InitCloudDrive()
         {
             CloudeDrives = Cloud.InitCloudBoxs();
-            combCloudDisk.ItemsSource = CloudeDrives;
-            combCloudDisk.SelectedIndex = 0;
+            combCloudDrive.ItemsSource = CloudeDrives;
+            combCloudDrive.SelectedIndex = 0;
         }
 
         private void usercontrol_Loaded(object sender, RoutedEventArgs e)
@@ -55,6 +55,15 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
             }
         }
 
+        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)
         {
@@ -70,39 +79,97 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
             if(cloudFileUser != null)
             {
                 CurrentUser = cloudFileUser;
-                if ((CurrentUser as GoogleDriveUserItem) != null)
+
+                switch(cloudFileUser.cloudType)
                 {
-                    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)
+                    case CloudType.GoogleDrive:
+                        if ((CurrentUser as GoogleDriveUserItem) != null)
                         {
-                            filesList.Add(file);
+                            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;
                         }
-                    }
-                    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;
-           var item = menuItem.DataContext as GoogleDriveFiles;
+            if (menuItem == null)
+                return;
 
-            var googleItem = CurrentUser as GoogleDriveUserItem;
             string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
-            var filename = await googleItem.DownloadGoogleFile(item, docPath);
-            if (filename != null)
+            switch (CurrentUser.cloudType)
             {
-                string[] filePaths = { filename };
-                await Task.Delay(3);
-                MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
-                parentWindow.LoadPdfViewer(filePaths);
+                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;
+
             }
+
+
+
+           
         }
+
+       
     }
 }