/// <summary> /// Find is getting data from remote (redis) storage. After this /// it writes updated version of data into locaL (litedb) storage /// </summary> /// <param name="key"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> private T Find <T>(string key) { var liteDbService = new LiteDbService(); var dynamicConfig = new DynamicConfig { ApplicationName = ApplicationName, Name = key, IsActive = 1 }; var configurationReaderFactory = new ConfigurationServiceFactory(); var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString); var redisResult = reader.Read <DynamicConfig>(dynamicConfig); // If redis result fits with requested data type if (redisResult?.Value is T) { liteDbService.RemoveConfig(key); liteDbService.AddConfig(redisResult); return((T)Convert.ChangeType(redisResult.Value, typeof(T))); } return(default(T)); }
public static void UpdateDataBase(LiteDbService <Country> db, IEnumerable <Country> countries) { db.DeleteAll(); foreach (var item in countries) { db.UpsertItem(item); } }
public static void Main() { Application.Init(); LiteDbService.Inicializar(); var fichario = new Fichario(); var controleDados = new Controlador(fichario); JanelaPrincipal.Criar(controleDados, Application.Top); Application.Run(); }
/// <summary> /// GetValue is getting data from local (litedb) storage. If it can't find /// any results from local storage, it checks from remote (redis) storage periodically. /// </summary> /// <param name="key">Key section of configuration data</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetValue <T>(string key) { try { // Checking is application trying to access authorized config if (ApplicationName == ReferencedApp) { var liteDbService = new LiteDbService(); // Creating new scheduled service with specified time interval. Task.Factory.StartNew(() => { var isCancelled = _cancellationToken.IsCancellationRequested; if (!isCancelled) { // ConfigFunc is creating job with status async Task <bool> ConfigFunc() { return(await ConfigJob(key, TimeSpan.FromMilliseconds(RefreshTimerIntervalInMs))); } // Worker is taking job function to use with time interval ConfigJobWorker( ConfigFunc, TimeSpan.FromMilliseconds(RefreshTimerIntervalInMs), _cancellationToken); } }, _cancellationToken); var currentConfig = liteDbService.GetConfig(ApplicationName + "." + key); if (currentConfig != null) { if (currentConfig.Value is T) { return((T)Convert.ChangeType(currentConfig.Value, typeof(T))); } return(default(T)); } return(Find <T>(key)); } return(default(T)); } catch (Exception e) { Console.WriteLine(e); return(default(T)); } }
public SearchCountryViewModel(IRestService restService) { _service = restService; ClosePopUpCommand = new Command(async() => await ExecuteClosePopUpCommand()); ItemTresholdReachedCommand = new Command(async() => await ExecuteItemTresholdReachedCommand()); SearchCountryCommand = new Command(ExecuteSearchCountryCommand); CountrySelectedCommand = new Command <Country>(async(args) => await ExecuteCountrySelectedCommand(args)); Countries = new ObservableCollection <Country>(); _db = new LiteDbService <Country>(); CurrentPage = 2; ItemTreshold = 1; SetDarkTheme(); }
public MainPageViewModel(IRestService restService) { _service = restService; _dbGlobal = new LiteDbService <GlobalTotals>(); _db = new LiteDbService <Country>(); ChangeCountryCommand = new Command(async(args) => await ExecuteChangeCountryCommand()); RefreshGlobalCommand = new Command(async() => await ExecuteRefreshGlobalCommand()); RefreshCountryCommand = new Command(async() => await ExecuteRefreshCountryCommand()); NavigateToSearchCountryCommand = new Command(async() => await ExecuteNavigateToSearchCountryCommand()); NavigateToReadMorePageCommand = new Command(async() => await ExecuteNavigateToReadMorePageCommand()); ShowChangeLanguagePagePopUpCommand = new Command(async() => await ExecuteShowChangeLanguagePagePopUpCommand()); ChangeThemeAppCommand = new Command(ExecuteChangeThemeAppCommand); GetAppVersion(); }
/// <summary> /// ConfigJob is the definition of scheduled job of worker. /// It's comparing local (litedb) data with remote (redis) storage data. Also it's /// making neccessary updates on local. /// </summary> /// <param name="key"></param> /// <param name="refreshTimerIntervalInMs"></param> /// <returns></returns> private async Task <bool> ConfigJob(string key, TimeSpan refreshTimerIntervalInMs) { var isCancelled = _cancellationToken.IsCancellationRequested; // if task not cancelled if (!isCancelled) { await Task.Delay(refreshTimerIntervalInMs, _cancellationToken); var liteDbService = new LiteDbService(); var dynamicConfig = new DynamicConfig { ApplicationName = ApplicationName, Name = key, IsActive = 1 }; var configurationReaderFactory = new ConfigurationServiceFactory(); var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString); var redisResult = reader.Read <DynamicConfig>(dynamicConfig); var liteDbResult = liteDbService.GetConfig(key); if (redisResult != null && liteDbResult != null) { // Comparing data changes if (redisResult.Value != liteDbResult.Value) { liteDbService.RemoveConfig(key); liteDbService.AddConfig(redisResult); return(true); } } } return(false); }