コード例 #1
0
ファイル: NginxMonitorForm.cs プロジェクト: sy26856/AMShell
        public void runTaskShell(CmdShell cmds, TaskShell task)
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                string shdir = itemConfig.nginx.NginxPath;
                if (null != shdir)
                {
                    if (shdir.EndsWith("/"))
                    {
                        shdir = shdir.Substring(0, shdir.Length - 1);
                    }
                    shdir = shdir.Substring(0, shdir.LastIndexOf("/") + 1);
                }

                string shell = task.Shell;
                if (shell.Contains("{nginx_dir}"))
                {
                    shell = shell.Replace("{nginx_dir}", shdir);
                }

                if (shell.Contains("{nginx}"))
                {
                    shell = shell.Replace("{nginx}", itemConfig.nginx.NginxPath);
                }

                shell = shell.Replace("//", "/");

                monitorForm.RunShell(shell, false);
            });
        }
コード例 #2
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem item = customShellListView.SelectedItems[0];
                CmdShell     cmds = (CmdShell)item.Tag;
                if (cmds.TaskType == TaskType.Default)
                {
                    CustomShellForm form = new CustomShellForm(seConfig, itemConfig.tomcat.Uuid);
                    form.SetUpdater(cmds);
                    form.ShowDialog(this);

                    shellView.Text  = "";
                    btn_run.Enabled = false;
                    RenderCustomShellList();
                }
                else if (cmds.TaskType == TaskType.Timed)
                {
                    TimedTaskForm form = new TimedTaskForm(itemConfig.tomcat.Index);
                    form.setCallback(new TimedTaskForm.AsyncCallback(editTaskFinish));
                    form.SetUpdater(cmds);
                    form.ShowDialog(this);
                }
                else if (cmds.TaskType == TaskType.Condition)
                {
                    ConditionTaskForm form = new ConditionTaskForm(seConfig, itemConfig.tomcat.Index);
                    form.setCallback(new ConditionTaskForm.AsyncCallback(editTaskFinish));
                    form.SetUpdater(cmds);
                    form.ShowDialog(this);
                }
            }
            catch { }
        }
コード例 #3
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
 private void customShellListView_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (customShellListView.SelectedItems.Count > 0)
     {
         ListViewItem item = customShellListView.SelectedItems[0];
         if (null != item)
         {
             CmdShell      cmds = (CmdShell)item.Tag;
             StringBuilder sb   = new StringBuilder();
             foreach (TaskShell task in cmds.ShellList)
             {
                 if (cmds.TaskType == TaskType.Default)
                 {
                     sb.AppendLine(task.Shell);
                 }
                 else if (cmds.TaskType == TaskType.Timed)
                 {
                     sb.AppendLine(string.Format("{0} - {1}", task.DateTime, task.Shell));
                 }
             }
             shellView.Text = sb.ToString();
             if (cmds.TaskType == TaskType.Default)
             {
                 btn_run.Enabled = true;
             }
             return;
         }
     }
     btn_run.Enabled = false;
     shellView.Text  = "";
 }
コード例 #4
0
ファイル: IceMonitorForm.cs プロジェクト: sy26856/AMShell
        public void runTaskShell(CmdShell cmds, TaskShell task)
        {
            ThreadPool.QueueUserWorkItem((a) => {
                string srvdir = itemConfig.ice.IceSrvDir;
                if (null != srvdir)
                {
                    if (!srvdir.EndsWith("/"))
                    {
                        srvdir += "/";
                    }
                }

                string shell = task.Shell;
                if (shell.Contains("{icesrv_dir}"))
                {
                    shell = shell.Replace("{icesrv_dir}", srvdir);
                }

                if (shell.Contains("{server_name}"))
                {
                    shell = shell.Replace("{server_name}", l_server_name.Text);
                }

                if (shell.Contains("{adminsh}"))
                {
                    shell = shell.Replace("{adminsh}", srvdir + "bin/admin.sh");
                }
                shell = shell.Replace("//", "/");

                monitorForm.RunShell(shell, false);
            });
        }
