<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Fabric;
using System.Fabric.Description;
using System.Linq;
using System.Threading.Tasks;

namespace SceneSkope.ServiceFabric.Utilities
{
    public class FabricConfigurationProvider : IConfigurationProvider
    {
        private KeyedCollection<string, ConfigurationProperty> _configurationProperties;

        public FabricConfigurationProvider(string configurationSectionName)
        {
            if (string.IsNullOrWhiteSpace(configurationSectionName))
            {
                throw new ArgumentNullException($"{nameof(configurationSectionName)}");
            }

            var activationContext = FabricRuntime.GetActivationContext();
            var configPackage = activationContext.GetConfigurationPackageObject("Config");
            UseConfiguration(configPackage, configurationSectionName);
        }

        public bool HasConfiguration => _configurationProperties != null;

        public string GetValue(string name) => _configurationProperties.ReadConfigurationString(name);
        public string TryGetValue(string name) => _configurationProperties.TryReadConfigurationString(name);

        private void UseConfiguration(ConfigurationPackage configPackage, string configurationSectionName)
        {
            if (!configPackage.Settings.Sections.Contains(configurationSectionName))
            {
                _configurationProperties = null;
            }
            else
            {
                _configurationProperties = configPackage.Settings.Sections[configurationSectionName].Parameters;
            }
        }
    }
}<commit_msg>Added int helper to configuration provider<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Fabric;
using System.Fabric.Description;
using System.Linq;
using System.Threading.Tasks;

namespace SceneSkope.ServiceFabric.Utilities
{
    public class FabricConfigurationProvider : IConfigurationProvider
    {
        private KeyedCollection<string, ConfigurationProperty> _configurationProperties;

        public FabricConfigurationProvider(string configurationSectionName)
        {
            if (string.IsNullOrWhiteSpace(configurationSectionName))
            {
                throw new ArgumentNullException($"{nameof(configurationSectionName)}");
            }

            var activationContext = FabricRuntime.GetActivationContext();
            var configPackage = activationContext.GetConfigurationPackageObject("Config");
            UseConfiguration(configPackage, configurationSectionName);
        }

        public bool HasConfiguration => _configurationProperties != null;

        public string GetValue(string name) => _configurationProperties.ReadConfigurationString(name);
        public string TryGetValue(string name) => _configurationProperties.TryReadConfigurationString(name);

        private void UseConfiguration(ConfigurationPackage configPackage, string configurationSectionName)
        {
            if (!configPackage.Settings.Sections.Contains(configurationSectionName))
            {
                _configurationProperties = null;
            }
            else
            {
                _configurationProperties = configPackage.Settings.Sections[configurationSectionName].Parameters;
            }
        }

        public bool TryParseInt(string name, out int value)
        {
            var stringValue = _configurationProperties.TryReadConfigurationString(name);
            if (!string.IsNullOrWhiteSpace(stringValue))
            {
                return int.TryParse(stringValue, out value);
            }
            else
            {
                value = 0;
                return false;
            }
        }

        public int ReadIntOrDefault(string name, int defaultValue)
        {
            if (_configurationProperties == null)
            {
                return defaultValue;
            }
            else
            {
                int value;
                if (!TryParseInt(name, out value))
                {
                    value = defaultValue;
                }
                return value;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06705744431418523, 'fraction_numerical': 0.00023446658851113716, 'mean_word_length': 2.423756019261637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6036543', 'n_tokens_mistral': 925, 'n_tokens_neox': 895, 'n_words': 184}