Beispiel #1
0
        private void runCurrentToolInToolList()
        {
            CompiledTool ct = (toolList.SelectedItem as CompiledTool);

            if (ct == null)
            {
                return;
            }

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                ct.ToolMain.Invoke(ct.Instance, new object[] { hwMatrixLarge.CurrentFrame, frStrip.Data() });
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message, "Error During Tool Execution", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();

                Cursor.Current = Cursors.Default;
            }
        }
Beispiel #2
0
        private void toolList_SelectedIndexChanged(object sender, EventArgs e)
        {
            CompiledTool ct = (toolList.SelectedItem as CompiledTool);

            if (ct == null)
            {
                return;
            }

            propertyGrid.SelectedObject = ct.Instance;
        }
Beispiel #3
0
        private void loadTools()
        {
            if (!Directory.Exists("tools"))
            {
                return;
            }

            string[] fxFiles = Directory.GetFiles("tools", "*.cs", SearchOption.TopDirectoryOnly);
            foreach (String s in fxFiles)
            {
                TextReader tr        = new StreamReader(s);
                String     fileName  = Path.GetFileNameWithoutExtension(s);
                String     className = "Tool_" + fileName;

                StringBuilder srcCode = new StringBuilder(512);
                foreach (string ns in mNamespaces)
                {
                    srcCode.AppendFormat("using {0};\n", ns);
                }
                srcCode.Append("namespace BadgeScript { public class ");
                srcCode.Append(className);
                srcCode.Append(": ScriptedTool {");
                srcCode.Append(tr.ReadToEnd());
                srcCode.Append("} }");

                CompilerResults result = mProvider.CompileAssemblyFromSource(
                    mCompilerParam,
                    srcCode.ToString());

                if (result.Errors.Count > 0)
                {
                    StringBuilder errMsgs = new StringBuilder(512);
                    foreach (CompilerError ce in result.Errors)
                    {
                        errMsgs.Append("Line ");
                        errMsgs.Append(ce.Line.ToString());
                        errMsgs.Append(":    ");
                        errMsgs.Append(ce.ErrorText);
                        errMsgs.Append(Environment.NewLine);
                        errMsgs.Append(Environment.NewLine);
                    }
                    MessageBox.Show(errMsgs.ToString(), "Error compiling \"" + s + "\"", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    CompiledTool ct = new CompiledTool();

                    ct.Label = fileName;

                    ct.CompiledType = result.CompiledAssembly.GetType("BadgeScript." + className);
                    if (ct.CompiledType == null)
                    {
                        MessageBox.Show("Could not find compiled tool type information.", "Error compiling \"" + s + "\"", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }

                    ct.ToolMain = ct.CompiledType.GetMethod("main", BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
                    if (ct.ToolMain == null)
                    {
                        MessageBox.Show("Could not find main() function in compiled tool.", "Error compiling \"" + s + "\"", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }

                    ct.Instance = Activator.CreateInstance(ct.CompiledType, false);
                    if (ct.Instance == null)
                    {
                        MessageBox.Show("Could not create instance of tool.", "Error compiling \"" + s + "\"", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }

                    mTools.Add(ct);

                    toolList.Items.Add(ct);
                }
            }
        }