public SimilaritiesReport FindForIncident(int incidentId) { using (var cmd = _uow.CreateCommand()) { cmd.CommandText = @"select Id, Name, Properties from IncidentContextCollections where IncidentId = @incidentId"; cmd.AddParameter("incidentId", incidentId); var collections = new List <SimilarityCollection>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var json = (string)reader["Properties"]; var properties = CoderrDtoSerializer.Deserialize <ContextCollectionPropertyDbEntity[]>(json); var col = new SimilarityCollection(incidentId, reader.GetString(1)); col.GetType().GetProperty("Id").SetValue(col, reader.GetInt32(0)); foreach (var entity in properties) { var prop = new Similarity(entity.Name); prop.LoadValues( entity.Values.Select(x => new SimilarityValue(x.Value, x.Percentage, x.Count)).ToArray()); col.Properties.Add(prop); } collections.Add(col); } } return(collections.Count == 0 ? null : new SimilaritiesReport(incidentId, collections)); } }
private T Deserialize <T>(Message message) { var reader = new StreamReader(message.BodyStream, Encoding.UTF8); var json = reader.ReadToEnd(); return(CoderrDtoSerializer.Deserialize <T>(json)); }
public IReadOnlyList <ErrorReportEntity> GetReportsUsingSql() { using (var cmd = _unitOfWork.CreateCommand()) { cmd.CommandText = @"SELECT QueueReports.* FROM QueueReports ORDER BY QueueReports.Id"; cmd.Limit(10); try { var reports = new List <ErrorReportEntity>(); var idsToRemove = new List <int>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var json = ""; try { json = (string)reader["body"]; var report = _reportDtoConverter.LoadReportFromJson(json); var newReport = _reportDtoConverter.ConvertReport(report, (int)reader["ApplicationId"]); newReport.RemoteAddress = (string)reader["RemoteAddress"]; var claims = CoderrDtoSerializer.Deserialize <Claim[]>((string)reader["Claims"]); newReport.User = new ClaimsPrincipal(new ClaimsIdentity(claims)); reports.Add(newReport); idsToRemove.Add(reader.GetInt32(0)); } catch (Exception ex) { _logger.Error("Failed to deserialize " + json, ex); } } } if (idsToRemove.Any()) { _unitOfWork.ExecuteNonQuery("DELETE FROM QueueReports WHERE Id IN (" + string.Join(",", idsToRemove) + ")"); } return(reports); } catch (Exception ex) { throw cmd.CreateDataException(ex); } } }
public object Receive() { var msg = _queue.Receive(); var reader = new StreamReader(msg.BodyStream, Encoding.UTF8); var json = reader.ReadToEnd(); var metadata = MetadataHeader.Deserialize(msg); var type = Type.GetType(metadata.AssemblyQualifiedTypeName); if (type == null) { throw new NotSupportedException("Failed to get type class from string '" + metadata.AssemblyQualifiedTypeName + "'."); } return(CoderrDtoSerializer.Deserialize(json, type)); }
public async Task <GetSimilaritiesResult> ExecuteAsync(GetSimilarities query) { using (var cmd = _unitOfWork.CreateDbCommand()) { cmd.CommandText = @"select Name, Properties from IncidentContextCollections where IncidentId = @incidentId"; cmd.AddParameter("incidentId", query.IncidentId); var collections = new List <GetSimilaritiesCollection>(); using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var json = (string)reader["Properties"]; var properties = CoderrDtoSerializer.Deserialize <ContextCollectionPropertyDbEntity[]>(json); var col = new GetSimilaritiesCollection { Name = reader.GetString(0) }; col.Similarities = (from prop in properties let values = prop.Values.Select(x => new GetSimilaritiesValue(x.Value, x.Percentage, x.Count)) select new GetSimilaritiesSimilarity(prop.Name) { Values = Enumerable.ToArray(values) } ).ToArray(); collections.Add(col); } } return(new GetSimilaritiesResult { Collections = collections.ToArray() }); } }