public async Task LoadAsync(FeatureContext featureContext, Func<FeatureContext, Task<DashboardSettings>> settingsProvider, Func<FeatureContext, Task<DashboardCommonData>> commonDataProvider, Func<DashboarLoadParams, Task<List<DashboardUser>>> usersProvider, Func<DashboarLoadParams, Task<List<DashboardVersion>>> versionsProvider, Func<DashboarLoadParams, Task<List<DashboardException>>> exceptionsProvider, Func<DashboarLoadParams, Task<List<DashboardFeatureByCount>>> mostUsedFeaturesProvider, Func<DashboarLoadParams, Task<List<DashboardFeatureByCount>>> leastUsedFeaturesProvider, Func<DashboarLoadParams, Task<List<DashboardFeatureByTime>>> slowestFeaturesProvider) { if (featureContext == null) throw new ArgumentNullException(nameof(featureContext)); if (settingsProvider == null) throw new ArgumentNullException(nameof(settingsProvider)); if (commonDataProvider == null) throw new ArgumentNullException(nameof(commonDataProvider)); if (usersProvider == null) throw new ArgumentNullException(nameof(usersProvider)); if (versionsProvider == null) throw new ArgumentNullException(nameof(versionsProvider)); if (exceptionsProvider == null) throw new ArgumentNullException(nameof(exceptionsProvider)); if (mostUsedFeaturesProvider == null) throw new ArgumentNullException(nameof(mostUsedFeaturesProvider)); if (leastUsedFeaturesProvider == null) throw new ArgumentNullException(nameof(leastUsedFeaturesProvider)); if (slowestFeaturesProvider == null) throw new ArgumentNullException(nameof(slowestFeaturesProvider)); var settings = await settingsProvider(featureContext); var dataProvider = await commonDataProvider(featureContext); var loadParams = new DashboarLoadParams(featureContext, settings, dataProvider); this.Users = await usersProvider(loadParams); this.Versions = await versionsProvider(loadParams); this.Exceptions = await exceptionsProvider(loadParams); this.MostUsedFeatures = await mostUsedFeaturesProvider(loadParams); this.LeastUsedFeatures = await leastUsedFeaturesProvider(loadParams); this.SlowestFeatures = await slowestFeaturesProvider(loadParams); }
public DashboarLoadParams(FeatureContext featureContext, DashboardSettings settings, DashboardCommonData data) { if (featureContext == null) throw new ArgumentNullException(nameof(featureContext)); if (settings == null) throw new ArgumentNullException(nameof(settings)); if (data == null) throw new ArgumentNullException(nameof(data)); this.FeatureContext = featureContext; this.Settings = settings; this.Data = data; }
private async void DashboardScreenLoaded(object sender, RoutedEventArgs e) { var core = AppContextObsolete.AppContext; var feature = Feature.StartNew(@"Dashboard", @"Load"); try { using (var featureContext = new FeatureContext(core, feature)) { await this.ViewModel.LoadAsync(featureContext, DashboardDataProvider.GetSettingsAsync, DashboardDataProvider.GetCommonDataAsync, DashboardDataProvider.GetUsersAsync, DashboardDataProvider.GetVersionsAsync, DashboardDataProvider.GetExceptionsAsync, DashboardDataProvider.GetMostUsedFeaturesAsync, DashboardDataProvider.GetLeastUsedFeaturesAsync, DashboardDataProvider.GetSlowestFeaturesAsync); } } catch (Exception ex) { core.Log(ex.ToString(), LogLevel.Error); core.FeatureManager.Write(feature, ex); } }
public static Task<DashboardCommonData> GetCommonDataAsync(FeatureContext featureContext) { if (featureContext == null) throw new ArgumentNullException(nameof(featureContext)); { var contexts = new Dictionary<long, DbFeatureContextRow>(); var features = new Dictionary<long, DbFeatureRow>(); var dbContext = featureContext.DbContext; dbContext.Fill(contexts, (r, map) => { var row = new DbFeatureContextRow(r.GetInt32(0), r.GetString(1)); map.Add(row.Id, row); }, new Query(@"SELECT ID, NAME FROM FEATURE_CONTEXTS")); dbContext.Fill(features, (r, map) => { var row = new DbFeatureRow(r.GetInt32(0), r.GetString(1), r.GetInt32(2)); map.Add(row.Id, row); }, new Query(@"SELECT ID, NAME, CONTEXT_ID FROM FEATURES")); return Task.FromResult(new DashboardCommonData(contexts, features)); } }
public static Task<DashboardSettings> GetSettingsAsync(FeatureContext featureContext) { if (featureContext == null) throw new ArgumentNullException(nameof(featureContext)); var feature = featureContext.Feature; { var maxUsers = default(int?); var maxMostUsedFeatures = default(int?); var log = featureContext.AppContext.Log; // TODO : Load settings from db for the context var contextForSettings = nameof(Dashboard); var settings = new List<Setting>(); foreach (var setting in settings) { var name = setting.Name; var value = setting.Value; if (name.Equals(nameof(DashboardSettings.MaxUsers), StringComparison.OrdinalIgnoreCase)) { maxUsers = ValueParser.ParseInt(value, log); break; } if (name.Equals(nameof(DashboardSettings.MaxMostUsedFeatures), StringComparison.OrdinalIgnoreCase)) { maxMostUsedFeatures = ValueParser.ParseInt(value, log); break; } } if (maxUsers == null) { log($@"Unable to find value for '{nameof(DashboardSettings.MaxUsers)}'", LogLevel.Warn); } if (maxMostUsedFeatures == null) { log($@"Unable to find value for '{nameof(DashboardSettings.MaxMostUsedFeatures)}'", LogLevel.Warn); } return Task.FromResult(DashboardSettings.Default); } }