Esempio n. 1
0
        public static List <AutomationCommand> GenerateCommandsandControls()
        {
            var commandList = new List <AutomationCommand>();

            var commandClasses = Assembly.GetExecutingAssembly().GetTypes()
                                 .Where(t => t.Namespace == "taskt.Commands")
                                 .Where(t => t.Name != "ScriptCommand")
                                 .Where(t => t.IsAbstract == false)
                                 .Where(t => t.BaseType.Name == "ScriptCommand")
                                 .ToList();

            var cmdAssemblyPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*Commands.dll");

            foreach (var path in cmdAssemblyPaths)
            {
                commandClasses.AddRange(Assembly.LoadFrom(path).GetTypes()
                                        .Where(t => t.Namespace == "taskt.Commands")
                                        .Where(t => t.Name != "ScriptCommand")
                                        .Where(t => t.IsAbstract == false)
                                        .Where(t => t.BaseType.Name == "ScriptCommand")
                                        .ToList());
            }
            var userPrefs = new ApplicationSettings().GetOrCreateApplicationSettings();

            //Loop through each class
            foreach (var commandClass in commandClasses)
            {
                var    groupingAttribute = commandClass.GetCustomAttributes(typeof(Group), true);
                string groupAttribute    = "";
                if (groupingAttribute.Length > 0)
                {
                    var attributeFound = (Group)groupingAttribute[0];
                    groupAttribute = attributeFound.Name;
                }

                //Instantiate Class
                ScriptCommand newCommand = (ScriptCommand)Activator.CreateInstance(commandClass);

                //If command is enabled, pull for display and configuration
                if (newCommand.CommandEnabled)
                {
                    var newAutomationCommand = new AutomationCommand();
                    newAutomationCommand.CommandClass = commandClass;
                    newAutomationCommand.Command      = newCommand;
                    newAutomationCommand.DisplayGroup = groupAttribute;
                    newAutomationCommand.FullName     = string.Join(" - ", groupAttribute, newCommand.SelectionName);
                    newAutomationCommand.ShortName    = newCommand.SelectionName;

                    if (userPrefs.ClientSettings.PreloadBuilderCommands)
                    {
                        //newAutomationCommand.RenderUIComponents();
                    }

                    //call RenderUIComponents to render UI controls
                    commandList.Add(newAutomationCommand);
                }
            }

            return(commandList);
        }
Esempio n. 2
0
        public static Control CreateDefaultLabelFor(string parameterName, ScriptCommand parent)
        {
            var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault();

            var propertyAttributesAssigned = variableProperties.GetCustomAttributes(typeof(PropertyDescription), true);

            Label inputLabel = new Label();

            if (propertyAttributesAssigned.Length > 0)
            {
                var attribute = (PropertyDescription)propertyAttributesAssigned[0];
                inputLabel.Text = attribute.Description;
            }
            else
            {
                inputLabel.Text = parameterName;
            }

            inputLabel.AutoSize  = true;
            inputLabel.Font      = new Font("Segoe UI Light", 12);
            inputLabel.ForeColor = Color.White;
            inputLabel.Name      = "lbl_" + parameterName;
            CreateDefaultToolTipFor(parameterName, parent, inputLabel);
            return(inputLabel);
        }
Esempio n. 3
0
        private void ExecuteCommand(ScriptCommand programCommand)
        {
            string command = programCommand.Domain + "/" + programCommand.Target + "/" + programCommand.CommandString +
                             "/" + System.Uri.EscapeDataString(programCommand.CommandArguments);
            var interfaceCommand = new MigInterfaceCommand(command);

            HomeGenie.InterfaceControl(interfaceCommand);
        }
Esempio n. 4
0
        private void SetupCommand()
        {
            ScriptCommand scriptCommand = new ScriptCommand();

            scriptCommand.CommandInfo = this.CommandInfo;
            this.Command = (InternalCommand)scriptCommand;
            this.Command.commandRuntime = (ICommandRuntime)(this.commandRuntime = new MshCommandRuntime(this.Context, this.CommandInfo, (InternalCommand)scriptCommand));
            this.CommandSessionState    = this.Context.EngineSessionState;
        }
