예제 #1
0
        /// <summary>
        /// Close the current database.
        /// Saves any pending changes first.
        /// </summary>
        public void CloseDatabase()
        {
            databaseEntry.Reset();

            UpdateDatabase();

            if (localTAManager != null)
            {
                localTAManager.Dispose();
                localTAManager = null;
            }

            if (localDB != null)
            {
                localDB.Dispose();
                localDB = null;
            }
        }
예제 #2
0
        /// <summary>
        /// Request that the database be purged of (possibly sensitive) chat information.
        /// </summary>
        public void PurgeChatInfo()
        {
            if (databaseAccessMutex.WaitOne())
            {
                try
                {
                    databaseEntry.PurgeChatInfo(localDB);

                    if (localDB.HasChanges())
                    {
                        KPDatabaseDataSet datasetChanges = (KPDatabaseDataSet)localDB.GetChanges();

                        if (datasetChanges != null)
                        {
                            try
                            {
                                // Notify watchers so that they can view the database with
                                // Row changed/inserted/deleted flags still visible
                                OnDatabaseChanging(new DatabaseWatchEventArgs(datasetChanges));

                                UpdateDatabase();

                                // Notify watchers when database has been fully updated.
                                OnDatabaseChanged(new DatabaseWatchEventArgs(null));
                            }
                            finally
                            {
                                datasetChanges.Dispose();
                            }
                        }
                    }
                }
                finally
                {
                    databaseAccessMutex.ReleaseMutex();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Given a list of messages, add them to the database in the
        /// appropriate structure.
        /// </summary>
        /// <param name="messageList">The list of messages to add.</param>
        /// <param name="parseEnded">A flag to indicate whether the parsing
        /// has ended.  If so, close out all waiting values.</param>
        internal void ProcessNewMessages(List <Message> messageList, bool parseEnded)
        {
            // Can't process messages if no db present.
            if (localDB == null)
            {
                return;
            }

            if ((messageList == null) || (messageList.Count == 0))
            {
                databaseEntry.UpdatePlayerInfo(localDB, Parsing.MsgManager.Instance.PlayerInfoList);
                return;
            }

            int totalMessageCount = messageList.Count;
            int messageNumber     = 0;

            // lock database while we're modifying it
            if (databaseAccessMutex.WaitOne())
            {
                try
                {
                    foreach (var message in messageList)
                    {
                        databaseEntry.AddMessageToDatabase(localDB, message);

                        OnMessageProcessed(new ReaderStatusEventArgs(++messageNumber, totalMessageCount, false, false));
                    }

                    databaseEntry.UpdatePlayerInfo(localDB, Parsing.MsgManager.Instance.PlayerInfoList);
                }
                catch (Exception e)
                {
                    OnMessageProcessed(new ReaderStatusEventArgs(++messageNumber, totalMessageCount, false, true));
                    Logger.Instance.Log(e);
                }
                finally
                {
                    databaseAccessMutex.ReleaseMutex();
                    OnMessageProcessed(new ReaderStatusEventArgs(++messageNumber, totalMessageCount, true, false));
                }
            }

            databaseEntry.MessageBatchSent();

            // Only push updates to disk every 5 seconds, unless parse is ending.
            if (parseEnded == false)
            {
                DateTime currentTime = DateTime.Now;
                if (lastUpdateTime + updateDelayWindow > currentTime)
                {
                    return;
                }

                lastUpdateTime = currentTime;
            }

            KPDatabaseDataSet datasetChanges = null;

            try
            {
                if (localDB.HasChanges())
                {
                    datasetChanges = (KPDatabaseDataSet)localDB.GetChanges();

                    // Notify watchers so that they can view the database with
                    // Row changed/inserted/deleted flags still visible
                    OnDatabaseChanging(new DatabaseWatchEventArgs(datasetChanges));

                    UpdateDatabase();

                    // Notify watchers when database has been fully updated.
                    OnDatabaseChanged(new DatabaseWatchEventArgs(null));
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e);
            }
            finally
            {
                if (datasetChanges != null)
                {
                    datasetChanges.Dispose();
                }
            }

            if (parseEnded == true)
            {
                databaseEntry.Reset();
            }
        }