Example #1
0
        private static void SerializeUnknownTelemetryHelper(ITelemetry telemetryItem, JsonSerializationWriter jsonSerializationWriter)
        {
            DictionarySerializationWriter dictionarySerializationWriter = new DictionarySerializationWriter();

            telemetryItem.SerializeData(dictionarySerializationWriter); // Properties and Measurements are covered as part of Data if present
            telemetryItem.CopyGlobalPropertiesIfExist(dictionarySerializationWriter.AccumulatedDictionary);

            if (telemetryItem.Extension != null)
            {
                DictionarySerializationWriter extensionSerializationWriter = new DictionarySerializationWriter();
                telemetryItem.Extension.Serialize(extensionSerializationWriter); // Extension is supposed to be flattened as well

                Utils.CopyDictionary(extensionSerializationWriter.AccumulatedDictionary, dictionarySerializationWriter.AccumulatedDictionary);
                Utils.CopyDictionary(extensionSerializationWriter.AccumulatedMeasurements, dictionarySerializationWriter.AccumulatedMeasurements);
            }

            jsonSerializationWriter.WriteProperty("name", telemetryItem.WriteTelemetryName(EventTelemetry.TelemetryName));
            telemetryItem.WriteEnvelopeProperties(jsonSerializationWriter); // No need to copy Context - it's serialized here from the original item

            jsonSerializationWriter.WriteStartObject("data");
            jsonSerializationWriter.WriteProperty("baseType", typeof(EventData).Name);
            jsonSerializationWriter.WriteStartObject("baseData");

            jsonSerializationWriter.WriteProperty("ver", 2);
            jsonSerializationWriter.WriteProperty("name", EventNameForUnknownTelemetry);

            jsonSerializationWriter.WriteProperty("properties", dictionarySerializationWriter.AccumulatedDictionary);
            jsonSerializationWriter.WriteProperty("measurements", dictionarySerializationWriter.AccumulatedMeasurements);

            jsonSerializationWriter.WriteEndObject(); // baseData
            jsonSerializationWriter.WriteEndObject(); // data
        }
Example #2
0
        private static void SerializeTelemetryItem(ITelemetry telemetryItem, JsonSerializationWriter jsonSerializationWriter)
        {
            jsonSerializationWriter.WriteStartObject();

            if (telemetryItem is IAiSerializableTelemetry serializeableTelemetry)
            {
                telemetryItem.CopyGlobalPropertiesIfExist();
                telemetryItem.FlattenIExtensionIfExists();
                SerializeHelper(telemetryItem, jsonSerializationWriter, telemetryName: serializeableTelemetry.TelemetryName, baseType: serializeableTelemetry.BaseType);
            }
            else
            {
                SerializeUnknownTelemetryHelper(telemetryItem, jsonSerializationWriter);
            }

            jsonSerializationWriter.WriteEndObject();
        }