Exemplo n.º 1
0
        public void Store(Handnotes handnotes)
        {
            try
            {
                using (var session = ModelEntities.OpenSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var existingHandNote = session
                                               .Query <Handnotes>()
                                               .FirstOrDefault(x => x.PokersiteId == handnotes.PokersiteId && x.Gamenumber == handnotes.Gamenumber);

                        if (existingHandNote != null)
                        {
                            existingHandNote.HandTag = handnotes.HandTag;
                            existingHandNote.Note    = handnotes.Note;
                        }
                        else
                        {
                            existingHandNote = handnotes;
                        }

                        session.SaveOrUpdate(existingHandNote);
                        transaction.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Couldn't save hand notes", e);
            }
        }
Exemplo n.º 2
0
        public IList <HandHistory> GetGames(IEnumerable <long> gameNumbers, short pokersiteId)
        {
            var handHistoryParserFactory = ServiceLocator.Current.GetInstance <IHandHistoryParserFactory>();

            var handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser((EnumPokerSites)pokersiteId);

            using (var session = ModelEntities.OpenSession())
            {
                List <HandHistory> historyList = new List <HandHistory>();

                Disjunction restriction = Restrictions.Disjunction();
                restriction.Add(Restrictions.Conjunction()
                                .Add(Restrictions.On <Handhistory>(x => x.Gamenumber).IsIn(gameNumbers.ToList()))
                                .Add(Restrictions.Where <Handhistory>(x => x.PokersiteId == pokersiteId)));

                var list = session.QueryOver <Handhistory>()
                           .Where(restriction)
                           .List();

                foreach (var history in list)
                {
                    var result = handHistoryParser.ParseFullHandHistory(history.HandhistoryVal);

                    if (result == null)
                    {
                        continue;
                    }

                    historyList.Add(result);
                }

                return(historyList);
            }
        }
Exemplo n.º 3
0
        private List <IPlayer> GetAliasesListInternal()
        {
            try
            {
                using (var session = ModelEntities.OpenSession())
                {
                    var aliasesEntities = session.Query <Aliases>().Fetch(x => x.Players).ToArray();

                    var aliases = aliasesEntities.Select(x => new AliasCollectionItem
                    {
                        PlayerId       = x.AliasId,
                        Name           = x.AliasName,
                        PlayersInAlias = new ObservableCollection <PlayerCollectionItem>(x.Players.Select(p =>
                                                                                                          new PlayerCollectionItem
                        {
                            PlayerId  = p.PlayerId,
                            PokerSite = (EnumPokerSites)p.PokersiteId,
                            Name      = p.Playername
                        }))
                    }).OfType <IPlayer>().ToList();

                    return(aliases);
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Couldn't get aliases list", e);
            }

            return(new List <IPlayer>());
        }
Exemplo n.º 4
0
        public void DeletePlayerNotes(IEnumerable <Playernotes> playernotes)
        {
            if (playernotes == null || playernotes.Count() == 0)
            {
                return;
            }

            try
            {
                using (var session = ModelEntities.OpenSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var playernotesIds = playernotes.Select(x => x.PlayerNoteId).Distinct().ToArray();

                        var playernotesToDelete = session.Query <Playernotes>()
                                                  .Where(x => playernotesIds.Contains(x.PlayerNoteId))
                                                  .ToArray();

                        playernotesToDelete.ForEach(x => session.Delete(x));

                        transaction.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Could not delete player notes", e);
            }
        }
Exemplo n.º 5
0
 public Aliases GetAlias(string aliasName)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(session.Query <Aliases>().FirstOrDefault(x => x.AliasName == aliasName));
     }
 }
Exemplo n.º 6
0
 public IEnumerable <ImportedFile> GetImportedFiles(IEnumerable <string> fileNames)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(GetImportedFiles(fileNames, session));
     }
 }
Exemplo n.º 7
0
 public IList <Handnotes> GetHandNotes(short pokersiteId)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(session.Query <Handnotes>().Where(x => x.PokersiteId == pokersiteId).ToList());
     }
 }
