Beispiel #1
0
            public void Execute()
            {
                try {
                    MethodInfo mi = ActiveObject.GetType().GetMethod(MethodName,
                                                                     BindingFlags.Public |
                                                                     BindingFlags.Instance |
                                                                     //BindingFlags.DeclaredOnly |
                                                                     BindingFlags.NonPublic
                                                                     );
                    mi.Invoke(ActiveObject, args);
                } catch (ThreadAbortException) {
                    Trace.WriteLine("TaskQueue.Task.Execute: ThreadAbortException, no problem");
                } catch (Exception exception) {
                    Exception innerException = exception.InnerException;
                    if (innerException == null)
                    {
                        innerException = exception;
                    }
                    string strMessage    = OopsFormatter.ApplyFormatting(innerException.Message);
                    string strStackTrace = OopsFormatter.ApplyFormatting(innerException.StackTrace);

                    System.Windows.Forms.MessageBox.Show(strMessage + "\r\n" + strStackTrace, "Oops...");
                }
            }
Beispiel #2
0
        public static Assembly CompileCSharp(EditForm editForm, string CSharpCode)
        {
            // Code compiler and provider
            CodeDomProvider cc = new CSharpCodeProvider();

            // Compiler parameters
            CompilerParameters cp = new CompilerParameters();

            // Sept 15, 2007 -> 3, 30 oct 2007 -> 4
            if (!Properties.Settings.Default.SkipWarnings)
            {
                cp.WarningLevel = 4;
            }

            // Add common assemblies
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");

            // LSLEditor.exe contains all base SecondLife class stuff
            cp.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);

            // Compiling to memory
            cp.GenerateInMemory = true;

            // Does this work?
            cp.IncludeDebugInformation = true;

            // Wrap strCSharpCode into my namespace
            string strRunTime = "namespace LSLEditor\n{\n";

            strRunTime += CSharpCode;
            strRunTime += "\n}\n";

            int intDefaultLineNumber = FindDefaultLineNumber(strRunTime);

            // Here we go
            CompilerResults cr = cc.CompileAssemblyFromSource(cp, strRunTime);

            // get the listview to store some errors
            ListView ListViewErrors = editForm.parent.SyntaxErrors.ListView;

            // Console.WriteLine(cr.Errors.HasWarnings.ToString());
            // Check for compilation errors...
            if (ListViewErrors != null && (cr.Errors.HasErrors || cr.Errors.HasWarnings))
            {
                int intNr = 1;
                foreach (CompilerError err in cr.Errors)
                {
                    int intLine = err.Line;
                    if (intLine < intDefaultLineNumber)
                    {
                        intLine -= 4;
                    }
                    else
                    {
                        intLine -= 5;
                    }
                    string strError      = OopsFormatter.ApplyFormatting(err.ErrorText);
                    int    intImageIndex = 0;
                    if (err.IsWarning)
                    {
                        intImageIndex = 1;
                    }
                    ListViewItem lvi = new ListViewItem(new string[] {
                        "",                                             // 0
                        intNr.ToString(),                               // 1
                        strError,                                       // 2
                        editForm.ScriptName,                            // 3
                        intLine.ToString(),                             // 4
                        err.Column.ToString(),                          // 5
                        editForm.ProjectName,                           // 6
                        editForm.FullPathName,                          // 7
                        editForm.guid.ToString(),                       // 8
                        editForm.IsScript.ToString()                    // 9
                    }, intImageIndex);
                    ListViewErrors.Items.Add(lvi);
                    intNr++;
                }
                return(null);
            }
            return(cr.CompiledAssembly);
        }