コード例 #5
0
ファイル: App.cs プロジェクト: codemerx/CodemerxDecompile
        public static void Main(string[] args)
        {
            GeneratorProjectInfo generatorProjectInfo = CommandLineManager.Parse(args);
            CmdShell             shell = new CmdShell();

            shell.Run(generatorProjectInfo);
        }
コード例 #6
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
        public void editTaskFinish(CmdShell cs)
        {
            shellView.Text  = "";
            btn_run.Enabled = false;

            AppConfig.Instance.SaveConfig(2);
            RenderCustomShellList();
        }
コード例 #7
0
        public void ExitTest()
        {
            var shell = new CmdShell(recorder);

            shell.Exited.Should().BeFalse();
            shell.Run("exit");
            shell.Exited.Should().BeTrue();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var msBuildCommandPrompt = @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat";
            var somePath             = @"C:\temp";

            var cmdCommands = $@"
CD /

none_existing_command /oops
ping example.com -n 2
none_existing_command /oops

CALL ""{msBuildCommandPrompt}""

CD ""{somePath}""

CALL MsBuild SomeProject.csproj^
 /target:Build^
 /p:Configuration=Release^
 /verbosity:normal^
 /maxCpuCount

ECHO ErrorLever = %ERRORLEVEL%";

            var exitCode1 = new CmdShell()
                            .ExecAndShowCatched(cmdCommands);

            StringBuilder output;
            var           exitCode1_2 = new CmdShell()
                                        .ExecAndShowCatched(cmdCommands, out output);

            var exitCode2 = new CmdShell()
                            .ExecAndShow(cmdCommands);

            var exitCode3 = new CmdShell()
                            .ExecExample(cmdCommands);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("exit code is {0} for ExecAndShowCatched", exitCode1);
            Console.WriteLine("exit code is {0} for ExecAndShowCatched with outputs", exitCode1_2);
            Console.WriteLine("exit code is {0} for ExecAndShow", exitCode2);
            Console.WriteLine("exit code is {0} for ExecExample", exitCode3);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("========================================================");
            Console.WriteLine("Click to show intercepted outputs for ExecAndShowCatched");
            Console.WriteLine("========================================================");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Console.ReadKey();
            Console.WriteLine(output);
        }
コード例 #9
0
ファイル: NginxMonitorForm.cs プロジェクト: sy26856/AMShell
        public void addTimedTaskFinish(CmdShell cs)
        {
            cs.Target = itemConfig.nginx.Uuid;

            seConfig.CustomShellList.Add(cs);

            AppConfig.Instance.SaveConfig(2);

            RenderCustomShellList();
        }
コード例 #10
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
        public void addConditionTaskFinish(CmdShell cs)
        {
            cs.Target = itemConfig.tomcat.Uuid;

            seConfig.CustomShellList.Add(cs);

            AppConfig.Instance.SaveConfig(2);

            RenderCustomShellList();
        }
コード例 #11
0
        public void StartupTest()
        {
            using (var shell = new CmdShell(recorder))
            {
                recorder.Out.Should().HaveCount(5);
                recorder.Out[3].Should().StartWith("Haterm");
                recorder.Out[4].Should().BeEmpty();

                recorder.Err.Should().BeEmpty();
            }
        }
コード例 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name   = stb_name.Text;
            string cmdstr = cmd.Text;

            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show(this, "请定义一个名称");
                return;
            }
            if (string.IsNullOrWhiteSpace(cmdstr))
            {
                MessageBox.Show(this, "请输入要执行的命令");
                return;
            }
            List <TaskShell> cmdList = new List <TaskShell>();

            string[]  cmds = cmdstr.Split('\n');
            TaskShell task = null;

            foreach (string c in cmds)
            {
                if (!string.IsNullOrWhiteSpace(c.Trim()))
                {
                    task       = new TaskShell();
                    task.Uuid  = Guid.NewGuid().ToString("N");
                    task.Name  = "";
                    task.Shell = c.Trim();
                    cmdList.Add(task);
                }
            }
            bool isnew = false;

            if (shell == null)
            {
                shell        = new CmdShell();
                shell.Uuid   = Guid.NewGuid().ToString("N");
                shell.Target = uuid;
                isnew        = true;
            }
            shell.Name      = name;
            shell.Type      = "自定义脚本";
            shell.TaskType  = TaskType.Default;
            shell.ShellList = cmdList;
            if (isnew)
            {
                config.CustomShellList.Add(shell);
            }

            AppConfig.Instance.SaveConfig(2);

            this.Close();
        }
