public ITrackerReportResults BuildReport(IReportSpecification specification) { using (var httpClient = new HttpClient()) { httpClient.Timeout = _commandTimeout; Task <ITrackerReportResults> task = httpClient.PostAsJsonAsync(_serviceUri.ToString(), specification).ContinueWith(x => { if (x.IsFaulted) { if (x.Exception != null) { throw new ReportGenerationException(x.Exception); } } var s = x.Result.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <ITrackerReportResults>(s, new InternalTrackerReportResultsConverter(), new InternalAggregationResultConverter(), new InternalMeasurementResultConverter(), new InternalMeasurementCollectionConverter(), new InternalAggregationResultCollectionConverter()); return(result); }); task.Wait(); var trackerReportResult = task.Result; return(trackerReportResult); } }
private DataTable createFilterDataTable(IReportSpecification specifications, bool excludeList = false) { var table = new DataTable(); table.Columns.Add("Filter", typeof(string)); if (!excludeList) { foreach (var filter in specifications.FilterCombinations) { if (filter.Filters != null && filter.Filters.Any()) { table.Rows.Add(filter.Filters.First()); } } } else { if (specifications.ExcludeFilters != null) { foreach (var filter in specifications.ExcludeFilters) { if (filter.Filters != null && filter.Filters.Any()) { table.Rows.Add(filter.Filters.First()); } } } } return(table); }
public ITrackerReportResults Post(IReportSpecification reportSpecification) { var mongoReportGenerator = new MongoReportGenerator( ConfigurationManager.ConnectionStrings["MongoConnectionString"].ConnectionString); return mongoReportGenerator.GeneratorReport(reportSpecification); }
private static BsonDocument buildMatchCondition(IReportSpecification specification) { IMongoQuery orClause = createSearchClauseForAnyFilter(specification); IMongoQuery typeNameClause = createSearchClauseForAnyType(specification); // Query.EQ("TypeName", specification.TrackerTypeName); IMongoQuery dateClause = Query.And(Query.GTE("TimeSlot", specification.FromDateUtc), Query.LTE("TimeSlot", specification.ToDateUtc)); var conditions = new BsonDocument(dateClause.ToBsonDocument()); conditions.AddRange(typeNameClause.ToBsonDocument()); if (orClause != null) { conditions.AddRange(orClause.ToBsonDocument()); } var match = new BsonDocument { { "$match", conditions } }; return(match); }
public ITrackerReportResults Post(IReportSpecification reportSpecification) { var reportGenerator = getReportGenerator(reportSpecification.ReportSourceType); var returnResult = reportGenerator.BuildReport(reportSpecification); return(returnResult); }
private static IMongoQuery createSearchClauseForAnyType(IReportSpecification specification) { IMongoQuery orQueries = Query.In("TypeName", new BsonArray(specification.TypeNames)); IMongoQuery orClause = Query.Or(orQueries); return(orClause); }
private DataTable createTypeNameDataTable(IReportSpecification specifications) { var table = new DataTable(); table.Columns.Add("TypeName", typeof(string)); foreach (var tn in specifications.TypeNames) { table.Rows.Add(tn); } return(table); }
private static IMongoQuery createSearchClauseForAnyFilter(IReportSpecification specification) { List <IMongoQuery> orQueries = specification.FilterCombinations .Select(filter => Query.In("SearchFilters", new BsonArray(filter.Filters))).ToList(); if (orQueries.Any()) { IMongoQuery orClause = Query.Or(orQueries); return(orClause); } return(null); }
public ITrackerReportResults GeneratorReport(IReportSpecification specification) { BsonDocument match = buildMatchCondition(specification); BsonDocument projection = buildProjection(specification); BsonDocument group = buildResultGroup(specification); var pipeline = new[] { match, projection, group }; AggregateResult queryResults = _mongoCollection.Value.Aggregate(pipeline); if (!(queryResults.Ok && queryResults.ResultDocuments.Any())) return null; return ToMongoAggregationResult(specification, queryResults); }
private static IMongoQuery createFilteredOrClause(IReportSpecification specification) { if (specification.FilterCombinations.Count() == 0) { return(null); } IEnumerable <IMongoQuery> orQueries = specification.FilterCombinations .Select(filter => Query.In("SearchFilters", new BsonArray(filter.Filters))); IMongoQuery orClause = Query.Or(orQueries); return(orClause); }
private static ITrackerReportResults ToMongoAggregationResult(IReportSpecification specification, AggregateResult queryResults) { const string utcDateKey = "UtcDateTime"; const string totalKey = "_Total"; const string occurrenceKey = "_Occurrence"; const string KEY_FILTER = "KeyFilter"; const string ID_KEY = "_id"; const string TYPE_KEY = "Type"; var results = new MongoTrackerResults(specification); if (!queryResults.ResultDocuments.Any()) { return(results); } int count = queryResults.ResultDocuments.Count(); List <string> names = queryResults.ResultDocuments.First().Names.Where(x => !(x == utcDateKey || x == "_id")).ToList(); foreach (BsonDocument document in queryResults.ResultDocuments) { BsonDocument dateTime = document[utcDateKey].AsBsonDocument; long total = document[totalKey].ToInt64(); long occurrence = document[occurrenceKey].ToInt64(); string typeName = document[ID_KEY][TYPE_KEY].AsString; string keyFilter = document[ID_KEY][KEY_FILTER].ToString(); DateTime utcDateTime = ConvertDateTimeDocumentToDateTime(dateTime); IAggregationBuildableResult trackerResult = results.AddAggregationResult(utcDateTime, typeName, keyFilter, occurrence, total); var relevantNames = names.Where(x => x.GetFullyQualifiedNameFromFormattedString().StartsWith(typeName)); foreach (string key in relevantNames) { string fullyQualifiedName = key.GetFullyQualifiedNameFromFormattedString(); BsonValue measurementResult = document[key]; IMeasurement measurement = specification.Counters.FirstOrDefault(x => x.FullyQualifiedPropertyName == fullyQualifiedName); if (measurement != null) { trackerResult.AddMeasurementResult(measurement, measurementResult.ToString()); } } } return(results); }
private static BsonDocument buildResultGroup(IReportSpecification specification) { var timeElement = new BsonElement("Time", "$Time"); var typeElement = new BsonElement("Type", "$Type"); var keyfltr = new BsonElement("KeyFilter", "$KeyFilter"); var idDocument = new BsonDocument(new List <BsonElement>() { timeElement, typeElement, keyfltr }); var elements = new List <BsonElement> { new BsonElement("_id", idDocument) }; elements.AddRange(specification.Counters.Select( counter => new BsonElement(counter.FormatFieldName(), new BsonDocument { { "$sum", string.Format("$Measurement.{0}", counter.FullyQualifiedPropertyName) } }))); elements.AddRange(new[] { new BsonElement("_Occurrence", new BsonDocument { { "$sum", "$Measurement._Occurrence" } }), new BsonElement("_Total", new BsonDocument { { "$sum", "$Measurement._Total" } }), new BsonElement("UtcDateTime", new BsonDocument { { "$last", "$Time" } }) }); var group = new BsonDocument { { "$group", new BsonDocument(elements) } }; return(@group); }
private static BsonDocument buildMatchCondition(IReportSpecification specification) { IMongoQuery orClause = createSearchClauseForAllFilters(specification); IMongoQuery typeNameClause = createSearchClauseForAllTypes(specification); // Query.EQ("TypeName", specification.TrackerTypeName); IMongoQuery dateClause = Query.And(Query.GTE("TimeSlot", specification.FromDateUtc), Query.LTE("TimeSlot", specification.ToDateUtc)); var conditions = new BsonDocument(dateClause.ToBsonDocument()); conditions.AddRange(typeNameClause.ToBsonDocument()); if (orClause != null) conditions.AddRange(orClause.ToBsonDocument()); var match = new BsonDocument { { "$match", conditions } }; return match; }
public ITrackerReportResults BuildReport(IReportSpecification specification) { BsonDocument match = buildMatchCondition(specification); BsonDocument projection = buildProjection(specification); BsonDocument group = buildResultGroup(specification); var pipeline = new[] { match, projection, group }; AggregateResult queryResults = _mongoCollection.Value.Aggregate(pipeline); if (!(queryResults.Ok && queryResults.ResultDocuments.Any())) { _logger.Debug(string.Format("No Results Returned for Aggregation Pipeline: {0} {1}", pipeline.ToJson(), System.Environment.NewLine)); } else { _logger.Debug(string.Format("Results Returned for Aggregation Pipeline: {0} {1}", pipeline.ToJson(), System.Environment.NewLine)); } return(ToMongoAggregationResult(specification, queryResults)); }
public ITrackerReportResults BuildReport(IReportSpecification specification) { //this has not been tested!!!! try { using (var client = new HttpClient()) { HttpResponseMessage httpResponseMessage = client.PostAsJsonAsync(_serviceUrl, specification).Result; if (!httpResponseMessage.IsSuccessStatusCode) { Configurator.Configuration.Logger.Warn(string.Format("Getting report data failed {0}", httpResponseMessage.StatusCode)); } return(httpResponseMessage.Content.ReadAsAsync <ITrackerReportResults>().Result); } } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); throw ex; } }
public ITrackerReportResults BuildReport(IReportSpecification specification) { //this has not been tested!!!! try { using (var client = new HttpClient()) { HttpResponseMessage httpResponseMessage = client.PostAsJsonAsync(_serviceUrl, specification).Result; if (!httpResponseMessage.IsSuccessStatusCode) { Configurator.Configuration.Logger.Warn(string.Format("Getting report data failed {0}", httpResponseMessage.StatusCode)); } return httpResponseMessage.Content.ReadAsAsync<ITrackerReportResults>().Result; } } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); throw ex; } }
public ITrackerReportResults GeneratorReport(IReportSpecification specification, bool differentiation) { using (var httpClient = new HttpClient()) { Task<IEnumerable<IAggregationResult>> task = httpClient.PostAsJsonAsync(_serviceUri.ToString(), specification) .ContinueWith(x => x.Result.Content.ReadAsAsync<IEnumerable<IAggregationResult>>().Result); task.ContinueWith(x => { if (task.IsFaulted) { if (task.Exception != null) throw new ReportGenerationException(task.Exception); } IEnumerable<IAggregationResult> results = task.Result; return results; }); task.Wait(); } return null; }
private static BsonDocument buildProjection(IReportSpecification specification) { var year = new BsonElement("year", new BsonDocument("$year", new BsonString("$TimeSlot"))); var month = new BsonElement("month", new BsonDocument("$month", new BsonString("$TimeSlot"))); var day = new BsonElement("day", new BsonDocument("$dayOfMonth", new BsonString("$TimeSlot"))); var hour = new BsonElement("hour", new BsonDocument("$hour", new BsonString("$TimeSlot"))); var minute = new BsonElement("minute", new BsonDocument("$minute", new BsonString("$TimeSlot"))); List <BsonElement> timeParts; switch (specification.Resolution) { case ReportResolution.Year: timeParts = new List <BsonElement> { year }; break; case ReportResolution.Month: timeParts = new List <BsonElement> { year, month }; break; case ReportResolution.Day: timeParts = new List <BsonElement> { year, month, day }; break; case ReportResolution.Hour: timeParts = new List <BsonElement> { year, month, day, hour }; break; default: timeParts = new List <BsonElement> { year, month, day, hour, minute }; break; } var time = new BsonElement("Time", new BsonDocument(timeParts)); var type = new BsonElement("Type", "$TypeName"); var keyfltr = new BsonElement("KeyFilter", "$KeyFilter"); var measurements = new List <BsonElement>(); measurements.AddRange(new[] { new BsonElement("Measurement._Occurrence", "$Measurement._Occurrence"), new BsonElement("Measurement._Total", "$Measurement._Total") }); measurements.AddRange(specification.Counters.Select( counter => new BsonElement( string.Format("Measurement.{0}", counter.FullyQualifiedPropertyName.GetFullyQualifiedNameFromFormattedString()), string.Format("$Measurement.{0}", counter.PropertyName)))); var projectElements = new List <BsonElement>(); projectElements.Add(time); projectElements.Add(type); projectElements.Add(keyfltr); projectElements.AddRange(measurements); var projection = new BsonDocument { { "$project", new BsonDocument(projectElements) } }; return(projection); }
private static BsonDocument buildResultGroup(IReportSpecification specification) { var timeElement = new BsonElement("Time", "$Time"); var typeElement = new BsonElement("Type", "$Type"); var keyfltr = new BsonElement("KeyFilter", "$KeyFilter"); var idDocument = new BsonDocument(new List<BsonElement>() { timeElement, typeElement, keyfltr}); var elements = new List<BsonElement> {new BsonElement("_id", idDocument)}; elements.AddRange(specification.Counters.Select( counter => new BsonElement(counter.FormatFieldName(), new BsonDocument { {"$sum", string.Format("$Measurement.{0}", counter.FullyQualifiedPropertyName)} }))); elements.AddRange(new[] { new BsonElement("_Occurrence", new BsonDocument { {"$sum", "$Measurement._Occurrence"} }), new BsonElement("_Total", new BsonDocument { {"$sum", "$Measurement._Total"} }), new BsonElement("UtcDateTime", new BsonDocument { {"$last", "$Time"} }) }); var group = new BsonDocument { { "$group", new BsonDocument(elements) } }; return @group; }
private static ITrackerReportResults ToMongoAggregationResult(IReportSpecification specification, AggregateResult queryResults) { const string utcDateKey = "UtcDateTime"; const string totalKey = "_Total"; const string occurrenceKey = "_Occurrence"; const string KEY_FILTER = "KeyFilter"; const string ID_KEY = "_id"; const string TYPE_KEY = "Type"; var results = new MongoTrackerResults(specification); if (! queryResults.ResultDocuments.Any()) return results; int count = queryResults.ResultDocuments.Count(); List<string> names = queryResults.ResultDocuments.First().Names.Where(x => !(x == utcDateKey || x == "_id")).ToList(); foreach (BsonDocument document in queryResults.ResultDocuments) { BsonDocument dateTime = document[utcDateKey].AsBsonDocument; long total = document[totalKey].ToInt64(); long occurrence = document[occurrenceKey].ToInt64(); string typeName = document[ID_KEY][TYPE_KEY].AsString; string keyFilter = document[ID_KEY][KEY_FILTER].ToString(); DateTime utcDateTime = ConvertDateTimeDocumentToDateTime(dateTime); IAggregationBuildableResult trackerResult = results.AddAggregationResult(utcDateTime, typeName, keyFilter, occurrence, total); var relevantNames = names.Where(x => x.GetFullyQualifiedNameFromFormattedString().StartsWith(typeName)); foreach (string key in relevantNames ) { string fullyQualifiedName = key.GetFullyQualifiedNameFromFormattedString(); BsonValue measurementResult = document[key]; IMeasurement measurement = specification.Counters.FirstOrDefault(x => x.FullyQualifiedPropertyName == fullyQualifiedName); if (measurement != null) trackerResult.AddMeasurementResult(measurement, measurementResult.ToString()); } } return results; }
private static BsonDocument buildProjectionOrig(IReportSpecification specification) { var year = new BsonElement("year", new BsonDocument("$year", new BsonString("$TimeSlot"))); var month = new BsonElement("month", new BsonDocument("$month", new BsonString("$TimeSlot"))); var day = new BsonElement("day", new BsonDocument("$dayOfMonth", new BsonString("$TimeSlot"))); var hour = new BsonElement("hour", new BsonDocument("$hour", new BsonString("$TimeSlot"))); var minute = new BsonElement("minute", new BsonDocument("$minute", new BsonString("$TimeSlot"))); List<BsonElement> timeParts; switch (specification.Resolution) { case ReportResolution.Year: timeParts = new List<BsonElement> { year }; break; case ReportResolution.Month: timeParts = new List<BsonElement> { year, month }; break; case ReportResolution.Day: timeParts = new List<BsonElement> { year, month, day }; break; case ReportResolution.Hour: timeParts = new List<BsonElement> { year, month, day, hour }; break; default: timeParts = new List<BsonElement> { year, month, day, hour, minute }; break; } var time = new BsonElement("Time", new BsonDocument(timeParts)); var measurements = new List<BsonElement>(); measurements.AddRange(new[] { new BsonElement("Measurement._Occurrence", "$Measurement._Occurrence"), new BsonElement("Measurement._Total", "$Measurement._Total") }); measurements.AddRange(specification.Counters.Select( counter => new BsonElement(string.Format("Measurement.{0}", counter.PropertyName), string.Format("$Measurement.{0}", counter.PropertyName)))); var projectElements = new List<BsonElement>(); projectElements.Add(time); projectElements.AddRange(measurements); var projection = new BsonDocument { { "$project", new BsonDocument(projectElements) } }; return projection; }
private DataTable createFilterDataTable(IReportSpecification specifications) { var table = new DataTable(); table.Columns.Add("Filter", typeof (string)); foreach (var filter in specifications.FilterCombinations) { if (filter.Filters != null && filter.Filters.Any()) table.Rows.Add(filter.Filters.First()); } return table; }
private static BsonDocument buildResultGroupOrig(IReportSpecification specification) { var elements = new List<BsonElement> { new BsonElement("_id", new BsonString("$Time")) }; elements.AddRange(specification.Counters.Select( counter => new BsonElement(counter.PropertyName, new BsonDocument { {"$sum", string.Format("$Measurement.{0}", counter.PropertyName)} }))); elements.AddRange(new[] { new BsonElement("_Occurrence", new BsonDocument { {"$sum", "$Measurement._Occurrence"} }), new BsonElement("_Total", new BsonDocument { {"$sum", "$Measurement._Total"} }), new BsonElement("UtcDateTime", new BsonDocument { {"$last", "$Time"} }) }); var group = new BsonDocument { { "$group", new BsonDocument(elements) } }; return @group; }
private static ITrackerReportResults ToMongoAggregationResult(IReportSpecification specification, AggregateResult result) { const string utcDateKey = "UtcDateTime"; const string totalKey = "_Total"; const string occurrenceKey = "_Occurrence"; int count = result.ResultDocuments.Count(); List<string> names = result.ResultDocuments.First().Names.Where(x => !(x == utcDateKey || x == "_id")).ToList(); var results = new MongoTrackerResults(specification); foreach (BsonDocument document in result.ResultDocuments) { BsonDocument dateTime = document[utcDateKey].AsBsonDocument; long total = document[totalKey].ToInt64(); long occurrence = document[occurrenceKey].ToInt64(); DateTime utcDateTime = ConvertDateTimeDocumentToDateTime(dateTime); IAggregationResult trackerResult = results.AddAggregationResult(utcDateTime, occurrence, total); foreach (string key in names) { string fullyQualifiedName = key.GetFullyQualifiedNameFromFormattedString(); BsonValue measurementResult = document[key]; IMeasurement measurement = specification.Counters.FirstOrDefault(x => x.FullyQualifiedPropertyName == fullyQualifiedName); if (measurement != null) trackerResult.AddMeasurementResult(measurement, measurementResult.ToString()); } } return results; }
private DataTable createTypeNameDataTable(IReportSpecification specifications) { var table = new DataTable(); table.Columns.Add("TypeName", typeof(string)); foreach (var tn in specifications.TypeNames) { table.Rows.Add(tn); } return table; }
public ITrackerReportResults BuildReport(IReportSpecification specification) { try { var results = new SqlTrackerResults(specification); using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { if (Configurator.UseBuckets && (specification.OffsetTotalsByHours == TimeSpan.Zero | specification.OffsetTotalsByHours.Hours != Configurator.DayTotalTZOffset().Hours)) { command.CommandText = "dbo.GenerateReportUsingBuckets"; } else { command.CommandText = "dbo.GenerateReport"; command.Parameters.Add("@OffsetTotalsTo", SqlDbType.SmallInt); command.Parameters["@OffsetTotalsTo"].Value = specification.OffsetTotalsByHours.Hours; } command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@StartDt", SqlDbType.DateTime); command.Parameters["@StartDt"].Value = specification.FromDateUtc; command.Parameters.Add("@EndDt", SqlDbType.DateTime); command.Parameters["@EndDt"].Value = specification.ToDateUtc; command.Parameters.Add("@Resolution", SqlDbType.SmallInt); command.Parameters["@Resolution"].Value = (int)specification.Resolution; SqlParameter flParameter; flParameter = command.Parameters.AddWithValue("@FilterList", createFilterDataTable(specification)); flParameter.SqlDbType = SqlDbType.Structured; flParameter.TypeName = "dbo.FilterList"; SqlParameter tnParameter; tnParameter = command.Parameters.AddWithValue("@TypeNameList", createTypeNameDataTable(specification)); tnParameter.SqlDbType = SqlDbType.Structured; tnParameter.TypeName = "dbo.TypeName"; var sqlReader = command.ExecuteReader(); string query = command.CommandText; foreach (SqlParameter p in command.Parameters) { query = query.Replace(p.ParameterName, p.Value.ToString()); } int timeSlotC = sqlReader.GetOrdinal("MeasureTime"); var mesurementTypeList = new Dictionary<string, IMeasurement>(); while (sqlReader.Read()) { DateTime? measurementDate = null; if (!sqlReader.IsDBNull(timeSlotC)) { measurementDate = sqlReader.GetDateTime(timeSlotC); string typeName = null; if (sqlReader["TypeName"] != DBNull.Value) typeName = (string) sqlReader["TypeName"]; string measurementName = null; if (sqlReader["MeasurementName"] != DBNull.Value) measurementName = (string) sqlReader["MeasurementName"]; IMeasurement measurement = null; string typeFullyName = null; if (typeName != null && measurementName != null) { typeFullyName = string.Concat(typeName, ".", measurementName); mesurementTypeList.TryGetValue(typeFullyName, out measurement); } if (measurement == null) { if (typeFullyName != null) { measurement = specification.Counters.FirstOrDefault( x => x.FullyQualifiedPropertyName == typeFullyName) ?? new SqlMeasurement() { TrackerTypeName = typeName, Description = typeName, DisplayName = typeName, PropertyName = measurementName }; mesurementTypeList.Add(typeFullyName, measurement); } else { measurement = new SqlMeasurement() { TrackerTypeName = typeName, Description = typeName, DisplayName = typeName, PropertyName = measurementName }; } } results.AddAggregationResult(measurementDate, typeName, (sqlReader.HasColumn("Filter") && sqlReader["Filter"] != DBNull.Value) ? (string) sqlReader["Filter"] : null, measurement, (long) sqlReader["MeasurementValue"]); } } } } return results; } catch (Exception ex) { _logger.Error(ex.Message, ex); throw; } }
private static IMongoQuery createSearchClauseForAllFilters(IReportSpecification specification) { List<IMongoQuery> orQueries = specification.FilterCombinations .Select(filter => Query.All("SearchFilters", new BsonArray(filter.Filters))).ToList(); if (orQueries.Any()) { IMongoQuery orClause = Query.Or(orQueries); return orClause; } return null; }
public ITrackerReportResults BuildReport(IReportSpecification specification) { BsonDocument match = buildMatchCondition(specification); BsonDocument projection = buildProjection(specification); BsonDocument group = buildResultGroup(specification); var pipeline = new[] {match, projection, group}; AggregateResult queryResults = _mongoCollection.Value.Aggregate(pipeline); if (!(queryResults.Ok && queryResults.ResultDocuments.Any())) _logger.Debug(string.Format("No Results Returned for Aggregation Pipeline: {0} {1}", pipeline.ToJson(), System.Environment.NewLine)); else _logger.Debug(string.Format("Results Returned for Aggregation Pipeline: {0} {1}", pipeline.ToJson(), System.Environment.NewLine)); return ToMongoAggregationResult(specification, queryResults); }
public MongoTrackerResults(IReportSpecification specification) { _fromDateUtc = specification.FromDateUtc; _toDateUtc = specification.ToDateUtc; _resolution = specification.Resolution; }
private static IMongoQuery createFilteredOrClause(IReportSpecification specification) { if (specification.FilterCombinations.Count() == 0) return null; IEnumerable<IMongoQuery> orQueries = specification.FilterCombinations .Select(filter => Query.In("SearchFilters", new BsonArray(filter.Filters))); IMongoQuery orClause = Query.Or(orQueries); return orClause; }
public ITrackerReportResults Post(IReportSpecification reportSpecification) { var reportGenerator = getReportGenerator(reportSpecification.ReportSourceType); var returnResult = reportGenerator.BuildReport(reportSpecification); return returnResult; }
private static IMongoQuery createSearchClauseForAllTypes(IReportSpecification specification) { IMongoQuery orQueries = Query.All("TypeName", new BsonArray(specification.TypeNames)); IMongoQuery orClause = Query.Or(orQueries); return orClause; }
public MongoTrackerResults(IReportSpecification specification) { _fromDateUtc = specification.FromDateUtc; _toDateUtc = specification.ToDateUtc; _resolution = specification.Resolution; }
public ITrackerReportResults BuildReport(IReportSpecification specification) { try { var results = new SqlTrackerResults(specification); var retryStrategy = new Incremental(_maxRetries, TimeSpan.FromMilliseconds(_initialRetry), TimeSpan.FromSeconds(_incrementalRetry)); var retryPolicy = new RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy); using (var connection = new SqlConnection(_connectionString)) { connection.OpenWithRetry(retryPolicy); using (var command = connection.CreateCommand()) { if (Configurator.Configuration.UseBuckets && (specification.OffsetTotalsByHours == TimeSpan.Zero | specification.OffsetTotalsByHours.Hours != Configurator.Configuration.DayTotalTZOffset.Hours)) { command.CommandText = "dbo.GenerateReportUsingBuckets"; } else { command.CommandText = "dbo.GenerateReport"; command.Parameters.Add("@OffsetTotalsTo", SqlDbType.SmallInt); command.Parameters["@OffsetTotalsTo"].Value = specification.OffsetTotalsByHours.Hours; } command.CommandTimeout = _commandTimeout; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@StartDt", SqlDbType.DateTime); command.Parameters["@StartDt"].Value = specification.FromDateUtc; command.Parameters.Add("@EndDt", SqlDbType.DateTime); command.Parameters["@EndDt"].Value = specification.ToDateUtc; command.Parameters.Add("@Resolution", SqlDbType.SmallInt); command.Parameters["@Resolution"].Value = (int)specification.Resolution; SqlParameter flParameter; flParameter = command.Parameters.AddWithValue("@FilterList", createFilterDataTable(specification)); flParameter.SqlDbType = SqlDbType.Structured; flParameter.TypeName = "dbo.FilterList"; SqlParameter tnParameter; tnParameter = command.Parameters.AddWithValue("@TypeNameList", createTypeNameDataTable(specification)); tnParameter.SqlDbType = SqlDbType.Structured; tnParameter.TypeName = "dbo.TypeName"; SqlParameter xFlParameter; xFlParameter = command.Parameters.AddWithValue("@ExcludeFilterList", createFilterDataTable(specification, true)); xFlParameter.SqlDbType = SqlDbType.Structured; xFlParameter.TypeName = "dbo.FilterList"; var sqlReader = command.ExecuteReaderWithRetry(retryPolicy); string query = command.CommandText; foreach (SqlParameter p in command.Parameters) { query = query.Replace(p.ParameterName, p.Value.ToString()); } int timeSlotC = sqlReader.GetOrdinal("MeasureTime"); var mesurementTypeList = new Dictionary <string, IMeasurement>(); while (sqlReader.Read()) { DateTime?measurementDate = null; if (!sqlReader.IsDBNull(timeSlotC)) { measurementDate = new DateTimeOffset(sqlReader.GetDateTime(timeSlotC), specification.OffsetTotalsByHours.Negate()).UtcDateTime; string typeName = null; if (sqlReader["TypeName"] != DBNull.Value) { typeName = (string)sqlReader["TypeName"]; } string measurementName = null; if (sqlReader["MeasurementName"] != DBNull.Value) { measurementName = (string)sqlReader["MeasurementName"]; } IMeasurement measurement = null; string typeFullyName = null; if (typeName != null && measurementName != null) { typeFullyName = string.Concat(typeName, ".", measurementName); mesurementTypeList.TryGetValue(typeFullyName, out measurement); } if (measurement == null) { if (typeFullyName != null) { measurement = specification.Counters.FirstOrDefault( x => x.FullyQualifiedPropertyName == typeFullyName) ?? new SqlMeasurement() { TrackerTypeName = typeName, Description = typeName, DisplayName = typeName, PropertyName = measurementName }; mesurementTypeList.Add(typeFullyName, measurement); } else { measurement = new SqlMeasurement() { TrackerTypeName = typeName, Description = typeName, DisplayName = typeName, PropertyName = measurementName }; } } results.AddAggregationResult(measurementDate, typeName, (sqlReader.HasColumn("Filter") && sqlReader["Filter"] != DBNull.Value) ? (string)sqlReader["Filter"] : null, measurement, (long)sqlReader["MeasurementValue"]); } } } } return(results); } catch (Exception ex) { _logger.Error(ex.Message, ex); throw; } }