Пример #1
0
		public void Setup()
		{
			_dialog = new ProgressDialog();
			_dialog.Text = "Unit Test";
			_dialog.Overview = "Pretending to do some work...";
			_countForWork = 0;
		}
        {
			LexEntryRepositoryLoaderService x = new LexEntryRepositoryLoaderService(pathToLift);
			return x.GetLexEntryRepository();
		}
        private void Load()
        {
			using (ProgressDialog dlg = new ProgressDialog())
			{
				dlg.Overview = "Please wait while WeSay loads your data.";
				BackgroundWorker worker = new BackgroundWorker();
				worker.DoWork += delegate (object sender, DoWorkEventArgs args)
									 {
										 ProgressState progressState = (ProgressState) args.Argument;
										 try
										 {

											 _lexEntryRepository = new LexEntryRepository(_pathToLift, progressState);
											 args.Result = _lexEntryRepository;

										 }
										 catch(Exception error)
										 {
											 args.Cancel = true;//review
											 args.Result = error;
											 progressState.ExceptionThatWasEncountered = error;
										 }
									 };
				dlg.BackgroundWorker = worker;
				dlg.CanCancel = false;

				dlg.ShowDialog();
				if (dlg.DialogResult != DialogResult.OK)
				{
					Exception err = dlg.ProgressStateResult.ExceptionThatWasEncountered;
					if (err != null)
					{
						throw err;
					}
					else if (dlg.ProgressStateResult.State ==
							 ProgressState.StateValue.StoppedWithError)
					{
Пример #3
0
		private bool PopulateDefinitionsWithUI()
		{
			using (ProgressDialog dlg = new ProgressDialog())
			{
				dlg.Overview = "Please wait while WeSay preprocesses your LIFT file.";
				BackgroundWorker preprocessWorker = new BackgroundWorker();
				preprocessWorker.DoWork += DoPopulateDefinitionsWork;
				dlg.BackgroundWorker = preprocessWorker;
				dlg.CanCancel = true;
				dlg.ShowDialog();
				if (dlg.ProgressStateResult.ExceptionThatWasEncountered != null)
				{
					ErrorReport.ReportNonFatalMessage(
							String.Format(
									"WeSay encountered an error while preprocessing the file '{0}'.  Error was: {1}",
									_liftFilePath,
									dlg.ProgressStateResult.ExceptionThatWasEncountered.Message));
				}
				return (dlg.DialogResult == DialogResult.OK);
			}
		}
		/// <summary>
		///
		/// </summary>
		/// <returns>false if not successful or cancelled</returns>
		private bool DoTransformWithProgressDialog(bool failureWouldBeFatal)
		{
			using (ProgressDialog dlg = new ProgressDialog())
			{
				dlg.Overview =string.Format("{0}", _taskMessage);
				BackgroundWorker worker = new BackgroundWorker();
				worker.DoWork += OnDoTransformWork;
				dlg.BackgroundWorker = worker;
				dlg.CanCancel = true;
				//dlg.CancelRequested += new EventHandler(OnCancelRequested);
				dlg.ShowDialog();
				if (dlg.ProgressStateResult!=null && dlg.ProgressStateResult.ExceptionThatWasEncountered != null)
				{
					if(failureWouldBeFatal)
						Palaso.Reporting.ErrorReport.ReportFatalException(dlg.ProgressStateResult.ExceptionThatWasEncountered);
				   else
					{
						Palaso.Reporting.ErrorReport.ReportNonFatalException(dlg.ProgressStateResult.ExceptionThatWasEncountered);
					}
					return false;
				}
				return !dlg.ProgressState.Cancel;
			}
		}
Пример #5
0
		/// <summary>
		///
		/// </summary>
		/// <returns>true if everything is ok, false if something went wrong</returns>
		public bool MigrateIfNeeded()
		{
			if (Migrator.IsMigrationNeeded(_liftFilePath))
			{
				using (ProgressDialog dlg = new ProgressDialog())
				{
					dlg.Overview =
							"Please wait while WeSay migrates your lift database to the required version.";
					BackgroundWorker migrationWorker = new BackgroundWorker();
					migrationWorker.DoWork += DoMigrateLiftFile;
					dlg.BackgroundWorker = migrationWorker;
					dlg.CanCancel = false;

					dlg.ShowDialog();
					if (dlg.DialogResult != DialogResult.OK)
					{
						Exception err = dlg.ProgressStateResult.ExceptionThatWasEncountered;
						if (err != null)
						{
							ErrorNotificationDialog.ReportException(err, null, false);
						}
						else if (dlg.ProgressStateResult.State ==
								 ProgressState.StateValue.StoppedWithError)
						{
							ErrorReport.ReportNonFatalMessage(
									"Failed." + dlg.ProgressStateResult.LogString, null, false);
						}
						return false;
					}
				}
			}
			return true;
		}
Пример #6
0
		/// <summary>
		///
		/// </summary>
		/// <param name="arguments"></param>
		/// <returns>false if not successful or cancelled</returns>
		private static bool DoTransformWithProgressDialog(TransformWorkerArguments arguments)
		{
			using (ProgressDialog dlg = new ProgressDialog())
			{
				dlg.Overview = "Please wait...";
				BackgroundWorker worker = new BackgroundWorker();
				worker.DoWork += OnDoTransformWork;
				dlg.BackgroundWorker = worker;
				dlg.CanCancel = true;
				//dlg.CancelRequested += new EventHandler(OnCancelRequested);
				dlg.ProgressState.Arguments = arguments;
				dlg.ShowDialog();
				if (dlg.ProgressStateResult != null &&
					dlg.ProgressStateResult.ExceptionThatWasEncountered != null)
				{
					ErrorNotificationDialog.ReportException(
							dlg.ProgressStateResult.ExceptionThatWasEncountered, null, false);
					return false;
				}
				return !dlg.ProgressState.Cancel;
			}
		}
Пример #7
0
		private long MeasureProgressUpdateCost(bool doMakeProgressCalls, int iterationsToDo)
		{
			_dialog = new ProgressDialog();
			BackgroundWorker worker = new BackgroundWorker();
			worker.DoWork += OnDoSomeWork;
			_dialog.BackgroundWorker = worker;
			WorkArguments args = new WorkArguments();
			args.doMakeProgressCalls = doMakeProgressCalls;
			args.secondsToUseUp = 0;
			args.iterationsToDo = iterationsToDo;
			_dialog.ProgressState.Arguments = args;
			Stopwatch w = new Stopwatch();
			w.Start();
			_dialog.ShowDialog();
			_dialog.Close();
			_dialog.Dispose();
			_dialog = null;
			w.Stop();
			worker.Dispose();
			Debug.WriteLine("Took "+ w.Elapsed);
			return w.ElapsedMilliseconds;
		}