Exemplo n.º 8
0
        private List <IPlayer> GetPlayersListInternal()
        {
            try
            {
                List <IPlayer> players = new List <IPlayer>();

                using (var session = ModelEntities.OpenSession())
                {
                    players.AddRange(session.Query <Players>().ToArray().Select(x => new PlayerCollectionItem
                    {
                        PlayerId  = x.PlayerId,
                        PokerSite = (EnumPokerSites)x.PokersiteId,
                        Name      = x.Playername
                    }));

                    return(players);
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Couldn't get player list", e);
            }

            return(new List <IPlayer>());
        }
Exemplo n.º 9
0
        public HandHistory GetGame(long gameNumber, short pokersiteId)
        {
            using (var session = ModelEntities.OpenSession())
            {
                var hh = session.Query <Handhistory>().FirstOrDefault(x => x.Gamenumber == gameNumber && x.PokersiteId == pokersiteId);

                if (hh == null)
                {
                    return(null);
                }

                var handHistoryParserFactory = ServiceLocator.Current.GetInstance <IHandHistoryParserFactory>();

                var handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser((EnumPokerSites)pokersiteId, hh.HandhistoryVal);

                var result = handHistoryParser.ParseFullHandHistory(hh.HandhistoryVal);

                if (result == null)
                {
                    return(null);
                }

                if (result.GameDescription != null)
                {
                    result.GameDescription.Site = (EnumPokerSites)pokersiteId;
                }

                return(result);
            }
        }
Exemplo n.º 10
0
        public void SaveAlias(AliasCollectionItem aliasToSave)
        {
            using (var session = ModelEntities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var playersIds = aliasToSave.PlayersInAlias.Select(x => x.PlayerId).ToArray();

                    var players = session.Query <Players>().Where(x => playersIds.Contains(x.PlayerId)).ToArray();

                    var alias = new Aliases()
                    {
                        AliasId   = aliasToSave.PlayerId,
                        AliasName = aliasToSave.Name,
                        Players   = players
                    };

                    session.SaveOrUpdate(alias);

                    transaction.Commit();

                    if (aliasToSave.PlayerId == 0)
                    {
                        aliasToSave.PlayerId = alias.AliasId;
                    }
                }
            }
        }
Exemplo n.º 11
0
 public Players GetPlayer(int playerId)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(session.Query <Players>().FirstOrDefault(x => x.PlayerId == playerId));
     }
 }
Exemplo n.º 12
0
 public Players GetPlayer(string playerName, short pokersiteId)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(session.Query <Players>().FirstOrDefault(x => x.Playername == playerName && x.PokersiteId == pokersiteId));
     }
 }
Exemplo n.º 13
0
 public Tournaments GetTournament(string tournamentId, string playerName, short pokersiteId)
 {
     using (var session = ModelEntities.OpenSession())
     {
         return(session.Query <Tournaments>().FirstOrDefault(x => x.Tourneynumber == tournamentId && x.Player.Playername == playerName && x.SiteId == pokersiteId));
     }
 }
Exemplo n.º 14
0
        public void DeleteTournament(string tournamentId, int pokerSiteId)
        {
            if (string.IsNullOrEmpty(tournamentId))
            {
                return;
            }

            try
            {
                LogProvider.Log.Info($"Deleting tournament #{tournamentId} [{(EnumPokerSites)pokerSiteId}]");

                // get all hands and players
                using (var session = ModelEntities.OpenSession())
                {
                    var tournaments = session
                                      .Query <Tournaments>()
                                      .Where(x => x.Tourneynumber == tournamentId && x.SiteId == pokerSiteId)
                                      .Fetch(x => x.Player)
                                      .ToList();

                    var handHistories = (from handHistory in session.Query <Handhistory>()
                                         where handHistory.Tourneynumber == tournamentId && handHistory.PokersiteId == pokerSiteId
                                         select new Handhistory
                    {
                        HandhistoryId = handHistory.HandhistoryId,
                        Gamenumber = handHistory.Gamenumber,
                        HandhistoryVal = string.Empty,
                        Handtimestamp = handHistory.Handtimestamp
                    }).ToList();

                    var playersHandHistories = tournaments
                                               .Select(x => x.Player.PlayerId)
                                               .Distinct()
                                               .ToDictionary(x => x, x => handHistories);

                    using (var transaction = session.BeginTransaction())
                    {
                        playerStatisticRepository.DeletePlayerStatistic(playersHandHistories);

                        tournaments.ForEach(tournament =>
                        {
                            tournament.Player.Tourneyhands -= playersHandHistories[tournament.Player.PlayerId].Count;
                            session.Update(tournament.Player);
                        });

                        handHistories.ForEach(x => session.Delete(x));
                        tournaments.ForEach(x => session.Delete(x));

                        transaction.Commit();
                    }
                }

                LogProvider.Log.Info($"Tournament #{tournamentId} [{(EnumPokerSites)pokerSiteId}] deleted.");
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Could not delete tournament ${tournamentId} [{(EnumPokerSites)pokerSiteId}].", e);
            }
        }
Exemplo n.º 15
0
        public Handhistory GetHandHistory(long gameNumber, short pokersiteId)
        {
            using (var session = ModelEntities.OpenSession())
            {
                var hh = session.Query <Handhistory>().FirstOrDefault(x => x.Gamenumber == gameNumber && x.PokersiteId == pokersiteId);

                return(hh ?? null);
            }
        }
