Beispiel #1
0
        //上传文件夹
        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            try
            {
                string dirPath = FileHelper.GetFolderToOpen(false);
                if (dirPath == null)
                {
                    return;
                }

                ulong dirSize = FileHelper.GetDirectorySize(dirPath);
                if (this.IsNetworkDisk)
                {
                    NetworkDiskState state     = this.fileDirectoryOutter.GetNetworkDiskState(this.netDiskID);
                    ulong            available = state.TotalSize - state.SizeUsed;
                    if (available < dirSize)
                    {
                        MessageBox.Show(string.Format("空间不足!网络硬盘剩余空间为{0},所需空间为{1}!", PublicHelper.GetSizeString(available), PublicHelper.GetSizeString(dirSize)));
                        return;
                    }
                }

                string   containerPath = this.currentDirPath;
                string[] names         = dirPath.Split('\\');
                string   dirName       = names[names.Length - 1];
                this.fileDirectoryOutter.Upload(this.ownerID, this.netDiskID, dirPath, containerPath + dirName);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #2
0
        private void   文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = FileHelper.GetFileToOpen("请选择要上传的文件");
                if (filePath == null)
                {
                    return;
                }

                string fileName = FileHelper.GetFileNameNoPath(filePath);
                foreach (ListViewItem item in this.listView_fileDirectory.Items)
                {
                    if (((FileOrDirectoryTag)item.Tag).IsFile && item.Text.ToLower() == fileName.ToLower())
                    {
                        if (!WindowsHelper.ShowQuery(string.Format("{0}已经存在,确定要覆盖它吗?", fileName)))
                        {
                            return;
                        }
                    }
                }

                if (this.IsNetworkDisk)
                {
                    ulong            fileSize  = FileHelper.GetFileSize(filePath);
                    NetworkDiskState state     = this.fileDirectoryOutter.GetNetworkDiskState(this.netDiskID);
                    ulong            available = state.TotalSize - state.SizeUsed;
                    if (available < fileSize)
                    {
                        MessageBox.Show(string.Format("网络硬盘剩余空间为{0},无法上传大小为{1}的文件!", PublicHelper.GetSizeString(available), PublicHelper.GetSizeString(fileSize)));
                        return;
                    }
                }


                this.fileDirectoryOutter.Upload(this.ownerID, this.netDiskID, filePath, this.currentDirPath + fileName);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Beispiel #3
0
        public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
        {
            #region ReqDirectory
            if (informationType == this.fileDirectoryInfoTypes.ReqDirectory)
            {
                ReqDirectoryContract contract = CompactPropertySerializer.Default.Deserialize <ReqDirectoryContract>(info, 0);
                SharedDirectory      dir      = this.networkDisk.GetNetworkDisk(sourceUserID, contract.NetDiskID, contract.DirectoryPath);
                return(CompactPropertySerializer.Default.Serialize <ResDirectoryContract>(new ResDirectoryContract(dir)));
            }
            #endregion

            #region ReqNetworkDiskState
            if (informationType == this.fileDirectoryInfoTypes.ReqNetworkDiskState)
            {
                string netDiskID = null;
                if (info != null)
                {
                    netDiskID = System.Text.Encoding.UTF8.GetString(info);
                }
                NetworkDiskState state = this.networkDisk.GetNetworkDiskState(sourceUserID, netDiskID);
                return(CompactPropertySerializer.Default.Serialize <ResNetworkDiskStateContract>(new ResNetworkDiskStateContract(state)));
            }
            #endregion

            if (informationType == this.fileDirectoryInfoTypes.Rename)
            {
                RenameContract contract = CompactPropertySerializer.Default.Deserialize <RenameContract>(info, 0);
                try
                {
                    this.networkDisk.Rename(sourceUserID, contract.NetDiskID, contract.ParentDirectoryPath, contract.IsFile, contract.OldName, contract.NewName);
                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));
                }
                catch (Exception ee)
                {
                    string error = "";
                    if (ee is IOException)
                    {
                        error = string.Format("{0} 正在被使用!", Path.GetFileName(contract.OldName));
                    }
                    else
                    {
                        error = ee.Message;
                    }
                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));;
                }
            }

            #region DownloadFile
            if (informationType == this.fileDirectoryInfoTypes.Download)
            {
                DownloadContract contract      = CompactPropertySerializer.Default.Deserialize <DownloadContract>(info, 0);
                string           fileOrDirPath = this.networkDisk.GetNetworkDiskRootPath(sourceUserID, contract.NetDiskID) + contract.SourceRemotePath;
                string           error         = "";
                try
                {
                    if (File.Exists(fileOrDirPath))
                    {
                        FileStream stream = File.OpenRead(fileOrDirPath);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        if (!Directory.Exists(fileOrDirPath))
                        {
                            error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fileOrDirPath));
                            return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                        }
                    }
                }
                catch (Exception ee)
                {
                    if (ee is FileNotFoundException)
                    {
                        error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fileOrDirPath));
                    }
                    else if (ee is IOException)
                    {
                        error = string.Format("{0} 正在被其它进程占用!", Path.GetFileName(fileOrDirPath));
                    }
                    else
                    {
                        error = ee.Message;
                    }

                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                }


                string projectID = null;
                this.fileController.BeginSendFile(sourceUserID, fileOrDirPath, Comment4NDisk.BuildComment(contract.SaveLocalPath, contract.NetDiskID), out projectID);

                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));
            }
            #endregion

            #region DeleteFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Delete)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    DeleteContract contract = CompactPropertySerializer.Default.Deserialize <DeleteContract>(info, 0);
                    this.networkDisk.DeleteFileOrDirectory(sourceUserID, contract.NetDiskID, contract.SourceParentDirectoryPath, contract.FilesBeDeleted, contract.DirectoriesBeDeleted);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region CopyFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Copy)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    CopyContract contract = CompactPropertySerializer.Default.Deserialize <CopyContract>(info, 0);
                    this.networkDisk.Copy(sourceUserID, contract.NetDiskID, contract.SourceParentDirectoryPath, contract.FilesBeCopyed, contract.DirectoriesBeCopyed, contract.DestParentDirectoryPath);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region MoveFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Move)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    MoveContract contract = CompactPropertySerializer.Default.Deserialize <MoveContract>(info, 0);
                    this.networkDisk.Move(sourceUserID, contract.NetDiskID, contract.OldParentDirectoryPath, contract.FilesBeMoved, contract.DirectoriesBeMoved, contract.NewParentDirectoryPath);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion
            return(null);
        }
