protected void OnSavingPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is Entity) { switch (e.PropertyName) { case "Name": case "Description": case "Value": case "StartingBalance": var saving = sender as Saving; var savingValue = sender as SavingValue; if (saving != null) { UpdateSaving(saving, true); } if (savingValue != null) { Save(savingValue); savingValue.Saving.Refresh(); CachedService.Clear(CachedServiceKeys.AllSavings); CachedService.Clear(CachedServiceKeys.AllIncomes); } break; } } }
private void LoadIncomes() { var incomeValues = Database.Query <IncomeValue, Income, Budget>(PetaPoco.Sql.Builder .Select("*") .From("IncomeValue") .InnerJoin("Income") .On("Income.Id = IncomeValue.IncomeId") .InnerJoin("Budget") .On("Budget.Id = IncomeValue.BudgetId") .Where("IncomeValue.BudgetId = @0", Budget.Id)).ToList(); BudgetIncomeValues.IsNotifying = false; BudgetIncomeValues.Clear(); incomeValues.ForEach(x => BudgetIncomeValues.Add(x)); AvailableIncomes.Clear(); AvailableIncomes.AddRange(CachedService.GetAllIncomes()); IncomeValueDate = DateTime.Now; IncomeValueValue = 0; SelectedAvailableIncome = null; BudgetIncomeValues.IsNotifying = true; BudgetIncomeValues.Refresh(); }
private void ReorderCashFlowGroup(CashFlowGroup itemToReorder, int placeAtIndex) { var itemsCopy = CashFlowGroups.ToList(); var itemToReorderIndex = itemsCopy.IndexOf(itemToReorder); if (itemToReorderIndex < 0 || itemToReorderIndex == placeAtIndex) { return; } SuppressEvent = true; itemsCopy.Insert(placeAtIndex, itemToReorder); if (placeAtIndex > itemToReorderIndex) { itemsCopy.RemoveAt(itemToReorderIndex); } else { itemsCopy.RemoveAt(itemToReorderIndex + 1); } int position = 1; itemsCopy.ForEach(x => x.Position = position++); using (var tx = Database.GetTransaction()) { Database.SaveAll(itemsCopy); tx.Complete(); } NotifyOfPropertyChange(() => CashFlowGroups); CachedService.Clear(CachedServiceKeys.AllCashFlowGroups); SuppressEvent = false; }
private bool DatabaseVerification() { var dbHelper = new DatabaseBackupHelper(); int applicationDatabaseVersion = 2; int currentDatabaseVersion = ConfigurationManager.GetValueOrDefault <int>(ConfigurationKeys.DatabaseVersion); if (currentDatabaseVersion == applicationDatabaseVersion) { dbHelper.CreateBackup(); return(true); } try { dbHelper.CreateBackup(); DatabaseUpdateHelper.UpdateIfNeeded(Database, currentDatabaseVersion); ConfigurationManager.Clear(); CachedService.Clear(); return(true); } catch (Exception ex) { var message = new StringBuilder(); message.AppendLine(string.Format("Błąd aktualizacji bazy danych do wersji {0}.", applicationDatabaseVersion)); message.AppendLine(); message.AppendLine(ex.Message); ShowMessage(message.ToString(), () => { TryClose(); }, null, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
public InfoWarningErrorMessageController() { Current.ServiceChanged += EhServiceChanged; _unreversedDoc = new ObservableCollection <InfoWarningErrorTextMessageItem>(); _reversedDoc = new Collections.ObservableCollectionReversingWrapper <InfoWarningErrorTextMessageItem>(_unreversedDoc); _currentDoc = _unreversedDoc; _commandClearAllMessages = new RelayCommand(EhClearAllMessages); _commandReverseMessages = new RelayCommand(EhReverseAllMessages); _shutDownService = new CachedService <IShutdownService, IShutdownService>(false, (shutdownService) => shutdownService.Closed += EhApplicationClosed, (shutdownService) => shutdownService.Closed -= EhApplicationClosed); _shutDownService.StartCaching(); var memento = Current.PropertyService.GetValue(PropertyKeyMessageControlState, RuntimePropertyKind.UserAndApplicationAndBuiltin, () => null); if (null != memento) { SetMemento(memento); } EhServiceChanged(); }
public async Task ServiceTest() { var serviceInfo = new CalledServiceInfo { Name = "Service", Id = Guid.NewGuid(), Endpoint = "Endpoint", CircuitBreakerInfo = new CircuitBreakerInfo { ExceptionCount = 1, BreakDuration = TimeSpan.FromMilliseconds(1) }, Timeout = TimeSpan.FromMilliseconds(100) }; var httpClientResponse = new HttpClientResponse { HttpStatusCode = HttpStatusCode.NoContent, Response = "" }; var cacheRegion = "cacheRegion"; var cache = Substitute.For <ICache>(); var httpClientWrapper = Substitute.For <IHttpClientWrapper>(); var tokenService = Substitute.For <ITokenService>(); httpClientWrapper.PostAsync(serviceInfo.Endpoint, null, CancellationToken.None).ReturnsForAnyArgs(httpClientResponse); var sut = new CachedService(cache, httpClientWrapper, tokenService); ServiceResponse actual = await sut.CallService(serviceInfo, cacheRegion, CancellationToken.None, null); Assert.AreEqual(ServiceResponseStatus.Success, actual.Status); }
public CashFlowTypesViewModel(IShellViewModel shell, IDatabase database, IConfigurationManager configuration, ICachedService cashedService, IEventAggregator eventAggregator) : base(shell, database, configuration, cashedService, eventAggregator) { SuppressEvent = false; _cashFlows = new BindableCollectionExt <CashFlow>(); _cashFlows.PropertyChanged += (s, e) => { OnPropertyChanged(s, e); CachedService.Clear(CachedServiceKeys.AllCashFlows); }; _cashFlowGroups = new BindableCollectionExt <CashFlowGroup>(); _cashFlowGroups.PropertyChanged += (s, e) => { if (SuppressEvent == true) { return; } OnPropertyChanged(s, e); CachedService.Clear(CachedServiceKeys.AllCashFlowGroups); CachedService.Clear(CachedServiceKeys.AllCashFlows); var cashFlowGroup = s as CashFlowGroup; _cashFlows.Where(x => x.CashFlowGroupId == cashFlowGroup.Id) .ForEach(x => x.Group = cashFlowGroup); NewCashFlowGroup = null; NewCashFlowGroup = CashFlowGroups.First(); }; }
public void AddNewCashFlowGroup() { using (var tx = Database.GetTransaction()) { int maxPosition = 1; if (Database.Count <CashFlowGroup>() > 0) { maxPosition = Database.ExecuteScalar <int>("SELECT MAX(Position) FROM CashFlowGroup"); } var cashFlowGroup = new CashFlowGroup { Name = NewGroupName, Description = NewGroupDescription, Position = maxPosition + 1, }; Database.Save(cashFlowGroup); tx.Complete(); _cashFlowGroups.Add(cashFlowGroup); } CachedService.Clear(); NewGroupName = string.Empty; NewGroupDescription = string.Empty; //LoadData(); IsNewGroupNameFocused = false; IsNewGroupNameFocused = true; NotifyOfPropertyChange(() => CashFlowGroups); }
public void DeleteCashFlowType(CashFlow cashFlow, bool omitConfirmation) { if (!omitConfirmation) { var hasBudgetPlansDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder .Select("COUNT(*)") .From("BudgetPlan") .Where("CashFlowId = @0", cashFlow.Id)) > 0; var hasExpensesDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder .Select("COUNT(*)") .From("Expense") .Where("CashFlowId = @0", cashFlow.Id)) > 0; if (hasBudgetPlansDefined || hasExpensesDefined) { Shell.ShowDialog <CashFlowDeleteConfirmationViewModel>(new { CashFlow = cashFlow }, () => DeleteCashFlowType(cashFlow, true), null); return; } } using (var tx = Database.GetTransaction()) { Database.Delete <BudgetPlan>("WHERE CashFlowId = @0", cashFlow.Id); Database.Delete <SavingValue>("WHERE ExpenseId IN (SELECT [Expense].Id FROM [Expense] WHERE CashFlowId = @0)", cashFlow.Id); Database.Delete <Expense>("WHERE CashFlowId = @0", cashFlow.Id); Database.Delete <CashFlow>(cashFlow); tx.Complete(); _cashFlows.Remove(cashFlow); } CachedService.Clear(); NotifyOfPropertyChange(() => CashFlows); //LoadData(); }
protected override void OnActivate() { if (!DatabaseVerification()) { return; } CachedService.LoadAll(); ShowCurrentBudget(); int updateIntervalMinutes = ConfigurationManager.GetValueOrDefault(ConfigurationKeys.UpdateMinutesInterval, 15); _timer.Interval = updateIntervalMinutes * 60 * 1000; if (ConfigurationManager.GetValueOrDefault <bool>(ConfigurationKeys.IsFirstRun, true)) { var message = new StringBuilder(); message.AppendLine("Witaj w programie Budżet Domowy"); message.AppendLine(); message.AppendLine("W pierwszej kolejności wprowadź dane dotyczące źródeł dochodów"); message.AppendLine("oraz ewentualnych kont oszczędnościowych itp. Aby to zrobić"); message.AppendLine("kliknij na przycisk 'Środki zewnętrzne' na górze ekranu."); message.AppendLine(); message.AppendLine("Aby dowiedzieć się jak korzystać z programu kliknij na"); message.AppendLine("ikonkę pomocy umieszczoną w prawym górnym rogu ekranu."); ShowMessage(message.ToString()); ConfigurationManager.SaveValue(ConfigurationKeys.IsFirstRun, false); } CheckForUpdates(false); }
private void LoadOrCreateDefaultBudget() { Diagnostics.Start(); using (var tx = Database.GetTransaction()) { var cashFlowList = CachedService.GetAllCashFlows(); var sql = PetaPoco.Sql.Builder .Select("*") .From("Budget") .Where("@0 BETWEEN DateFrom AND DateTo", BudgetDate.Date); Budget = Database.FirstOrDefault <Budget>(sql); if (Budget == null) { Budget = Budget.CreateEmptyForDate(BudgetDate, cashFlowList); Database.Save(Budget); } tx.Complete(); PublishRefreshRequest(Budget); } Budget.PropertyChanged += (s, e) => { Save(s as Budget); }; Diagnostics.Stop(); }
public override void LoadData() { CashFlowGroups.Clear(); var cashFlowList = CachedService.GetAllCashFlowGroups().Where(x => x.Id != CashFlowGroupToDelete.Id); cashFlowList.ForEach(x => CashFlowGroups.Add(x)); SelectedCashFlowGroup = CashFlowGroups.FirstOrDefault(); }
public void RemoveSavingValue(SavingValue savingValue) { using (var tx = Database.GetTransaction()) { Database.Delete(savingValue); tx.Complete(); CachedService.Clear(CachedServiceKeys.AllSavings); } LoadSavingsData(); }
public WordApiController(ILogger <WordApiController> logger, IWordService wordService, CachedService <NewWord> cachedService, IMapper mapper) { _logger = logger; _wordService = wordService; _cachedService = cachedService; _mapper = mapper; }
private void DeleteSaving(Saving saving) { using (var tx = Database.GetTransaction()) { Database.Delete(saving.CashFlow); Database.Delete(saving); tx.Complete(); CachedService.Clear(CachedServiceKeys.AllSavings); CachedService.Clear(CachedServiceKeys.AllCashFlows); } }
public override object Get(string groupName, string key) { if (!CachedService.ContainsKey(groupName)) { if (null != _logger) { _logger.WarnFormat("the grouopname:{0} is not exist", groupName); } throw new Exception("No exist the cached group name."); } return(CachedService[groupName].Get(key)); }
public ExampleApiController(ILogger <ExampleApiController> logger, IWordService wordService, IExampleService exampleService, CachedService <ExampleDto> cachedService, IMapper mapper) { _logger = logger; _wordService = wordService; _exampleService = exampleService; _cachedService = cachedService; _mapper = mapper; }
public override void Remove(string groupName) { if (!CachedService.ContainsKey(groupName)) { if (null != _logger) { _logger.WarnFormat("the grouopname:{0} is not exist", groupName); } throw new Exception("No exist the cached group name."); } CachedService[groupName].Remove(); }
public override void Update(string groupName, string key, object value, int seconds) { if (!CachedService.ContainsKey(groupName)) { if (null != _logger) { _logger.WarnFormat("the grouopname:{0} is not exist", groupName); } throw new Exception("No exist the cached group name."); } CachedService[groupName].Update(key, value, seconds); }
public void AddIncome() { string incomeDefaultName = CreateUniqueName("Dochody", Incomes.Select(x => x.Name).ToList()); var income = new Income { Name = incomeDefaultName, }; Save(income); CachedService.Clear(CachedServiceKeys.AllIncomes); LoadIncomesData(); }
private void SaveEquation(BudgetCalculatorEquation budgetCalculatorEquation) { using (var tx = Database.GetTransaction()) { Database.Save(budgetCalculatorEquation); var itemsToDelete = EquationToEdit.Items.Where(x => !budgetCalculatorEquation.Items.Any(y => x.Id == y.Id)); itemsToDelete.ForEach(x => Database.Delete(x)); Database.SaveAll(budgetCalculatorEquation.Items); tx.Complete(); CachedService.Clear(CachedServiceKeys.AllEquations); PublishRefreshRequest(budgetCalculatorEquation); } }
private void DeleteRevenue(Entity entity) { Delete(entity); if (entity is IncomeValue) { CachedService.Clear(CachedServiceKeys.AllIncomes); } if (entity is SavingValue) { CachedService.Clear(CachedServiceKeys.AllSavings); } RefreshSummaryValues(); }
private void DeleteEquation(BudgetCalculatorEquation equation) { using (var tx = Database.GetTransaction()) { // delete all related equations var equationsDeletedCounter = Database.Execute("DELETE FROM BudgetCalculatorEquation WHERE Id IN (SELECT BudgetCalculatorEquationId FROM BudgetCalculatorItem WHERE ForeignId = @0 AND ValueTypeName = 'CalculatorEquationValue')", equation.Id); Database.Execute("DELETE FROM BudgetCalculatorItem WHERE ForeignId = @0 AND ValueTypeName = 'CalculatorEquationValue'", equation.Id); Database.Execute("DELETE FROM BudgetCalculatorItem WHERE BudgetCalculatorEquationId = @0", equation.Id); Database.Delete(equation); tx.Complete(); CachedService.Clear(CachedServiceKeys.AllEquations); PublishRefreshRequest(equation); } }
private void LoadCashFlowGroups() { _cashFlowGroups.IsNotifying = false; _cashFlowGroups.Clear(); var cashFlowGroups = CachedService.GetAllCashFlowGroups(); cashFlowGroups.ForEach(x => _cashFlowGroups.Add(x)); _cashFlowGroups.IsNotifying = true; NewCashFlowGroup = CashFlowGroups.First(); NotifyOfPropertyChange(() => CashFlowGroups); }
private void UpdateSaving(Saving saving, bool updateCashFlow = false) { using (var tx = Database.GetTransaction()) { Database.Update(saving); if (updateCashFlow) { saving.CashFlow.Name = saving.Name; Database.Update(saving.CashFlow); } tx.Complete(); CachedService.Clear(CachedServiceKeys.AllSavings); CachedService.Clear(CachedServiceKeys.AllCashFlows); } }
private void LoadIncomesData() { Incomes.Clear(); var incomesList = CachedService.GetAllIncomes(); incomesList.ForEach(x => { Incomes.Add(x); x.PropertyChanged += (s, e) => { Save(x); CachedService.Clear(CachedServiceKeys.AllIncomes); }; }); }
static void Main(string[] args) { ICacheService service = new CachedService(); service.SaveData(new TestObject() { Id = 1, Name = "Test", InnerObject = new InnerObject { Amount = 2, Customer = "Customer" } }); service.SaveData(new TestObject() { Id = 2, Name = "Test2", InnerObject = new InnerObject { Amount = 3, Customer = "Customer2" } }); service.SaveData(new TestObject() { Id = 3, Name = "Test3", InnerObject = new InnerObject { Amount = 3, Customer = "Customer3" } }); var getData = service.GetData(1); Console.WriteLine($"{getData.Id}-{getData.Name}"); var getData2 = service.GetData(2); Console.WriteLine($"{getData2.Id}-{getData2.Name}"); var getData3 = service.GetData(1); Console.WriteLine($"{getData3.Id}-{getData3.Name}"); Console.ReadLine(); }
private void LoadSavingsData() { Savings.Clear(); var savingsList = CachedService.GetAllSavings(); savingsList.ForEach(x => { Savings.Add(x); var notifyPropertyChanged = (x.Values as BindableCollectionExt <SavingValue>); if (notifyPropertyChanged != null) { notifyPropertyChanged.PropertyChanged += OnSavingPropertyChanged; } }); }
private void SwapPositions(CashFlowGroup first, CashFlowGroup secound) { first.IsNotifying = false; secound.IsNotifying = false; var firstPosition = first.Position; first.Position = secound.Position; secound.Position = firstPosition; first.IsNotifying = true; secound.IsNotifying = true; base.Save(first); base.Save(secound); CachedService.Clear(); NotifyOfPropertyChange(() => CashFlowGroups); }
private void LoadCashFlows() { Diagnostics.Start(); ExpensesGridCashFlows.IsNotifying = false; ExpensesGridCashFlows.Clear(); CashFlows.Clear(); var cashFlowList = CachedService.GetAllCashFlows(); cashFlowList.ForEach(x => ExpensesGridCashFlows.Add(x)); cashFlowList.ForEach(x => CashFlows.Add(x)); ExpensesGridCashFlows.IsNotifying = true; SelectedExpenseCashFlow = CashFlows.FirstOrDefault(); NotifyOfPropertyChange(() => ExpensesGridCashFlows); Diagnostics.Stop(); }