Skip to content

Commit 902a33c

Browse files
committed
Add LogEvent to Web API
1 parent 3b005aa commit 902a33c

File tree

17 files changed

+138
-10
lines changed

17 files changed

+138
-10
lines changed

IntegrationEngine.ConsoleClient/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Options
2323
public string GetUsage()
2424
{
2525
var version = (Attribute.GetCustomAttribute(
26-
Assembly.GetEntryAssembly(),
26+
Assembly.GetEntryAssembly(),
2727
typeof(AssemblyInformationalVersionAttribute))
2828
as AssemblyInformationalVersionAttribute).InformationalVersion;
2929
var usage = new StringBuilder();

IntegrationEngine.ConsoleHost/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</dependentAssembly>
1515
<dependentAssembly>
1616
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
17-
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
17+
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
1818
</dependentAssembly>
1919
</assemblyBinding>
2020
</runtime>

IntegrationEngine.ConsoleHost/IntegrationEngine.ConsoleHost.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
<Reference Include="RazorEngine">
7070
<HintPath>..\packages\RazorEngine.3.5.3\lib\net45\RazorEngine.dll</HintPath>
7171
</Reference>
72+
<Reference Include="Elasticsearch.Net">
73+
<HintPath>..\packages\Elasticsearch.Net.1.4.0\lib\net45\Elasticsearch.Net.dll</HintPath>
74+
</Reference>
75+
<Reference Include="NLog">
76+
<HintPath>..\packages\NLog.3.1.0.0\lib\net45\NLog.dll</HintPath>
77+
</Reference>
78+
<Reference Include="NLog.Targets.ElasticSearch">
79+
<HintPath>..\packages\NLog.Targets.ElasticSearch.0.9.5.0\lib\net40\NLog.Targets.ElasticSearch.dll</HintPath>
80+
</Reference>
7281
</ItemGroup>
7382
<ItemGroup>
7483
<Compile Include="InEngineServerInstaller.cs">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="Elasticsearch.Net" version="1.4.0" targetFramework="net45" />
34
<package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />
45
<package id="Microsoft.Owin.Host.HttpListener" version="3.0.0" targetFramework="net45" />
6+
<package id="NLog" version="3.1.0.0" targetFramework="net45" />
7+
<package id="NLog.Targets.ElasticSearch" version="0.9.5.0" targetFramework="net45" />
58
<package id="RazorEngine" version="3.5.3" targetFramework="net45" />
69
</packages>

IntegrationEngine.Core/Storage/DatabaseRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using Common.Logging;using System;
1+
using Common.Logging;
2+
using IntegrationEngine.Model;
3+
using System;
24
using System.Collections.Generic;
35
using System.Data.Entity;
46
using System.Linq;
7+
using System.Linq.Expressions;
58
using System.Text;
69
using System.Threading.Tasks;
7-
using IntegrationEngine.Model;
810

911
namespace IntegrationEngine.Core.Storage
1012
{

IntegrationEngine.Core/Storage/ElasticsearchRepository.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using IntegrationEngine.Model;
33
using Nest;
44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
67
using System.Linq;
8+
using System.Linq.Expressions;
79

810
namespace IntegrationEngine.Core.Storage
911
{
@@ -24,8 +26,49 @@ public IEnumerable<TItem> SelectAll<TItem>() where TItem : class, IHasStringId
2426
h.Source.Id = h.Id;
2527
return h.Source;
2628
});
27-
var list = documents.ToList();
28-
return list;
29+
return documents.ToList();
30+
}
31+
32+
public IEnumerable<TItem> SelectAll<TItem, TKey>(Expression<Func<TItem, TKey>> orderBy,
33+
bool ascending = true,
34+
int pageIndex = 0,
35+
int rowCount = 10)
36+
where TItem : class, IHasStringId
37+
{
38+
var documents = ElasticClient.Search<TItem>(x => x.From(pageIndex).Size(rowCount))
39+
.Hits
40+
.Select(h => {
41+
h.Source.Id = h.Id;
42+
return h.Source;
43+
}).AsQueryable();
44+
if (ascending)
45+
documents.OrderBy(orderBy);
46+
else
47+
documents.OrderByDescending(orderBy);
48+
return documents.ToList();
49+
}
50+
51+
public IEnumerable<TItem> Search<TItem, TKey>(string query,
52+
Expression<Func<TItem, TKey>> orderBy,
53+
bool ascending = true,
54+
int pageIndex = 0,
55+
int rowCount = 10)
56+
where TItem : class, IHasStringId
57+
{
58+
var documents = ElasticClient.Search<TItem>(x => x
59+
.From(pageIndex)
60+
.Size(rowCount)
61+
.Query(q => q.Match(m => m.OnField("_all").Query(query)) || q.Fuzzy(fd => fd.OnField("_all").PrefixLength(1).Value(query).Boost(0.1))))
62+
.Hits
63+
.Select(h => {
64+
h.Source.Id = h.Id;
65+
return h.Source;
66+
}).AsQueryable();
67+
if (ascending)
68+
documents.OrderBy(orderBy);
69+
else
70+
documents.OrderByDescending(orderBy);
71+
return documents.AsEnumerable();
2972
}
3073

3174
public TItem SelectById<TItem>(object id) where TItem : class, IHasStringId
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using IntegrationEngine.Model;
22
using System;
3+
using System.Linq;
4+
using System.Linq.Expressions;
35
using System.Collections.Generic;
46

57
namespace IntegrationEngine.Core.Storage
68
{
79
public interface IElasticsearchRepository : IRepository<IHasStringId>
8-
{}
10+
{
11+
IEnumerable<TItem> SelectAll<TItem, TKey>(Expression<Func<TItem, TKey>> orderBy, bool ascending = true, int pageIndex = 0, int rowCount = 10) where TItem : class, IHasStringId;
12+
IEnumerable<TItem> Search<TItem, TKey>(string query, Expression<Func<TItem, TKey>> orderBy, bool ascending = true, int pageIndex = 0, int rowCount = 10) where TItem : class, IHasStringId;
13+
}
914
}
1015

IntegrationEngine.Model.net40/IntegrationEngine.Model.net40.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
<Compile Include="..\IntegrationEngine.Model\IHasLongId.cs">
107107
<Link>IHasLongId.cs</Link>
108108
</Compile>
109+
<Compile Include="..\IntegrationEngine.Model\LogEvent.cs">
110+
<Link>LogEvent.cs</Link>
111+
</Compile>
109112
</ItemGroup>
110113
<ItemGroup>
111114
<None Include="packages.config" />

IntegrationEngine.Model/IntegrationEngine.Model.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="TriggerPropertyExtension.cs" />
7575
<Compile Include="TriggerStateDescription.cs" />
7676
<Compile Include="IHasLongId.cs" />
77+
<Compile Include="LogEvent.cs" />
7778
</ItemGroup>
7879
<ItemGroup>
7980
<None Include="package.nuspec">
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using Nest;
3+
4+
namespace IntegrationEngine.Model
5+
{
6+
public class LogEvent : IHasStringId
7+
{
8+
public string Id { get; set; }
9+
[ElasticProperty(Name = "@timestamp")]
10+
public DateTimeOffset Timestamp { get; set; }
11+
public string Level { get; set; }
12+
public string Message { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)