Beispiel #4
0
 public ResNetworkDiskStateContract(NetworkDiskState state)
 {
     this.networkDiskState = state;
 }
Beispiel #5
0
        private void listView_fileDirectory_DragDrop(object sender, DragEventArgs e)
        {
            if ((this.ownerSharedAllDisk || this.IsNetworkDisk) && this.currentDirPath == null)
            {
                return;
            }

            try
            {
                string containerPath = this.currentDirPath;
                ListViewHitTestInfo containerInfo = this.listView_fileDirectory.HitTest(this.PointToClient(new Point(e.X, e.Y)));
                if (containerInfo.Item != null && !((FileOrDirectoryTag)containerInfo.Item.Tag).IsFile)
                {
                    containerPath += containerInfo.Item.Text + "\\";
                }

                ListViewItem targetItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
                if (targetItem != null)
                {
                    #region 内部拖动
                    if (targetItem == containerInfo.Item)
                    {
                        return;
                    }

                    if (containerPath != this.currentDirPath)
                    {
                        if (this.ExistSameNameItem(containerPath, targetItem.Text))
                        {
                            MessageBox.Show("目标目录中存在同名文件或文件夹,请更改名称后重试!");
                            return;
                        }
                    }

                    List <string> fileNames = new List <string>();
                    List <string> dirNames  = new List <string>();
                    if (((FileOrDirectoryTag)targetItem.Tag).IsFile)
                    {
                        fileNames.Add(targetItem.Text);
                    }
                    else
                    {
                        dirNames.Add(targetItem.Text);
                    }

                    OperationResult result = null;
                    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                    {
                        result = this.fileDirectoryOutter.Copy(this.ownerID, this.netDiskID, this.currentDirPath, fileNames, dirNames, containerPath);
                    }
                    else
                    {
                        if (this.currentDirPath != containerPath)
                        {
                            result = this.fileDirectoryOutter.Move(this.ownerID, this.netDiskID, this.currentDirPath, fileNames, dirNames, containerPath);
                        }
                    }

                    if (result != null && !result.Succeed)
                    {
                        MessageBox.Show(result.ErrorMessage);
                    }

                    this.LoadDirectory(this.currentDirPath, true);

                    #endregion
                    return;
                }


                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    #region 从外部拖入
                    string[] fileOrDirs = (string[])e.Data.GetData(DataFormats.FileDrop);
                    if (!this.allowUploadFolder)
                    {
                        foreach (string fileOrDirPath in fileOrDirs)
                        {
                            if (Directory.Exists(fileOrDirPath))
                            {
                                MessageBox.Show("不能够上传文件夹。");
                                return;
                            }
                        }
                    }

                    ulong fileSize = 0;
                    foreach (string fileOrDirPath in fileOrDirs)
                    {
                        if (File.Exists(fileOrDirPath))
                        {
                            fileSize += FileHelper.GetFileSize(fileOrDirPath);
                        }

                        if (Directory.Exists(fileOrDirPath))
                        {
                            fileSize += FileHelper.GetDirectorySize(fileOrDirPath);
                        }

                        string fileOrDirName = FileHelper.GetFileNameNoPath(fileOrDirPath);

                        if (this.ExistSameNameItem(containerPath, fileOrDirName))
                        {
                            MessageBox.Show("目标目录中存在同名文件或文件夹,请更改名称后重新上传!");
                            return;
                        }
                    }

                    if (this.IsNetworkDisk)
                    {
                        NetworkDiskState state     = this.fileDirectoryOutter.GetNetworkDiskState(this.netDiskID);
                        ulong            available = state.TotalSize - state.SizeUsed;
                        if (available < fileSize)
                        {
                            MessageBox.Show(string.Format("空间不足!网络硬盘剩余空间为{0},所需空间为{1}!", PublicHelper.GetSizeString(available), PublicHelper.GetSizeString(fileSize)));
                            return;
                        }
                    }

                    foreach (string fileOrDirPath in fileOrDirs)
                    {
                        if (File.Exists(fileOrDirPath))
                        {
                            string fileName = FileHelper.GetFileNameNoPath(fileOrDirPath);
                            this.fileDirectoryOutter.Upload(this.ownerID, this.netDiskID, fileOrDirPath, containerPath + fileName);
                        }

                        if (Directory.Exists(fileOrDirPath))
                        {
                            string[] names   = fileOrDirPath.Split('\\');
                            string   dirName = names[names.Length - 1];
                            this.fileDirectoryOutter.Upload(this.ownerID, this.netDiskID, fileOrDirPath, containerPath + dirName);
                            //this.UploadDirectory(filePath, containerPath);
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }