public static Dictionary <string, OptionStatusLine> GetOptionStatus(MongoConnection mongoConnection) { IMongoCollection <OptionResult> datas = mongoConnection.Database.GetCollection <OptionResult>(typeof(OptionResult).Name); BsonDocument projectionDocument = GetOptionResultProjectionBsonDocument(); BsonDocument groupingDocument = GetOptionResultGroupingBsonDocument(); IAggregateFluent <BsonDocument> aggregateFluent = datas.Aggregate().Project(projectionDocument).Group(groupingDocument); Task <List <BsonDocument> > aggregateTask = aggregateFluent.ToListAsync(); List <BsonDocument> aggregatedDocuments = aggregateTask.Result; Dictionary <string, OptionStatusLine> resultDictionary = new Dictionary <string, OptionStatusLine>(); foreach (BsonDocument optionResultGroup in aggregatedDocuments) { string name = optionResultGroup["_id"]["name"].AsString; bool success = optionResultGroup["_id"]["success"].AsBoolean; bool within10Minutes = optionResultGroup["_id"]["within10Minutes"].AsBoolean; bool within1Hour = optionResultGroup["_id"]["within1Hour"].AsBoolean; bool within24Hours = optionResultGroup["_id"]["within24Hours"].AsBoolean; int count = optionResultGroup["count"].AsInt32; OptionStatusLine line; if (resultDictionary.ContainsKey(name)) { line = resultDictionary[name]; } else { line = new OptionStatusLine(); resultDictionary.Add(name, line); } UpdateLine(success, within10Minutes, within1Hour, within24Hours, count, line); } return(resultDictionary); }
private static void UpdateLine(bool success, bool within10Minutes, bool within1Hour, bool within24Hours, int count, OptionStatusLine line) { line.ExecutionTotal += count; if (success) { line.SuccessTotal += count; if (within10Minutes) { line.Success10Minute += count; } if (within1Hour) { line.Success1Hour += count; } if (within24Hours) { line.Success24Hour += count; } } else { line.FailTotal += count; if (within10Minutes) { line.Fail10Minute += count; } if (within1Hour) { line.Fail1Hour += count; } if (within24Hours) { line.Fail24Hour += count; } } }