Beispiel #1
0
        private List<Parameter> GetCommandParameters(string command)
        {
            // Just get parameters
            string parameters = command.Substring(command.IndexOf("(") + 1);
            parameters = parameters.Substring(0, parameters.LastIndexOf(")"));
            parameters = parameters.Trim();

            string[] paramList = parameters.Split(',');

            if (parameters.Length == 0)
            {
                paramList = new string[0];
            }

            MethodInfo method = GetCommandMethod(command);
            ParameterInfo[] methodParams = method.GetParameters();

            if (paramList.Length != methodParams.Length)
            {
                throw new Exception ("Parse error: Method \"" + method.Name + "\" does not accept " + paramList.Length + " parameters.");
            }

            List<Parameter> returnList = new List<Parameter>();

            for (int i = 0; i < paramList.Length; i++)
            {
                Parameter param = new Parameter();

                param.parameterType = methodParams[i].ParameterType;

                // Check for memory parameters
                if (paramList[i].StartsWith("Memory(") == true)
                {
                    try
                    {
                        string loc = paramList[i].Substring(paramList[i].IndexOf("(") + 1, paramList[i].IndexOf(")") - paramList[i].IndexOf("(") - 1);

                        param.isMemory = Convert.ToInt32(loc) - 1;

                        if (param.isMemory < 0)
                        {
                            throw new Exception("Non-positive memory location.");
                        }
                        else if (param.isMemory >= memory.Count)
                        {
                            throw new Exception("Memory overflow.");
                        }
                    }
                    catch (Exception)
                    {
                        Exception ex = new Exception("Parse error: Cannot convert method memory location parameter: \"" + paramList[i] + "\"");

                        throw ex;
                    }
                }
                else
                {
                    try
                    {
                        param.value = Convert.ChangeType(paramList[i], param.parameterType);

                        // String support, cut away double quotes
                        if (param.value.GetType() == typeof(string))
                        {
                            // BugFix - if it is string and no quotes = error

                            if ((((string)param.value).EndsWith("\"") == true) && (((string)param.value).StartsWith("\"") == true))
                            {
                                string rem = (string)param.value;

                                rem = rem.Substring(1);
                                rem = rem.Substring(0, rem.Length - 1);

                                param.value = rem;
                            }
                            else
                            {
                                if (((string)param.value).StartsWith("\"") == false)
                                {
                                    throw new Exception("Parse error: Expecting double quote on start of param: " + ((string)param.value)[0]);
                                }
                                else
                                {
                                    throw new Exception("Parse error: Expecting double quote on end of param: " + ((string)param.value)[((string)param.value).Length - 1]);
                                }
                            }
                        }

                    }
                    catch (Exception)
                    {
                        Exception ex = new Exception("Parse error: Cannot convert method parameter: \"" + paramList[i] + "\" to: " + param.parameterType.ToString());

                        throw ex;
                    }
                }

                returnList.Add(param);
            }

            return returnList;
        }
Beispiel #2
0
        private void textBox_DragDrop(object sender, DragEventArgs e)
        {
            // Handle method drag and drop
            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                TreeNode transferNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");

                // Allow only methods to be transfered
                if (transferNode.Level != 2)
                {
                    return;
                }

                // Have to find correct method form now

                TreeNode classNode = transferNode.Parent;

                TreeNode assemblyNode = classNode.Parent;

                int foundAsm = -1;

                for (int i = 0; i < library.Count; i++)
                {
                    if (Path.GetFileName(library[i].Location) == assemblyNode.Text)
                    {
                        foundAsm = i;
                        break;
                    }
                }

                Assembly assembly = library[foundAsm];

                //
                // Get method info
                //

                foreach (Type type in assembly.GetTypes())
                {
                    if ((type.IsClass) && (type.Name == classNode.Text))
                    {
                        // Get class methods
                        foreach (MethodInfo method in type.GetMethods())
                        {
                            if (method.ToString() == transferNode.Text)
                            {
                                List<Parameter> list = new List<Parameter>();

                                for (int i = 0; i < method.GetParameters().Length; i++)
                                {
                                    Parameter param = new Parameter();
                                    param.parameterType = method.GetParameters()[i].ParameterType;

                                    /*
                                    if (param.parameterType == typeof(string))
                                    {
                                        param.value = "\"\"";
                                    }
                                    else
                                    {
                                        param.value = 0;
                                    }*/

                                    param.value = " ";

                                    list.Add(param);
                                }

                                int save = ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart;

                                string cmd = WriteCommand(type, method, list, -1);

                                ((TextBox)tabControl1.SelectedTab.Controls[0]).Text = ((TextBox)tabControl1.SelectedTab.Controls[0]).Text.Insert(((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart, cmd);

                                if (list.Count > 0)
                                {
                                    ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart = ((TextBox)tabControl1.SelectedTab.Controls[0]).Text.IndexOf("(", save) + 1;

                                    int save2 = ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart;

                                    ((TextBox)tabControl1.SelectedTab.Controls[0]).Text = ((TextBox)tabControl1.SelectedTab.Controls[0]).Text.Insert(((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart, " ");

                                    ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart = save2;
                                }
                                else
                                {
                                    ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart = save + cmd.Length;
                                }

                                return;
                            }
                        }

                        break;
                    }
                }
            }
            else if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem", false))
            {
                ListViewItem transferItem = (ListViewItem)e.Data.GetData("System.Windows.Forms.ListViewItem");

                int save = ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart;

                string txt = "Memory (" + Convert.ToInt32(transferItem.Text) + ")";

                ((TextBox)tabControl1.SelectedTab.Controls[0]).Text = ((TextBox)tabControl1.SelectedTab.Controls[0]).Text.Insert(((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart, txt);

                ((TextBox)tabControl1.SelectedTab.Controls[0]).SelectionStart = save + txt.Length;
            }
        }