Ejemplo n.º 1
0
        /// <summary>
        /// Gets a parameter value
        /// </summary>
        /// <param name="name">parameter name</param>
        /// <returns>parameter value</returns>
        public static string GetConfigValue(string name)
        {
            ConfigurationPackage package = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");

            System.Fabric.Description.ConfigurationSection serviceEnvironmentSection = package.Settings.Sections["ServiceEnvironment"];
            var value = serviceEnvironmentSection.Parameters[name].Value;

            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Simple helper to parse the ConfigurationSection from ServiceFabric Manifests for particular values.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        private static int GetValueAsInt(string key, System.Fabric.Description.ConfigurationSection section)
        {
            var result = int.TryParse(section.Parameters[key].Value, out var value);

            if (!result)
            {
                throw new Exception($"Code package could not be parsed for value {key}");
            }

            return(value);
        }
        public static int TryGetAsInt(this System.Fabric.Description.ConfigurationSection section, string name, int @default)
        {
            if (section.Parameters.Contains(name))
            {
                var value = section.Parameters[name];
                if (Int32.TryParse(value.Value, out int result))
                {
                    return(result);
                }
            }

            return(@default);
        }
        public static string Get(this System.Fabric.Description.ConfigurationSection section, string name)
        {
            if (section.Parameters.Contains(name))
            {
                var val = section.Parameters[name];

                if (!String.IsNullOrEmpty(val.Value))
                {
                    return(val.Value);
                }
            }

            throw new ArgumentNullException($"The configuration value of {name} was null or empty but is required.");
        }
Ejemplo n.º 5
0
 // Helper to get setting value from service fabric settings file
 public static ApiResult GetServiceFabricConfigSetting(string settingName)
 {
     try
     {
         ConfigurationPackage package = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
         System.Fabric.Description.ConfigurationSection serviceEnvironmentSection = package.Settings.Sections["ServiceEnvironment"];
         var settingValue = serviceEnvironmentSection.Parameters[settingName].Value;
         return(ApiResult.CreateSuccess(settingValue));
     }
     catch (Exception ex)
     {
         return(ApiResult.CreateError(ex.Message));
     }
 }