/// <summary> /// Execute synchronizer /// </summary> /// <returns></returns> public bool Update() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); string status = ": NOK"; using (new Logger.LogCallWrapper(ODataClientMethodName)) { try { LoadAndParseODataClientMethod(); using (var tran = new TransactionScope(TransactionScopeOption.RequiresNew, Utilities.GetDefaultIsolationLevel())) { using (var db = new EntityDbMock()) { db.Database.CommandTimeout = Settings.TimeOut; UpdateDatabase(db); db.SaveChanges(); } tran.Complete(); } status = ": OK"; return(true); } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder("DbEntityValidationException").AppendLine(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } Logger.LogException(ex, sb.ToString()); } catch (Exception ex) { Logger.LogException(ex); } finally { watch.Stop(); Console.WriteLine(string.Format(SynchronizerResource.EndProcessing, string.Format("{0} {1} in {2}ms", ODataClientMethodName.PadRight(20), status, watch.ElapsedMilliseconds))); Logger.LogTrace(string.Format(SynchronizerResource.EndProcessing, ODataClientMethodName)); } return(false); } }
protected override void UpdateDatabase(EntityDbMock db) { IList <LVCurrency> dbCurrencies = db.LVCurrencies.ToList(); foreach (var dbCurrency in dbCurrencies) { ExchangeRateModel updatedCurrency; if (parsedData.TryGetValue(dbCurrency.AlphabeticCode, out updatedCurrency)) { dbCurrency.ExchangeRate = Convert.ToDecimal(updatedCurrency.Value.Value, new CultureInfo("en-US")); dbCurrency.RateDate = updatedCurrency.RateDate != null ? updatedCurrency.RateDate.Value : (DateTime?)null; dbCurrency.IsDeleted = updatedCurrency.IsDeleted; parsedData.Remove(dbCurrency.AlphabeticCode); } else { dbCurrency.IsDeleted = true; } } int nextDisplayOrder = dbCurrencies.Count; //new currencies: foreach (var updatedCurrency in parsedData) { db.LVCurrencies.Add(new LVCurrency() { AlphabeticCode = updatedCurrency.Value.Code, Symbol = null, NumericCode = 0, RateDate = updatedCurrency.Value.RateDate, ExchangeRate = Convert.ToDecimal(updatedCurrency.Value.Value), DisplayOrder = nextDisplayOrder++, Description = updatedCurrency.Value.Name, IsDeleted = updatedCurrency.Value.IsDeleted, }); } IQuoteCalculationStatusDS domainService = new QuoteCalculationStatusDS(db); domainService.SetAllCreatedAsNotCalculated("ODataClient"); }