public int Main(string[] args) { if (nunitRunned) { Type type; FieldInfo field; //利用反射将含静态成员的类复位 //ServiceManager类复位 type = typeof(ServiceManager); field = type.GetField("services", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(ServiceManager.Services, new ArrayList()); field = type.GetField("serviceIndex", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(ServiceManager.Services, new Hashtable()); //Services类复位 type = typeof(Services); field = type.GetField("addinManager", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("addinRegistry", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("agency", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("domainManager", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("loader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("projectService", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("recentFiles", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("userSettings", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); //ServicesArxNet类复位 type = typeof(ServicesArxNet); field = type.GetField("addinManager", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("addinRegistry", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("agency", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("domainManager", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("loader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("projectService", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("recentFiles", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); field = type.GetField("userSettings", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetField); field.SetValue(null, null); } // Create SettingsService early so we know the trace level right at the start SettingsServiceArxNet settingsService = new SettingsServiceArxNet(); InternalTrace.Initialize("nunit-gui_%p.log", (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default)); log.Info("Starting NUnit GUI"); GuiOptionsArxNet guiOptions = new GuiOptionsArxNet(args); GuiAttachedConsole attachedConsole = null; if (guiOptions.console) { log.Info("Creating attached console"); attachedConsole = new GuiAttachedConsole(); } if (guiOptions.help) { MessageDisplay.Display(guiOptions.GetHelpText()); return 0; } if (!guiOptions.Validate()) { string message = "Error in command line"; MessageDisplay.Error(message + Environment.NewLine + Environment.NewLine + guiOptions.GetHelpText()); log.Error(message); return 2; } if (guiOptions.cleanup) { log.Info("Performing cleanup of shadow copy cache"); DomainManager.DeleteShadowCopyPath(); return 0; } if (!guiOptions.NoArgs) { if (guiOptions.lang != null) { log.Info("Setting culture to " + guiOptions.lang); Thread.CurrentThread.CurrentUICulture = new CultureInfo(guiOptions.lang); } } try { // Add Standard Services to ServiceManager log.Info("Adding Services"); ServiceManager.Services.AddService(settingsService); ServiceManager.Services.AddService(new DomainManager()); ServiceManager.Services.AddService(new RecentFilesService()); ServiceManager.Services.AddService(new ProjectService()); ServiceManager.Services.AddService(new TestLoaderArxNet(new GuiTestEventDispatcherArxNet())); ServiceManager.Services.AddService(new AddinRegistry()); ServiceManager.Services.AddService(new AddinManager()); ServiceManager.Services.AddService(new TestAgency()); // Initialize Services log.Info("Initializing Services"); ServiceManager.Services.InitializeServices(); } catch (SystemException ex) { MessageDisplay.FatalError("Service initialization failed.", ex); log.Error("Service initialization failed", ex); return 2; } // Create container in order to allow ambient properties // to be shared across all top-level forms. log.Info("Initializing AmbientProperties"); AppContainer c = new AppContainer(); AmbientProperties ambient = new AmbientProperties(); c.Services.AddService(typeof(AmbientProperties), ambient); log.Info("Constructing Form"); NUnitFormArxNet form = new NUnitFormArxNet(guiOptions); c.Add(form); try { log.Info("Starting Gui Application"); //FormsApplication.Run(form); Document doc = CADApplication.DocumentManager.MdiActiveDocument; CADApplication.ShowModelessDialog(doc.Window.Handle, form); //CADApplication.ShowModalDialog(form); //CADApplication.ShowModelessDialog(form); //log.Info("Application Exit"); } catch (SystemException ex) { log.Error("Gui Application threw an excepion", ex); //2012.12.23改 log.Info("Stopping Services"); ServiceManager.Services.StopAllServices(); ServiceManager.Services.ClearServices(); //2012.12.23改 throw; } /*finally { log.Info("Stopping Services"); ServiceManager.Services.StopAllServices(); } if (attachedConsole != null) { Console.WriteLine("Press Enter to exit"); Console.ReadLine(); attachedConsole.Close(); } log.Info("Exiting NUnit GUI"); InternalTrace.Close();*/ return 0; }
public NUnitFormArxNet( GuiOptionsArxNet guiOptions ) : base("NUnit") { InitializeComponent(); this.guiOptions = guiOptions; this.recentFilesService = ServicesArxNet.RecentFiles; this.userSettings = ServicesArxNet.UserSettings; this.presenter = new NUnitPresenterArxNet(this, TestLoader); }