Ejemplo n.º 1
0
 public void Save()
 {
     try
     {
         foreach (var ban in Bans.Where(x => !x.Saved).ToList())
         {
             var banToSave = new DAL.Models.Ban
             {
                 BannedBy = ban.BannedBy,
                 BannedOn = ban.BannedOn,
                 Duration = ban.Duration,
                 Level    = ban.Level,
                 BanType  = ban.Type,
                 IsPrefix = ban.Prefix,
                 IsSuffix = ban.Suffix,
                 Name     = ban.Name,
                 Note     = ban.Note
             };
             ban.Saved = true;
             _dbContext.Bans.Add(banToSave);
         }
         _dbContext.SaveChanges();
     }
     catch (DbException ex)
     {
         _logManager.Error(ex);
         throw;
     }
 }
Ejemplo n.º 2
0
 public void Save()
 {
     try
     {
         foreach (var history in History.Where(x => !x.Saved).ToList())
         {
             var auction = new DAL.Models.Auction
             {
                 BuyerName  = history.BuyerName,
                 ItemSoldId = history.ItemForSale,
                 SellerName = history.SellerName,
                 SoldFor    = history.SoldFor,
                 SoldOn     = history.SoldOn
             };
             _dbContext.Auctions.Attach(auction);
             history.Saved = true;
         }
         _dbContext.SaveChanges();
     }
     catch (DbException ex)
     {
         _logManager.Error(ex);
         throw;
     }
 }
Ejemplo n.º 3
0
        private void DbDumpTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            if (!_pendingLogs.Any())
            {
                return;
            }

            var logsToDump = new List <LogEntry>(_pendingLogs);

            _pendingLogs.Clear();

            try
            {
                foreach (var log in logsToDump)
                {
                    var logToSave = new DAL.Models.Log {
                        LogType = log.LogType, Text = log.Text, SessionId = _sessionId
                    };
                    _dbContext.Logs.Add(logToSave);
                }
                _dbContext.SaveChanges();
            }
            catch (DbException ex)
            {
                DatabaseFailureLog("{0}\n{1}", ex.Message, ex.StackTrace);

                if (logsToDump.Any())
                {
                    _pendingLogs.AddRange(logsToDump);
                    logsToDump.Clear();
                }
            }
        }
Ejemplo n.º 4
0
        private static void StartNewSession(ISmaugDbContext dbContext)
        {
            var newSession = dbContext.Sessions.Create();

            newSession.IpAddress = ConfigurationManager.AppSettings["host"];
            newSession.Port      = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
            dbContext.Sessions.Add(newSession);
            dbContext.SaveChanges();
            SessionId = newSession.Id;
        }
Ejemplo n.º 5
0
        public void Save()
        {
            try
            {
                foreach (var board in Boards.Where(x => !x.Saved).ToList())
                {
                    var boardToSave = new DAL.Models.Board
                    {
                        Name               = board.Name,
                        ReadGroup          = board.ReadGroup,
                        PostGroup          = board.PostGroup,
                        ExtraReaders       = board.ExtraReaders,
                        ExtraRemovers      = board.ExtraRemovers,
                        OTakeMessage       = board.OTakeMessage,
                        OPostMessage       = board.OPostMessage,
                        ORemoveMessage     = board.ORemoveMessage,
                        OCopyMessage       = board.OCopyMessage,
                        OListMessage       = board.OListMessage,
                        PostMessage        = board.PostMessage,
                        OReadMessage       = board.ORemoveMessage,
                        MinimumReadLevel   = board.MinimumReadLevel,
                        MinimumPostLevel   = board.MinimumPostLevel,
                        MinimumRemoveLevel = board.MinimumRemoveLevel,
                        MaximumPosts       = board.MaximumPosts,
                        BoardObjectId      = board.BoardObjectId
                    };
                    board.Saved = true;
                    _dbContext.Boards.Add(boardToSave);

                    foreach (var note in board.Notes.Where(y => !y.Saved).ToList())
                    {
                        var noteToSave = new DAL.Models.Note
                        {
                            DateSent      = note.DateSent,
                            IsPoll        = note.IsPoll,
                            RecipientList = note.RecipientList,
                            Sender        = note.Sender,
                            Subject       = note.Subject,
                            Text          = note.Text
                        };
                        note.Saved = true;
                        boardToSave.Notes.Add(noteToSave);
                    }
                }
                _dbContext.SaveChanges();
            }
            catch (DbException ex)
            {
                _logManager.Error(ex);
                throw;
            }
        }
