Ejemplo n.º 1
0
 private void TbCommand_OnKeyDown(object sender, KeyEventArgs e)
 {
     switch (e.Key)
     {
     case Key.Enter:
         TbTerminalLog.Text += TbCurPass.Text + TbCommand.Text + "\n";
         var result = _serverProxy.RunScript(TbCommand.Text);
         if (result.Success && !string.IsNullOrEmpty(result.Response))
         {
             TbTerminalLog.Text += result.Response;
         }
         UpdateCurrentLocation();
         TbCommand.Clear();
         break;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 监听Redis执行命令
        /// </summary>
        /// <param name="command"></param>
        public static void Excute(TbCommand command)
        {
            var success = 0;
            var job     = TbJob.Find("ID", command.Jobid);

            if (job == null)
            {
                return;
            }

            Type jobtype;
            var  type = (CommandType)command.Commandtype;

            switch (type)
            {
            case CommandType.Pause:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                PauseToQuartz(jobtype, job);
                job.State = 0;
                //job.Lastedend = DateTime.Now.TimeSpan();
                success = job.SaveAsync() ? 1 : 0;
                break;

            case CommandType.Delete:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                if (job.State == 0)
                {
                    DelteToQuartz(jobtype, job);
                }
                DeleteDll(job.ID);
                if (job.Delete() > 0)
                {
                    var zip = TbZip.Find("JobID", command.Jobid);
                    zip?.Delete();
                    success = 1;
                }
                break;

            case CommandType.Stop:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                DelteToQuartz(jobtype, job);
                job.State = 0;
                //job.Lastedend = DateTime.Now.TimeSpan();
                job.SaveAsync();
                success = 1;
                break;

            case CommandType.Start:
                if (job.State == 1)
                {
                    jobtype = GetJobType(command.Jobid);
                    PauseToQuartz(jobtype, job);
                    File.Delete(GetJobPath(job.ID) + "zip");
                }
                if (Dictionary.ContainsKey(job.Name))
                {
                    jobtype = GetJobType(command.Jobid);
                    ResumeToQuartz(jobtype, job);
                    job.State = 1;
                    //job.Runcount++;
                    //job.Lastedstart = DateTime.Now.TimeSpan();
                    success = job.SaveAsync() ? 1 : 0;
                    break;
                }
                var path = CreateFile(job.ID, job.NodeID);
                DownLoadZip(job.ID, path);
                var json = new Dictionary <string, object>();
                if (!job.Datamap.IsNullOrWhiteSpace())
                {
                    json = job.Datamap.ToJsonEntity <Dictionary <string, object> >();
                }
                if (!json.ContainsKey("jobid"))
                {
                    json.Add("jobid", job.ID);
                }
                JoinToQuartz(GetJobType(command.Jobid), job, json);
                job.State = 1;
                //job.Runcount++;
                //job.Lastedstart = DateTime.Now.TimeSpan();
                success = job.SaveAsync() ? 1 : 0;
                break;

            case CommandType.ReStart:
                //var jsons = new Dictionary<string, object>();
                //if (!job.Datamap.IsNullOrWhiteSpace())
                //    jsons = job.Datamap.ToJsonEntity<Dictionary<string, object>>();
                //if (!jsons.ContainsKey("jobid"))
                //    jsons.Add("jobid", job.ID);
                //jobtype = GetJobType(command.Jobid);
                //ResumeToQuartz(jobtype);
                //job.State = 1;
                //job.Runcount++;
                //job.Lastedstart = DateTime.Now.TimeSpan();
                //success = job.SaveAsync() ? 1 : 0;
                break;

            default:
                break;
            }
            command.Success = success;
        }