public async Task <TelemetryInitializeResponse> Initialize(TelemetryInitializeRequest request) { try { Stopwatch sw = Stopwatch.StartNew(); if (!ApiRequestsValidator.IsRequestValid(request)) { return(new TelemetryInitializeResponse() { Exception = new BadRequestException("Request is not valid") }); } TelemetryRootObject program = await work.GetMonitoredProgram(request.TelemetryKey).ConfigureAwait(false); if (program == null) { { return(new TelemetryInitializeResponse { Exception = new InvalidOperationException($"Program [{request.TelemetryKey}] is null") }); } } string ip = "0.0.0.0"; ClientAppUser clientAppUser = await TelemetryControllerHelpers.GetUserOrAddIfMissing(this.work, request.UserInfo, ip).ConfigureAwait(false); await this.work.CompleteAsync().ConfigureAwait(false); TelemetryInitializeResponse response = new TelemetryInitializeResponse { UserId = clientAppUser.PublicId }; sw.Stop(); this.telemetryClient.TrackEvent("Initialize", new Dictionary <string, string>() { { $"ProgramName", request.ProgramInfo?.Name }, { $"ExecutionTime", sw.ElapsedMilliseconds.ToString() }, { $"ProgramId", program.ProgramId.ToString() }, { $"TelemetryKey", program.TelemetryKey.ToString() }, }); return(response); } catch (Exception ex) { return(new TelemetryInitializeResponse { Exception = new InvalidOperationException("Error while processing telemetry initialize request", ex) }); } }
public async Task <TelemetryInitializeResponse> Initialize(TelemetryInitializeRequest request) { try { if (!ApiRequestsValidator.IsRequestValid(request)) { return(new TelemetryInitializeResponse() { Exception = new BadRequestException("Request is not valid") }); } TelemetryRootObject program = await work.GetMonitoredProgram(request.TelemetryKey).ConfigureAwait(false); if (program == null) { { return(new TelemetryInitializeResponse { Exception = new InvalidOperationException($"Program [{request.TelemetryKey}] is null") }); } } string ip = this.Request.GetClientIp(); ClientAppUser clientAppUser = await TelemetryControllerHelpers.GetUserOrAddIfMissing(this.work, request.UserInfo, ip).ConfigureAwait(false); await this.work.CompleteAsync().ConfigureAwait(false); TelemetryInitializeResponse response = new TelemetryInitializeResponse { UserId = clientAppUser.PublicId }; return(response); } catch (Exception ex) { return(new TelemetryInitializeResponse { Exception = new InvalidOperationException("Error while processing telemetry initialize request", ex) }); } }