Esempio n. 5
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ScriptSection sec   = null;
            ScriptCommand n_cmd = null;
            var           node  = treeViewRoot.SelectedNode;
            DialogResult  dr;

            if (node.Level <= 2)
            {
                if (node.PrevNode == null && node.NextNode == null)
                {
                    MessageBox.Show("唯一的Scetion或Scene不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    dr = MessageBox.Show("确定要删除这条数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        if (node.Level == 1)
                        {
                            scriptRoot[m_cur_index].removeScene((ScriptScene)node.Tag);
                        }
                        else
                        {
                            ScriptScene scene = (ScriptScene)node.Parent.Tag;
                            scene.removeSection((ScriptSection)node.Tag);
                        }
                        treeViewRoot.Nodes.Remove(node);
                    }
                    return;
                }
            }
            else if (node.Level == 3)
            {
                MessageBox.Show("不能被删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                sec   = (ScriptSection)getLeve2Nodes(node).Tag;
                n_cmd = (ScriptCommand)node.Tag;
            }
            dr = MessageBox.Show("确定要删除这条数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                if (node.Nodes.Count < 1)
                {
                    sec.removeCode(n_cmd);
                }
                else
                {
                    RemoveCode(sec, node);
                }
                node.Remove();
            }
        }
Esempio n. 6
0
            public static Instruction FromScriptCommand(ScriptCommand scriptCommand)
            {
                var item = new Instruction();

                item.mnemonic    = scriptCommand.ToString();
                item.description = ProgrammableChip.GetCommandDescription(scriptCommand);
                item.example     = ProgrammableChip.GetCommandExample(scriptCommand);

                return(item);
            }
Esempio n. 7
0
        /// <summary>
        /// Returns a new 'Top-Level' command.
        /// </summary>
        public ScriptAction AddNewParentCommand(ScriptCommand scriptCommand)
        {
            ScriptAction newExecutionCommand = new ScriptAction()
            {
                ScriptCommand = scriptCommand
            };

            Commands.Add(newExecutionCommand);
            return(newExecutionCommand);
        }
 protected void setScriptCommand(IScriptCommand value)
 {
     _scriptCommand = value;
     _command       = new SimpleCommand()
     {
         CanExecuteDelegate = (p) => !(ScriptCommand is NullScriptCommand) &&
                              ScriptCommand.CanExecute(ParameterDicConverter.Convert(p)),
         ExecuteDelegate = (p) => ScriptRunner.RunScriptAsync(ParameterDicConverter.Convert(p), ScriptCommand)
     };
 }
Esempio n. 9
0
        public static ScriptCommand ParseCommand(Dictionary <string, object> dict)
        {
            // Try to find the type
            Type commandType = Type.GetType("Nintendo.Blitz.News.Command." + dict["Command"] + "Command");

            // Declare a variable to hold the command
            ScriptCommand command;

            // Check if no type was found
            if (commandType == null)
            {
                // Create a new generic ScriptCommand
                command = new ScriptCommand();

                // Set the command type
                command.CommandType = (CommandType)EnumUtil.GetEnumValueFromString(typeof(CommandType), (string)dict["Command"]);

                // Return the command
                return(command);
            }

            // Create a new instance of the correct ScriptCommand
            command = (ScriptCommand)Activator.CreateInstance(commandType);

            // Set the command type
            command.CommandType = (CommandType)EnumUtil.GetEnumValueFromString(typeof(CommandType), (string)dict["Command"]);

            // Loop over every value of the command
            foreach (string key in dict.Keys)
            {
                // Skip Command
                if (key == "Command")
                {
                    continue;
                }

                // Get the property
                PropertyInfo propertyInfo = commandType.GetProperty(key);

                // Check if this is an enum
                if (propertyInfo.PropertyType.IsEnum)
                {
                    // Convert the string to the enum
                    propertyInfo.SetValue(command, EnumUtil.GetEnumValueFromString(propertyInfo.PropertyType, (string)dict[key]));
                }
                else
                {
                    // Set directly
                    propertyInfo.SetValue(command, dict[key]);
                }
            }

            // Return the command
            return(command);
        }
Esempio n. 10
0
        public override async Task ExecuteAsync(GameEvent E)
        {
            var cmd = new ScriptCommand()
            {
                CommandName      = "killplayer",
                ClientNumber     = E.Target.ClientNumber,
                CommandArguments = new[] { E.Origin.ClientNumber.ToString() }
            };

            await cmd.Execute(E.Owner);
        }
