public void SaveDeck(ITracker tracker, SerializableVersion versionIncrease, IEnumerable <CardInstance> cardsCollection) { ErrorMessage = String.Empty; if (Deck.Class == null) { ErrorMessage = "Please select deck class"; return; } if (versionIncrease == new SerializableVersion(0, 0)) { //overwrite //we were working on current version - do nothing } else { //save current cards List <CardInstance> cards = new List <CardInstance>(Deck.SelectedVersion.Cards); //undo changes in curr version //Deck.SelectedVersion points to curret latest Deck.SelectedVersion.Cards = savedState.History.Where(dv => dv.VersionId == Deck.SelectedVersionId).First().Cards; //create new verson wih new cards int major, minor; if (versionIncrease.Major == 1) { major = versionIncrease.Major + GetMaxMajor(); minor = 0; } else if (versionIncrease.Minor == 1) { major = Deck.SelectedVersion.Version.Major; minor = versionIncrease.Minor + GetMaxMinor(major); } else { throw new ArgumentOutOfRangeException(nameof(versionIncrease), "Method accepts only version increase by 0 or 1"); } Deck.CreateVersion( major, minor, trackerFactory.GetDateTimeNow()); //now Deck.SelectedVersion points to new version foreach (CardInstance ci in cards) { Deck.SelectedVersion.Cards.Add((CardInstance)ci.Clone()); } } if (!tracker.Decks.Contains(this.Deck)) { tracker.Decks.Add(this.Deck); } trackerFactory.GetFileManager().SaveDatabase(); this.EndEdit(); messanger.Send(new Utils.Messages.EditDeck() { Deck = this.Deck }, Utils.Messages.EditDeck.Context.EditFinished); }
public ICardsDatabase GetLatestCardsDB() { string url = settings.VersionCheck_CardsDBUrl; ICardsDatabase returnValue = null; var requestErrorPolicy = Policy .Handle <System.Net.WebException>() .Fallback( () => { returnValue = trackerFactory.GetService <ICardsDatabase>(); }, (ex, context) => { Logger.Trace(ex, "Exception when retreiving cards DB from {0}", url); Logger log = LogManager.GetLogger(App.UserInfoLogger); log.Info(ex.Message); } ); requestErrorPolicy.Execute(() => { Logger.Trace("Start retreiving cards DB from {0}", url); IHTTPService httpService = trackerFactory.GetService <IHTTPService>(); string cardsDBContent = httpService.SendGetRequest(url); ICardsDatabase cardsDB = trackerFactory.GetFileManager().UpdateCardsDB(cardsDBContent); Logger.Trace("Finished retreiving cards DB from {0}", url); returnValue = cardsDB; }); return(returnValue); }
public void CommandButtonCreateExecute(object parameter) { GameOutcome?outcome = EnumManager.ParseEnumString <GameOutcome>(parameter as string); this.ErrorMessage = null; if (tracker.ActiveDeck == null) { this.ErrorMessage += "Please select active deck" + Environment.NewLine; } if (!this.Game.OpponentClass.HasValue) { this.ErrorMessage += "Please select opponent class" + Environment.NewLine; } this.ErrorMessage = this.ErrorMessage?.Trim(); if ((tracker.ActiveDeck != null) && (outcome.HasValue) && this.Game.OpponentClass.HasValue) { UpdateGameData(outcome); DataModel.Game addedGame = this.Game; tracker.Games.Add(this.Game); messanger.Send( new Utils.Messages.EditDeck() { Deck = game.Deck }, Utils.Messages.EditDeck.Context.StatsUpdated); trackerFactory.GetFileManager().SaveDatabase(); this.Game = new DataModel.Game(); //restore values that are likely the same, like game type, player rank etc this.Game.Type = addedGame.Type; this.Game.PlayerRank = addedGame.PlayerRank; this.Game.PlayerLegendRank = addedGame.PlayerLegendRank; this.BeginEdit(); this.UpdateBindings(); RaisePropertyChangedEvent(String.Empty); } }
private void CommandDeleteDeckExecute(EditDeck editDeck) { if (deckService.CanDelete(editDeck.Deck)) { deckService.DeleteDeck(editDeck.Deck); } trackerFactory.GetFileManager().SaveDatabase(); ApplyFilter(); }
private void CommandDeleteDeckExecute(object param) { if (deckService.CanDelete(SelectedDeck)) { deckService.DeleteDeck(SelectedDeck); } trackerFactory.GetFileManager().SaveDatabase(); ApplyFilter(); }
public void DoneClicked(object param) { var newRewards = Rewards.Where(r => !tracker.Rewards.Contains(r)); //fix up excaly same date DateTime date = trackerFactory.GetDateTimeNow(); foreach (Reward r in newRewards) { r.Date = date; } trackerFactory.GetTracker().Rewards.AddRange(newRewards); trackerFactory.GetFileManager().SaveDatabase(); Rewards.Clear(); RewardReason = null; }
public void GetLatestCardsDB() { var requestErrorPolicy = Policy .Handle <System.Net.WebException>() .Fallback(() => { /* do nothing*/ }); string url = "https://raw.githubusercontent.com/MarioZG/elder-scrolls-legends-tracker/master/ESLTracker/Resources/cards.json"; requestErrorPolicy.Execute(() => { IHTTPService httpService = (IHTTPService)trackerFactory.GetService <IHTTPService>(); string cardsDBContent = httpService.SendGetRequest(url); trackerFactory.GetFileManager().UpdateCardsDB(cardsDBContent); }); }
public void DoneClicked(object param) { var newRewards = RewardsAdded.Where(r => !tracker.Rewards.Contains(r)); //fix up excaly same date DateTime date = trackerFactory.GetDateTimeNow(); foreach (Reward r in newRewards) { r.Date = date; r.ArenaDeck = ArenaDeck; } trackerFactory.GetTracker().Rewards.AddRange(newRewards); trackerFactory.GetFileManager().SaveDatabase(); rewards.Clear(); rewards = new PropertiesObservableCollection <Reward>(CreateEmptySet(), Rewards_CollectionChanged); RewardReason = null; RefreshRewardLists(); }
public void Exit(object parameter) { bool checkIfCanClose = false; if (parameter != null && parameter is bool) { checkIfCanClose = (bool)parameter; } OverlayToolbar ot = this.OverlayWindows.GetWindowByType <OverlayToolbar>(); if (!checkIfCanClose || (checkIfCanClose && ot.CanClose(CommandExit))) { trackerFactory.GetFileManager().SaveDatabase(); MainWindow.UpdateOverlay = false; ot.Close(); settings.LastActiveDeckId = tracker.ActiveDeck?.DeckId; settings.Save(); ((App)Application.Current).CloseApplication(); } }