Beispiel #1
0
        private void MacroMain(IMacroEventListener listener)
        {
            try {
                InitEnv();
                //AppDomain.CurrentDomain.Load(_assembly.FullName);
                MethodInfo mi = _assembly.EntryPoint;
                if (DebugOpt.Macro)
                {
                    Type[] ts = _assembly.GetTypes();
                    foreach (Type t in ts)
                    {
                        Debug.WriteLine("Found Type " + t.FullName);

                        mi = _assembly.GetType("JScript Main").GetMethod("Main");
                        Debug.WriteLine("Method Found " + mi.Name);
                    }
                }

                if (mi == null)
                {
                    MacroUtil.InvokeMessageBox(MacroPlugin.Instance.Strings.GetString("Message.MacroModule.NoEntryPoint"));
                }
                else
                {
                    mi.Invoke(null, BindingFlags.InvokeMethod, null, new object[1] {
                        new string[0]
                    }, CultureInfo.CurrentUICulture);
                }
            }
            catch (TargetInvocationException tex) {
                Exception inner = tex.InnerException;
                lock (_traceWindowLock) {
                    if (_traceWindow == null)
                    {
                        MacroUtil.InvokeMessageBox(String.Format(MacroPlugin.Instance.Strings.GetString("Message.MacroExec.ExceptionWithoutTraceWindow"), inner.Message));
                        Debug.WriteLine("TargetInvocationException");
                        Debug.WriteLine(inner.GetType().Name);
                        Debug.WriteLine(inner.Message);
                        Debug.WriteLine(inner.StackTrace);
                    }
                    else
                    {
                        _traceWindow.AddLine(MacroPlugin.Instance.Strings.GetString("Message.MacroExec.ExceptionInMacro"));
                        _traceWindow.AddLine(String.Format("{0} : {1}", inner.GetType().FullName, inner.Message));
                        _traceWindow.AddLine(inner.StackTrace);
                    }
                }
            }
            catch (Exception ex) {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
            finally {
                CloseAll();
                if (listener != null)
                {
                    listener.IndicateMacroFinished();
                }

                lock (_traceWindowLock) {
                    if (_traceWindow != null)
                    {
                        if (_traceWindow.Visible)
                        {
                            _traceWindow.HideOnCloseButton = false;
                        }
                        else
                        {
                            MacroTraceWindow traceWindow = _traceWindow;
                            _traceWindow.BeginInvoke(
                                (System.Windows.Forms.MethodInvoker) delegate() {
                                traceWindow.Dispose();
                            });
                        }
                        _traceWindow = null;
                    }
                }
            }
        }