Inheritance: IJsonWriter
        private static void SerializeTraceTelemetry(TraceTelemetry traceTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            traceTelemetry.WriteTelemetryName(writer, TraceTelemetry.TelemetryName);
            traceTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                // TODO: MetricTelemetry should write type as this.data.baseType once Common Schema 2.0 compliant.
                writer.WriteProperty("baseType", traceTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", traceTelemetry.Data.ver);
                    writer.WriteProperty("message", traceTelemetry.Message);

                    if (traceTelemetry.SeverityLevel.HasValue)
                    {
                        writer.WriteProperty("severityLevel", traceTelemetry.SeverityLevel.Value.ToString());
                    }

                    writer.WriteProperty("properties", traceTelemetry.Properties); // TODO: handle case where the property dictionary doesn't need to be instantiated.

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
        /// <summary>
        /// Serializes this object in JSON format.
        /// </summary>
        private static void SerializePerformanceCounter(PerformanceCounterTelemetry performanceCounter, JsonWriter writer)
        {
            writer.WriteStartObject();

            performanceCounter.WriteTelemetryName(writer, PerformanceCounterTelemetry.TelemetryName);
            performanceCounter.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                writer.WriteProperty("baseType", performanceCounter.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", performanceCounter.Data.ver);
                    writer.WriteProperty("categoryName", performanceCounter.Data.categoryName);
                    writer.WriteProperty("counterName", performanceCounter.Data.counterName);
                    writer.WriteProperty("instanceName", performanceCounter.Data.instanceName);
                    writer.WriteProperty("value", performanceCounter.Data.value);
                    writer.WriteProperty("properties", performanceCounter.Data.properties);

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
        private static void SerializeRequestTelemetry(RequestTelemetry requestTelemetry, JsonWriter jsonWriter)
        {
            jsonWriter.WriteStartObject();

            requestTelemetry.WriteTelemetryName(jsonWriter, RequestTelemetry.TelemetryName);
            requestTelemetry.WriteEnvelopeProperties(jsonWriter);
            jsonWriter.WritePropertyName("data");
            {
                jsonWriter.WriteStartObject();

                // TODO: MetricTelemetry should write type as this.data.baseType once Common Schema 2.0 compliant.
                jsonWriter.WriteProperty("baseType", requestTelemetry.BaseType);
                jsonWriter.WritePropertyName("baseData");
                {
                    jsonWriter.WriteStartObject();

                    jsonWriter.WriteProperty("ver", requestTelemetry.Data.ver);
                    jsonWriter.WriteProperty("id", requestTelemetry.Data.id);
                    jsonWriter.WriteProperty("name", requestTelemetry.Data.name);
                    jsonWriter.WriteProperty("startTime", requestTelemetry.Timestamp);
                    jsonWriter.WriteProperty("duration", requestTelemetry.Duration);
                    jsonWriter.WriteProperty("success", requestTelemetry.Data.success);
                    jsonWriter.WriteProperty("responseCode", requestTelemetry.Data.responseCode);
                    jsonWriter.WriteProperty("url", requestTelemetry.Data.url);
                    jsonWriter.WriteProperty("measurements", requestTelemetry.Data.measurements);
                    jsonWriter.WriteProperty("httpMethod", requestTelemetry.Data.httpMethod);
                    jsonWriter.WriteProperty("properties", requestTelemetry.Data.properties);

                    jsonWriter.WriteEndObject();
                }

                jsonWriter.WriteEndObject();
            }

            jsonWriter.WriteEndObject();
        }
        private static void SerializeSessionStateTelemetry(SessionStateTelemetry sessionStateTelemetry, JsonWriter jsonWriter)
        {
            jsonWriter.WriteStartObject();

            sessionStateTelemetry.WriteEnvelopeProperties(jsonWriter);
            sessionStateTelemetry.WriteTelemetryName(jsonWriter, SessionStateTelemetry.TelemetryName);
            jsonWriter.WritePropertyName("data");
            {
                jsonWriter.WriteStartObject();

                jsonWriter.WriteProperty("baseType", typeof(SessionStateData).Name);
                jsonWriter.WritePropertyName("baseData");
                {
                    jsonWriter.WriteStartObject();

                    jsonWriter.WriteProperty("ver", 2);
                    jsonWriter.WriteProperty("state", sessionStateTelemetry.State.ToString());

                    jsonWriter.WriteEndObject();
                }

                jsonWriter.WriteEndObject();
            }

            jsonWriter.WriteEndObject();
        }
 public void WritePropertyIDictionaryStringStringWritesPropertyNameFollowedByValuesInCurlyBraces()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var writer = new JsonWriter(stringWriter);
         writer.WriteProperty("name", new Dictionary<string, string> { { "key1", "1" } });
         AssertEx.StartsWith("\"name\":{", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
         AssertEx.EndsWith("}", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
        private static void SerializeDependencyTelemetry(DependencyTelemetry dependencyTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            dependencyTelemetry.WriteTelemetryName(writer, DependencyTelemetry.TelemetryName);
            dependencyTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                // TODO: DependencyTelemetry should write type as this.data.baseType once Common Schema 2.0 compliant.
                writer.WriteProperty("baseType", dependencyTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", dependencyTelemetry.Data.ver);
                    writer.WriteProperty("name", dependencyTelemetry.Data.name);

                    writer.WriteProperty("commandName", dependencyTelemetry.Data.commandName);
                    writer.WriteProperty("kind", (int)dependencyTelemetry.Data.kind);
                    writer.WriteProperty("value", dependencyTelemetry.Data.value);

                    writer.WriteProperty("dependencyKind", (int)dependencyTelemetry.Data.dependencyKind);
                    writer.WriteProperty("success", dependencyTelemetry.Data.success);
                    writer.WriteProperty("async", dependencyTelemetry.Data.async);
                    writer.WriteProperty("dependencySource", (int)dependencyTelemetry.Data.dependencySource);
                    writer.WriteProperty("dependencyTypeName", dependencyTelemetry.Data.dependencyTypeName);

                    writer.WriteProperty("properties", dependencyTelemetry.Data.properties);
                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
        private static void SerializeExceptionTelemetry(ExceptionTelemetry exceptionTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            exceptionTelemetry.WriteTelemetryName(writer, ExceptionTelemetry.TelemetryName);
            exceptionTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                writer.WriteProperty("baseType", exceptionTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", exceptionTelemetry.Data.ver);
                    writer.WriteProperty(
                        "handledAt",
                        Utils.PopulateRequiredStringValue(exceptionTelemetry.Data.handledAt, "handledAt", typeof(ExceptionTelemetry).FullName));
                    writer.WriteProperty("properties", exceptionTelemetry.Data.properties);
                    writer.WriteProperty("measurements", exceptionTelemetry.Data.measurements);
                    writer.WritePropertyName("exceptions");
                    {
                        writer.WriteStartArray();

                        SerializeExceptions(exceptionTelemetry.Exceptions, writer);

                        writer.WriteEndArray();
                    }

                    if (exceptionTelemetry.Data.severityLevel.HasValue)
                    {
                        writer.WriteProperty("severityLevel", exceptionTelemetry.Data.severityLevel.Value.ToString());
                    }

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
        /// <summary>
        /// Serializes the crash thread frames.
        /// </summary>
        /// <param name="frames">The frames.</param>
        /// <param name="writer">The writer.</param>
        private static void SerializeCrashThreadFrames(IList<CrashTelemetryThreadFrame> frames, JsonWriter writer)
        {
            bool first = true;
            foreach (CrashTelemetryThreadFrame frame in frames)
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                first = false;

                writer.WriteStartObject();

                writer.WriteProperty("address", frame.Address);
                writer.WriteProperty("symbol", frame.Symbol);
                writer.WriteProperty("registers", frame.Registers);

                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Serializes <paramref name="telemetryItems"/> and write the response to <paramref name="streamWriter"/>.
        /// </summary>
        private static void SeializeToStream(IEnumerable<ITelemetry> telemetryItems, TextWriter streamWriter)
        {
            JsonWriter jsonWriter = new JsonWriter(streamWriter);

            int telemetryCount = 0;
            foreach (ITelemetry telemetryItem in telemetryItems)
            {
                if (telemetryCount++ > 0)
                {
                    streamWriter.Write(Environment.NewLine);
                }

                SerializeTelemetryItem(telemetryItem, jsonWriter);
            }
        }
Exemplo n.º 10
0
        private static void SerializeEventTelemetry(EventTelemetry eventTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            eventTelemetry.WriteTelemetryName(writer, EventTelemetry.TelemetryName);
            eventTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                writer.WriteProperty("baseType", eventTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", eventTelemetry.Data.ver);
                    writer.WriteProperty("name", eventTelemetry.Data.name);
                    writer.WriteProperty("measurements", eventTelemetry.Data.measurements);
                    writer.WriteProperty("properties", eventTelemetry.Data.properties);

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 11
0
 private static void SerializeTelemetryItem(ITelemetry telemetryItem, JsonWriter jsonWriter)
 {
     if (telemetryItem is EventTelemetry)
     {
         EventTelemetry eventTelemetry = telemetryItem as EventTelemetry;
         SerializeEventTelemetry(eventTelemetry, jsonWriter);
     }
     else if (telemetryItem is ExceptionTelemetry)
     {
         ExceptionTelemetry exceptionTelemetry = telemetryItem as ExceptionTelemetry;
         SerializeExceptionTelemetry(exceptionTelemetry, jsonWriter);
     }
     else if (telemetryItem is MetricTelemetry)
     {
         MetricTelemetry metricTelemetry = telemetryItem as MetricTelemetry;
         SerializeMetricTelemetry(metricTelemetry, jsonWriter);
     }
     else if (telemetryItem is PageViewTelemetry)
     {
         PageViewTelemetry pageViewTelemetry = telemetryItem as PageViewTelemetry;
         SerializePageViewTelemetry(pageViewTelemetry, jsonWriter);
     }
     else if (telemetryItem is DependencyTelemetry)
     {
         DependencyTelemetry remoteDependencyTelemetry = telemetryItem as DependencyTelemetry;
         SerializeDependencyTelemetry(remoteDependencyTelemetry, jsonWriter);
     }
     else if (telemetryItem is RequestTelemetry)
     {
         RequestTelemetry requestTelemetry = telemetryItem as RequestTelemetry;
         SerializeRequestTelemetry(requestTelemetry, jsonWriter);
     }
     else if (telemetryItem is SessionStateTelemetry)
     {
         SessionStateTelemetry sessionStateTelemetry = telemetryItem as SessionStateTelemetry;
         SerializeSessionStateTelemetry(sessionStateTelemetry, jsonWriter);
     }
     else if (telemetryItem is TraceTelemetry)
     {
         TraceTelemetry traceTelemetry = telemetryItem as TraceTelemetry;
         SerializeTraceTelemetry(traceTelemetry, jsonWriter);
     }
     else if (telemetryItem is PerformanceCounterTelemetry)
     {
         PerformanceCounterTelemetry performanceCounterTelemetry = telemetryItem as PerformanceCounterTelemetry;
         SerializePerformanceCounter(performanceCounterTelemetry, jsonWriter);
     }
     else if (telemetryItem is CrashTelemetry)
     {
         CrashTelemetry crashTelemetry = telemetryItem as CrashTelemetry;
         SerializeCrash(crashTelemetry, jsonWriter);
     }
     else
     {   
         string msg = string.Format(CultureInfo.InvariantCulture, "Unknown telemtry type: {0}", telemetryItem.GetType());                
         CoreEventSource.Log.LogVerbose(msg);
     }
 }
Exemplo n.º 12
0
 public void WritePropertyNameThrowsArgumentExceptionWhenPropertyNameIsEmptyToPreventOurOwnErrors()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new JsonWriter(stringWriter);
         Assert.Throws<ArgumentException>(() => jsonWriter.WritePropertyName(string.Empty));
     }
 }
Exemplo n.º 13
0
 public void WritePropertyIDictionaryStringStringWritesValuesWithoutDoubleQuotes()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var writer = new JsonWriter(stringWriter);
         writer.WriteProperty("name", new Dictionary<string, string> { { "key1", "1" } });
         Assert.Contains("\"key1\":\"1\"", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Serializes the crash.
        /// </summary>
        /// <param name="telemetry">The telemetry.</param>
        /// <param name="writer">The writer.</param>
        private static void SerializeCrash(CrashTelemetry telemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            telemetry.WriteTelemetryName(writer, CrashTelemetry.TelemetryName);
            telemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                writer.WriteProperty("baseType", telemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", telemetry.Data.ver);
                    writer.WriteProperty("handledAt", Utils.PopulateRequiredStringValue(telemetry.Data.handledAt, "handledAt", typeof(ExceptionTelemetry).FullName));
                    writer.WriteProperty("stackTrace", telemetry.StackTrace);

                    // write headers
                    writer.WritePropertyName("headers");
                    {
                        writer.WriteStartObject();

                        writer.WriteProperty("id", telemetry.Headers.Id);
                        writer.WriteProperty("process", telemetry.Headers.Process);
                        writer.WriteProperty("processId", telemetry.Headers.ProcessId);
                        writer.WriteProperty("parentProcess", telemetry.Headers.ParentProcess);
                        writer.WriteProperty("parentProcessId", telemetry.Headers.ParentProcessId);
                        writer.WriteProperty("crashThread", telemetry.Headers.CrashThreadId);
                        writer.WriteProperty("applicationPath", telemetry.Headers.ApplicationPath);
                        writer.WriteProperty("applicationIdentifier", telemetry.Headers.ApplicationId);
                        writer.WriteProperty("exceptionType", telemetry.Headers.ExceptionType);
                        writer.WriteProperty("exceptionCode", telemetry.Headers.ExceptionCode);
                        writer.WriteProperty("exceptionAddress", telemetry.Headers.ExceptionAddress);
                        writer.WriteProperty("exceptionReason", telemetry.Headers.ExceptionReason);

                        writer.WriteEndObject();
                    }

                    // write threads
                    writer.WritePropertyName("threads");
                    {
                        writer.WriteStartArray();
                        JsonSerializer.SerializeCrashThreads(telemetry.Threads, writer);
                        writer.WriteEndArray();
                    }

                    // write threads
                    writer.WritePropertyName("binaries");
                    {
                        writer.WriteStartArray();
                        JsonSerializer.SerializeCrashBinaries(telemetry.Binaries, writer);
                        writer.WriteEndArray();
                    }

                    // write threads
                    writer.WritePropertyName("attachments");
                    {
                        writer.WriteStartObject();
                        writer.WriteProperty("description", telemetry.Attachments.Description);
                        writer.WriteProperty("userName", HockeyClient.Current.AsInternal().UserID);
                        writer.WriteProperty("userEmail", HockeyClient.Current.AsInternal().ContactInformation);
                        writer.WriteEndObject();
                    }

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 15
0
        private static void SerializeMetricTelemetry(MetricTelemetry metricTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            metricTelemetry.WriteTelemetryName(writer, MetricTelemetry.TelemetryName);
            metricTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                // TODO: MetricTelemetry should write type as this.data.baseType once Common Schema 2.0 compliant.
                writer.WriteProperty("baseType", metricTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", metricTelemetry.Data.ver);
                    writer.WritePropertyName("metrics");
                    {
                        writer.WriteStartArray();
                        writer.WriteStartObject();
                        writer.WriteProperty("name", metricTelemetry.Metric.name);
                        writer.WriteProperty("kind", metricTelemetry.Metric.kind.ToString());
                        writer.WriteProperty("value", metricTelemetry.Metric.value);
                        writer.WriteProperty("count", metricTelemetry.Metric.count);
                        writer.WriteProperty("min", metricTelemetry.Metric.min);
                        writer.WriteProperty("max", metricTelemetry.Metric.max);
                        writer.WriteProperty("stdDev", metricTelemetry.Metric.stdDev);
                        writer.WriteEndObject();
                        writer.WriteEndArray();
                    }

                    writer.WriteProperty("properties", metricTelemetry.Data.properties);

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Serializes the crash threads.
        /// </summary>
        /// <param name="threads">The threads.</param>
        /// <param name="writer">The writer.</param>
        private static void SerializeCrashThreads(IList<CrashTelemetryThread> threads, JsonWriter writer)
        {
            bool first = true;
            foreach (CrashTelemetryThread thread in threads)
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                first = false;

                writer.WriteStartObject();

                writer.WriteProperty("id", thread.Id);
                writer.WritePropertyName("frames");
                {
                    writer.WriteStartArray();

                    JsonSerializer.SerializeCrashThreadFrames(thread.Frames, writer);

                    writer.WriteEndArray();
                }

                writer.WriteEndObject();
            }
        }
Exemplo n.º 17
0
        private static void SerializePageViewTelemetry(PageViewTelemetry pageViewTelemetry, JsonWriter writer)
        {
            writer.WriteStartObject();

            pageViewTelemetry.WriteTelemetryName(writer, PageViewTelemetry.TelemetryName);
            pageViewTelemetry.WriteEnvelopeProperties(writer);
            writer.WritePropertyName("data");
            {
                writer.WriteStartObject();

                // TODO: MetricTelemetry should write type as this.data.baseType once Common Schema 2.0 compliant.
                writer.WriteProperty("baseType", pageViewTelemetry.BaseType);
                writer.WritePropertyName("baseData");
                {
                    writer.WriteStartObject();

                    writer.WriteProperty("ver", pageViewTelemetry.Data.ver);
                    writer.WriteProperty("name", pageViewTelemetry.Data.name);
                    writer.WriteProperty("url", pageViewTelemetry.Data.url);
                    writer.WriteProperty("duration", pageViewTelemetry.Data.duration);
                    writer.WriteProperty("measurements", pageViewTelemetry.Data.measurements);
                    writer.WriteProperty("properties", pageViewTelemetry.Data.properties);

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Serializes the crash binaries.
        /// </summary>
        /// <param name="binaries">The binaries.</param>
        /// <param name="writer">The writer.</param>
        private static void SerializeCrashBinaries(IList<CrashTelemetryBinary> binaries, JsonWriter writer)
        {
            bool first = true;
            foreach (CrashTelemetryBinary binary in binaries)
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                first = false;

                writer.WriteStartObject();

                writer.WriteProperty("startAddress", binary.StartAddress);
                writer.WriteProperty("endAddress", binary.EndAddress);
                writer.WriteProperty("name", binary.Name);
                writer.WriteProperty("cpuType", binary.CpuType);
                writer.WriteProperty("cpuSubType", binary.CpuSubType);
                writer.WriteProperty("uuid", binary.Uuid);
                writer.WriteProperty("path", binary.Path);

                writer.WriteEndObject();
            }
        }
Exemplo n.º 19
0
 public void WritePropertyStringThrowsArgumentNullExceptionForNameInputAsNull()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var writer = new JsonWriter(stringWriter);
         Assert.Throws<ArgumentNullException>(() => writer.WriteProperty(null, "value"));
     }
 }