Esempio n. 1
0
 private void OnOutputReceived(object sender, OnResponseReceivedArgs e)
 {
     switch (e.ResponseType)
     {
     case ProtocolTypes.TYPE_PUT_CONTENT:
     {
         PutContentRes res = e.GetResponse <PutContentRes>();
         if (res.ErorrOccured)
         {
             LogEvent("请求上传文件失败,请关闭窗口并重试。");
         }
         else
         {
             LogEvent("请求上传文件成功。正在上传文件...");
             mSendFilesThread = new Thread(SendContent);
             mSendFilesThread.IsBackground = true;
             mSendFilesThread.Start();
         }
     }
     break;
     }
 }
 public void ReceiveResponse()
 {
     try
     {
         do
         {
             if (IsClosed)
             {
                 return;
             }
             int    protocalType         = mSocketTalker.ReceiveInt();
             string responseJSON         = mSocketTalker.ReceiveString();
             OnResponseReceivedArgs args = new OnResponseReceivedArgs();
             args.ResponseType = protocalType;
             args.ResponseJSON = responseJSON;
             mForm.Invoke(mOnResponseReceivedHandler, this, args);
         } while (mIsOnlyOnce == false);
     }
     catch (Exception e)
     {
         Close(e);
     }
 }
Esempio n. 3
0
        private void OnOutputReceived(object sender, OnResponseReceivedArgs e)
        {
            switch (e.ResponseType)
            {
            case ProtocolTypes.TYPE_LIST_CONTENTS:
            {
                ListContentsRes res = e.GetResponse <ListContentsRes>();
                if (res.ErorrOccured)
                {
                    mErrorLable.Text = res.ErrorMessage;
                    mErrorLable.Show();
                    mContentList.Items.Clear();
                }
                else
                {
                    mErrorLable.Text = "";
                    mErrorLable.Hide();
                    mContentList.Items.Clear();

                    if (res.Drivers != null && res.Drivers.Length > 0)
                    {
                        foreach (string driver in res.Drivers)
                        {
                            ListViewItem item = new ListViewItem();
                            item.ImageKey = "driver.png";
                            item.Text     = driver;
                            mContentList.Items.Add(item);
                        }
                    }
                    if (res.Directories != null && res.Directories.Length > 0)
                    {
                        foreach (string directory in res.Directories)
                        {
                            ListViewItem item = new ListViewItem();
                            item.ImageKey = "folder.png";
                            item.Text     = Path.GetFileName(directory);
                            mContentList.Items.Add(item);
                        }
                    }
                    if (res.Files != null && res.Files.Length > 0)
                    {
                        foreach (string file in res.Files)
                        {
                            ListViewItem item = new ListViewItem();
                            item.ImageKey = "file.png";
                            item.Text     = Path.GetFileName(file);
                            mContentList.Items.Add(item);
                        }
                    }
                }
                mGoToOrRefreshButton.Text = "刷新";
            }
            break;

            case ProtocolTypes.TYPE_RENAME_CONTENT:
            {
                RenameContentRes res = e.GetResponse <RenameContentRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "重命名失败");
                }
                SendListContentsReq();
            }
            break;

            case ProtocolTypes.TYPE_DELETE_CONTENTS:
            {
                DeleteContentsRes res = e.GetResponse <DeleteContentsRes>();
                if (res.ErorrOccured)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (string result in res.DeleteResults)
                    {
                        if (result != null)
                        {
                            builder.AppendLine(result);
                        }
                    }
                    MessageBox.Show(builder.ToString(), "删除出现错误");
                }
                SendListContentsReq();
            }
            break;

            case ProtocolTypes.TYPE_CREATE_DIRECTORY:
            {
                CreateDirectoryRes res = e.GetResponse <CreateDirectoryRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "新建文件夹失败");
                }
                SendListContentsReq();
            }
            break;

            case ProtocolTypes.TYPE_START_PROCESS:
            {
                StartProcessRes res = e.GetResponse <StartProcessRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "打开进程失败");
                }
            }
            break;

            case ProtocolTypes.TYPE_GET_CONTENT_INFO:
            {
                GetContentInfoRes res = e.GetResponse <GetContentInfoRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "获取属性失败");
                }
                else
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (TextInfo result in res.InfoList)
                    {
                        builder.AppendLine(result.Name + " : " + result.Value);
                    }
                    MessageBox.Show(builder.ToString(), "数学");
                }
            }
            break;

            case ProtocolTypes.TYPE_MOVE_CONTENTS:
            {
                MoveContentsRes res = e.GetResponse <MoveContentsRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "移动出现错误");
                }
                else
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (string result in res.MoveResults)
                    {
                        if (result != null)
                        {
                            builder.AppendLine(result);
                        }
                    }
                    if (builder.Length > 0)
                    {
                        MessageBox.Show(builder.ToString(), "移动出现错误");
                    }
                }
                SendListContentsReq();
            }
            break;

            case ProtocolTypes.TYPE_COPY_CONTENTS:
            {
                CopyContentsRes res = e.GetResponse <CopyContentsRes>();
                if (res.ErorrOccured)
                {
                    MessageBox.Show(res.ErrorMessage, "复制出现错误");
                }
                else
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (string result in res.CopyResults)
                    {
                        if (result != null)
                        {
                            builder.AppendLine(result);
                        }
                    }
                    if (builder.Length > 0)
                    {
                        MessageBox.Show(builder.ToString(), "复制出现错误");
                    }
                }
                SendListContentsReq();
            }
            break;
            }
        }