Ejemplo n.º 1
0
        private void mNewFolderMenuItem_Click(object sender, EventArgs e)
        {
            InputDialog dialog = new InputDialog();

            dialog.Title           = "请输入文件夹名称";
            dialog.AllowEmpty      = false;
            dialog.Result          = "新建文件夹";
            dialog.SelectionStart  = 0;
            dialog.SelectionLength = dialog.Result.Length;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                CreateDirectoryReq req = new CreateDirectoryReq();
                req.Container = mCurrentDirectory;
                req.Name      = dialog.Result;
                mClient.SendRequest(ProtocolTypes.TYPE_CREATE_DIRECTORY, req);
            }
        }
Ejemplo n.º 2
0
        public override void ProcessRequest()
        {
            CreateDirectoryReq req = mSocketTalker.ReceiveObject <CreateDirectoryReq>();
            CreateDirectoryRes res = new CreateDirectoryRes();

            try
            {
                Content content = new Content(req.Container);
                switch (content.Type)
                {
                case Content.TYPE_NOT_FOUND:
                    throw new KnownException("无法在路径 " + content.Path + " 上创建目录,因为它代表的不是一个驱动器或目录。");

                case Content.TYPE_DRIVER:
                    if (IsFileOrDirectoryNameValid(req.Name) == false)
                    {
                        throw new KnownException("要创建的目录名称 " + req.Name + "是无效的。");
                    }
                    Directory.CreateDirectory(content.Path + req.Name + Path.DirectorySeparatorChar);
                    break;

                case Content.TYPE_FILE:
                    throw new KnownException("无法在路径 " + content.Path + " 上创建目录,因为它代表是一个文件。");

                case Content.TYPE_DIRECTORY:
                    if (IsFileOrDirectoryNameValid(req.Name) == false)
                    {
                        throw new KnownException("要创建的目录名称 " + req.Name + "是无效的。");
                    }
                    Directory.CreateDirectory(content.Path + req.Name + Path.DirectorySeparatorChar);
                    break;
                }

                mSocketTalker.SendInt(ProtocolTypes.TYPE_CREATE_DIRECTORY);
                mSocketTalker.SendObject(res);
            }
            catch (Exception e)
            {
                res.ErorrOccured = true;
                res.ErrorMessage = e.Message;

                mSocketTalker.SendInt(ProtocolTypes.TYPE_CREATE_DIRECTORY);
                mSocketTalker.SendObject(res);
            }
        }