-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWebServices.cs
87 lines (71 loc) · 2.87 KB
/
WebServices.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Collections.Generic;
using System.Linq;
using BenchmarksAnalyzer.ServiceModel;
using BenchmarksAnalyzer.ServiceModel.Types;
using ServiceStack;
using ServiceStack.OrmLite;
namespace BenchmarksAnalyzer.ServiceInterface
{
public class WebServices : Service
{
public object Any(Ping request)
{
var status = "";
status += Db.Count<TestPlan>() > 0 ? "DB OK" : "DB FAIL";
return new PingResponse {
Result = status,
};
}
public TestPlan Any(GetTestPlan request)
{
var plan = Db.SingleById<TestPlan>(request.Id);
if (plan == null)
throw HttpError.NotFound("Plan {0} does not exist".Fmt(request.Id));
return plan;
}
public object Any(SearchTestResults request)
{
var testRun = request.TestRunId != null
? Db.SingleById<TestRun>(request.TestRunId.Value)
: Db.Single(Db.From<TestRun>()
.Where(x => x.TestPlanId == request.TestPlanId)
.OrderByDescending(x => x.Id));
if (testRun == null)
return new List<TestResult>();
var query = Db.From<TestResult>()
.Where(q => q.TestPlanId == request.TestPlanId
&& q.TestRunId == testRun.Id);
if (request.Host != null)
query.Where(q => q.Hostname.Contains(request.Host));
if (request.Port != null)
query.Where(q => q.Port == request.Port);
if (request.RequestPath != null)
query.Where(q => q.RequestPath.Contains(request.RequestPath));
var results = Db.Select(query.Limit(request.Skip, request.Take));
var total = Db.Count(query);
var response = request.ConvertTo<SearchTestResultsResponse>();
response.Total = (int)total;
response.Results = results.ConvertAll(x => x.ToDisplayResult());
return response;
}
public object Any(ViewTestPlan request)
{
var testPlan = Db.Single<TestPlan>(q => q.Slug == request.Slug);
if (testPlan == null)
throw HttpError.NotFound(request.Slug);
var testRun = request.Id != null
? Db.Single<TestRun>(x =>
x.TestPlanId == testPlan.Id && x.Id == request.Id)
: Db.Single(Db.From<TestRun>()
.Where(x => x.TestPlanId == testPlan.Id)
.OrderByDescending(x => x.Id));
var testResults = Db.Select<TestResult>(q => q.TestRunId == testRun.Id);
return new ViewTestPlanResponse
{
TestPlan = testPlan,
TestRun = testRun,
Results = testResults.ConvertAll(x => x.ToDisplayResult())
};
}
}
}