Exemplo n.º 16
0
        public Handnotes GetHandNote(long gameNumber, short pokersiteId)
        {
            using (var session = ModelEntities.OpenSession())
            {
                var hn = session.Query <Handnotes>().FirstOrDefault(x => x.Gamenumber == gameNumber && x.PokersiteId == pokersiteId);

                return(hn);
            }
        }
Exemplo n.º 17
0
        public IEnumerable <Playernotes> GetPlayerNotes(string playerName, short pokersiteId)
        {
            using (var session = ModelEntities.OpenSession())
            {
                var playerNotes = session.Query <Playernotes>()
                                  .Where(x => x.Player.Playername == playerName && x.PokersiteId == pokersiteId)
                                  .ToArray();

                return(playerNotes);
            }
        }
Exemplo n.º 18
0
        public IEnumerable <Playernotes> GetPlayerNotes(int playerId)
        {
            using (var session = ModelEntities.OpenSession())
            {
                var playerNotes = session.Query <Playernotes>()
                                  .Where(x => x.PlayerId == playerId)
                                  .ToArray();

                return(playerNotes);
            }
        }
Exemplo n.º 19
0
        public void RemoveAlias(AliasCollectionItem aliasToRemove)
        {
            using (var session = ModelEntities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var aliasEntity = session.Load <Aliases>(aliasToRemove.PlayerId);

                    session.Delete(aliasEntity);

                    transaction.Commit();
                }
            }
        }
Exemplo n.º 20
0
 public void Store(Playernotes playernotes)
 {
     try
     {
         using (var session = ModelEntities.OpenSession())
         {
             using (var transaction = session.BeginTransaction())
             {
                 session.SaveOrUpdate(playernotes);
                 transaction.Commit();
             }
         }
     }
     catch (Exception e)
     {
         LogProvider.Log.Error(this, "Couldn't save player notes", e);
     }
 }
Exemplo n.º 21
0
 public void Store(Tournaments tournament)
 {
     try
     {
         using (var session = ModelEntities.OpenSession())
         {
             using (var transaction = session.BeginTransaction())
             {
                 session.SaveOrUpdate(tournament);
                 transaction.Commit();
             }
         }
     }
     catch (Exception e)
     {
         LogProvider.Log.Error(this, "Couldn't save tournament", e);
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Gets tournaments list for the specified ids of players
        /// </summary>
        /// <param name="playerIds"></param>
        /// <returns></returns>
        public IList <Tournaments> GetPlayerTournaments(IEnumerable <int> playerIds)
        {
            if (playerIds.IsNullOrEmpty())
            {
                return(new List <Tournaments>());
            }

            try
            {
                using (var session = ModelEntities.OpenSession())
                {
                    return(session.Query <Tournaments>().Where(x => playerIds.Contains(x.Player.PlayerId)).Fetch(x => x.Player).ToList());
                }
            }
            catch (Exception ex)
            {
                LogProvider.Log.Error(this, "Could not read tournaments", ex);
            }

            return(new List <Tournaments>());
        }
Exemplo n.º 23
0
        public IPlayer GetActivePlayer()
        {
            IPlayer activePlayer = new PlayerCollectionItem();

            string dataPath = StringFormatter.GetActivePlayerFilePath();

            if (File.Exists(dataPath))
            {
                var splittedResult = File.ReadAllText(dataPath).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                if (splittedResult.Length < 2)
                {
                    try
                    {
                        using (var session = ModelEntities.OpenSession())
                        {
                            var alias = session.Query <Aliases>().Fetch(x => x.Players).FirstOrDefault(x => x.AliasName.Equals(splittedResult[0]));

                            if (alias != null)
                            {
                                activePlayer = new AliasCollectionItem
                                {
                                    PlayerId       = alias.AliasId,
                                    Name           = alias.AliasName,
                                    PlayersInAlias = new ObservableCollection <PlayerCollectionItem>(alias.Players.Select(p =>
                                                                                                                          new PlayerCollectionItem
                                    {
                                        PlayerId  = p.PlayerId,
                                        PokerSite = (EnumPokerSites)p.PokersiteId,
                                        Name      = p.Playername
                                    }))
                                };
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LogProvider.Log.Error(this, "Couldn't get active alias", e);
                    }

                    return(activePlayer);
                }

                if (!short.TryParse(splittedResult[1], out short pokerSiteId))
                {
                    return(activePlayer);
                }

                try
                {
                    using (var session = ModelEntities.OpenSession())
                    {
                        var player = session.Query <Players>().FirstOrDefault(x => x.Playername.Equals(splittedResult[0]) && x.PokersiteId == pokerSiteId);

                        if (player != null)
                        {
                            activePlayer = new PlayerCollectionItem {
                                PlayerId = player.PlayerId, Name = player.Playername, PokerSite = (EnumPokerSites)player.PokersiteId
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    LogProvider.Log.Error(this, "Couldn't get active player", e);
                }
            }

            return(activePlayer);
        }