コード例 #13
0
        public void RunCmdTest()
        {
            using (var shell = new CmdShell(recorder))
            {
                recorder.Out.Clear();
                recorder.Err.Clear();

                shell.Run("echo 1");
                recorder.Out.Should().HaveCount(2);
                recorder.Err.Should().BeEmpty();
            }
        }
コード例 #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            string name  = task_name.Text;
            int    count = customShellListView.Items.Count;

            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show(this, "请输入任务名称");
                task_name.Focus();
            }
            else if (count == 0)
            {
                MessageBox.Show(this, "请添加任务指令脚本(Shell)");
                shell_name.Focus();
            }
            else
            {
                ListView.ListViewItemCollection coll = customShellListView.Items;
                if (null == cmdShell)
                {
                    cmdShell          = new CmdShell();
                    cmdShell.Type     = "定时任务";
                    cmdShell.TaskType = TaskType.Timed;
                }
                cmdShell.Name = name;

                JObject          obj       = null;
                JArray           list      = new JArray();
                List <TaskShell> shellList = new List <TaskShell>();
                TaskShell        task      = null;

                foreach (ListViewItem item in coll)
                {
                    obj           = (JObject)item.Tag;
                    task          = new TaskShell();
                    task.Uuid     = Guid.NewGuid().ToString("N");
                    task.DateTime = obj["time"].ToString();
                    task.Shell    = obj["code"].ToString();
                    task.Name     = obj["name"].ToString();
                    shellList.Add(task);
                }
                cmdShell.ShellList = shellList;

                if (null != this.callback)
                {
                    this.callback(cmdShell);
                }

                this.Close();
            }
        }
コード例 #15
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
        public void runTaskShell(CmdShell cmds, TaskShell task)
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                string shdir = itemConfig.tomcat.TomcatDir;
                if (null != shdir)
                {
                    if (!shdir.EndsWith("/"))
                    {
                        shdir += "/";
                    }
                }

                string shell = task.Shell;
                if (shell.Contains("{tomcat_dir}"))
                {
                    shell = shell.Replace("{tomcat_dir}", shdir);
                }

                if (shell.Contains("{tomcat_webapps}"))
                {
                    shell = shell.Replace("{tomcat_webapps}", shdir + "webapps/");
                }

                if (shell.Contains("{tomcat_logs}"))
                {
                    shell = shell.Replace("{tomcat_logs}", shdir + "logs/");
                }

                if (shell.Contains("{tomcat_startup}"))
                {
                    shell = shell.Replace("{tomcat_startup}", shdir + "bin/startup.sh");
                }

                if (shell.Contains("{tomcat_shutdown}"))
                {
                    shell = shell.Replace("{tomcat_shutdown}", shdir + "bin/shutdown.sh");
                }

                shell = shell.Replace("//", "/");

                monitorForm.RunShell(shell, false);
            });
        }
コード例 #16
0
ファイル: TomcatMonitorForm.cs プロジェクト: sy26856/AMShell
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (customShellListView.SelectedItems.Count > 0)
            {
                try
                {
                    ListViewItem item = customShellListView.SelectedItems[0];
                    DialogResult dr   = MessageBox.Show(this, "您确定要删除此项吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        customShellListView.Items.Remove(item);
                        CmdShell cmds = (CmdShell)item.Tag;
                        seConfig.CustomShellList.Remove(cmds);

                        AppConfig.Instance.SaveConfig(2);
                    }
                }
                catch { }
            }
        }
