コード例 #1
0
		public XslTransformWithProgress(string inputFilePath, string outputFilePath, Stream xsltStream, string xpathToCountSteps)
		{
			_inputFilePath = inputFilePath;
			_outputFilePath = outputFilePath;
			_xsltStream = xsltStream;
			_xpathToCountSteps = xpathToCountSteps;
			_progressState = null;
		}
コード例 #2
0
 public XslTransformWithProgress(string inputFilePath, string outputFilePath, Stream xsltStream, string xpathToCountSteps)
 {
     _inputFilePath     = inputFilePath;
     _outputFilePath    = outputFilePath;
     _xsltStream        = xsltStream;
     _xpathToCountSteps = xpathToCountSteps;
     _progressState     = null;
 }
コード例 #3
0
		private void WaitForFinish(ConsoleProgressState progress, ProgressState.StateValue expectedResult)
		{
			DateTime giveUpTime = DateTime.Now.AddSeconds(5);
			while (progress.State != expectedResult)
			{
				if (DateTime.Now > giveUpTime)
				{
					Assert.Fail("Didn't get expected result");
				}
				Thread.Sleep(10);
			}
		}
コード例 #4
0
		public void Setup()
		{
			_dummyParentForm = new Form();
			_dummyParentForm.Name = "dummy form";
			_dummyParentForm.Text = "Dummy Form";
			_dummyParentForm.Show();
			Application.DoEvents();
			_command = new TestCommand();
			//_progressLog = "";
			_progressHandler = new ProgressDialogHandler(_dummyParentForm, _command);
			_progressState = new ProgressDialogProgressState(_progressHandler);
			_commandFinishedCalled = false;
		}
コード例 #5
0
ファイル: LiftPreparer.cs プロジェクト: jwickberg/libpalaso
		public void PopulateDefinitions(ProgressState state)
		{
			state.StatusLabel = "Updating Lift File...";
			try
			{
				string pathToLift = _liftFilePath;
				string temp1 = Utilities.ProcessLiftForLaterMerging(pathToLift);
				//    int liftProducerVersion = GetLiftProducerVersion(pathToLift);

				string outputPath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
				XmlWriterSettings settings = new XmlWriterSettings();
				settings.Indent = true;
				settings.NewLineOnAttributes = true;

				using (
						Stream xsltStream =
								Assembly.GetExecutingAssembly().GetManifestResourceStream(
										"WeSay.LexicalModel.Migration.populateDefinitionFromGloss.xslt")
						)
				{
					XslTransformWithProgress transformer = new XslTransformWithProgress(
							temp1, outputPath, xsltStream, "//sense");
					state.StatusLabel = "Populating Definitions from Glosses";
					transformer.Transform(state);
				}

				MoveTempOverRealAndBackup(pathToLift, outputPath);
			}
			catch (Exception error)
			{
				state.ExceptionThatWasEncountered = error;
				state.State = ProgressState.StateValue.StoppedWithError;
				throw;
				// this will put the exception in the e.Error arg of the RunWorkerCompletedEventArgs
			}
		}
コード例 #6
0
ファイル: LiftPreparer.cs プロジェクト: jwickberg/libpalaso
		public void MigrateLiftFile(ProgressState state)
		{
			try
			{
				string oldVersion = Validator.GetLiftVersion(_liftFilePath);
				string status = String.Format("Migrating from {0} to {1}",
											  oldVersion,
											  Validator.LiftVersion);
				Logger.WriteEvent(status);
				state.StatusLabel = status;
				string migratedFile = Migrator.MigrateToLatestVersion(_liftFilePath);
				//this was hard on test, as it would fail if the file ended in ".tmp"
				//      string nameForOldFile = _liftFilePath.Replace(".lift", "." + oldVersion + ".lift");
				var extension = Path.GetExtension(_liftFilePath);
				string nameForOldFile = _liftFilePath.Replace(extension, "." + oldVersion + extension);

				if (File.Exists(nameForOldFile))
						// like, if we tried to convert it before and for some reason want to do it again
				{
					File.Delete(nameForOldFile);
				}
				File.Move(_liftFilePath, nameForOldFile);
				File.Move(migratedFile, _liftFilePath);

				//review: CJP asks I'm not sure why this is required to be passed back via results. ???
				//args.Result = args.Argument as ProgressState;
			}
			catch (Exception e)
			{
				//currently, error reporter can choke because this is
				//being called from a non sta thread.
				//so let's leave it to the progress dialog to report the error
				//                Reporting.ErrorReporter.ReportException(e,null, false);
				state.ExceptionThatWasEncountered = e;
				state.WriteToLog(e.Message);
				state.State = ProgressState.StateValue.StoppedWithError;
			}
		}
コード例 #7
0
ファイル: CommandTests.cs プロジェクト: jwickberg/libpalaso
			protected override void DoWork2(ProgressState progress)
			{
				progress.TotalNumberOfSteps = 100;
				while (_countForWork < 100)
				{
					DoPretendWork();
					_countForWork++;
					progress.NumberOfStepsCompleted = _countForWork;
				}
				progress.State = ProgressState.StateValue.Finished;
			}
