|
@@ -1,4 +1,5 @@
|
|
|
-using PDF_Office.Helper;
|
|
|
+using Microsoft.Win32;
|
|
|
+using PDF_Office.Helper;
|
|
|
using PDF_Office.Model.CloudDrive;
|
|
|
using PDF_Office.Properties;
|
|
|
using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
|
|
@@ -10,6 +11,7 @@ using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
{
|
|
@@ -42,14 +44,27 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
|
|
|
#region 事件
|
|
|
/// <summary>
|
|
|
+ /// 根据目录,更新文件列表
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand<FileOperation> OpenFolderCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 选中文件夹,更新指定文件夹里的文件列表
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand<FolderBaseItem> SelectedFolderCommand { get; set; }
|
|
|
+ /// <summary>
|
|
|
/// 下载并打开文件
|
|
|
/// </summary>
|
|
|
public DelegateCommand<FileOperation> OpenFileCommand { get; set; }
|
|
|
- public DelegateCommand<FileOperation> OpenFolderCommand { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 上传文件
|
|
|
+ /// </summary>
|
|
|
+ public DelegateCommand<FileOperation> UpLoadFileCommand { get; set; }
|
|
|
+
|
|
|
public DelegateCommand<CloudBoxItem> LoginCommand { get; set; }
|
|
|
public DelegateCommand<UserBaseItem> RemoveUserCommand { get; set; }
|
|
|
|
|
|
- public DelegateCommand<FolderBaseItem> SelectedFolderCommand { get; set; }
|
|
|
#endregion
|
|
|
|
|
|
public CloudFilesContentViewModel()
|
|
@@ -66,69 +81,27 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
|
|
|
private void InitCommand()
|
|
|
{
|
|
|
- OpenFileCommand = new DelegateCommand<FileOperation>(OpenFile);
|
|
|
OpenFolderCommand = new DelegateCommand<FileOperation>(OpenFolder);
|
|
|
- LoginCommand = new DelegateCommand<CloudBoxItem>(LoginUser);
|
|
|
- RemoveUserCommand = new DelegateCommand<UserBaseItem>(RemoveUser);
|
|
|
- SelectedFolderCommand = new DelegateCommand<FolderBaseItem>(SelectedFolder_Command);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 在文件夹列表,选择文件夹
|
|
|
- /// </summary>
|
|
|
- private void SelectedFolder_Command(FolderBaseItem obj)
|
|
|
- {
|
|
|
- if(obj != null)
|
|
|
- {
|
|
|
- var objIndex = FolderItems.IndexOf(obj);
|
|
|
- var count = FolderItems.Count;
|
|
|
-
|
|
|
- if (objIndex == count - 1)
|
|
|
- return;
|
|
|
+ SelectedFolderCommand = new DelegateCommand<FolderBaseItem>(SelectedFolder);
|
|
|
|
|
|
- if (obj.Level == -1)
|
|
|
- {
|
|
|
-
|
|
|
- for(int i = 1; i < count; i++)
|
|
|
- {
|
|
|
- FolderItems.RemoveAt(i);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(objIndex != -1)
|
|
|
- {
|
|
|
- for(int i = count - 1; i > objIndex; i--)
|
|
|
- {
|
|
|
- FolderItems.Remove(FolderItems[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- SelectedFolder(obj.Operation);
|
|
|
- }
|
|
|
- }
|
|
|
+ OpenFileCommand = new DelegateCommand<FileOperation>(OpenFile);
|
|
|
+ UpLoadFileCommand = new DelegateCommand<FileOperation>(UpLoadFile);
|
|
|
|
|
|
+ LoginCommand = new DelegateCommand<CloudBoxItem>(LoginUser);
|
|
|
+ RemoveUserCommand = new DelegateCommand<UserBaseItem>(RemoveUser);
|
|
|
|
|
|
- public async void CheckDrive(CloudBoxItem cloudDriveItem)
|
|
|
- {
|
|
|
- await CloudManager.LoginUser(cloudDriveItem.CloudDiskType);
|
|
|
}
|
|
|
|
|
|
#region 云盘公用接口
|
|
|
|
|
|
#endregion
|
|
|
- public void OpenCloudDrive_Click()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
#region 用户帐号
|
|
|
|
|
|
/// <summary>
|
|
|
/// 登录
|
|
|
/// </summary>
|
|
|
- public async void LoginUser(CloudBoxItem cloudDriveItem)
|
|
|
+ private async void LoginUser(CloudBoxItem cloudDriveItem)
|
|
|
{
|
|
|
if (cloudDriveItem != null)
|
|
|
await CloudManager.LoginUser(cloudDriveItem.CloudDiskType);
|
|
@@ -138,7 +111,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
/// <summary>
|
|
|
/// 移除用户
|
|
|
/// </summary>
|
|
|
- public async void RemoveUser(UserBaseItem user)
|
|
|
+ private async void RemoveUser(UserBaseItem user)
|
|
|
{
|
|
|
if(user != null)
|
|
|
{
|
|
@@ -151,65 +124,68 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 切换用户
|
|
|
- /// </summary>
|
|
|
- public void SwitchUser()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 文件
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取文件夹和文件的列表
|
|
|
- /// </summary>
|
|
|
- public void GetFiles()
|
|
|
- {
|
|
|
|
|
|
+ private async void OpenFolder(FileOperation fileOperation)
|
|
|
+ {
|
|
|
+ FilesList = await CloudManager.OpenFolder(fileOperation);
|
|
|
+ AddFolder(fileOperation);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 选择为当前目录
|
|
|
+ /// 在文件夹列表,选择文件夹
|
|
|
/// </summary>
|
|
|
- public void SelectedFolder()
|
|
|
+ private void SelectedFolder(FolderBaseItem obj)
|
|
|
{
|
|
|
+ if (obj != null)
|
|
|
+ {
|
|
|
+ var objIndex = FolderItems.IndexOf(obj);
|
|
|
+ var count = FolderItems.Count;
|
|
|
|
|
|
- }
|
|
|
+ if (objIndex == count - 1)
|
|
|
+ return;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 下载并打开文件
|
|
|
- /// </summary>
|
|
|
- public async void OpenFile(FileOperation fileOperation)
|
|
|
- {
|
|
|
- await CloudManager.OpenFile(fileOperation);
|
|
|
- }
|
|
|
+ if (obj.Level == -1)
|
|
|
+ {
|
|
|
|
|
|
- public async void OpenFolder(FileOperation fileOperation)
|
|
|
- {
|
|
|
- FilesList = await CloudManager.OpenFolder(fileOperation);
|
|
|
- AddFolder(fileOperation);
|
|
|
+ for (int i = 1; i < count; i++)
|
|
|
+ {
|
|
|
+ FolderItems.RemoveAt(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (objIndex != -1)
|
|
|
+ {
|
|
|
+ for (int i = count - 1; i > objIndex; i--)
|
|
|
+ {
|
|
|
+ FolderItems.Remove(FolderItems[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SelectedFolder(obj.Operation);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在文件列表点击文件夹,而更新文件列表
|
|
|
/// </summary>
|
|
|
/// <param name="fileOperation"></param>
|
|
|
- public async void SelectedFolder(FileOperation fileOperation)
|
|
|
+ private async void SelectedFolder(FileOperation fileOperation)
|
|
|
{
|
|
|
FilesList = await CloudManager.OpenFolder(fileOperation);
|
|
|
}
|
|
|
|
|
|
private void AddFolder(FileOperation folder)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if (folder != null)
|
|
|
{
|
|
|
- if(folder.DoFile != null)
|
|
|
+ if (folder.DoFile != null)
|
|
|
{
|
|
|
FolderBaseItem folderItem = new FolderBaseItem();
|
|
|
folderItem.FolderName = folder.DoFile.Name;
|
|
@@ -229,12 +205,40 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 下载并打开文件
|
|
|
+ /// </summary>
|
|
|
+ private async void OpenFile(FileOperation fileOperation)
|
|
|
+ {
|
|
|
+ await CloudManager.OpenFile(fileOperation);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上传文件
|
|
|
/// </summary>
|
|
|
- public void UpLoadFile()
|
|
|
+ private async void UpLoadFile(FileOperation fileOperation)
|
|
|
{
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+ openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
|
|
|
+ openFileDialog.Multiselect = true;
|
|
|
+ if ((bool)openFileDialog.ShowDialog())
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
|
|
|
+ {
|
|
|
+ fileOperation.SourceFile = openFileDialog.FileName;
|
|
|
+ fileOperation.SourceFileName = openFileDialog.SafeFileName;
|
|
|
+ var result = await CloudManager.UpLoadFile(fileOperation);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ FilesList = await CloudManager.OpenFolder(fileOperation);
|
|
|
+ MessageBox.Show("文件上传完成");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("文件上传失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
#endregion
|