public void SetupFromSettingsFile(IConfigReader configReader, TimeSpan currentTimeOfTheDay)
        {
            // reading the number of daily pushes
            this.DailyPushes = TelemetryScheduler.ReadTelemetryDailyPushes(configReader);

            // parsing time from telemetryPushTimeParamValue
            var telemetryPushTimeParamValue = configReader.GetUnencryptedConfigValue(
                ConfigReader.DiagnosticsSectionName,
                ConfigReader.TestOnlyTelemetryPushTimeParamName,
                string.Empty);

            TimeSpan telemetryPushTime;

            if (!TimeSpan.TryParse(telemetryPushTimeParamValue, out telemetryPushTime))
            {
                // the first batch of telemetry is sent after 30min that the cluster came up
                // the time of the push time will be than be 30min + 24h - (24/dailyPushes)
                TimeSpan totalTimeToPushTime = this.InitialSendDelay.Add(TimeSpan.FromHours(24.0 - this.SendInterval.TotalHours));
                this.PushTime = (currentTimeOfTheDay.Add(totalTimeToPushTime) < TimeSpan.FromDays(1)) ? currentTimeOfTheDay.Add(totalTimeToPushTime) : currentTimeOfTheDay.Add(totalTimeToPushTime).Subtract(TimeSpan.FromDays(1));
                this.IsTestOnlyTelemetryPushTimeSet = false;
            }
            else
            {
                this.PushTime = telemetryPushTime;
                this.IsTestOnlyTelemetryPushTimeSet = true;
            }

            this.UpdateScheduler(false, false, TimeSpan.FromHours(0.0), currentTimeOfTheDay);
        }
        public TelemetryEtwSink(
            ITelemetryWriter telemetryWriter,
            string clusterId,
            string tenantId,
            string clusterType,
            string serviceFabricVersion,
            string nodeName,
            bool isScaleMin,
            TelemetryScheduler telemetryScheduler)
        {
            string clusterDevType = isScaleMin.ToString();

            this.telemetryWriter = telemetryWriter;

            // creating filter to only aggregate traces which are white-listed
            this.telemetryFilter = new TelemetryFilter();

            // creating the unique identifier of the cluster/node
            this.telemetryIdentifier = new TelemetryIdentifiers(clusterId, tenantId, nodeName);

            // getting path to where telemetry will be persisted
            Utility.CreateWorkSubDirectory(
                Utility.TraceSource,
                LogSourceId,
                TelemetryWorkSubDirectoryKey,
                AggregationPersistenceFolder,
                Utility.DcaWorkFolder,
                out this.telemetryPersistFilePath);

            this.telemetryPersistFilePath = Path.Combine(this.telemetryPersistFilePath, TelemetryEtwSink.TelemetryPersistFileName);

            // initializing the collection of telemetry (first it tries to load it from file, if fails an empty collection is created)
            bool telCollectionloadedFromDisk;

            this.telemetryCollection = TelemetryCollection.LoadOrCreateTelemetryCollection(this.telemetryPersistFilePath, this.telemetryIdentifier, telemetryScheduler.DailyPushes, out telCollectionloadedFromDisk, Utility.TraceSource.WriteError);

            // updating the scheduling for sending telemetry based on the persisted (or not persisted) telemetryCollection.
            telemetryScheduler.UpdateScheduler(telCollectionloadedFromDisk, this.telemetryCollection.TotalPushes > 0, this.telemetryCollection.PushTime, DateTime.Now.ToLocalTime().TimeOfDay);
            this.telemetryCollection.PushTime = telemetryScheduler.PushTime;

            // creating environment telemetry and including it in the collection
            this.environmentTelemetry = new EnvironmentTelemetry(
                clusterType,
                serviceFabricVersion,
                clusterDevType);

            this.telemetryCollection.Aggregate(this.environmentTelemetry);

            this.telemetryPerformanceInstrumentation = new TelemetryPerformanceInstrumentation();
            this.telemetryCollection.Aggregate(this.telemetryPerformanceInstrumentation);

            this.telemetryLock = new object();

            Utility.TraceSource.WriteInfo(LogSourceId, "{0}, Initial send telemetry delay of {1} at a frequency of every {2} minutes.", this.telemetryIdentifier, telemetryScheduler.SendDelay, telemetryScheduler.SendInterval.TotalMinutes);
            this.telemetrySendTimer = new System.Threading.Timer(this.SendTelemetry, null, telemetryScheduler.SendDelay, telemetryScheduler.SendInterval);
        }