public void Upgrade() { IDictionary <Version, MemberInfo> upgradingMethods = HelperStuff.GetAvailableDatabaseUpgradeMethods(this._member); IList <MemberInfo> beforeUpgradeMethods = HelperStuff.GetBeforeUpgradeMethods(this._member); IList <MemberInfo> afterUpgradeMethods = HelperStuff.GetAfterUpgradeMethods(this._member); logger.Debug("Starting transaction."); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew)) { Version versionOfDatabase = GetVersionOfDatabase(); logger.Debug("Current version of database is {versionOfDatabase}.", versionOfDatabase); Version versionOfLibrary = HelperStuff.GetVersionOfLibrary(this._member); logger.Debug("Current version of library is {versionOfLibrary}.", versionOfLibrary); var methodsForProcessing = upgradingMethods .Where(m => m.Key > versionOfDatabase && m.Key <= versionOfLibrary) .OrderBy(m => m.Key); foreach (var item in beforeUpgradeMethods) { logger.Debug("Running Before Upgrade method with Name: {beforeUpgradeMethods}.", item.Name); HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item, this); } foreach (var item in methodsForProcessing) { logger.Debug("Running Upgrade method {methodName} {methodVersion}", item.Value.Name, item.Key.ToString(4)); HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item.Value, this); } foreach (var item in afterUpgradeMethods) { logger.Debug("Running Upgrade method {afterUpgradeMethods} ", item.Name); HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item, this); } // if there was some update, set version if (methodsForProcessing.Count() > 0) { // should I place here upgrade method version or library version??? // for now I'm using method version, 'cause it can be added new method for version and not incrementing library version (which is weird, but ...) Version upgradedToVersion = methodsForProcessing.Last().Key; logger.Info("Writing new database version {upgradedToVersion}.", upgradedToVersion.ToString(4)); SetVersionOfDatabase(upgradedToVersion); } logger.Debug("Commiting transaction."); ts.Complete(); if (this._connection.State != ConnectionState.Closed) { this._connection.Close(); } } }
protected virtual TResult GetDataFromContentFunction() { TResult data = default(TResult); if (this.contentInfo.Function == null) { Logger.Info("Starting GetDataFromContentFunction : No contentFunction for type " + typeof(TResult).ToString()); return(data); } try { Logger.Debug("Starting GetDataFromContentFunction for type " + typeof(TResult).ToString()); data = this.contentInfo.Function(this.contentInfo.Parameters); this.contentInfo.DataLoaded = DateTime.Now; Logger.Debug("Finished GetDataFromContentFunction for type " + typeof(TResult).ToString()); return(data); } catch (Exception e) { Logger.Error("Get Content from ContentFunction call error", e); return(data); } }
private void Cleaning_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { int iteration = 0; startAgain: ESTraceLogger.Debug($"ElasticCacheProvider Cleaning_Elapsed: Starting (iteration {iteration})"); //find expired keys var res = client .Search <Bag <T> >(s => s .Query(q => q .DateRange(dr => dr.LessThan(DateTime.Now).Field(f => f.ExpirationTime)) ) .Source(false) .Size(9000) ); if (res.IsValid) { ESTraceLogger.Info($"ElasticCacheProvider Cleaning_Elapsed: Successfull query. Found {res.Total} records to delete"); Devmasters.Batch.Manager.DoActionForAll <string>(res.Hits.Select(m => m.Id), id => { ESTraceLogger.Debug($"ElasticCacheProvider Cleaning_Elapsed: removing record {id}"); Remove(id); return(new Batch.ActionOutputData() { }); }, true); } ESTraceLogger.Debug($"ElasticCacheProvider Cleaning_Elapsed: End (iteration {iteration})"); if (res.Total > 9100 && iteration < 10) { iteration++; goto startAgain; } }