Ejemplo n.º 1
0
 /// <summary>
 /// Creates an <see cref="ISwitch"/>
 /// </summary>
 /// <param name="name">The name of the switch</param>
 /// <param name="switchType">The full-qualified type name of the switch to create</param>
 /// <param name="refValue">The reference value</param>
 /// <param name="cacheDuration">Optional duration to cache the result for</param>
 /// <returns>A new <see cref="ISwitch"/> object</returns>
 public static ISwitch CreateSwitch(
     string name,
     string switchType,
     object refValue,
     StorageDuration cacheDuration = StorageDuration.None)
 {
     var typeObj = Type.GetType(switchType);
     return CreateSwitch(name, typeObj, refValue, cacheDuration);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Stores the state of the specified switch
        /// </summary>
        /// <param name="name">The name of the switch</param>
        /// <param name="state">Whether or not the switch is active</param>
        /// <param name="duration">The duration to store the state for</param>
        public void StoreState(string name, bool state, StorageDuration duration)
        {
            var key = MakeKey(name);
            this.OutgoingCookies.Remove(key);

            if (duration != StorageDuration.None)
            {
                var cookie = new HttpCookie(key);
                cookie.Value = state.ToString();

                this.SetCookieExpiration(duration, cookie);
                this.OutgoingCookies.Add(cookie);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an <see cref="ISwitch"/>
        /// </summary>
        /// <param name="name">The name of the switch</param>
        /// <param name="switchType">The <see cref="Type"/> of switch to create</param>
        /// <param name="refValue">The reference value</param>
        /// <param name="cacheDuration">Optional duration to cache the result for</param>
        /// <returns>A new <see cref="ISwitch"/> object</returns>
        public static ISwitch CreateSwitch(
            string name, 
            Type switchType, 
            object refValue, 
            StorageDuration cacheDuration = StorageDuration.None)
        {
            var featureSwitch = Activator.CreateInstance(switchType) as ISwitch;
            featureSwitch.Name = name;
            featureSwitch.CacheDuration = cacheDuration;

            if (refValue != null)
            {
                featureSwitch.SetRefValue(refValue);
            }

            return featureSwitch;
        }
Ejemplo n.º 4
0
 protected virtual void SetCookieExpiration(StorageDuration duration, HttpCookie cookie)
 {
     switch (duration)
     {
         case StorageDuration.Medium:
             cookie.Expires = DateTime.Now.AddDays(1);
             break;
         case StorageDuration.Long:
             cookie.Expires = DateTime.Now.AddDays(14);
             break;
         case StorageDuration.ForEver:
             cookie.Expires = DateTime.Now.AddYears(1);
             break;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Does absolutely nothing...
 /// </summary>
 /// <param name="name">The name of the switch</param>
 /// <param name="state">Whether or not the switch is active</param>
 /// <param name="duration">The duration to store the state for</param>
 public void StoreState(string name, bool state, StorageDuration duration)
 {
 }