Пример #1
0
        /* Function: Dispose
         */
        protected override void Dispose(bool strictRulesApply)
        {
            // If strict rules apply then the connection object will have to dispose of itself.  We can't do it here.
            if (!strictRulesApply && connection != null && connection.IsOpen)
            {
                if (databaseLock.IsLocked)
                {
                    throw new Exception("Attempted to dispose of database when there were still locks held.");
                }

                Cleanup(Delegates.NeverCancel);
                SaveSystemVariablesAndVersion();

                connection.Dispose();
                connection = null;

                usedTopicIDs.Clear();
                usedLinkIDs.Clear();
                usedImageLinkIDs.Clear();
                usedClassIDs.Clear();
                usedContextIDs.Clear();

                classIDReferenceChangeCache.Clear();
                contextIDReferenceChangeCache.Clear();

                SQLite.API.Result shutdownResult = SQLite.API.ShutDown();

                if (shutdownResult != SQLite.API.Result.OK)
                {
                    throw new SQLite.Exceptions.UnexpectedResult("Could not shut down SQLite.", shutdownResult);
                }
            }
        }
Пример #2
0
        /* Function: Start
         *
         * Dependencies:
         *
         *		- <Config.Manager> must be started before using the rest of the class.
         */
        public bool Start(Errors.ErrorList errors)
        {
            EngineInstance.AddStartupWatcher(this);

            SQLite.API.Result sqliteResult = SQLite.API.Initialize();

            if (sqliteResult != SQLite.API.Result.OK)
            {
                throw new SQLite.Exceptions.UnexpectedResult("Could not initialize SQLite.", sqliteResult);
            }

            Path databaseFile = EngineInstance.Config.WorkingDataFolder + "/CodeDB.nd";

            connection = new SQLite.Connection();
            bool success = false;

            if (!EngineInstance.HasIssues(StartupIssues.NeedToStartFresh |
                                          StartupIssues.FileIDsInvalidated |
                                          StartupIssues.CodeIDsInvalidated |
                                          StartupIssues.CommentIDsInvalidated))
            {
                try
                {
                    connection.Open(databaseFile, false);

                    Version version = GetVersion();

                    if (BinaryFile.IsCompatible(version, Engine.Instance.Version, "2.0.2") == true)
                    {
                        LoadSystemVariables();
                        success = true;
                    }
                }
                catch { }
            }

            if (!success)
            {
                connection.Dispose();

                if (System.IO.File.Exists(databaseFile))
                {
                    System.IO.File.Delete(databaseFile);
                }

                connection.Open(databaseFile, true);
                CreateDatabase();

                EngineInstance.AddStartupIssues(StartupIssues.CodeIDsInvalidated |
                                                StartupIssues.CommentIDsInvalidated |
                                                StartupIssues.NeedToReparseAllFiles,
                                                dontNotify: this);
            }

            started = true;
            return(true);
        }
Пример #3
0
        /* Function: Start
         *
         * Dependencies:
         *
         *		- <Config.Manager> must be started before using the rest of the class.
         */
        public bool Start(Errors.ErrorList errors)
        {
            SQLite.API.Result sqliteResult = SQLite.API.Initialize();

            if (sqliteResult != SQLite.API.Result.OK)
            {
                throw new SQLite.Exceptions.UnexpectedResult("Could not initialize SQLite.", sqliteResult);
            }

            Path databaseFile = EngineInstance.Config.WorkingDataFolder + "/CodeDB.nd";

            connection = new SQLite.Connection();
            bool success = false;

            if (EngineInstance.Config.ReparseEverything == false)
            {
                try
                {
                    connection.Open(databaseFile, false);

                    Version version = GetVersion();

                    if (Version.BinaryDataCompatibility(version, Engine.Instance.Version, "2.0") == true)
                    {
                        LoadSystemVariables();
                        success = true;
                    }
                }
                catch { }
            }

            if (!success)
            {
                connection.Dispose();

                if (System.IO.File.Exists(databaseFile))
                {
                    System.IO.File.Delete(databaseFile);
                }

                EngineInstance.Config.ReparseEverything = true;
                reparsingEverything = true;

                connection.Open(databaseFile, true);
                CreateDatabase();
            }

            return(true);
        }
Пример #4
0
 public UnexpectedResult(string message, SQLite.API.Result result)
     : base(message + "  Unexpected SQLite result: " + result)
 {
 }