Esempio n. 11
0
        public void RaiseEvent(UUID script, string id, string module, string command, string k)
        {
            ScriptCommand c = OnScriptCommand;

            if (c == null)
            {
                return;
            }

            c(script, id, module, command, k);
        }
 private void onException(Script script, ScriptCommand command, Exception e)
 {
     if (e is ValidateException)
     {
         Assert.Fail(e.Message);
     }
     else
     {
         throw (e);
     }
 }
Esempio n. 13
0
        public CheckBox CreateCheckBoxFor(string parameterName, ScriptCommand parent)
        {
            var checkBox = new CheckBox();

            checkBox.DataBindings.Add("Checked", parent, parameterName, false, DataSourceUpdateMode.OnPropertyChanged);
            checkBox.Name     = parameterName;
            checkBox.AutoSize = true;
            checkBox.Size     = new Size(20, 20);
            checkBox.UseVisualStyleBackColor = true;
            checkBox.Margin = new Padding(0, 8, 0, 0);
            return(checkBox);
        }
Esempio n. 14
0
        public List <Control> CreateDefaultOutputGroupFor(string parameterName, ScriptCommand parent, IfrmCommandEditor editor)
        {
            var controlList         = new List <Control>();
            var label               = CreateDefaultLabelFor(parameterName, parent);
            var variableNameControl = AddVariableNames(CreateStandardComboboxFor(parameterName, parent), editor);
            var helpers             = CreateUIHelpersFor(parameterName, parent, new Control[] { variableNameControl }, editor);

            controlList.Add(label);
            controlList.AddRange(helpers);
            controlList.Add(variableNameControl);
            return(controlList);
        }
Esempio n. 15
0
        // Reads a line in the script as a command.
        protected virtual bool PerformCommand(string commandName, CommandParam parameters)
        {
            List <string> matchingFormats = new List <string>();
            CommandParam  newParams       = null;

            // Search for the correct command.
            for (int i = 0; i < commands.Count; i++)
            {
                ScriptCommand command = commands[i];
                if (command.HasName(commandName))
                {
                    if (command.HasParameters(parameters, out newParams))
                    {
                        // Run the command.
                        command.Action(newParams);
                        return(true);
                    }
                    else
                    {
                        // Preemptively append the possible overloads to the error message.
                        for (int j = 0; j < command.ParameterOverloads.Count; j++)
                        {
                            matchingFormats.Add(command.Name + " " +
                                                CommandParamParser.ToString(command.ParameterOverloads[j]));
                        }
                    }
                }
            }

            // Throw an error because the command was not found.
            if (matchingFormats.Count > 0)
            {
                Console.WriteLine(CommandParamParser.ToString(parameters));
                string msg = "No matching overload found for the command " + commandName + "\n";
                msg += "Possible overloads include:\n";
                for (int i = 0; i < matchingFormats.Count; i++)
                {
                    msg += "  * " + matchingFormats[i];
                    if (i + 1 < matchingFormats.Count)
                    {
                        msg += "\n";
                    }
                }
                ThrowCommandParseError(msg);
            }
            else
            {
                ThrowCommandParseError(commandName + " is not a valid command");
            }

            return(false);
        }
Esempio n. 16
0
        public static ComboBox CreateStandardComboboxFor(string parameterName, ScriptCommand parent)
        {
            var standardComboBox = new ComboBox();

            standardComboBox.Font = new Font("Segoe UI", 12, FontStyle.Regular);
            standardComboBox.DataBindings.Add("Text", parent, parameterName, false, DataSourceUpdateMode.OnPropertyChanged);
            standardComboBox.Height = 30;
            standardComboBox.Width  = 300;
            standardComboBox.Name   = parameterName;
            standardComboBox.Click += StandardComboBox_Click;

            return(standardComboBox);
        }
Esempio n. 17
0
        public List <Control> CreateDefaultDropdownGroupFor(string parameterName, ScriptCommand parent, IfrmCommandEditor editor)
        {
            var controlList = new List <Control>();
            var label       = CreateDefaultLabelFor(parameterName, parent);
            var input       = CreateDropdownFor(parameterName, parent);
            var helpers     = CreateUIHelpersFor(parameterName, parent, new Control[] { input }, (frmCommandEditor)editor);

            controlList.Add(label);
            controlList.AddRange(helpers);
            controlList.Add(input);

            return(controlList);
        }
