internal TelemetryContext DeepClone(IDictionary <string, string> properties)
        {
            var newTelemetryContext = new TelemetryContext(properties);

            // This check avoids accessing the public accessor GlobalProperties
            // unless needed, to avoid the penality of ConcurrentDictionary instantiation.
            if (this.GlobalPropertiesValue != null)
            {
                Utils.CopyDictionary(this.GlobalProperties, newTelemetryContext.GlobalProperties);
            }

            if (this.PropertiesValue != null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                Utils.CopyDictionary(this.Properties, newTelemetryContext.Properties);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            newTelemetryContext.Initialize(this, this.instrumentationKey);

            // RawObject collection is not cloned by design, they share the same collection.
            newTelemetryContext.rawObjectsTemp = this.rawObjectsTemp;
            newTelemetryContext.rawObjectsPerm = this.rawObjectsPerm;
            return(newTelemetryContext);
        }
        public void InitializeSetsTelemetryInstrumentationKeyFromArgument()
        {
            var source = new TelemetryContext { InstrumentationKey = "TestValue" };
            var target = new TelemetryContext();

            target.Initialize(source, "OtherTestValue");

            Assert.Equal("OtherTestValue", target.InstrumentationKey);
        }
        public void InitializeDoesNotOverrideTelemetryInstrumentationKey()
        {
            var source = new TelemetryContext { InstrumentationKey = "SourceValue" };
            var target = new TelemetryContext { InstrumentationKey = "TargetValue" };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("TargetValue", target.InstrumentationKey);
        }
        public void InitializeDoesNotOverwriteTags()
        {
            string tagName = "TestTag";
            var source = new TelemetryContext { Tags = { { tagName, "Source Value" } } };
            var target = new TelemetryContext { Tags = { { tagName, "Target Value" } } };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("Target Value", target.Tags[tagName]);
        }
        public void InitializeSetsTelemetryInstrumentationKeyFromArgument()
        {
            var source = new TelemetryContext {
                InstrumentationKey = "TestValue"
            };
            var target = new TelemetryContext();

            target.Initialize(source, "OtherTestValue");

            Assert.Equal("OtherTestValue", target.InstrumentationKey);
        }
Esempio n. 6
0
        public void InitializeSetsFlagsFromArgument()
        {
            var source = new TelemetryContext();
            var target = new TelemetryContext {
                Flags = 0x00100000
            };

            target.Initialize(source, source.InstrumentationKey);

            Assert.AreEqual(0x00100000, target.Flags);
        }
Esempio n. 7
0
        public void InitializeSetsTelemetryInstrumentationKeyFromSource()
        {
            var source = new TelemetryContext {
                InstrumentationKey = "TestValue"
            };
            var target = new TelemetryContext();

            target.Initialize(source, source.InstrumentationKey);

            Assert.AreEqual("TestValue", target.InstrumentationKey);
        }
        public void InitializeCopiesTags()
        {
            string tagName = "TestTag";
            string tagValue = "TestValue";
            var source = new TelemetryContext { Tags = { { tagName, tagValue } } };
            var target = new TelemetryContext();

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal(tagValue, target.Tags[tagName]);
        }
        public void InitializeDoesNotOverrideTelemetryInstrumentationKey()
        {
            var source = new TelemetryContext {
                InstrumentationKey = "SourceValue"
            };
            var target = new TelemetryContext {
                InstrumentationKey = "TargetValue"
            };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("TargetValue", target.InstrumentationKey);
        }
        public void InitializeCopiesTags()
        {
            string tagName  = "TestTag";
            string tagValue = "TestValue";
            var    source   = new TelemetryContext {
                Tags = { { tagName, tagValue } }
            };
            var target = new TelemetryContext();

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal(tagValue, target.Tags[tagName]);
        }
        private static string CopyAndSerialize(TelemetryContext source)
        {
            // Create a copy of the source context to verify that Serialize writes property values stored in tags
            // dictionary even if their context objects (User, Location, etc) haven't been initialized yet.
            var target = new TelemetryContext();

            target.Initialize(source, source.InstrumentationKey);

            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                Telemetry.WriteTelemetryContext(new JsonWriter(stringWriter), source);
                return(stringWriter.ToString());
            }
        }
        public void InitializeDoesNotOverwriteTags()
        {
            string tagName = "TestTag";
            var    source  = new TelemetryContext {
                Tags = { { tagName, "Source Value" } }
            };
            var target = new TelemetryContext {
                Tags = { { tagName, "Target Value" } }
            };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("Target Value", target.Tags[tagName]);
        }
        private static string CopyAndSerialize(TelemetryContext source)
        {
            // Create a copy of the source context to verify that Serialize writes property values stored in tags
            // dictionary even if their context objects (User, Location, etc) haven't been initialized yet.
            var target = new TelemetryContext();
            target.Initialize(source, source.InstrumentationKey);

            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                Telemetry.WriteTelemetryContext(new JsonWriter(stringWriter), source);
                return stringWriter.ToString();
            }
        }