示例#1
0
        private void BuildButtons(StartLight light)
        {
            foreach (Statement statement in light.ScriptsList)
            {
                Button tempBtn  = new Button();
                Button tempBtn2 = new Button();
                tempBtn.Content = statement.Label;
                tempBtn.Name    = "exec_" + statement.Identity;
                tempBtn.ToolTip = statement.Description;
                switch (statement.OperationType.ToLowerInvariant())
                {
                case "ssh":
                    if (statement.ServerName.ToSafeString() != "")
                    {
                        tempBtn.Click += new RoutedEventHandler((e, o) =>
                                                                Behaviours.ExecScriptWithLog()(
                                                                    light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])],
                                                                    txtTailPars.Text,
                                                                    execBar,
                                                                    txtBox,
                                                                    light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])].ServerName,
                                                                    light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])].ServerUser,
                                                                    light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])].ServerPassword));
                    }
                    else
                    {
                        tempBtn.Click += new RoutedEventHandler((e, o) =>
                                                                Behaviours.ExecScriptWithLog()(
                                                                    light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])],
                                                                    txtTailPars.Text,
                                                                    execBar,
                                                                    txtBox,
                                                                    light.ServerName,
                                                                    light.ServerUser,
                                                                    light.ServerPassword));
                    }
                    break;

                case "localosstatement":
                    tempBtn.Click += new RoutedEventHandler((e, o) =>
                                                            Behaviours.StartProcess()(statement, txtTailPars.Text, txtBox, this.execBar));
                    break;

                default:
                    break;
                }

                btnMain.Children.Add(tempBtn);

                tempBtn2.Content = "script";
                tempBtn2.Name    = "script_" + statement.Identity;
                tempBtn2.Click  += new RoutedEventHandler(
                    (e, o) => MessageBox.Show(light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])].ScriptToLaunch + " " + light.ScriptsList[Convert.ToInt16(tempBtn.Name.Split('_')[1])].Parameters + txtTailPars.Text)

                    );
                btnMainScripts.Children.Add(tempBtn2);
            }
        }