Esempio n. 18
0
        public List <Control> CreateDataGridViewGroupFor(string parameterName, ScriptCommand parent, IfrmCommandEditor editor)
        {
            var controlList = new List <Control>();
            var label       = CreateDefaultLabelFor(parameterName, parent);
            var gridview    = CreateDataGridView(parent, parameterName);
            var helpers     = CreateUIHelpersFor(parameterName, parent, new Control[] { gridview }, (frmCommandEditor)editor);

            controlList.Add(label);
            controlList.AddRange(helpers);
            controlList.Add(gridview);

            return(controlList);
        }
Esempio n. 19
0
        public List <Control> CreateDefaultInputGroupFor(string parameterName, ScriptCommand parent, IfrmCommandEditor editor, int height = 30, int width = 300)
        {
            var controlList = new List <Control>();
            var label       = CreateDefaultLabelFor(parameterName, parent);
            var input       = CreateDefaultInputFor(parameterName, parent, height, width);
            var helpers     = CreateUIHelpersFor(parameterName, parent, new Control[] { input }, (frmCommandEditor)editor);

            controlList.Add(label);
            controlList.AddRange(helpers);
            controlList.Add(input);

            return(controlList);
        }
        private ListViewItem CreateScriptCommandListViewItem(ScriptCommand cmdDetails)
        {
            ListViewItem newCommand = new ListViewItem();

            newCommand.Text = cmdDetails.GetDisplayValue();
            newCommand.SubItems.Add(cmdDetails.GetDisplayValue());
            newCommand.SubItems.Add(cmdDetails.GetDisplayValue());
            //cmdDetails.RenderedControls = null;
            newCommand.Tag        = cmdDetails;
            newCommand.ForeColor  = cmdDetails.DisplayForeColor;
            newCommand.BackColor  = Color.DimGray;
            newCommand.ImageIndex = _uiImages.Images.IndexOfKey(cmdDetails.GetType().Name);
            return(newCommand);
        }
Esempio n. 21
0
        /// <summary>
        /// adds a command as a nested command to a top-level command
        /// </summary>
        public ScriptAction AddAdditionalAction(ScriptCommand scriptCommand)
        {
            if (AdditionalScriptCommands == null)
            {
                AdditionalScriptCommands = new List <ScriptAction>();
            }

            ScriptAction newExecutionCommand = new ScriptAction()
            {
                ScriptCommand = scriptCommand
            };

            AdditionalScriptCommands.Add(newExecutionCommand);
            return(newExecutionCommand);
        }
Esempio n. 22
0
 private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (treeViewRoot.SelectedNode.Level > 2)
     {
         ScriptCommand cmd = (ScriptCommand)treeViewRoot.SelectedNode.Tag;
         if (cmd.Keys.Length > 0)
         {
             CCodeEditDlg dlg = new CCodeEditDlg(cmd);
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 treeViewRoot.SelectedNode.Text = CScenario.getNodeText(cmd);
             }
         }
     }
 }
Esempio n. 23
0
 private void treeViewRoot_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (treeViewRoot.SelectedNode.Level > 2)
     {
         //treeViewRoot.l
         ScriptCommand cmd = (ScriptCommand)treeViewRoot.SelectedNode.Tag;
         if (cmd.Keys.Length > 0)
         {
             CCodeEditDlg dlg = new CCodeEditDlg(cmd);
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 treeViewRoot.SelectedNode.Text = CScenario.getNodeText(cmd);
             }
         }
     }
 }
