private BsonDocument SearchMatchingDocument(ICollection <BsonDocument> list, ATDateTime amiDt, string dateColumn) { DateTime dateTime = new DateTime(amiDt.Year, amiDt.Month, amiDt.Day); foreach (BsonDocument doc in list) { DateTime dt = (DateTime)doc.GetElement(dateColumn).Value; if (dt.Date == dateTime.Date) { return(doc); } } return(null); }
public void MongoQueryToAFL(string filterExpression, string dateColumn, string projection) { YTrace.Trace("Begin MongoQueryToAFL method: " + filterExpression, YTrace.TraceLevel.Information); InitDataArrays(projection); try { ICollection <BsonDocument> list = null; try { list = dao.findFiltered(filterExpression, dateColumn); } catch (Exception e) { YTrace.Trace("Exception in DAO: " + e.ToString(), YTrace.TraceLevel.Error); } ATDateTime first = this.DateAndTime[0]; YTrace.Trace("First date (Ami): " + first.ToString(), YTrace.TraceLevel.Information); ATDateTime last = this.DateAndTime[this.DateAndTime.Length - 1]; YTrace.Trace("Last date (Ami): " + last.ToString(), YTrace.TraceLevel.Information); /* * DateTime firstDate = new DateTime(first.Year, first.Month, first.Day); * YTrace.Trace("First date: " + firstDate.ToString(), YTrace.TraceLevel.Information); * DateTime lastDate = new DateTime(last.Year, last.Month, last.Day); * YTrace.Trace("Last date: " + lastDate.ToString(), YTrace.TraceLevel.Information); */ for (int idx = 0; idx < this.DateAndTime.Length; idx++) { ATDateTime dateIterator = this.DateAndTime[idx]; YTrace.Trace("Check date: " + dateIterator.ToString(), YTrace.TraceLevel.Information); BsonDocument foundDoc = SearchMatchingDocument(list, dateIterator, dateColumn); AddToAFLs(foundDoc, idx); } InitAFLs(); } catch (Exception e) { YTrace.Trace("Error: " + e.ToString(), YTrace.TraceLevel.Error); YException.Show("Error while executing MongoQueryToAFL: ", e); } }