Beispiel #1
0
        public async Task AddDiagnosticInfo()
        {
            Request.Query.TryGetValue("vendorToken", out var vendorToken);
            var content = await Request.Body.ReadToEndAsync();

            var info = _serializer.Deserialize <BodyModelInfo>(content);

            await HandleAuthorizedRequest(async login =>
            {
                if (!_vendors.TryGet(login, out var vendor))
                {
                    Response.StatusCode = 403;
                    return;
                }

                var isVendorTokenValid    = vendor.Token.Equals(vendorToken);
                var isAnotherVendorsModel = !vendor.ModelSeries.Contains(info.ModelSeries) &&
                                            _bodyModelsStorage.Contains(info.ModelSeries);

                if (!isVendorTokenValid || isAnotherVendorsModel)
                {
                    Response.StatusCode = 403;
                    return;
                }

                if (_bodyModelsStorage.Contains(info.ModelSeries, info.Revision))
                {
                    Response.StatusCode = 409;
                    return;
                }

                vendor.ModelSeries.Add(info.ModelSeries);
                await _bodyModelsStorage.Add(info);
            });
        }
        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);
        }