Esempio n. 24
0
        private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ScriptSection sec   = null;
            ScriptCommand n_cmd = null;
            var           node  = treeViewRoot.SelectedNode;

            if (node.Level <= 2)
            {
                if (node.PrevNode == null && node.NextNode == null)
                {
                    MessageBox.Show("唯一的Scetion或Scene不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (node.Level == 1)
                    {
                        scriptRoot[m_cur_index].removeScene((ScriptScene)node.Tag);
                    }
                    else
                    {
                        ScriptScene scene = (ScriptScene)node.Parent.Tag;
                        scene.removeSection((ScriptSection)node.Tag);
                    }
                }
            }
            else if (node.Level == 3)
            {
                MessageBox.Show("不能被删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                sec   = (ScriptSection)node.Parent.Parent.Tag;
                n_cmd = (ScriptCommand)node.Tag;
                sec.removeCode(n_cmd);
            }

            copyNode      = new TreeNode();
            copyNode.Text = node.Text;
            copyNode.Tag  = node.Tag;
            copyNode      = CopyTreeNode(copyNode, node);
            cutNodeParent = node.Parent;
            粘帖ToolStripMenuItem.Enabled = true;
            node.Remove();
            isCut = true;
        }
Esempio n. 25
0
        public async Task <string> AddServers(string subscriptionId)
        {
            string server = string.Empty;

            try
            {
                string psladdserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addserver.ps1";
                string psl_Script   = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdserver);
                }
                List <string> list     = new List <string>();
                string        bodyText = await this.Request.Content.ReadAsStringAsync();

                var      data             = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.DeserializeObject(bodyText).ToString());
                var      commandData      = ((JObject)data["ServerDetails"]).ToObject <Dictionary <string, object> >();
                string   ConnectionBroker = commandData["ConnectionBroker"] as string;
                string   serverNames      = commandData["ServerNames"] as string;
                string[] ServerNames      = serverNames.Split(',');

                for (int i = 0; i < ServerNames.Length; i++)
                {
                    list.Add(ServerNames[i]);
                }
                string rawData = string.Empty;
                foreach (var servername in ServerNames)
                {
                    string key  = ConnectionBroker + ":" + servername;
                    var    dict = new Dictionary <string, object> {
                        { "ConnectionBroker", ConnectionBroker }, { "Server", servername }
                    };
                    var command = new ScriptCommand(psl_Script,
                                                    new[] { "ConnectionBroker", "Server" });
                    command.Init(dict);
                    server = AdminCommandsController.ProccessCommandSub(command);
                }
            }
            catch (Exception ex)
            {
                //ErrorHelper.WriteErrorToEventLog(ex.Message);
                ErrorHelper.SendExcepToDB(ex, " AddServers", subscriptionId);
                throw ex;
            }

            return(server);
        }
Esempio n. 26
0
        public void RunNextCommand()
        {
            ScriptCommand cmd = _reader.ReadEnum <ScriptCommand>();

            switch (cmd)
            {
            case ScriptCommand.End: EndCommand(); break;

            case ScriptCommand.GoTo: GoToCommand(); break;

            case ScriptCommand.Call: CallCommand(); break;

            case ScriptCommand.Return: ReturnCommand(); break;

            case ScriptCommand.HealParty: HealPartyCommand(); break;

            case ScriptCommand.GivePokemon: GivePokemonCommand(); break;

            case ScriptCommand.GivePokemonForm: GivePokemonFormCommand(); break;

            case ScriptCommand.GivePokemonFormItem: GivePokemonFormItemCommand(); break;

            case ScriptCommand.MoveObj: MoveObjCommand(); break;

            case ScriptCommand.AwaitObjMovement: AwaitObjMovementCommand(); break;

            case ScriptCommand.DetachCamera: DetachCameraCommand(); break;

            case ScriptCommand.AttachCamera: AttachCameraCommand(); break;

            case ScriptCommand.Delay: DelayCommand(); break;

            case ScriptCommand.SetFlag: SetFlagCommand(); break;

            case ScriptCommand.ClearFlag: ClearFlagCommand(); break;

            case ScriptCommand.Warp: WarpCommand(); break;

            case ScriptCommand.Message: MessageCommand(); break;

            case ScriptCommand.AwaitMessage: AwaitMessageCommand(); break;

            default: throw new InvalidDataException();
            }
        }
Esempio n. 27
0
        public static List <AutomationCommand> GenerateAutomationCommands(ImageList uiImages, List <Type> commandClasses)
        {
            uiImages.ImageSize = new Size(18, 18);
            uiImages.Images.Add("BrokenCodeCommentCommand", Resources.command_broken);

            List <AutomationCommand> newAutomationCommands = new List <AutomationCommand>();

            foreach (var commandClass in commandClasses)
            {
                var    groupingAttribute = commandClass.GetCustomAttributes(typeof(CategoryAttribute), true);
                string groupAttribute    = "";
                if (groupingAttribute.Length > 0)
                {
                    var attributeFound = (CategoryAttribute)groupingAttribute[0];
                    groupAttribute = attributeFound.Category;
                }

                //Instantiate Class
                ScriptCommand newCommand = (ScriptCommand)Activator.CreateInstance(commandClass);
                uiImages.Images.Add(newCommand.CommandName, newCommand.CommandIcon);
                newCommand.CommandIcon = null;
                GC.Collect();

                AutomationCommand newAutomationCommand = null;
                //If command is enabled, pull for display and configuration
                if (newCommand.CommandEnabled)
                {
                    newAutomationCommand = new AutomationCommand();
                    newAutomationCommand.CommandClass = commandClass;
                    newAutomationCommand.Command      = newCommand;
                    newAutomationCommand.DisplayGroup = groupAttribute;
                    newAutomationCommand.FullName     = string.Join(" - ", groupAttribute, newCommand.SelectionName);
                    newAutomationCommand.ShortName    = newCommand.SelectionName;
                    newAutomationCommand.Description  = CommandsHelper.GetDescription(commandClass);
                }

                if (newAutomationCommand != null)
                {
                    newAutomationCommands.Add(newAutomationCommand);
                }
            }

            return(newAutomationCommands.Distinct().ToList());
        }