Ejemplo n.º 6
0
        public void Save()
        {
            try
            {
                foreach (var news in News.Where(x => !x.Saved).ToList())
                {
                    var newsToSave = new DAL.Models.News
                    {
                        CreatedBy = news.CreatedBy,
                        CreatedOn = news.CreatedOn,
                        Header    = news.Header,
                        IsActive  = news.Active,
                        Level     = news.Level,
                        Name      = news.Name
                    };
                    news.Saved = true;
                    _dbContext.News.Add(newsToSave);

                    foreach (var entry in news.Entries.Where(y => !y.Saved).ToList())
                    {
                        var entryToSave = new DAL.Models.NewsEntry
                        {
                            IsActive = entry.Active,
                            Name     = entry.Name,
                            PostedBy = entry.PostedBy,
                            PostedOn = entry.PostedOn,
                            Title    = entry.Title,
                            Text     = entry.Text
                        };
                        entry.Saved = true;
                        newsToSave.Entries.Add(entryToSave);
                    }
                }
                _dbContext.SaveChanges();
            }
            catch (DbException ex)
            {
                _logManager.Error(ex);
                throw;
            }
        }
Ejemplo n.º 7
0
        public void Save()
        {
            try
            {
                foreach (var clan in Clans.Where(x => !x.Saved).ToList())
                {
                    var clanToSave = _dbContext.Clans.FirstOrDefault(x => x.Id == clan.ID);
                    if (clanToSave == null)
                    {
                        clanToSave          = new DAL.Models.Clan();
                        clanToSave.Name     = clan.Name;
                        clanToSave.ClanType = (int)clan.ClanType;
                    }

                    clanToSave.Description  = clan.Description;
                    clanToSave.BoardId      = clan.Board;
                    clanToSave.Motto        = clan.Motto;
                    clanToSave.DeityName    = clan.Deity;
                    clanToSave.Badge        = clan.Badge;
                    clanToSave.RecallRoomId = clan.RecallRoom;
                    clanToSave.StoreRoomId  = clan.StoreRoom;

                    // Stats
                    if (clanToSave.Stats == null)
                    {
                        clanToSave.Stats = new ClanStats();
                    }
                    clanToSave.Stats.PvE_Kills         = clan.PvEKills;
                    clanToSave.Stats.PvE_Deaths        = clan.PvEDeaths;
                    clanToSave.Stats.Illegal_PvP_Kills = clan.IllegalPvPKill;
                    clanToSave.Stats.Score             = clan.Score;
                    clanToSave.Stats.Favour            = clan.Favour;
                    clanToSave.Stats.Strikes           = clan.Strikes;
                    clanToSave.Stats.MemberLimit       = clan.MemberLimit;
                    clanToSave.Stats.Alignment         = clan.Alignment;

                    // Members
                    foreach (var member in clan.Members)
                    {
                        var clanMember = clanToSave.Members.FirstOrDefault(x => x.Name == member.Name);
                        if (clanMember == null)
                        {
                            clanMember = new ClanMember();
                            clanToSave.Members.Add(clanMember);
                        }

                        clanMember.Name    = member.Name;
                        clanMember.Joined  = member.Joined;
                        clanMember.ClassId = member.Class;
                        clanMember.Level   = member.Level;
                        clanMember.Kills   = member.Kills;
                        clanMember.Deaths  = member.Deaths;
                        // TODO Notes
                        clanMember.ClanRank = (int)GetClanRank(member.Name, clan);
                    }

                    // Ranks

                    // Items
                }
                _dbContext.SaveChanges();
            }
            catch (DbException ex)
            {
                _logManager.Error(ex);
                throw;
            }
        }