コード例 #8
0
        public void Transform(ProgressState progressState)
        {
            _progressState = progressState;
            using (Stream outputStream = File.Create(OutputFilePath))
            {
                var inputDocument = new XmlDocument {
                    PreserveWhitespace = true
                };
                inputDocument.Load(_inputFilePath);

                var transform = new XslCompiledTransform();
                try
                {
                    //all this just to allow a DTD statement in the source xslt
                    var readerSettings = new XmlReaderSettings {
                        DtdProcessing = DtdProcessing.Parse
                    };

                    _progressState.StatusLabel = "Preparing...";
                    using (Stream stream = _xsltStream)
                    {
                        using (XmlReader xsltReader = XmlReader.Create(stream, readerSettings))
                        {
                            XsltSettings settings = new XsltSettings(true, true);
                            transform.Load(xsltReader, settings, new XmlUrlResolver());
                            xsltReader.Close();
                        }

                        stream.Close();
                    }

                    _progressState.StatusLabel = "Processing...";
                    int         entriesCount  = 1;
                    XmlNodeList nodeCountList = inputDocument.SelectNodes(_xpathToCountSteps);
                    if (nodeCountList != null)
                    {
                        entriesCount = nodeCountList.Count;
                    }

                    _progressState.TotalNumberOfSteps = entriesCount;
                    if (_xsltArguments == null)
                    {
                        _xsltArguments = new XsltArgumentList();
                    }

                    _xsltArguments.XsltMessageEncountered += OnXsltMessageEncountered;
                    transform.Transform(inputDocument, _xsltArguments, outputStream);

                    outputStream.Close();                     //let the next guy get at the file
                    Debug.Assert(_progressState.NumberOfStepsCompleted <= entriesCount,
                                 "Should use up more than we reserved for ourselves");
                    _progressState.NumberOfStepsCompleted = entriesCount;
                    _progressState.State = ProgressState.StateValue.Finished;
                }
                catch (CancelingException)                 //not an error
                {
                    _progressState.State = ProgressState.StateValue.Finished;
                }
                catch (Exception err)
                {
                    //currently, error reporter can choke because this is
                    //being called from a non sta thread.
                    //so let's leave it to the progress dialog to report the error
                    //                Reporting.ErrorReporter.ReportException(args,null, false);
                    _progressState.ExceptionThatWasEncountered = err;
                    _progressState.WriteToLog(err.Message);
                    _progressState.State = ProgressState.StateValue.StoppedWithError;
                }
#if NET461
                finally
                {
                    _progressState.StatusLabel = "Cleaning up...";
                    transform.TemporaryFiles?.Delete();
                }
#endif
            }
        }
コード例 #9
0
		public void Transform(ProgressState progressState)
		{
			_progressState = progressState;
			XslCompiledTransform transform = null;
			using (Stream outputStream = File.Create(OutputFilePath))
			{
				XmlDocument inputDocument = new XmlDocument();
				inputDocument.PreserveWhitespace = true;
				inputDocument.Load(_inputFilePath);

				try
				{
					transform = new XslCompiledTransform();

					//all this just to allow a DTD statement in the source xslt
					XmlReaderSettings readerSettings = new XmlReaderSettings();
					readerSettings.ProhibitDtd = false;

					_progressState.StatusLabel = "Preparing...";
					using (Stream stream = _xsltStream)
					{
						using (XmlReader xsltReader = XmlReader.Create(stream, readerSettings))
						{
							XsltSettings settings = new XsltSettings(true, true);
							transform.Load(xsltReader, settings, new XmlUrlResolver());
							xsltReader.Close();
						}
						stream.Close();
					}

					_progressState.StatusLabel = "Processing...";
					int entriesCount = 1;
					XmlNodeList nodeCountList = inputDocument.SelectNodes(_xpathToCountSteps);
					if (nodeCountList != null)
					{
						entriesCount = nodeCountList.Count;
					}
					_progressState.TotalNumberOfSteps = entriesCount;
					if (_xsltArguments == null)
					{
						_xsltArguments = new XsltArgumentList();
					}
					_xsltArguments.XsltMessageEncountered += OnXsltMessageEncountered;
					transform.Transform(inputDocument, _xsltArguments, outputStream);

					outputStream.Close(); //let the next guy get at the file
					Debug.Assert(_progressState.NumberOfStepsCompleted <= entriesCount,
								 "Should use up more than we reserved for ourselves");
					_progressState.NumberOfStepsCompleted = entriesCount;
					_progressState.State = ProgressState.StateValue.Finished;
				}
				catch (CancelingException) //not an error
				{
					_progressState.State = ProgressState.StateValue.Finished;
				}
				catch (Exception err)
				{
					//currently, error reporter can choke because this is
					//being called from a non sta thread.
					//so let's leave it to the progress dialog to report the error
					//                Reporting.ErrorReporter.ReportException(args,null, false);
					_progressState.ExceptionThatWasEncountered = err;
					_progressState.WriteToLog(err.Message);
					_progressState.State = ProgressState.StateValue.StoppedWithError;
				}
				finally
				{
					if (transform != null)
					{
						_progressState.StatusLabel = "Cleaning up...";
						TempFileCollection tempfiles = transform.TemporaryFiles;
						if (tempfiles != null) // tempfiles will be null when debugging is not enabled
						{
							tempfiles.Delete();
						}
					}
				}
			}
		}
コード例 #10
0
		private static void WaitOnProgressState(ref ProgressState _progressState, ProgressState.StateValue expectedState)
		{
			DateTime giveUpTime = DateTime.Now.AddSeconds(5);
			while (_progressState.State != expectedState)
			{
				if (DateTime.Now > giveUpTime)
				{
					Assert.AreEqual(expectedState, _progressState.State);
				}
			  //  Thread.Sleep(10);
				Application.DoEvents();
			}
		}
コード例 #11
0
		private void OnProgressStateLog(object sender, ProgressState.LogEvent e)
		{
			_logBuilder.AppendLine(e.message);
		}