Esempio n. 1
0
        static void Main(string[] args)
        {
            if ( args.Length < 3 ) {
                Console.WriteLine( "Invalid arguments." );
                WriteUsage();
                return;
            }

            // extract names from command line
            string sourceXmlFileName = args[0];
            string diffgramFileName = args[1];
            string patchedXmlFileName = args[2];

            var msg = "Patching " + sourceXmlFileName + " with " + diffgramFileName;
            log.Info(msg);
            Console.WriteLine(msg);

            FileStream patchedFile = new FileStream( patchedXmlFileName, FileMode.Create, FileAccess.Write );

            XmlPatch xmlPatch = new XmlPatch();
            try {
                xmlPatch.Patch( sourceXmlFileName, patchedFile, new XmlTextReader( diffgramFileName ) );
            }
            catch (Exception ex) {
                log.Error(ex.Message, ex);
                WriteError(ex.Message);
                return;
            }

            patchedFile.Close();

            msg = "The patched document has been saved to " + patchedXmlFileName;
            log.Info(msg);
            Console.WriteLine(msg);
        }
Esempio n. 2
0
		//these functions use the current FileInfo object to create
		//temporary files. The testInfo object must be set before they are called.


		private string GetActualCompare(TestInfo testInfo, ReportAssembly reportAssembly, string missingReport, string extension)
		{
			Assembly assembly = reportAssembly.Assembly;

			foreach (TestClass testclass in reportAssembly.TestClasses)
			{
				if (testclass.Name == testInfo.TestClassName)
				{
					foreach (Test test in testclass.Tests)
					{
						if (test.Name == testInfo.TestName && testclass.TestNamespace == testInfo.TestNamespace)
						{
							string result = test.Result;
							string baseResourceName = testInfo.BaseFileName;
							XmlReaderSettings readerSettings = new XmlReaderSettings();

							if (result == ReportDiffgram || missingReport != null)
							{
								using (Stream reportStream = missingReport != null ? null : assembly.GetManifestResourceStream(baseResourceName + ".Report.xml"))
								{
									if (reportStream != null || missingReport != null)
									{
										XmlPatch patcher = new XmlPatch();
										using (XmlReader reportReader = missingReport != null ?
											XmlReader.Create(new StringReader(missingReport)) :
											XmlReader.Create(reportStream, readerSettings))
										{
											StringReader compareStringReader;
											if (missingReport != null)
											{
												compareStringReader = ExtractStringReaderFromCompareByName(reportReader, extension);
											}
											else
											{
												using (XmlReader diffReader = XmlReader.Create(new StringReader(test.Content), readerSettings))
												{
													using (MemoryStream compareStream = new MemoryStream())
													{
														patcher.Patch(reportReader, new UncloseableStream(compareStream), diffReader);
														compareStream.Position = 0;
														//the filestream is now the expected test report, containing a compare. 
														//Now to get that compare...

														compareStringReader = ExtractStringReaderFromCompareByName(XmlReader.Create(compareStream), extension);
													}
												}
											}

											//and apply the diffgram within in to the original Compare.orm
											using (Stream compareStream = assembly.GetManifestResourceStream(string.Format("{0}.{1}", baseResourceName, extension)))
											{
												if (compareStream != null)
												{
													using (XmlReader compareReader = XmlReader.Create(compareStream, readerSettings))
													{
														using (MemoryStream patchedCompareStream = new MemoryStream())
														{
															using (XmlReader reportCompareReader = XmlReader.Create(compareStringReader, readerSettings))
															{
																//an exception thrown here is generally caused by the report suite being outdated. 
																patcher.Patch(compareReader, new UncloseableStream(patchedCompareStream), reportCompareReader);
															}
															patchedCompareStream.Position = 0;
															using (MemoryStream patchedOutputStream = new MemoryStream())
															{
																using (XmlReader reader = XmlReader.Create(patchedCompareStream))
																{
																	XmlWriterSettings writerSettings = new XmlWriterSettings();
																	writerSettings.Indent = true;
																	writerSettings.IndentChars = "\t";
																	writerSettings.CloseOutput = false;
																	using (XmlWriter writer = XmlWriter.Create(patchedOutputStream, writerSettings))
																	{
																		FormatXml(reader, writer);
																	}
																}
																patchedOutputStream.Position = 0;
																return new StreamReader(patchedOutputStream).ReadToEnd();
															}
														}
													}
												}
											}
										}
									}
								}
							}
							return null;
						}
					}
				}
			}
			Debug.Fail("Internal Error. function: GetActualCompare.");
			return null;
		}