/// <summary> /// Initializes <see cref="TimeSeriesProducer"/>. /// </summary> public override void Initialize() { base.Initialize(); Dictionary <string, string> settings = Settings; string setting; int intValue; double doubleValue; // Parse required settings if (!settings.TryGetValue(nameof(Servers), out setting) || string.IsNullOrWhiteSpace(setting)) { throw new ArgumentException($"Required \"{nameof(Servers)}\" setting is missing."); } Servers = setting.Trim(); m_servers = Servers.Split(',').Select(uri => new Uri(uri)).ToArray(); // Parse optional settings if (settings.TryGetValue(nameof(Topic), out setting) && !string.IsNullOrWhiteSpace(setting)) { Topic = setting.Trim(); } else { Topic = TimeSeriesProducer.DefaultTopic; } if (settings.TryGetValue(nameof(Partitions), out setting) && int.TryParse(setting, out intValue)) { Partitions = intValue; } else { Partitions = TimeSeriesProducer.DefaultPartitions; } if (settings.TryGetValue(nameof(TrackConsumerOffset), out setting)) { TrackConsumerOffset = setting.ParseBoolean(); } else { TrackConsumerOffset = DefaultTrackConsumerIndex; } if (!settings.TryGetValue(nameof(ConsumerOffsetFileName), out setting) || string.IsNullOrWhiteSpace(setting)) { setting = Name + ".offset"; } ConsumerOffsetFileName = FilePath.GetAbsolutePath(setting); if (settings.TryGetValue(nameof(ConsumerOffsetCacheInterval), out setting) && double.TryParse(setting, out doubleValue)) { ConsumerOffsetCacheInterval = doubleValue; } else { ConsumerOffsetCacheInterval = DefaultConsumerOffsetCacheInterval; } if (settings.TryGetValue(nameof(ReadDelay), out setting) && int.TryParse(setting, out intValue)) { ReadDelay = intValue; } else { ReadDelay = DefaultReadDelay; } if (settings.TryGetValue(nameof(CacheMetadataLocally), out setting)) { CacheMetadataLocally = setting.ParseBoolean(); } else { CacheMetadataLocally = TimeSeriesProducer.DefaultCacheMetadataLocally; } if (CacheMetadataLocally) { m_cacheMetadataLocally = new LongSynchronizedOperation(() => TimeSeriesMetadata.CacheLocally(m_metadata, MetadataTopic, OnStatusMessage)) { IsBackground = true } } ; if ((object)OutputMeasurements != null && OutputMeasurements.Length > 0) { m_outputMeasurementKeys = new HashSet <MeasurementKey>(OutputMeasurements.Select(m => m.Key)); } }
/// <summary> /// Initializes <see cref="TimeSeriesProducer"/>. /// </summary> public override void Initialize() { base.Initialize(); Dictionary <string, string> settings = Settings; string setting; int value; // Parse required settings if (!settings.TryGetValue(nameof(Servers), out setting) || string.IsNullOrWhiteSpace(setting)) { throw new ArgumentException($"Required \"{nameof(Servers)}\" setting is missing."); } Servers = setting.Trim(); m_servers = Servers.Split(',').Select(uri => new Uri(uri)).ToArray(); // Parse optional settings if (settings.TryGetValue(nameof(Topic), out setting) && !string.IsNullOrWhiteSpace(setting)) { Topic = setting.Trim(); } else { Topic = DefaultTopic; } if (settings.TryGetValue(nameof(Partitions), out setting) && int.TryParse(setting, out value)) { Partitions = value; } else { Partitions = DefaultPartitions; } if (settings.TryGetValue(nameof(Encoding), out setting)) { Encoding = setting; } else { Encoding = null; } if (settings.TryGetValue(nameof(TimestampFormat), out setting)) { TimestampFormat = setting; } else { TimestampFormat = DefaultTimestampFormat; } if (settings.TryGetValue(nameof(ValueFormat), out setting)) { ValueFormat = setting; } else { ValueFormat = DefaultValueFormat; } if (settings.TryGetValue(nameof(SerializeMetadata), out setting)) { SerializeMetadata = setting.ParseBoolean(); } else { SerializeMetadata = DefaultSerializeMetadata; } if (settings.TryGetValue(nameof(CacheMetadataLocally), out setting)) { CacheMetadataLocally = setting.ParseBoolean(); } else { CacheMetadataLocally = DefaultCacheMetadataLocally; } if (CacheMetadataLocally) { m_cacheMetadataLocally = new LongSynchronizedOperation(() => TimeSeriesMetadata.CacheLocally(m_metadata, MetadataTopic, status => OnStatusMessage(MessageLevel.Info, status))) { IsBackground = true } } ; }