/// <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); }
/// <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); } }
/// <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; }
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; } }
/// <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) { }