Ejemplo n.º 1
0
        public TelemetryCollector(
            Persistence.IStorageManager storage,
            ITelemetryUploader telemetryUploader,
            IInvokeSynchronization synchronization,
            MultiInstance.IInstancesCounter instancesCounter,
            IShutdown shutdown,
            ILogSourcesManager logSourcesManager,
            IMemBufferTraceAccess traceAccess
            )
        {
            this.telemetryUploader = telemetryUploader;
            this.synchronization   = synchronization;
            this.traceAccess       = traceAccess;

            this.telemetryStorageEntry = storage.GetEntry("telemetry");
            this.sessionStartedMillis  = Environment.TickCount;

            this.currentSessionId = telemetryUploader.IsTelemetryConfigured ?
                                    ("session" + Guid.NewGuid().ToString("n")) : null;

            this.transactionInvoker = new AsyncInvokeHelper(synchronization,
                                                            (Action)(() => DoSessionsRegistryTransaction(TransactionFlag.Default)), new object[0]);

            shutdown.Cleanup += (s, e) => shutdown.AddCleanupTask(DisposeAsync());

            if (currentSessionId != null)
            {
                CreateCurrentSessionSection();
                InitStaticTelemetryProperties();

                logSourcesManager.OnLogSourceAdded += (s, e) =>
                {
                    ++totalNfOfLogs;
                    var nfOfSimultaneousLogs = logSourcesManager.Items.Count();
                    maxNfOfSimultaneousLogs = Math.Max(maxNfOfSimultaneousLogs, nfOfSimultaneousLogs);
                };
            }

            if (telemetryUploader.IsTelemetryConfigured && instancesCounter.IsPrimaryInstance)
            {
                this.workerCancellation     = new CancellationTokenSource();
                this.workerCancellationTask = new TaskCompletionSource <int>();
                this.worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }
Ejemplo n.º 2
0
        public void BeforeEach()
        {
            storage          = Substitute.For <Persistence.IStorageManager>();
            uploader         = Substitute.For <ITelemetryUploader>();
            instancesCounter = Substitute.For <MultiInstance.IInstancesCounter>();
            shutdown         = Substitute.For <IShutdown>();
            traceAccess      = Substitute.For <IMemBufferTraceAccess>();

            collector = new TelemetryCollector(
                storage, uploader,
                new SerialSynchronizationContext(),
                instancesCounter, shutdown,
                traceAccess,
                new TraceSourceFactory()
                );

            uploader.IsIssuesReportingConfigured.Returns(true);
        }
Ejemplo n.º 3
0
        public TelemetryCollector(
            Persistence.IStorageManager storage,
            ITelemetryUploader telemetryUploader,
            ISynchronizationContext synchronization,
            MultiInstance.IInstancesCounter instancesCounter,
            IShutdown shutdown,
            IMemBufferTraceAccess traceAccess,
            ITraceSourceFactory traceSourceFactory
            )
        {
            this.trace             = traceSourceFactory.CreateTraceSource("Telemetry");
            this.telemetryUploader = telemetryUploader;
            this.synchronization   = synchronization;
            this.traceAccess       = traceAccess;

            this.telemetryStorageEntry = storage.GetEntry("telemetry");
            this.sessionStartedMillis  = Environment.TickCount;

            this.currentSessionId = telemetryUploader.IsTelemetryConfigured ?
                                    ("session" + Guid.NewGuid().ToString("n")) : null;

            this.transactionInvoker = new AsyncInvokeHelper(synchronization,
                                                            () => DoSessionsRegistryTransaction(TransactionFlag.Default));

            shutdown.Cleanup += (s, e) => shutdown.AddCleanupTask(DisposeAsync());

            if (currentSessionId != null)
            {
                CreateCurrentSessionSection();
                InitStaticTelemetryProperties();
            }

            if (telemetryUploader.IsTelemetryConfigured && instancesCounter.IsPrimaryInstance)
            {
                this.workerCancellation     = new CancellationTokenSource();
                this.workerCancellationTask = new TaskCompletionSource <int>();
                this.worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }