示例#1
0
        public async Task <ActionResult> GetRawData(Guid telemetryKey, TelemetryItemTypes type, DateTime startDate, DateTime endDate)
        {
            var sw     = Stopwatch.StartNew();
            var result = await this.Work.GetRawData(telemetryKey, type, startDate, endDate).ConfigureAwait(false);

            sw.Stop();

            this.telemetryClient.TrackEvent("RawDataExported", new Dictionary <string, string>()
            {
                { "TelemetryKey", telemetryKey.ToString() },
                { "StartDate", startDate.ToString("o") },
                { "EndDate", endDate.ToString("o") },
                { "Elapsed", sw.ElapsedMilliseconds.ToString() },
                { "TimeSpan", (endDate - startDate).TotalDays.ToString(CultureInfo.InvariantCulture) },
                { "TelemetryType", type.ToString() },
            });
            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = $"{type}_Report_{startDate:yyyy-MM-dd}-{endDate:yyyy-MM-dd}.raw.json",
                Inline   = false,
            };

            this.Response.AppendHeader("Content-Disposition", cd.ToString());
            var json = this.Json(result, JsonRequestBehavior.AllowGet);

            json.MaxJsonLength = Int32.MaxValue;
            return(json);
        }
示例#2
0
        public async Task <IHttpActionResult> ClearTelemetryData(Guid telemetryKey, TelemetryItemTypes?dataType)
        {
            var prg = await this.Work.Programs.GetByTelemetryKey(telemetryKey).ConfigureAwait(false);

            if (prg == null)
            {
                return(this.BadRequest($"Program with key {telemetryKey} does not exist"));
            }
            try
            {
                this.telemetryClient.TrackEvent("AttemptedToClearTelemetryData", new Dictionary <string, string>()
                {
                    { $"ProgramName", prg.Name },
                    { $"DataType", dataType?.ToString() ?? "ALL" },
                });
                this.Work.Programs.ClearTelemetryData(prg, dataType);

                await this.Work.CompleteAsync(TimeSpan.FromMinutes(15)).ConfigureAwait(false);

                this.telemetryClient.TrackEvent("ClearedTelemetryData", new Dictionary <string, string>()
                {
                    { $"ProgramName", prg.Name },
                    { $"DataType", dataType?.ToString() ?? "ALL" },
                });
            }
            catch (Exception ex)
            {
                var props = new Dictionary <string, string>()
                {
                    { $"ProgramName", prg.Name },
                    { $"Exception", ex.ToString() },
                    { $"DataType", dataType?.ToString() ?? "ALL" },
                };
                var wrapper = new InvalidOperationException($"Error while clearing telemetry data for {prg.Name} (Key: {telemetryKey})", ex);

                this.telemetryClient.TrackEvent($"TelemetryDataClearingError", props);
                this.telemetryClient.TrackException(wrapper, props);
                this.telemetryClient.Flush();
                return(this.InternalServerError(wrapper));
            }
            return(this.Ok($"{dataType?.ToString() ?? "ALL" } Telemetry data cleared."));
        }