コード例 #17
0
        public static void Main(string[] args)
        {
            IShell shell = null;

            try
            {
                shell = new CmdShell(new DualWrapper());
                using (var haterm = new Haterm(CmdTerminal.Instance, shell))
                {
                    shell = null;
                    haterm.Run();
                }
            }
            finally
            {
                if (shell != null)
                {
                    shell.Dispose();
                }
            }
        }
コード例 #18
0
        public void runTaskShell(CmdShell cmds, TaskShell task)
        {
            ThreadPool.QueueUserWorkItem((a) => {
                string shdir = itemConfig.spring.ShFileDir;
                if (null != shdir)
                {
                    if (!shdir.EndsWith("/"))
                    {
                        shdir += "/";
                    }
                }

                string shell = task.Shell;
                if (shell.Contains("{sh_bin_dir}"))
                {
                    shell = shell.Replace("{sh_bin_dir}", shdir);
                }

                if (shell.Contains("{project_dir}"))
                {
                    shell = shell.Replace("{project_dir}", l_source_path.Text);
                }

                if (shell.Contains("{build_sh_file}"))
                {
                    shell = shell.Replace("{build_sh_file}", itemConfig.spring.BuildFileName);
                }

                if (shell.Contains("{ctl_sh_file}"))
                {
                    shell = shell.Replace("{ctl_sh_file}", itemConfig.spring.CrlFileName);
                }
                shell = shell.Replace("//", "/");

                monitorForm.RunShell(shell, false);
            });
        }
コード例 #19
0
 protected void CmdExecute(string command)
 {
     CmdShell.Execute(command);
 }
コード例 #20
0
        private void button2_Click(object sender, EventArgs e)
        {
            string name  = task_name.Text;
            int    count = customShellListView.Items.Count;

            Object item1 = scb_condition1.SelectedItem;
            Object item2 = scb_condition2.SelectedItem;
            Object item3 = scb_condition3.SelectedItem;

            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show(this, "请输入任务名称");
                task_name.Focus();
            }
            else if (item1 == null)
            {
                MessageBox.Show(this, "请至少选择一个条件");
            }
            else if (count == 0)
            {
                MessageBox.Show(this, "请添加任务指令脚本(Shell)");
                shell_name.Focus();
            }
            else
            {
                string        condition = "";
                ConditionItem ci1       = (ConditionItem)item1;
                condition += getItemUuid(ci1) + "," + (scb_status1.SelectedIndex == 1 ? "Y" : "N");
                if (item2 != null)
                {
                    ConditionItem ci2 = (ConditionItem)item2;
                    condition += getItemCondi(1) + getItemUuid(ci2) + "," + (scb_status2.SelectedIndex == 1 ? "Y" : "N");

                    if (item3 != null)
                    {
                        ConditionItem ci3 = (ConditionItem)item2;
                        condition += getItemCondi(2) + getItemUuid(ci3) + "," + (scb_status3.SelectedIndex == 1 ? "Y" : "N");
                    }
                }

                ListView.ListViewItemCollection coll = customShellListView.Items;
                if (null == cmdShell)
                {
                    cmdShell      = new CmdShell();
                    cmdShell.Uuid = Guid.NewGuid().ToString("N");
                }
                JObject          obj       = null;
                JArray           list      = new JArray();
                List <TaskShell> shellList = new List <TaskShell>();
                TaskShell        task      = null;
                cmdShell.Name      = name;
                cmdShell.TaskType  = TaskType.Condition;
                cmdShell.Condition = condition;
                cmdShell.Type      = "条件任务";
                foreach (ListViewItem item in coll)
                {
                    obj        = (JObject)item.Tag;
                    task       = new TaskShell();
                    task.Uuid  = Guid.NewGuid().ToString("N");
                    task.Shell = obj["code"].ToString();
                    task.Name  = obj["name"].ToString();
                    shellList.Add(task);
                }
                cmdShell.ShellList = shellList;

                if (null != this.callback)
                {
                    this.callback(cmdShell);
                }

                this.Close();
            }
        }
コード例 #21
0
 public void SetUpdater(CmdShell cmds)
 {
     cmdShell = cmds;
 }