コード例 #1
0
ファイル: DatabaseReader.cs プロジェクト: mbout4it/kparser
        public override void Import(ImportSourceType importSource, IDBReader dbReaderManager, bool modifyTimestamp)
        {
            this.upgradeTimestamp = modifyTimestamp;
            this.useTimeRange     = false;
            IsRunning             = true;

            try
            {
                // Reset the thread
                if ((readerThread != null) &&
                    ((readerThread.ThreadState == System.Threading.ThreadState.Running) ||
                     (readerThread.ThreadState == System.Threading.ThreadState.Background)))
                {
                    readerThread.Abort();
                }

                this.dbReaderManager = dbReaderManager;
                readerThread         = null;

                // Create the thread
                switch (importSource)
                {
                case ImportSourceType.KParser:
                    if (dbReaderManager is KParserReadingManager)
                    {
                        readerThread = new Thread(ImportKParserDB);
                    }
                    break;

                case ImportSourceType.DVSParse:
                case ImportSourceType.DirectParse:
                    if (dbReaderManager is DirectParseReadingManager)
                    {
                        readerThread = new Thread(ImportDirectParseDB);
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }

                readerThread.IsBackground = true;
                readerThread.Name         = "Read database thread";
                readerThread.Start();
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e);
                IsRunning = false;
                OnReaderStatusChanged(new ReaderStatusEventArgs(0, 0, false, true));

                dbReaderManager.CloseDatabase();
            }
        }
コード例 #2
0
ファイル: DatabaseReader.cs プロジェクト: mbout4it/kparser
        /// <summary>
        /// Join two KParser parses.  They must have already had
        /// timestamps upgraded, if applicable.
        /// </summary>
        private void JoinKParserDB()
        {
            int  rowCount   = 0;
            int  totalCount = 0;
            bool completed  = false;

            try
            {
                KParserReadingManager db1 = dbReaderManager as KParserReadingManager;
                if (db1 == null)
                {
                    throw new ArgumentNullException();
                }
                if (db1.Database == null)
                {
                    throw new ArgumentNullException();
                }

                KParserReadingManager db2 = dbReaderManager2 as KParserReadingManager;
                if (db2 == null)
                {
                    throw new ArgumentNullException();
                }
                if (db2.Database == null)
                {
                    throw new ArgumentNullException();
                }

                var allLines = Enumerable.Concat
                                   (db1.Database.RecordLog.AsEnumerable(),
                                   db2.Database.RecordLog.AsEnumerable());

                var orderedLines = from line in allLines
                                   orderby line.Timestamp, line.RecordLogID
                select line;

                List <ChatLine> chatLines = new List <ChatLine>(100);

                totalCount = allLines.Count();

                // Read the (fixed) record log from the database, reconstruct
                // the chat line, and send it to the new database.
                foreach (var logLine in orderedLines)
                {
                    rowCount++;
                    if (IsRunning == false)
                    {
                        break;
                    }

                    chatLines.Add(new ChatLine(logLine.MessageText, logLine.Timestamp));

                    OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, false));

                    if (chatLines.Count > 99)
                    {
                        OnReaderDataChanged(new ReaderDataEventArgs(chatLines));
                        chatLines = new List <ChatLine>(100);
                    }
                }

                if (chatLines.Count > 0)
                {
                    OnReaderDataChanged(new ReaderDataEventArgs(chatLines));
                }

                completed = IsRunning;

                List <PlayerInfo> playerInfoList = new List <PlayerInfo>();

                foreach (var player in db1.Database.Combatants)
                {
                    playerInfoList.Add(new PlayerInfo()
                    {
                        Name          = player.CombatantName,
                        CombatantType = (EntityType)player.CombatantType,
                        Info          = player.PlayerInfo
                    });
                }

                foreach (var player in db2.Database.Combatants)
                {
                    playerInfoList.Add(new PlayerInfo()
                    {
                        Name          = player.CombatantName,
                        CombatantType = (EntityType)player.CombatantType,
                        Info          = player.PlayerInfo
                    });
                }

                WaywardGamers.KParser.Parsing.MsgManager.Instance.PlayerInfoList = playerInfoList;
            }
            catch (ThreadAbortException e)
            {
                Logger.Instance.Log(e);
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e);
            }
            finally
            {
                IsRunning = false;
                OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, (completed == false)));
                dbReaderManager.CloseDatabase();
                dbReaderManager2.CloseDatabase();
            }
        }
コード例 #3
0
ファイル: DatabaseReader.cs プロジェクト: mbout4it/kparser
        /// <summary>
        /// Import (reparse) KParser database files.
        /// </summary>
        private void ImportKParserDB()
        {
            int  rowCount   = 0;
            int  totalCount = 0;
            bool completed  = false;

            try
            {
                KParserReadingManager readingManager = dbReaderManager as KParserReadingManager;
                if (readingManager == null)
                {
                    throw new ArgumentNullException();
                }

                KPDatabaseReadOnly readDataSet = readingManager.Database;
                if (readDataSet != null)
                {
                    List <ChatLine> chatLines = new List <ChatLine>(100);

                    totalCount = readDataSet.RecordLog.Count;

                    // Read the (fixed) record log from the database, reconstruct
                    // the chat line, and send it to the new database.
                    foreach (var logLine in readDataSet.RecordLog)
                    {
                        rowCount++;
                        if (IsRunning == false)
                        {
                            break;
                        }

                        if (useTimeRange == true)
                        {
                            DateTime logLineTime = logLine.Timestamp;
                            if (upgradeTimestamp == true)
                            {
                                logLineTime = logLine.Timestamp.ToUniversalTime();
                            }

                            if ((logLineTime >= startOfTimeRange) && (logLineTime <= endOfTimeRange))
                            {
                                chatLines.Add(new ChatLine(logLine.MessageText, logLineTime));
                            }
                        }
                        else
                        {
                            if (upgradeTimestamp == true)
                            {
                                chatLines.Add(new ChatLine(logLine.MessageText, logLine.Timestamp.ToUniversalTime()));
                            }
                            else
                            {
                                chatLines.Add(new ChatLine(logLine.MessageText, logLine.Timestamp));
                            }
                        }

                        OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, false));

                        if (chatLines.Count > 99)
                        {
                            OnReaderDataChanged(new ReaderDataEventArgs(chatLines));
                            chatLines = new List <ChatLine>(100);
                        }
                    }

                    if (chatLines.Count > 0)
                    {
                        OnReaderDataChanged(new ReaderDataEventArgs(chatLines));
                    }

                    completed = IsRunning;

                    List <PlayerInfo> playerInfoList = new List <PlayerInfo>();
                    foreach (var player in readDataSet.Combatants)
                    {
                        playerInfoList.Add(new PlayerInfo()
                        {
                            Name          = player.CombatantName,
                            CombatantType = (EntityType)player.CombatantType,
                            Info          = player.PlayerInfo
                        });
                    }

                    WaywardGamers.KParser.Parsing.MsgManager.Instance.PlayerInfoList = playerInfoList;
                }
                else
                {
                    throw new InvalidDataException("No database to parse.");
                }
            }
            catch (ThreadAbortException e)
            {
                Logger.Instance.Log(e);
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e);
            }
            finally
            {
                IsRunning = false;
                OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, (completed == false)));
                dbReaderManager.CloseDatabase();
            }
        }