Пример #1
0
 public void DontShowMessageBoxForAsserts()
 {
     using (DebugProcs debugProcs = new DebugProcs(false))
     {
         ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
         // asserts - this brings up a message box if ShowAssertMessageBox doesn't work
         bldr.SetIntPropValues(1, 0, 0);
     }
 }
Пример #2
0
		public void DontShowMessageBoxForAsserts()
		{
			using (DebugProcs debugProcs = new DebugProcs(false))
			{
				ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
				// asserts - this brings up a message box if ShowAssertMessageBox doesn't work
				bldr.SetIntPropValues(1, 0, 0);
			}
		}
Пример #3
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for FwApp takes an array of command-line arguments.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		public FwApp(string[] rgArgs)
		{
#if DEBUG
			m_debugProcs = new DebugProcs();
#endif
			SetGlobalExceptionHandler();

			if (s_app != null)
			{
				throw new InvalidOperationException("Multiple instances of the FwApp object " +
					"are not allowed.");
				// The following code is pointless since right away we catch the exception we might throw.
				// If s_app is not null then this is clearly a case where we didn't call Dispose(),
				// so it is legitimate to throw an InvalidOperationException. The commented out code
				// was added in changelist 10709.
				//// If s_app is pointing to something, make sure it's still a valid object
				//// by referencing the ResourceString() method. If that doesn't cause an
				//// error, then it's not valid to instantiate another application object.
				//// The dispose method sets s_app to null but there might be a case where
				//// we try to instantiate an FwApp before the garbage collection has taken
				//// place on a previous instantiation (e.g. in tests).
				//try
				//{
				//    if (FwApp.GetResourceString(string.Empty) == string.Empty)
				//    {
				//        throw new InvalidOperationException("Multiple instances of the FwApp object " +
				//            "are not allowed");
				//    }
				//}
				//catch
				//{
				//}
			}

			s_app = this;

			// Fix for TE-975.
			// Force the broadcast window to be initialized in the current thread.
			// See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=911603&SiteID=1
			FakeDelegate fd = delegate() {};
			Microsoft.Win32.SystemEvents.InvokeOnEventsThread(fd);

			m_HelperControl = new Control();
			m_HelperControl.CreateControl();

			Application.AddMessageFilter(this);

			// Store the command line arguments for use by each new application window.
			try
			{
				m_commandLineArgs = ParseCommandLine(rgArgs);
				SetUICulture();
			}
			catch (Exception e)
			{
				ErrorReporter.ReportException(e);
			}
		}