Esempio n. 28
0
 protected void CommonInitialization(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, SessionStateInternal sessionState)
 {
     base.CommandSessionState = sessionState;
     base._context = context;
     this._rethrowExitException = base.Context.ScriptCommandProcessorShouldRethrowExit;
     base._context.ScriptCommandProcessorShouldRethrowExit = false;
     ScriptCommand thisCommand = new ScriptCommand {
         CommandInfo = base.CommandInfo
     };
     base.Command = thisCommand;
     base.Command.commandRuntime = base.commandRuntime = new MshCommandRuntime(base.Context, base.CommandInfo, thisCommand);
     base.CommandScope = useLocalScope ? base.CommandSessionState.NewScope(base.FromScriptFile) : base.CommandSessionState.CurrentScope;
     base.UseLocalScope = useLocalScope;
     this._scriptBlock = scriptBlock;
     if (!base.UseLocalScope && !this._rethrowExitException)
     {
         CommandProcessorBase.ValidateCompatibleLanguageMode(this._scriptBlock, context.LanguageMode, base.Command.MyInvocation);
     }
 }
Esempio n. 29
0
        public static Script Load(string content)
        {
            var script = new Script();

            var lines = StripComments(content).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < lines.Length; ++i)
            {
                lines[i] = lines[i].Trim();
                if (lines[i].Length == 0)
                {
                    continue;
                }

                script._commands.Add(ScriptCommand.FromLine(i + 1, lines[i]));
            }

            return(script);
        }
        private ListViewItem CreateScriptCommandListViewItem(ScriptCommand cmdDetails)
        {
            ListViewItem newCommand = new ListViewItem();

            newCommand.Text = cmdDetails.GetDisplayValue();
            newCommand.SubItems.Add(cmdDetails.GetDisplayValue());
            newCommand.SubItems.Add(cmdDetails.GetDisplayValue());
            newCommand.ToolTipText = cmdDetails.GetDisplayValue();
            newCommand.Tag         = cmdDetails;
            newCommand.ForeColor   = Color.SteelBlue;
            newCommand.BackColor   = Color.DimGray;

            if (UiImages != null)
            {
                newCommand.ImageIndex = UiImages.Images.IndexOfKey(cmdDetails.GetType().Name);
            }

            return(newCommand);
        }
 private void RecorderStatusChanged(object sender, RecorderStatusChangedEventArgs args)
 {
     Dispatcher.Invoke(new Action <bool>((isRunning) =>
     {
         if (isRunning)
         {
             btnRecordStop.Content    = "Stop";
             btnRecordStop.Background = Brushes.Red;
             btnRunStop.IsEnabled     = false;
         }
         else
         {
             btnRecordStop.Content    = "●Record";
             btnRecordStop.Background = Brushes.SkyBlue;
             btnRunStop.IsEnabled     = true;
             scriptBox.Text           = ScriptCommand.NormalizeScript(scriptBox.Text);
         }
     }), args.IsRunning);
 }
        protected void CommonInitialization(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, SessionStateInternal sessionState)
        {
            base.CommandSessionState   = sessionState;
            base._context              = context;
            this._rethrowExitException = base.Context.ScriptCommandProcessorShouldRethrowExit;
            base._context.ScriptCommandProcessorShouldRethrowExit = false;
            ScriptCommand thisCommand = new ScriptCommand {
                CommandInfo = base.CommandInfo
            };

            base.Command = thisCommand;
            base.Command.commandRuntime = base.commandRuntime = new MshCommandRuntime(base.Context, base.CommandInfo, thisCommand);
            base.CommandScope           = useLocalScope ? base.CommandSessionState.NewScope(base.FromScriptFile) : base.CommandSessionState.CurrentScope;
            base.UseLocalScope          = useLocalScope;
            this._scriptBlock           = scriptBlock;
            if (!base.UseLocalScope && !this._rethrowExitException)
            {
                CommandProcessorBase.ValidateCompatibleLanguageMode(this._scriptBlock, context.LanguageMode, base.Command.MyInvocation);
            }
        }
 public void Execute(byte[] script, ScriptCommand command)
 {
     action(script, command);
 }
 private void PushData(byte[] script, ScriptCommand command)
 {
     byte[] data = new byte[command.Code];
     Array.Copy(script, command.Offset + 1, data, 0, command.Code);
     dataStack.Add(data);
 }
 private void PushData4(byte[] script, ScriptCommand command)
 {
     int dataLength = command.Length - 5;
     byte[] data = new byte[dataLength];
     Array.Copy(script, command.Offset + 5, data, 0, dataLength);
     dataStack.Add(data);
 }
 private void ExecuteCheckSigVerify(byte[] script, ScriptCommand command)
 {
     //todo: add test
     bool success = CheckSig(script);
     if (!success)
     {
         valid = false;
         dataStack.Add(new byte[0]);
     }
 }
        private void ExecuteIf(byte[] script, ScriptCommand command)
        {
            if (!controlStack.ExecuteBranch)
            {
                controlStack.Push(false);
                return;
            }

            bool condition;
            if (!dataStack.Any())
            {
                condition = false;
                valid = false;
                //todo: terminate execution?
            }
            else
            {
                int index = dataStack.Count - 1;
                byte[] data = dataStack[index];
                dataStack.RemoveAt(index);
                condition = IsTrue(data);
            }
            if (command.Code == BitcoinScript.OP_NOTIF)
            {
                condition = !condition;
            }
            controlStack.Push(condition);
        }
 private void ExecuteDepth(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     BigInteger val = dataStack.Count;
     byte[] item = val.ToByteArray();
     dataStack.Add(item);
 }
