public BsonDocument GetProject(MongoCursor <BsonDocument> cursor, string projectName, string runTimeVersion) { BsonDocument ret = new BsonDocument(); if (cursor.Count() != 0) { ret = cursor.First(); } else { ret.Add("@project-name", projectName); ret.Add("@runtime-version", runTimeVersion); } return(ret); }
public Atributo searchOther(String t) { try { String at = t.Replace("_", "-"); var q = Query.EQ("atributo", at); MongoCursor <Atributo> result = coll.Find(q); return(result.First()); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } finally { server.Disconnect(); } }
/// <summary> /// Analyze the data in the Mongodb, and put associated data in to different tables /// </summary> /// <returns>Returns true when finshed analyzing data</returns> public bool AnalyzeData(int dropDownIndex, int days) { DateTime date = DateTime.Now.Subtract(TimeSpan.FromDays(days)); SortByBuilder sbb = new SortByBuilder(); sbb.Descending("_id"); var lastDocs = collection.FindAllAs <BsonDocument>().SetSortOrder(sbb).SetLimit(15); Hashtable idRunNameTable = new Hashtable(); ArrayList keyList = new ArrayList(); foreach (BsonDocument lastDoc in lastDocs) { BsonObjectId id = lastDoc["_id"].AsObjectId; BsonDocument testRun = lastDoc["TestRun"].AsBsonDocument; string testRunName = testRun["@testRunName"].AsString; string userName = testRun["@userName"].AsString; string timeStamp = testRun["@timeStamp"].AsString; string hashtableKey = @"""" + testRunName + @""" """ + userName + @""" """ + timeStamp + @""""; idRunNameTable.Add(hashtableKey, id); //Track the order of each test run keyList.Add(hashtableKey); } BsonObjectId objectId = null; if (dropDownIndex >= 0) { objectId = (BsonObjectId)idRunNameTable[keyList[dropDownIndex]]; } bool ret = false; successAllConfigTable = new Hashtable(); failAllConfigTable = new Hashtable(); successConfigTable = new Hashtable(); failConfigTable = new Hashtable(); //var projectNames = collection.Distinct("TestRun.Configuration.test-results.@project-name").ToList(); Hashtable projectAutomationTable = this.GetProjectAutomationTable(objectId, days); var filteredTable = projectAutomationTable.Cast <DictionaryEntry>().Where(x => ((ArrayList)x.Value).Count != 0).ToDictionary(x => (string)x.Key, x => (ArrayList)x.Value); var projectNames = filteredTable.Keys; int progress = 0; int totalNumProject = projectNames.Count; foreach (string project in projectNames) { ArrayList automationNameList = (ArrayList)filteredTable[project]; int report = progress * 100 / totalNumProject; OnProgressUpdate(report); foreach (string automation in automationNameList) { MongoCursor <BsonDocument> testSuccess = null; if (dropDownIndex == -1) { var queryResults1 = Query.And(Query.GT("Date", date), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "True")))))); testSuccess = collection.Find(queryResults1); } else { var queryResults1 = Query.And(Query.EQ("_id", objectId), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "True")))))); testSuccess = collection.Find(queryResults1); } MongoCursor <BsonDocument> testAll; if (dropDownIndex == -1) { var queryResults2 = Query.And(Query.GT("Date", date), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.EQ("@name", automation))))); testAll = collection.Find(queryResults2); } else { var queryResults2 = Query.And(Query.EQ("_id", objectId), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.EQ("@name", automation))))); testAll = collection.Find(queryResults2); } MongoCursor <BsonDocument> testFail; if (dropDownIndex == -1) { var queryResults3 = Query.And(Query.GT("Date", date), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "False")))))); testFail = collection.Find(queryResults3); } else { var queryResults3 = Query.And(Query.EQ("_id", objectId), Query.ElemMatch("TestRun.Configuration.test-results", Query.And( Query.EQ("@project-name", project), Query.ElemMatch("test-suite.results.test-case", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "False")))))); testFail = collection.Find(queryResults3); } if (testSuccess.Count() != testAll.Count() && testSuccess.Count() != 0) { IEnumerable <BsonDocument> diffs = testAll.Except(testSuccess); foreach (BsonDocument diffBson in diffs) { BsonDocument testRun = diffBson["TestRun"].AsBsonDocument; string version = testRun["@runtimeVersion"].AsString; var failQuery = Query.And( Query.EQ("@project-name", project), Query.EQ("@runtime-version", version), Query.ElemMatch("failures.automation", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "False")))); MongoCursor <BsonDocument> failCursor = failCollection.Find(failQuery); List <Automation> failureAutomationList = new List <Automation>(); BsonArray failAutomation = new BsonArray(); if (failCursor.Count() != 0) { BsonDocument failTypeDoc = failCursor.First(); BsonDocument failures = failTypeDoc["failures"].AsBsonDocument; var failAutoJson = failures.ToJson(); failureAutomationList = JsonConvert.DeserializeObject <Failures>(failAutoJson).automation; } string failureType = string.Empty; string failureMsg = string.Empty; if (failureAutomationList.Count != 0) { var failAutomationWithName = failureAutomationList.Find(x => x.name.Equals(automation)); var failStatus = failAutomationWithName.status; failureType = failStatus.failureType; failureMsg = failStatus.message; } BsonArray configs = testRun["Configuration"].AsBsonArray; foreach (BsonDocument config in configs) { var configJson = config.ToJson(); var configDeserial = JsonConvert.DeserializeObject <Configuration>(configJson); string templateName = configDeserial.templateName; var testResultsDeserial = configDeserial.testResults; var testResultOnProject = testResultsDeserial.Find(x => x.projectName.Equals(project)); var testSuite = testResultOnProject.testSuite; var testResults = testSuite.results; var testCase = testResults.TestCases; var unitTestResult = testCase.Find(x => x.name.Equals(automation)); //To be done string errorMsg = string.Empty; if (failCursor.Count() == 0) { failureType = "Failure"; } if (failConfigTable.ContainsKey(templateName) == false) { Hashtable projectTable = new Hashtable(); ArrayList list = new ArrayList(); Hashtable detailTable = new Hashtable(); list.Add(failureType); list.Add(version); list.Add(errorMsg); detailTable.Add(automation, list); projectTable.Add(project, detailTable); failConfigTable.Add(templateName, projectTable); } else { Hashtable table = (Hashtable)failConfigTable[templateName]; if (table == null) { table = new Hashtable(); } if (table.ContainsKey(project)) { Hashtable errorTable = (Hashtable)table[project]; if (errorTable.ContainsKey(automation) == false) { ArrayList list = new ArrayList(); list.Add(failureType); list.Add(version); list.Add(errorMsg); errorTable.Add(automation, list); table[project] = errorTable; } } else { Hashtable errorTable = new Hashtable(); ArrayList list = new ArrayList(); list.Add(failureType); list.Add(version); list.Add(errorMsg); errorTable.Add(automation, list); table.Add(project, errorTable); } failConfigTable[templateName] = table; } } } } if (testAll.Count() != testFail.Count() && testFail.Count() != 0) { IEnumerable <BsonDocument> diff = testAll.Except(testFail); foreach (BsonDocument diffBson in diff) { BsonDocument testRun = diffBson["TestRun"].AsBsonDocument; string version = testRun["@runtimeVersion"].AsString; BsonArray configs = testRun["Configuration"].AsBsonArray; foreach (BsonDocument config in configs) { var configJson = config.ToJson(); var configDeserial = JsonConvert.DeserializeObject <Configuration>(configJson); string templateName = configDeserial.templateName; var testResultsDeserial = configDeserial.testResults; var testResultOnProject = testResultsDeserial.Find(x => x.projectName.Equals(project)); var testSuite = testResultOnProject.testSuite; var testResults = testSuite.results; var testCase = testResults.TestCases; var unitTestResult = testCase.Find(x => x.name.Equals(automation)); if (successConfigTable.ContainsKey(templateName) == false) { Hashtable projectTable = new Hashtable(); Hashtable detailTable = new Hashtable(); ArrayList list = new ArrayList(); list.Add(version); detailTable.Add(automation, list); projectTable.Add(project, detailTable); successConfigTable.Add(templateName, projectTable); } else { Hashtable table = (Hashtable)successConfigTable[templateName]; if (table == null) { table = new Hashtable(); } if (table.ContainsKey(project) == true) { Hashtable detailTable = (Hashtable)table[project]; ArrayList list = new ArrayList(); if (detailTable.ContainsKey(automation) == false) { list.Add(version); detailTable.Add(automation, list); } else { list = (ArrayList)detailTable[automation]; list.Add(version); detailTable[automation] = list; } table[project] = detailTable; } else { Hashtable detailTable = new Hashtable(); ArrayList list = new ArrayList(); if (detailTable.ContainsKey(automation) == false) { list.Add(version); detailTable.Add(automation, list); } table.Add(project, detailTable); } successConfigTable[templateName] = table; } } } } if (testFail.Count() == 0) { BsonDocument first = testSuccess.First(); string version = this.GetRuntimeVersion(first); if (successAllConfigTable.ContainsKey(project) == false) { ArrayList list = new ArrayList(); list.Add(version); Hashtable table = new Hashtable(); table.Add(automation, list); successAllConfigTable.Add(project, table); } else { Hashtable table = (Hashtable)successAllConfigTable[project]; ArrayList list = (ArrayList)table[automation]; if (list == null) { list = new ArrayList(); } list.Add(version); table[automation] = list; successAllConfigTable[project] = table; } } if (testSuccess.Count() == 0) { BsonDocument first = testFail.First(); string version = this.GetRuntimeVersion(first); var failQuery = Query.And( Query.EQ("@project-name", project), Query.EQ("@runtime-version", version), Query.ElemMatch("failures.automation", Query.And( Query.EQ("@name", automation), Query.EQ("@success", "False")))); MongoCursor <BsonDocument> failCursor = failCollection.Find(failQuery); List <Automation> failureAutomationList = new List <Automation>(); BsonArray failAutomation = new BsonArray(); if (failCursor.Count() != 0) { BsonDocument failTypeDoc = failCursor.First(); BsonDocument failures = failTypeDoc["failures"].AsBsonDocument; var failAutoJson = failures.ToJson(); failureAutomationList = JsonConvert.DeserializeObject <Failures>(failAutoJson).automation; } string failureType = string.Empty; string failureMsg = string.Empty; if (failureAutomationList.Count != 0) { var failAutomationWithName = failureAutomationList.Find(x => x.name.Equals(automation)); var failStatus = failAutomationWithName.status; failureType = failStatus.failureType; failureMsg = failStatus.message; } if (failCursor.Count() == 0) { failureType = "Failure"; } string errorMsg = string.Empty; foreach (BsonDocument fail in testFail) { BsonDocument testRun = fail["TestRun"].AsBsonDocument; BsonArray configs = testRun["Configuration"].AsBsonArray; foreach (BsonDocument config in configs) { var configJson = config.ToJson(); var configDeserial = JsonConvert.DeserializeObject <Configuration>(configJson); string templateName = configDeserial.templateName; var testResultsDeserial = configDeserial.testResults; var testResultOnProject = testResultsDeserial.Find(x => x.projectName.Equals(project)); var testSuite = testResultOnProject.testSuite; var testResults = testSuite.results; var testCase = testResults.TestCases; var unitTestResult = testCase.Find(x => x.name.Equals(automation)); //To be done errorMsg = string.Empty; } } if (failAllConfigTable.ContainsKey(project) == false) { ArrayList list = new ArrayList(); list.Add(failureType); list.Add(version); list.Add(errorMsg); Hashtable table = new Hashtable(); table.Add(automation, list); failAllConfigTable.Add(project, table); } else { Hashtable table = (Hashtable)failAllConfigTable[project]; ArrayList list = (ArrayList)table[automation]; if (list == null) { list = new ArrayList(); } list.Add(failureType); list.Add(version); list.Add(errorMsg); table[automation] = list; failAllConfigTable[project] = table; } } } progress++; } OnProgressUpdate(100); ret = true; return(ret); }