Beispiel #1
0
 private void InitializeSession()
 {
     if (!isInitialized)
     {
         lock (initializedLock)
         {
             if (!isInitialized && isManifestCompleted && isMACAddressCompleted && isHardwareIdCompleted)
             {
                 List <KeyValuePair <string, object> > list = persistentPropertyBag.GetAllProperties().ToList();
                 list.Add(new KeyValuePair <string, object>("VS.Core.Session.IsCloned", isSessionCloned));
                 list.Add(new KeyValuePair <string, object>("VS.TelemetryApi.Session.IsShort", startedDisposing));
                 list.Add(new KeyValuePair <string, object>("VS.TelemetryApi.Session.ForcedReadManifest", ManifestManager.ForcedReadManifest));
                 list.Add(new KeyValuePair <string, object>("VS.TelemetryApi.DefaultChannels", StringExtensions.Join((IEnumerable <string>)defaultSessionChannelsId, ",")));
                 diagnosticTelemetry.PostDiagnosticTelemetryWhenSessionInitialized(this, list);
                 persistentPropertyBag.Clear();
                 TelemetryEvent telemetryEvent;
                 while (telemetryBufferChannel.TryDequeue(out telemetryEvent))
                 {
                     defaultContext.ProcessEvent(telemetryEvent);
                     PostProcessedEvent(telemetryEvent);
                 }
                 isInitialized = true;
                 while (telemetryBufferChannel.TryDequeue(out telemetryEvent))
                 {
                     defaultContext.ProcessEvent(telemetryEvent, false);
                     PostProcessedEvent(telemetryEvent);
                 }
                 telemetryBufferChannel = null;
                 identityTelemetry.IdentityInformationProvider.SchedulePostPersistedSharedPropertyAndSendAnyFaults(this, contextScheduler ?? new TelemetryScheduler());
                 identityTelemetry.PostIdentityTelemetryWhenSessionInitialized(this);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Set up telemetry session properties
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="initializerObject"></param>
        /// <param name="isCloned"></param>
        private TelemetrySession(TelemetrySessionSettings settings, bool isCloned, TelemetrySessionInitializer initializerObject)
        {
            CodeContract.RequiresArgumentNotNull <TelemetrySessionInitializer>(initializerObject, "initializerObject");
            initializerObject.Validate();
            initializerObject.AppInsightsInstrumentationKey = settings.AppInsightsInstrumentationKey;
            initializerObject.AsimovInstrumentationKey      = settings.AsimovInstrumentationKey;
            TelemetryService.EnsureEtwProviderInitialized();
            sessionInitializer      = initializerObject;
            sessionSettings         = settings;
            isSessionCloned         = isCloned;
            cancellationTokenSource = initializerObject.CancellationTokenSource;
            diagnosticTelemetry     = initializerObject.DiagnosticTelemetry;
            identityTelemetry       = initializerObject.IdentityTelemetry;
            optinStatusReader       = initializerObject.OptinStatusReader;
            channelValidators       = initializerObject.ChannelValidators;
            telemetryBufferChannel  = new TelemetryBufferChannel();
            initializerObject.WatsonSessionChannelBuilder.Build(this);
            WatsonSessionChannel sessionChannel = initializerObject.WatsonSessionChannelBuilder.WatsonSessionChannel;

            if (IsValidChannel(sessionChannel))
            {
                watsonSessionChannel = sessionChannel;
            }
            machineInformationProvider    = initializerObject.MachineInformationProvider;
            macInformationProvider        = initializerObject.MACInformationProvider;
            userInformationProvider       = initializerObject.UserInformationProvider;
            defaultContextPropertyManager = initializerObject.DefaultContextPropertyManager;
            persistentPropertyBag         = initializerObject.PersistentPropertyBag;
            initializerObject.EventProcessorChannelBuilder.Build(this);
            persistentSharedProperties = initializerObject.PersistentSharedProperties;
            EventProcessor             = initializerObject.EventProcessorChannelBuilder.EventProcessor;
            if (initializerObject.CustomActionToAdd != null)
            {
                foreach (IEventProcessorAction item in initializerObject.CustomActionToAdd)
                {
                    EventProcessor.AddCustomAction(item);
                }
            }
            eventProcessorChannel    = initializerObject.EventProcessorChannelBuilder.EventProcessorChannel;
            telemetryManifestManager = new Lazy <ITelemetryManifestManager>(() => initializerObject.TelemetryManifestManagerBuilder.Build(this));
            contextScheduler         = initializerObject.ContextScheduler;
            if (initializerObject.ChannelsToAdd != null)
            {
                AddSessionChannels(initializerObject.ChannelsToAdd);
            }
            defaultContext = CreateDefaultContext();
            macInformationProvider.MACAddressHashCalculationCompleted += MACAddressHashCalculationCompleted;
            identityTelemetry.IdentityInformationProvider.HardwareIdCalculationCompleted += HardwareIdCalculationCompleted;
        }