Esempio n. 39
0
        public void RegisterCommand(string name, ScriptCommand command)
        {
            if(this.HasCommand(name, false))
            {
                throw new CommandAlreadyDefinedException("Command \"" + command + "\" has already been defined");
            }

            this.commands[name] = command;
        }
        private void ExecuteRot(byte[] script, ScriptCommand command)
        {
            //todo: add tests
            if (dataStack.Count < 3)
            {
                valid = false;
                return;
            }

            byte[] item3 = dataStack[dataStack.Count - 3];
            dataStack.RemoveAt(dataStack.Count - 3);
            dataStack.Add(item3);
        }
 private void ExecuteSha256(byte[] script, ScriptCommand command)
 {
     byte[] data = PopData();
     if (data == null)
     {
         valid = false;
         return;
     }
     dataStack.Add(CryptoUtils.Sha256(data));
 }
 private void ExecuteDup(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     byte[] item = PopData();
     if (item == null)
     {
         valid = false;
     }
     dataStack.Add(item);
     dataStack.Add(item);
 }
 private void ExecuteRoll(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     if (dataStack.Count < 2)
     {
         valid = false;
         return;
     }
     byte[] numAsBytes = PopData();
     BigInteger numAsBigInt = new BigInteger(numAsBytes);
     if (numAsBigInt < 0 || numAsBigInt >= dataStack.Count)
     {
         valid = false;
         return;
     }
     // We assume that dataStack.Count is always less then int.MaxValue. Therefore, this conversion should never fail.
     int num = (int) numAsBigInt;
     byte[] item = dataStack[dataStack.Count - num];
     dataStack.RemoveAt(dataStack.Count - num);
     dataStack.Add(item);
 }
        private void ExecuteEqualVerify(byte[] script, ScriptCommand command)
        {
            if (dataStack.Count < 2)
            {
                valid = false;
                return;
            }
            byte[] item1 = PopData();
            byte[] item2 = PopData();

            bool equal = item1.SequenceEqual(item2);

            if (!equal)
            {
                valid = false;
                dataStack.Add(new byte[0]);
            }
        }
 private void ExecuteNip(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     if (dataStack.Count < 2)
     {
         valid = false;
         return;
     }
     dataStack.RemoveAt(dataStack.Count - 2);
 }
        private void ExecuteIfDup(byte[] script, ScriptCommand command)
        {
            //todo: add tests
            byte[] item = PopData();

            if (item == null)
            {
                valid = false;
                return;
            }

            dataStack.Add(item);

            if (IsTrue(item))
            {
                dataStack.Add(item);
            }
        }
 private void ExecuteDrop(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     byte[] item = PopData();
     if (item == null)
     {
         valid = false;
     }
 }
        private void ExecuteSwap(byte[] script, ScriptCommand command)
        {
            //todo: add tests
            if (dataStack.Count < 2)
            {
                valid = false;
                return;
            }

            byte[] item1 = PopData();
            byte[] item2 = PopData();

            dataStack.Add(item1);
            dataStack.Add(item2);
        }
 private void ExecuteDisabled(byte[] script, ScriptCommand command)
 {
     valid = false;
 }
 private void ExecuteToAltStack(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     byte[] data = PopData();
     if (data == null)
     {
         valid = false;
         return;
     }
     altDataStack.Push(data);
 }
 private void ExecuteCodeSeparator(byte[] script, ScriptCommand command)
 {
     // todo: add tests
     lastCodeSeparator = command.Offset;
 }
        private void ExecuteTuck(byte[] script, ScriptCommand command)
        {
            //todo: add tests
            if (dataStack.Count < 2)
            {
                valid = false;
                return;
            }

            byte[] item = dataStack[dataStack.Count - 1];
            ;
            dataStack.Insert(dataStack.Count - 2, item);
        }