Пример #4
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected virtual void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed || m_beingDisposed)
				return;
			m_beingDisposed = true;

			UpdateAppRuntimeCounter();

			if (disposing)
			{
				FwRegistrySettings.FirstTimeAppHasBeenRun = false;

				// Dispose managed resources here.
				Logger.ShutDown();
				Application.ThreadException -= new ThreadExceptionEventHandler(HandleTopLevelError);

				List<IFwMainWnd> mainWnds = new List<IFwMainWnd>(m_rgMainWindows); // Use another array, since m_rgMainWindows may change.
				m_rgMainWindows.Clear(); // In fact, just clear the main array, so the windows won't have to worry so much.
				foreach (IFwMainWnd mainWnd in mainWnds)
				{
					if (mainWnd is Form)
					{
						Form wnd = (Form)mainWnd;
						wnd.Closing -= new CancelEventHandler(OnClosingWindow);
						wnd.Closed -= new EventHandler(OnWindowClosed);
						wnd.Activated -= new EventHandler(fwMainWindow_Activated);
						wnd.HandleDestroyed -= new EventHandler(fwMainWindow_HandleDestroyed);
						wnd.Dispose();
					}
					else if (mainWnd is IDisposable)
						((IDisposable)mainWnd).Dispose();
				}
				if (m_caches != null)
				{
					foreach (FdoCache cache in m_caches.Values)
						cache.Dispose();
					m_caches.Clear();
				}
				if (m_findReplaceDlg != null)
					m_findReplaceDlg.Dispose();
#if DEBUG
				if (m_debugProcs != null)
					m_debugProcs.Dispose();
#endif
				// Close the splash screen if, for some reason, it's still hanging around. It
				// really shouldn't still be around by this time, except when some testing code
				// instantiates FwApp objects. This will make sure the splash screen goes away
				// when the FwApp object goes out of scope.
				CloseSplashScreen();
				ResourceHelper.ShutdownHelper();
				if (m_rgMainWindows != null)
					m_rgMainWindows.Clear();
				if (m_commandLineArgs != null)
					m_commandLineArgs.Clear();
				if (m_suppressedCaches != null)
					m_suppressedCaches.Clear();
				if (m_refreshViewCaches != null)
					m_refreshViewCaches.Clear();
				if (m_findPatterns != null)
					m_findPatterns.Clear();

				Application.RemoveMessageFilter(this);
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_rgMainWindows = null;
			m_activeMainWindow = null;
			m_commandLineArgs = null;
			m_SplashScreenWnd = null;
			m_findPatterns = null;
			m_findReplaceDlg = null;
			m_suppressedCaches = null;
			m_refreshViewCaches = null;
#if DEBUG
			m_debugProcs = null;
#endif
			m_caches = null;
			s_app = null;

			m_isDisposed = true;
			m_beingDisposed = false;
		}
Пример #5
0
		public virtual void FixtureSetup()
		{
#if false
			CheckDisposed();
#else

			/* We need to document cases where this needs to be worried about.
			 * I (RandyR) don't understand how this can happen, if the nunit framework
			 * creates a test class instance, calls this method, runs all its tests,
			 * calls the TestFictureTeardown code (Dispose),
			 * and then turns loose of the test class instance.
			 *
			 * If the above is what happens, then how can it be called twice?
			 * If the class can indeed be reused, and this method called more than once,
			 * in what contexts does it happen?
			 *
			 * Until we can nail down that context,
			 * let's see if we can live with the more rigid approach.
			 *
			 * Followup observation:
			 * I (RandyR) saw in some acceptance tests (UndoRedoTests) that a test TearDown
			 * method had called this method, as well as the Dispose method, as a way
			 * to be sure the next was set up correcly. That is not good!
			 * I fixed that class to not override this method or the Dispose method,
			 * but to just do all the setup/teardown stuff between each test.
			 */
			// Answer (TimS/EberhardB): NUnit doesn't create a new instance each time
			// a test fixture is run. Therefore we have to resurrect the instance, otherwise
			// we can't run tests twice in NUnit-GUI.
			// ENHANCE: We think our use of doing a Dispose in the TestFixtureTearDown is wrong,
			// since FixtureSetUp and FixtureTearDown go together, so FixtureTearDown should
			// clean the things that FixtureSetUp created (or that might be left over from
			// running the tests).
			if (m_isDisposed)
			{
				// in case we're running the same test twice we have to reset the m_isDisposed
				// flag, otherwise in FixtureTearDown we think that Dispose was already called.
				m_isDisposed = false;
				GC.ReRegisterForFinalize(this);
			}

#if false
			// This should already be disposed if we run this test fixture twice.
			if (m_DebugProcs != null)
				m_DebugProcs.Dispose();
#endif
#endif

			m_DebugProcs = new DebugProcs();
			try
			{
				StringUtils.InitIcuDataDir();
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}
		}
Пример #6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		protected virtual void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			// FWC-16: we have to call CoFreeUnusedLibraries. This causes sqlnclir.dll to get
			// unloaded. If we don't do this we get a deadlock after the fixture teardown
			// because we're running STA.
			CoFreeUnusedLibraries();

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_DebugProcs != null)
					m_DebugProcs.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_DebugProcs = null;

			m_isDisposed = true;
		}