Exemple #1
0
 /// <summary>
 /// Writes a set of properties to the configuration store.
 /// </summary>
 /// <param name="appName">The name of the affiliate application.</param>
 /// <param name="configProperties">The configuration properties to write.</param>
 public static void WriteAll(string appName, ConfigurationPropertyBag configProperties)
 {
     try
     {
         lock (syncLock)
         {
             // update property bag in the SSO store
             SSOConfigStore ssoStore = new SSOConfigStore();
             ((ISSOConfigStore)ssoStore).SetConfigInfo(appName, IDENTIFIER_GUID, configProperties);
             // force a refresh of the cached configuration properties for the specified application
             appConfigSettings.Remove(appName);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e.Message);
         throw;
     }
 }
Exemple #2
0
 /// <summary>
 /// Loads the configuration information for the specified affiliate application.
 /// </summary>
 /// <param name="appName">The name of the affiliate application.</param>
 private static void LoadSSOConfigInfo(string appName)
 {
     // NOTE: This is a classic implementation of the double-lock pattern in .NET
     // check if the application settings are in the cache
     if (appConfigSettings.ContainsKey(appName) == false)
     {
         // acquire a lock
         lock (syncLock)
         {
             if (appConfigSettings.ContainsKey(appName) == false)
             {
                 // get the configuration info from the SSO store
                 SSOConfigStore           ssoStore          = new SSOConfigStore();
                 ConfigurationPropertyBag configPropertyBag = new ConfigurationPropertyBag();
                 ((ISSOConfigStore)ssoStore).GetConfigInfo(appName, IDENTIFIER_GUID, SSOFlag.SSO_FLAG_RUNTIME, (IPropertyBag)configPropertyBag);
                 // add application configuration to cache
                 appConfigSettings.Add(appName, configPropertyBag);
             }
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// Reads all the configuration properties from teh specified application.
 /// </summary>
 /// <param name="appName">The name of the affiliate application.</param>
 /// <returns>The configuration properties for the specified SSO application.</returns>
 public static ConfigurationPropertyBag ReadAll(string appName)
 {
     try
     {
         // load configuration info from SSO store
         LoadSSOConfigInfo(appName);
         // get configuration property bag
         ConfigurationPropertyBag configPropertyBag = null;
         if (appConfigSettings.TryGetValue(appName, out configPropertyBag) == true)
         {
             return(configPropertyBag);
         }
         // not found
         return(null);
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e.Message);
         throw;
     }
 }
Exemple #4
0
 /// <summary>
 /// Writes a property to the configuration store.
 /// </summary>
 /// <param name="appName">The name of the affiliate application.</param>
 /// <param name="propName">The property name to write.</param>
 /// <param name="propValue">The property value to write.</param>
 public static void Write(string appName, string propName, string propValue)
 {
     try
     {
         // load configuration info from SSO store
         LoadSSOConfigInfo(appName);
         // get configuration properties for specified application
         ConfigurationPropertyBag configPropertyBag = appConfigSettings[appName];
         // write property value to configuration property bag
         object tempProp = propValue;
         configPropertyBag.Write(propName, ref tempProp);
         // update property bag in the SSO store
         SSOConfigStore ssoStore = new SSOConfigStore();
         ((ISSOConfigStore)ssoStore).SetConfigInfo(appName, IDENTIFIER_GUID, configPropertyBag);
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e.Message);
         throw;
     }
 }
Exemple #5
0
        /// <summary>
        /// Reads the value of a configuration property from the specified application.
        /// </summary>
        /// <typeparam name="T">Type of value to read.</typeparam>
        /// <param name="appName">The name of the affiliate application.</param>
        /// <param name="propName">The property name to read.</param>
        /// <param name="defaultValue">Default property value to return if the property is not found or is null.</param>
        /// <returns>The value of the property stored in the given affiliate application if the property exists, the default value otherwise.</returns>
        public static T Read <T>(string appName, string propName, T defaultValue)
        {
            try
            {
                // load configuration info from SSO store
                LoadSSOConfigInfo(appName);

                // read the property value from the SSO store
                object propValue = null;
                if (appConfigSettings.ContainsKey(appName) == true)
                {
                    // get application property bag
                    ConfigurationPropertyBag configPropertyBag = appConfigSettings[appName];
                    configPropertyBag.Read(propName, out propValue, 0);
                }

                // return property value if property exists, otherwise the default for type T
                if (propValue != null)
                {
                    if (typeof(T).IsEnum == true)
                    {
                        return((T)Enum.Parse(typeof(T), propValue.ToString()));
                    }
                    else
                    {
                        return((T)Convert.ChangeType(propValue, typeof(T)));
                    }
                }
                return(defaultValue);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
                throw;
            }
        }