private CISink FindSink(bool aUseXmlSink) { Trace("[CA Cmd] FindSink() - START"); CISink ret = null; // string sinkToUse = KCrashItemSinkName; if (aUseXmlSink) { sinkToUse = KXmlCrashItemSinkName; } CISinkManager sinkManager = iCrashItemEngine.SinkManager; foreach (CISink sink in sinkManager) { Trace("[CA Cmd] FindSink() - found sink: " + sink.Name); if (sink.Name.ToUpper().Contains(sinkToUse)) { ret = sink; break; } } // Trace("[CA Cmd] FindSink() - END - ret: " + ret); return(ret); }
private void Menu_File_SaveAs_SinkFormat_Click(object aTag, string aCaption) { if (aTag is CISink) { CISink sink = (CISink)aTag; // CISinkSerializationParameters parameters = new CISinkSerializationParameters(CIContainer, base.UIManager.UIVersion, base.UIManager.UICommandLineArguments); FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "Save Location"; // if (dialog.ShowDialog() == DialogResult.OK) { parameters.OutputDirectory = new System.IO.DirectoryInfo(dialog.SelectedPath); // sink.Serialize(parameters); } } }
private CISink FindXmlSink() { UITrace("[CA Cmd] FindXmlSink() - START"); CISink ret = null; // CISinkManager sinkManager = iEngine.CrashItemEngine.SinkManager; foreach (CISink sink in sinkManager) { UITrace("[CA Cmd] FindXmlSink() - found sink: " + sink.Name); if (sink.Name.ToUpper().Contains("CRASH XML")) { ret = sink; break; } } // UITrace("[CA Cmd] FindXmlSink() - END - ret: " + ret); return(ret); }
private void TryToCreateOutput(CISink aXmlSink, CIContainer aContainer, CACmdLineFileSource aFile, CACmdLineMessage[] aMessagesToAdd) { Trace("[CA Cmd] TryToCreateOutput() - 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 Trace("[CA Cmd] TryToCreateOutput() - serializing..."); object output = aXmlSink.Serialize(sinkParams); Trace("[CA Cmd] TryToCreateOutput() - 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) { Trace("[CA Cmd] TryToCreateOutput() - outputException.Message: " + outputException.Message); Trace("[CA Cmd] TryToCreateOutput() - outputException.StackTrace: " + outputException.StackTrace); if (aFile != null) { // Something went wrong with CI serialisation for the specified container. outputEntry = aFile.AddOutput(aContainer, string.Empty, TOutputStatus.EFailed); // outputEntry.AddError("Could not Create CI", "CI output could not be created"); outputEntry.AddDiagnostic("CI Sink Exception Message", outputException.Message); outputEntry.AddDiagnostic("CI Sink Exception Stack", outputException.StackTrace); // Since we didn't manage to sink the container to CI 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 SetArchiveFileName(string aFileFullPath, CIContainer aContainer, CISink sink) { string fileName = Path.GetFileName(aFileFullPath); //add romid to filename if not already there CIInfoSW info = (CIInfoSW)aContainer.ChildByType(typeof(CIInfoSW)); if (info != null) { //RomID if (info.ImageCheckSum != 0) { string romid = info.ImageCheckSum.ToString("x8"); if (fileName.Length < 8 || fileName.Substring(0, 8) != romid) { fileName = romid + "_" + fileName; } } } string basename = Path.GetFileNameWithoutExtension(fileName); string extension = Path.GetExtension(aFileFullPath); string archiveNamePath = Path.Combine(iInputs.ArchivePath, fileName); //Path.GetFileName(iInputs.ArchivePath)); int counter = 1; while (File.Exists(archiveNamePath)) { archiveNamePath = Path.Combine(iInputs.ArchivePath, basename + "_" + counter.ToString() + extension); counter++; } iInputs.SinkParameters.OperationData1 = (Object)archiveNamePath; iBinFileArchivePathName = archiveNamePath; }
private void TryToCreateOutput() { CACmdLineFSEntityList <CACmdLineFileSource> inputFiles = iInputs.SourceFiles; // CISink sink = FindSink(iInputs.UseXmlSink); if (sink == null) { throw new CACmdLineException("CI Output Plugin Not Available", CACmdLineException.KErrSinkNotAvailable); } CACmdLineFSEntityList <CACmdLineFileSource> sourceFileNames = iInputs.SourceFiles; int progress = -1; int count = sourceFileNames.Count; // Emit progress banner if (iReportProgress) { Print("Creating CI content..."); } for (int i = 0; i < count; i++) { CACmdLineFileSource file = sourceFileNames[i]; System.Console.WriteLine("Starting to process file " + file.Name); // If the file has a corresponding source then we know that crash item recognised it. // Otherwise, we skip it. if (file.Source != null) { // 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 an associated container. In // the current mobile crash file format, there will be a 1:1 mapping, i.e. each file // will contain a single crash report ("container") and therefore if symbols were // found for just a single container (within the file) then it's good enough to treat // the file as archivable. foreach (CIContainer container in file.Containers) { // Firstly, add any meta-data errors/messages/warnings to this container // as crash item message entries AddMetaDataMessagesToContainer(container); SetArchiveFileName(file.Name, container, sink); foreach (CIMessage message in container.Messages) { if (message.Type == CrashItemLib.Crash.Messages.CIMessage.TType.ETypeError) { container.Status = CIContainer.TStatus.EStatusErrorContainer; } } // Now we can try to serialize the container to CI. 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 CI Sink directly to // create a stub 'FAILED' CI output file. // // NB: If Symbols were not available for the specified container, then // we don't create a CI file but instead callback to a helper that // will move the file to another temporary location for later repeat // processing bool hasSymbols = ContainsSymbols(container); if (container.Status == CIContainer.TStatus.EStatusErrorContainer) //normally don't output containers with errors { file.State = CACmdLineFileSource.TState.EStateUninitialized; if (iInputs.DecodeWithoutSymbols) //with force mode, output no matter what { TryToCreateOutput(sink, container, file, fileMessages); } } else if (hasSymbols || IsSymbollessMobileCrash(container)) { file.State = CACmdLineFileSource.TState.EStateProcessedAndReadyToBeArchived; TryToCreateOutput(sink, container, file, fileMessages); } else if (IsSymbollessMobileCrash(container)) //Crash api and registration files do not need symbols { file.State = CACmdLineFileSource.TState.EStateProcessedAndReadyToBeArchived; TryToCreateOutput(sink, container, file, fileMessages); } else { file.State = CACmdLineFileSource.TState.EStateSkippedDueToMissingSymbols; if (iInputs.DecodeWithoutSymbols) //with force mode, output no matter what { //remove this to prevent .corrupt_ci creation! TryToCreateOutput(sink, container, file, fileMessages); } } } } else { file.State = CACmdLineFileSource.TState.EStateSkippedDueToNotBeingRecognized; } // Move file to final location MoveProcessedFile(file); // Report progress as we work through the sources if (iReportProgress) { float newProgress = (((float)i + 1) / (float)count) * 100.0f; if ((int)newProgress != progress || i == count - 1) { progress = (int)newProgress; Print(string.Format("{0:d3}%", progress)); } } } }
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); }