Beispiel #1
0
        public override void ProcessRequest()
        {
            StartProcessReq req = mSocketTalker.ReceiveObject <StartProcessReq>();
            StartProcessRes res = new StartProcessRes();

            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName        = req.FileName;
                startInfo.Arguments       = req.Arguments;
                startInfo.CreateNoWindow  = req.CreateNoWindow;
                startInfo.UseShellExecute = req.UseShellExecute;
                Process.Start(startInfo);

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

                mSocketTalker.SendInt(ProtocolTypes.TYPE_START_PROCESS);
                mSocketTalker.SendObject(res);
            }
        }
Beispiel #2
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;
            }
        }