-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMessagesViewIndex.cs
More file actions
60 lines (56 loc) · 2.97 KB
/
MessagesViewIndex.cs
File metadata and controls
60 lines (56 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace ServiceControl.Audit.Persistence.RavenDB.Indexes
{
using System;
using System.Linq;
using Raven.Client.Documents.Indexes;
using ServiceControl.Audit.Auditing;
using ServiceControl.Audit.Monitoring;
public class MessagesViewIndex : AbstractIndexCreationTask<ProcessedMessage, MessagesViewIndex.SortAndFilterOptions>
{
public MessagesViewIndex()
{
Map = messages =>
from message in messages
let metadata = message.MessageMetadata
select new SortAndFilterOptions
{
MessageId = (string)metadata["MessageId"],
MessageType = (string)metadata["MessageType"],
IsSystemMessage = (bool)metadata["IsSystemMessage"],
Status = (bool)metadata["IsRetried"] ? MessageStatus.ResolvedSuccessfully : MessageStatus.Successful,
TimeSent = (DateTime)metadata["TimeSent"],
ProcessedAt = message.ProcessedAt,
ReceivingEndpointName = ((EndpointDetails)metadata["ReceivingEndpoint"]).Name,
CriticalTime = (TimeSpan?)metadata["CriticalTime"],
ProcessingTime = (TimeSpan?)metadata["ProcessingTime"],
DeliveryTime = (TimeSpan?)metadata["DeliveryTime"],
Query = new[] {
string.Join(' ', message.Headers.Values),
string.Join(' ', metadata.Values.Select(v => v.ToString() ?? string.Empty))
},
ConversationId = (string)metadata["ConversationId"]
};
Index(x => x.Query, FieldIndexing.Search);
// Not using typeof() to prevent dependency on Lucene.
// Unfortunately while "StandardAnalyzer" would probably be better and more future-proof here,
// we can't change this string without causing any existing audit database to completely rebuild this index.
// If this index *must* be changed for some other reason, the analyzer name should be changed at the same time.
Analyze(x => x.Query, "Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181");
}
public class SortAndFilterOptions
{
public string MessageId { get; set; }
public string MessageType { get; set; }
public bool IsSystemMessage { get; set; }
public MessageStatus Status { get; set; }
public DateTime ProcessedAt { get; set; }
public string ReceivingEndpointName { get; set; }
public TimeSpan? CriticalTime { get; set; }
public TimeSpan? ProcessingTime { get; set; }
public TimeSpan? DeliveryTime { get; set; }
public string ConversationId { get; set; }
public string[] Query { get; set; }
public DateTime TimeSent { get; set; }
}
}
}