Exemplo n.º 1
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);
        }
Exemplo n.º 2
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.DirectoryPath);
                return CompactPropertySerializer.Default.Serialize<ResDirectoryContract>(new ResDirectoryContract(dir));
            }
            #endregion

            #region ReqNetworkDiskState
            if (informationType == this.fileDirectoryInfoTypes.ReqNetworkDiskState)
            {
                NetworkDiskState state = this.networkDisk.GetNetworkDiskState(sourceUserID);
                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.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.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), 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.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.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.OldParentDirectoryPath, contract.FilesBeMoved, contract.DirectoriesBeMoved, contract.NewParentDirectoryPath);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return CompactPropertySerializer.Default.Serialize<OperationResultConatract>(resultContract);
            }
            #endregion
            return null;
        }
Exemplo n.º 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);
                string          fullPath      = this.ConstructFullPath(contract.DirectoryPath);
                SharedDirectory dir           = SharedDirectory.GetSharedDirectory(fullPath);
                return(CompactPropertySerializer.Default.Serialize <ResDirectoryContract>(new ResDirectoryContract(dir)));
            }
            #endregion

            #region Rename
            if (informationType == this.fileDirectoryInfoTypes.Rename)
            {
                RenameContract contract = CompactPropertySerializer.Default.Deserialize <RenameContract>(info, 0);
                string         fullPath = this.ConstructFullPath(contract.ParentDirectoryPath);
                try
                {
                    if (contract.IsFile)
                    {
                        File.Move(fullPath + contract.OldName, fullPath + contract.NewName);
                    }
                    else
                    {
                        Directory.Move(fullPath + contract.OldName, fullPath + 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)));;
                }
            }
            #endregion

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

                        return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                    }
                }
                else
                {
                    if (!Directory.Exists(fullPath))
                    {
                        string error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fullPath));
                        return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                    }
                }

                string fileID = null;
                this.fileOutter.BeginSendFile(sourceUserID, fullPath, Comment4NDisk.BuildComment(contract.SaveLocalPath, contract.NetDiskID), out fileID);
                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);
                    string         fullPath = this.ConstructFullPath(contract.SourceParentDirectoryPath);
                    if (contract.FilesBeDeleted != null)
                    {
                        foreach (string fileName in contract.FilesBeDeleted)
                        {
                            string filePath = fullPath + fileName;
                            if (File.Exists(filePath))
                            {
                                File.Delete(filePath);
                            }
                        }
                    }

                    if (contract.DirectoriesBeDeleted != null)
                    {
                        foreach (string dirName in contract.DirectoriesBeDeleted)
                        {
                            string dirPath = fullPath + dirName + "\\";
                            if (Directory.Exists(dirPath))
                            {
                                FileHelper.DeleteDirectory(dirPath);
                            }
                        }
                    }
                }
                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);
                    FileHelper.Copy(this.ConstructFullPath(contract.SourceParentDirectoryPath), contract.FilesBeCopyed, contract.DirectoriesBeCopyed, this.ConstructFullPath(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);
                    FileHelper.Move(this.ConstructFullPath(contract.OldParentDirectoryPath), contract.FilesBeMoved, contract.DirectoriesBeMoved, this.ConstructFullPath(contract.NewParentDirectoryPath));
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            return(null);
        }
Exemplo n.º 4
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);
                string fullPath = this.ConstructFullPath(contract.DirectoryPath);
                SharedDirectory dir = SharedDirectory.GetSharedDirectory(fullPath);
                return CompactPropertySerializer.Default.Serialize<ResDirectoryContract>(new ResDirectoryContract(dir));
            }
            #endregion

            #region Rename
            if (informationType == this.fileDirectoryInfoTypes.Rename)
            {
                RenameContract contract = CompactPropertySerializer.Default.Deserialize<RenameContract>(info, 0);
                string fullPath = this.ConstructFullPath(contract.ParentDirectoryPath);
                try
                {
                    if (contract.IsFile)
                    {
                        File.Move(fullPath + contract.OldName, fullPath + contract.NewName);
                    }
                    else
                    {
                        Directory.Move(fullPath + contract.OldName, fullPath + 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)); ;
                }
            }
            #endregion

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

                        return CompactPropertySerializer.Default.Serialize<OperationResultConatract>(new OperationResultConatract(error));
                    }
                }
                else
                {
                    if (!Directory.Exists(fullPath))
                    {
                        string error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fullPath));
                        return CompactPropertySerializer.Default.Serialize<OperationResultConatract>(new OperationResultConatract(error));
                    }
                }

                string fileID = null;
                this.fileOutter.BeginSendFile(sourceUserID, fullPath,  Comment4NDisk.BuildComment(contract.SaveLocalPath), out fileID);
                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);
                    string fullPath = this.ConstructFullPath(contract.SourceParentDirectoryPath);
                    if (contract.FilesBeDeleted != null)
                    {
                        foreach (string fileName in contract.FilesBeDeleted)
                        {
                            string filePath = fullPath + fileName;
                            if (File.Exists(filePath))
                            {
                                File.Delete(filePath);
                            }
                        }
                    }

                    if (contract.DirectoriesBeDeleted != null)
                    {
                        foreach (string dirName in contract.DirectoriesBeDeleted)
                        {
                            string dirPath = fullPath + dirName + "\\";
                            if (Directory.Exists(dirPath))
                            {
                                FileHelper.DeleteDirectory(dirPath);
                            }
                        }
                    }
                }
                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);
                    FileHelper.Copy(this.ConstructFullPath(contract.SourceParentDirectoryPath), contract.FilesBeCopyed, contract.DirectoriesBeCopyed, this.ConstructFullPath(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);
                    FileHelper.Move(this.ConstructFullPath(contract.OldParentDirectoryPath), contract.FilesBeMoved, contract.DirectoriesBeMoved, this.ConstructFullPath(contract.NewParentDirectoryPath));
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return CompactPropertySerializer.Default.Serialize<OperationResultConatract>(resultContract);
            }
            #endregion

            return null;
        }