private void AssociateInputFilesWithCrashItemSources() { CACmdLineFSEntityList <CACmdLineFileSource> sourceFileNames = iInputs.SourceFiles; CIEngineSourceCollection sources = iEngine.CrashItemEngine.Sources; int count = sources.Count; // Emit progress banner iProgressReporter.StepBegin("Categorizing files...", KStepKeyCategorizingInputFiles, count); // Check each source in the engine and try to map it back onto an input source // file name. The goal is to identify input files which have no corresponding crash engine // source. These files are unsupported. for (int i = 0; i < count; i++) { CIEngineSource source = sources[i]; string sourceFileName = source.FileName; // Try to match an input file with a given source object CACmdLineFileSource inputFile = sourceFileNames[sourceFileName]; if (inputFile != null) { inputFile.Source = source; } // Report progress as we work through the sources iProgressReporter.StepProgress(string.Empty, i, KStepKeyCategorizingInputFiles); } iProgressReporter.StepEnd(string.Empty, KStepKeyCategorizingInputFiles); }
private void TryToPrimeSources() { UITrace("[CA Cmd] TryToPrimeSources() - START"); CrashItemEngine.ClearAll(); // Prime engine with source files CACmdLineFSEntityList <CACmdLineFileSource> sourceFileNames = iInputs.SourceFiles; int count = sourceFileNames.Count; // Emit progress banner iProgressReporter.StepBegin("Locating crash files...", KStepKeyPrimingSources, count); skippedFiles.Clear(); for (int i = 0; i < count; i++) { CACmdLineFileSource file = sourceFileNames[i]; // try { // We prime each file individually. If an exception is thrown then we // record an appropriate error in the associated file object. UITrace("[CA Cmd] TryToPrimeSources() - priming: " + file); bool primeSuccess = CrashItemEngine.Prime(file); if (primeSuccess == false) { skippedFiles.Add(file.Name); } UITrace("[CA Cmd] TryToPrimeSources() - primed result: " + primeSuccess); } catch (Exception sourcePrimerException) { file.AddError("Error Identifying Source Type", "There was an error when attempting to identify the source file type. The file could not be processed."); file.AddDiagnostic("Crash Primer Exception Message", sourcePrimerException.Message); file.AddDiagnostic("Crash Primer Exception Stack", sourcePrimerException.StackTrace); } // Report progress as we work through the sources iProgressReporter.StepProgress(string.Empty, i, KStepKeyPrimingSources); } iProgressReporter.StepEnd(string.Empty, KStepKeyPrimingSources); UITrace("[CA Cmd] TryToPrimeSources() - END"); }
private void TryToCreateXmlOutput(CISink aXmlSink, CIContainer aContainer, CACmdLineFileSource aFile, CACmdLineMessage[] aMessagesToAdd) { UITrace("[CA Cmd] TryToCreateXmlOutput() - START - container source: {0}", aContainer.Source.MasterFileName); // By the time we are outputting a container, there should no longer be any messages // associated with the file. System.Diagnostics.Debug.Assert(aFile.Count == 0); // Check whether the file contained any errors or // messages of it own. if (aMessagesToAdd.Length > 0) { // Copy warnings, messages and errors into crash item container. // Diagnostic messages are not copied. CACmdLineFSEntity.CopyMessagesToContainer(aMessagesToAdd, aContainer); } // This is where we will record the output attempt CACmdLineFileSource.OutputEntry outputEntry = null; // try { // Finish preparing the sink parameters CISinkSerializationParameters sinkParams = iInputs.SinkParameters; sinkParams.Container = aContainer; // Perform serialization UITrace("[CA Cmd] TryToCreateXmlOutput() - serializing..."); object output = aXmlSink.Serialize(sinkParams); UITrace("[CA Cmd] TryToCreateXmlOutput() - serialization returned: " + output); if (aFile != null) { // Create new output string outputFileName = output is string?(string)output : string.Empty; // Save output file name outputEntry = aFile.AddOutput(aContainer, outputFileName, TOutputStatus.ESuccess); } // Merge in any diagnostic messages that were left into the output entry. // This ensure we output diagnostics in the final manifest data. outputEntry.AddRange(aMessagesToAdd, CACmdLineMessage.TType.ETypeDiagnostic); } catch (Exception outputException) { UITrace("[CA Cmd] TryToCreateXmlOutput() - outputException.Message: " + outputException.Message); UITrace("[CA Cmd] TryToCreateXmlOutput() - outputException.StackTrace: " + outputException.StackTrace); if (aFile != null) { // Something went wrong with XML serialisation for the specified container. outputEntry = aFile.AddOutput(aContainer, string.Empty, TOutputStatus.EFailed); // outputEntry.AddError("Could not Create XML", "XML output could not be created"); outputEntry.AddDiagnostic("XML Sink Exception Message", outputException.Message); outputEntry.AddDiagnostic("XML Sink Exception Stack", outputException.StackTrace); // Since we didn't manage to sink the container to XML successfully, we must // make sure we don't lose any associated messages from the original file. // Merge these into the output entry also. outputEntry.AddRange(aMessagesToAdd); } } }
private void TryToCreateXmlOutput() { CACmdLineFSEntityList <CACmdLineFileSource> inputFiles = iInputs.SourceFiles; // CISink xmlSink = FindXmlSink(); if (xmlSink == null) { throw new CACmdLineException("XML Output Plugin Not Available", CAPlugin.KErrCommandLinePluginSinkNotAvailable); } CACmdLineFSEntityList <CACmdLineFileSource> sourceFileNames = iInputs.SourceFiles; int count = sourceFileNames.Count; // Emit progress banner iProgressReporter.StepBegin("Creating crash XML content...", KStepKeyWritingOutputXml, count); for (int i = 0; i < count; i++) { CACmdLineFileSource file = sourceFileNames[i]; // If the file has a corresponding source then we know that crash item recognised it. if (file.Source == null) { // File is not supported by crash item engine. Create dummy container which we'll // serialize below. CACmdLineSource cmdLineSource = new CACmdLineSource(file.File); CIContainer failedContainer = CIContainer.NewErrorContainer(CrashItemEngine, cmdLineSource); file.Add(failedContainer); } // We copy and remove all the file-level messages. These will be added to the container // (where appropriate) or then to an output entry otherwise. CACmdLineMessage[] fileMessages = file.ToArray(); file.Clear(); // At this point, the input file is guaranteed to have associated containers. Either // valid ones (created by crash item engine) or a single 'FAILED' one which we just // added above. foreach (CIContainer container in file.Containers) { // Firstly, add any meta-data errors/messages/warnings to this container // as crash item message entries AddMetaDataMessagesToContainer(container); // Now we can try to serialize the container to XML. This method will // not throw an exception. // // If the operation succeeds, then the input file will have an associated // container object (and associated xml output file name) and we need not // do anymore. // // If it fails, then the input file will not be assigned the container // object and therefore, later on, we'll invoke the XML Sink directly to // create a stub 'FAILED' XML output file. TryToCreateXmlOutput(xmlSink, container, file, fileMessages); } // Report progress as we work through the sources iProgressReporter.StepProgress(string.Empty, i, KStepKeyWritingOutputXml); } iProgressReporter.StepEnd(string.Empty, KStepKeyWritingOutputXml); }