private async Task <bool> StreamAndSaveObservation(ContentURI docToCalcURI, IDictionary <string, string> fileOrFolderPaths, bool hasInitialColumnDictionary) { bool bHasObservation = false; string sId = string.Empty; string sFileToAnalyze = string.Empty; int i = 0; WriteColumnNameRow(); foreach (KeyValuePair <string, string> kvp in fileOrFolderPaths) { sId = kvp.Key; sFileToAnalyze = kvp.Value; if (await Helpers.FileStorageIO.URIAbsoluteExists( docToCalcURI, sFileToAnalyze)) { FileToAnalyzeReader = await Helpers.FileStorageIO.GetXmlReaderAsync(docToCalcURI, sFileToAnalyze); if (FileToAnalyzeReader != null) { using (FileToAnalyzeReader) { FileToAnalyzeReader.MoveToContent(); Ancestors.Clear(); AddObservations(docToCalcURI, hasInitialColumnDictionary); } } if (docToCalcURI.ErrorMessage != string.Empty) { //fix all errors before running an analysis break; } i++; } } if (docToCalcURI.ErrorMessage == string.Empty) { if (hasInitialColumnDictionary) { //save the observations file TextFile.Flush(); bHasObservation = true; } } return(bHasObservation); }
//allows derived classes to override the default streaming //and save method protected virtual bool StreamAndSaveObservation() { HasGoodObservationFile = false; if (this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths == null) { this.ObsCalculatorParams.ErrorMessage = Errors.MakeStandardErrorMsg("OBSERVATIONS_NOFILES_SAVETEXT"); return(false); } else { if (this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths.Count <= 0) { this.ObsCalculatorParams.ErrorMessage = Errors.MakeStandardErrorMsg("OBSERVATIONS_NOFILES_SAVETEXT"); return(false); } } bool bHasInitialColumnDictionary = InitColumnDictionary(); this.ObsCalculatorParams.AnalyzerParms.ObservationsPath = GetObservationFilePath(this.ObsCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath); if (!string.IsNullOrEmpty(this.ObsCalculatorParams.AnalyzerParms.ObservationsPath)) { if (bHasInitialColumnDictionary) { TextFile = new StreamWriter( this.ObsCalculatorParams.AnalyzerParms.ObservationsPath); //write the column headings WriteColumnNameRow(); } //+1 because the first column holds the stats for all comparisons //int iFileComparisonsCount = fileOrFolderPaths.Count + 1; //subscribers set a "Files" attribute property using this property this.ObsCalculatorParams.AnalyzerParms.FilesComparisonsCount = this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths.Count + 1; string sId = string.Empty; string sFileToAnalyze = string.Empty; int i = 0; //file order is not relevant in this addin, //but parallel won't work (yet) because of the way //the observationRoot gets built foreach (KeyValuePair <string, string> kvp in this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths) { sId = kvp.Key; sFileToAnalyze = kvp.Value; if (CalculatorHelpers.URIAbsoluteExists( this.ObsCalculatorParams.ExtensionDocToCalcURI, sFileToAnalyze)) { this.ObsCalculatorParams.AnalyzerParms.ObservationFile = sFileToAnalyze; this.ObsCalculatorParams.AnalyzerParms.FilePositionIndex = i; //stream and add the calculation (observation) //to the observationsRoot if (!CalculatorHelpers.URIAbsoluteExists( this.ObsCalculatorParams.ExtensionDocToCalcURI, this.ObsCalculatorParams.AnalyzerParms.ObservationFile)) { return(HasGoodObservationFile); } this.ObsCalculatorParams.DocToCalcReader = DevTreks.Data.Helpers.FileStorageIO.GetXmlReader( this.ObsCalculatorParams.ExtensionDocToCalcURI.URIDataManager.InitialDocToCalcURI, this.ObsCalculatorParams.AnalyzerParms.ObservationFile); if (this.ObsCalculatorParams.DocToCalcReader != null) { using (this.ObsCalculatorParams.DocToCalcReader) { this.ObsCalculatorParams.DocToCalcReader.MoveToContent(); this.ObsCalculatorParams.AnalyzerParms.Ancestors.Clear(); this.ObsCalculatorParams.CurrentElementNodeName = string.Empty; this.ObsCalculatorParams.ParentElementNodeName = string.Empty; LinkedViewCount = 0; AddObservations(bHasInitialColumnDictionary); } } if (this.ObsCalculatorParams.ErrorMessage != string.Empty) { //fix all errors before running an analysis this.ObsCalculatorParams.ErrorMessage = this.ObsCalculatorParams.ErrorMessage; break; } i++; } } if (this.ObsCalculatorParams.ErrorMessage == string.Empty) { if (bHasInitialColumnDictionary) { //save the observations file if (TextFile != null) { //2 passes means using syntax can't be used TextFile.Flush(); TextFile.Close(); HasGoodObservationFile = true; } } else { //second pass builds the observations StreamAndSaveObservation(); } } } return(HasGoodObservationFile); }