/// <summary> /// This function loads up the ozasmtSource file and adds its stats to a new finding called savedCreatedOzasmtAs /// which will have the fingdings in o2AssessmentTarget /// </summary> /// <param name="ozasmtSource"></param> /// <param name="o2AssessmentTarget"></param> /// <param name="savedCreatedOzasmtAs"></param> public bool addAssessmentStatsFromSourceToO2AssessmentAndSaveIt(string ozasmtSource, IO2Assessment o2AssessmentTarget, string savedCreatedOzasmtAs) { AssessmentRun assessmentRunToImport = OzasmtUtils_OunceV6.LoadAssessmentRun(ozasmtSource); var targetAssessmentRun = createAssessmentRunObject(o2AssessmentTarget); // map assessmentRunToImport to targetAssessmentRun // add targetAssessmentRun top level data targetAssessmentRun.AssessmentStats = assessmentRunToImport.AssessmentStats; targetAssessmentRun.AssessmentConfig = assessmentRunToImport.AssessmentConfig; targetAssessmentRun.Messages = assessmentRunToImport.Messages; // add Assessment data targetAssessmentRun.Assessment.assessee_name = assessmentRunToImport.Assessment.assessee_name; targetAssessmentRun.Assessment.AssessmentStats = assessmentRunToImport.AssessmentStats; targetAssessmentRun.Assessment.owner_name = assessmentRunToImport.Assessment.owner_name; targetAssessmentRun.Assessment.owner_type = assessmentRunToImport.Assessment.owner_type; // add project and file data //create backup of current findings var currentAssessmentDataBackup = targetAssessmentRun.Assessment.Assessment[0]; // there should only be one // assign current Assessment array to assessmentRunToImport.Assessment.Assessment targetAssessmentRun.Assessment.Assessment = assessmentRunToImport.Assessment.Assessment; // remove all findings references (since what we want is the stats foreach (var assessment in targetAssessmentRun.Assessment.Assessment) { if (assessment.AssessmentFile != null) { foreach (var assessmentFile in assessment.AssessmentFile) { assessmentFile.Finding = null; } } } // apppend the currentAssessmentDataBackup to the current Assessment Array var assessments = new List <Assessment>(targetAssessmentRun.Assessment.Assessment); assessments.Add(currentAssessmentDataBackup); targetAssessmentRun.Assessment.Assessment = assessments.ToArray(); //targetAssessmentRun.name = "AAAA"; // save it return(OzasmtUtils_OunceV6.SaveAssessmentRun(assessmentRun, savedCreatedOzasmtAs)); }
public bool importFile(string fileToLoad, IO2Assessment o2Assessment) { try { if (canLoadFile(fileToLoad)) { //o2Assessment.lastOzasmtImportWasItSucessfull = false; //o2Assessment.lastOzasmtImportFile = fileToLoad; //o2Assessment.lastOzasmtImportFileSize = Files.getFileSize(fileToLoad); //DateTime startImportTime = DateTime.Now; var timer = new O2Timer("Loaded assessment " + fileToLoad + " ").start(); AssessmentRun assessmentRunToImport = OzasmtUtils_OunceV6.LoadAssessmentRun(fileToLoad); timer.stop(); /* assessmentRun.AssessmentConfig = assessmentRunToImport.AssessmentConfig; * assessmentRun.AssessmentStats = assessmentRunToImport.AssessmentStats; * assessmentRun.Messages = assessmentRunToImport.Messages; * assessmentRun.name = assessmentRunToImport.name ?? OzasmtUtils_OunceV6.calculateAssessmentNameFromScans(assessmentRunToImport);*/ o2Assessment.name = assessmentRunToImport.name ?? OzasmtUtils_OunceV6.calculateAssessmentNameFromScans(assessmentRunToImport); // I don't think I need this since the O2Finding objects have the full strings // map top level objects /* * assessmentRun.FileIndeces = assessmentRunToImport.FileIndeces; * assessmentRun.StringIndeces = assessmentRunToImport.StringIndeces;*/ // import findings if (null != assessmentRunToImport.Assessment.Assessment) { foreach (Assessment assessment in assessmentRunToImport.Assessment.Assessment) { if (null != assessment.AssessmentFile) { foreach (AssessmentAssessmentFile assessmentFile in assessment.AssessmentFile) { if (assessmentFile.Finding != null) { foreach (AssessmentAssessmentFileFinding finding in assessmentFile.Finding) { o2Assessment.o2Findings.Add(OzasmtUtils_OunceV6.getO2Finding(finding, assessmentFile, assessmentRunToImport)); } } } } } } // if we made it this far all went ok; //o2Assessment.lastOzasmtImportTimeSpan = DateTime.Now - startImportTime; //o2Assessment.lastOzasmtImportWasItSucessfull = true; return(true); } } catch (Exception ex) { "in importAssessmentRun: {0}".error(ex.Message); } return(false); }