public DependencyState GetState(DependencyStateContext context) { if (!(context is AppConfigValueDependencyStateContext)) { return(null); } // Get the requested AppConfig var appConfigValueContext = (AppConfigValueDependencyStateContext)context; var appConfig = AppConfigProvider.GetAppConfigContextless(appConfigValueContext.Name, appConfigValueContext.StoreId, cascadeToDefault: true); // If the AppConfig doesn't exist or it doesn't match predicate, return a // state that will be different every time. The required behavior is that any AppConfig // that doesn't match the predicate should cause the dependecy to fail. if (appConfig == null || !appConfigValueContext.Predicate(appConfig.ConfigValue)) { // Generate a random long var rng = new Random(); var rngBuffer = new byte[8]; rng.NextBytes(rngBuffer); var failedHash = BitConverter.ToInt64(rngBuffer, 0); // Return that as the state return(new DependencyState( context: context, state: failedHash)); } // If the AppConfig exists and matches the predicate, return a state that tracks any changes in the AppConfig. return(new DependencyState( context: context, state: HashProvider.Hash(new object[] { appConfigValueContext.Name, appConfigValueContext.StoreId, appConfig.StoreId, appConfig.UpdatedOn.Ticks, }))); }
public DependencyState GetState(DependencyStateContext context) { if (!(context is AppConfigDependencyStateContext)) { return(null); } // Get the requested AppConfig var appConfigContext = (AppConfigDependencyStateContext)context; var appConfig = AppConfigProvider.GetAppConfigContextless(appConfigContext.Name, appConfigContext.StoreId, cascadeToDefault: true); // There are many cases to consider: creation, deletion, and modification; and default // store fallbacks in all three cases. // If the requested AppConfig doesn't exist, create a state that doesn't include the value if (appConfig == null) { return(new DependencyState( context: context, state: HashProvider.Hash(new object[] { appConfigContext.Name, appConfigContext.StoreId, }))); } // Create a state that includes both the requested and actual values. return(new DependencyState( context: context, state: HashProvider.Hash(new object[] { appConfigContext.Name, // The name of the AppConfig appConfigContext.StoreId, // The requested store ID appConfig.StoreId, // The actual store ID, in case the requested // store ID used the default store's value appConfig.UpdatedOn, // The timestamp of the last change }))); }