Esempio n. 53
0
        public bool TryGetCommand(string command, out ScriptCommand value, bool includeParent = true)
        {
            if (this.commands.TryGetValue(command, out value))
                return true;

            if (includeParent && this.parent != null && this.parent.TryGetCommand(command, out value))
                return true;

            return false;
        }
 private void ExecuteVerify(byte[] script, ScriptCommand command)
 {
     byte[] data = PopData();
     if (data == null)
     {
         valid = false;
         return;
     }
     if (!IsTrue(data))
     {
         valid = false;
         dataStack.Add(data);
     }
 }
 private void ExecuteOver(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     if (dataStack.Count < 2)
     {
         valid = false;
         return;
     }
     byte[] item = dataStack[dataStack.Count - 2];
     dataStack.Add(item);
 }
 private void ExecuteFromAltStack(byte[] script, ScriptCommand command)
 {
     //todo: add tests
     if (altDataStack.Count == 0)
     {
         valid = false;
         return;
     }
     byte[] data = altDataStack.Pop();
     dataStack.Add(data);
 }
 private void ExecuteElse(byte[] script, ScriptCommand command)
 {
     if (controlStack.IsEmpty)
     {
         valid = false;
         return;
     }
     bool executeBranch = !controlStack.ExecuteBranch;
     controlStack.Pop();
     controlStack.Push(executeBranch);
 }
 private void ExecuteReturn(byte[] script, ScriptCommand command)
 {
     valid = false;
     //todo: terminate execution?
 }
Esempio n. 59
0
        public void AddDateEvent(int year, int month, int day, ScriptCommand command)
        {
            int indexForDate = 0;
            string date = year.ToString() + "." + month.ToString() + "." + day.ToString();
            int index = 0;
            bool found = false;
            ScriptScope foundScope = null;
            foreach (var child in Scope.Children)
            {
                if (child is ScriptScope)
                {
                    var scope = ((ScriptScope)child);
                    var split = scope.Name.Split('.');
                    if (split.Length == 3)
                    {
                        int y = Convert.ToInt32(split[0]);
                        int m = Convert.ToInt32(split[1]);
                        int d = Convert.ToInt32(split[2]);
                        if ((y == year && m == month && d == day))
                        {
                            found = true;
                            foundScope = child as ScriptScope;
                            break;
                        }
                        if (y > year || (y == year && m > month) || (y == year && m == month && d > day))
                        {
                            break;
                        }

                    }
                }
                index++;
            }

            indexForDate = index;
            ScriptScope s = null;
            if (found)
            {
                s = new ScriptScope(date);
            }
            else
            {
                s = new ScriptScope(date);
                Scope.Insert(indexForDate, s);
            }

            s.Add(command);
            command.Parent = s;
        }
 private void ExecuteEndIf(byte[] script, ScriptCommand command)
 {
     if (controlStack.IsEmpty)
     {
         valid = false;
         return;
     }
     controlStack.Pop();
 }