public async Task <BodyModelInfo> GetDiagnosticInfo() { var query = Request.Query; if (!query.TryGetValue("modelSeries", out var series) || !query.TryGetValue("revision", out var revision) || !query.TryGetValue("vendorToken", out var vendorToken)) { throw new ArgumentException("Invalid arguments"); } return(await HandleAuthorizedRequest(async login => { var isVendorExist = _vendors.TryGet(login, out var vendor); var isVendorTokenValid = vendor.Token.Equals(vendorToken); var isVendorsModel = vendor.ModelSeries.Contains(series); if (!isVendorExist || !isVendorTokenValid || !isVendorsModel) { Response.StatusCode = 403; return null; } return await _bodyModelsStorage.Get(series, revision); })); }
public async Task <IEnumerable <string> > GetTelemetry() { return(await HandleAuthorizedRequest(async loging => { var series = Request.Query["modelSeries"]; var revision = Request.Query["revision"]; var model = await _bodyModelsStorage.Get(series, revision); return model.ReferenceValues.Keys.ToList(); })); }
public async Task <HealthReport> Check(BodyTelemetry bodyTelemetry) { var healthReport = new HealthReport { CheckResults = new Dictionary <string, string>() }; if (!_bodyModelsStorage.Contains(bodyTelemetry.BodyModelSeries, bodyTelemetry.BodyRevision)) { return(new HealthReport { Error = "Unknown body type" }); } var bodyDiagnosticInfo = await _bodyModelsStorage.Get(bodyTelemetry.BodyModelSeries, bodyTelemetry.BodyRevision); foreach (var(name, refValue) in bodyDiagnosticInfo.ReferenceValues) { if (bodyTelemetry.HardwareTelemetry.ContainsKey(name)) { var value = bodyTelemetry.HardwareTelemetry[name]; healthReport.CheckResults[name] = value > refValue ? $"ERROR! | {value} > {refValue}" : $"OK | {value} <= {refValue}"; } else { healthReport.CheckResults[name] = "unknown"; } } return(healthReport); }