Esempio n. 1
0
 /// <summary>
 /// Performs a checkpoint operation on the database.
 /// </summary>
 public void Checkpoint()
 {
     lock ( SyncLock )
     {
         Close(false);
         sModified = "yes";
         SaveProperties();
         cCache.Open(false);
         OpenScript();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Opens the database files.
        /// </summary>
        /// <returns>True if operation is sucessful.</returns>
        public bool Open()
        {
            lock( SyncLock )
            {
                bool newdata = false;

                if (TracingHelper.TraceEnabled)
                    TracingHelper.Write();

                if (!(new FileInfo(sFileProperties)).Exists)
                {
                    Create();
                    // this is a new database
                    newdata = true;
                }

                // todo: some parts are not necessary for read-only access
                LoadProperties();

                if (bReadOnly == true)
                {
                    dDatabase.SetReadOnly();

                    cCache = new Cache(sFileCache);

                    cCache.Open(true);
                    RunScript();

                    return false;
                }

                bool needbackup = false;

                if (sModified.Equals("yes-new-files"))
                {
                    RenameNewToCurrent(sFileScript);
                    RenameNewToCurrent(sFileBackup);
                }
                else if (sModified.Equals("yes"))
                {
                    if (IsAlreadyOpen())
                    {
                        throw TracingHelper.Error(TracingHelper.DATABASE_ALREADY_IN_USE);
                    }

                    // recovering after a crash (or forgot to close correctly)
                    RestoreBackup();

                    needbackup = true;
                }

                sModified = "yes";
                SaveProperties();

                cCache = new Cache(sFileCache);

                cCache.Open(false);
                RunScript();

                if (needbackup)
                {
                    Close(false);
                    sModified = "yes";
                    SaveProperties();
                    cCache.Open(false);
                }

                OpenScript();

                // this is a existing database
                return newdata;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Opens the database files.
        /// </summary>
        /// <returns>True if operation is sucessful.</returns>
        public bool Open()
        {
            lock ( SyncLock )
            {
                bool newdata = false;

                if (TracingHelper.TraceEnabled)
                {
                    TracingHelper.Write();
                }

                if (!(new FileInfo(sFileProperties)).Exists)
                {
                    Create();
                    // this is a new database
                    newdata = true;
                }

                // todo: some parts are not necessary for read-only access
                LoadProperties();

                if (bReadOnly == true)
                {
                    dDatabase.SetReadOnly();

                    cCache = new Cache(sFileCache);

                    cCache.Open(true);
                    RunScript();

                    return(false);
                }

                bool needbackup = false;

                if (sModified.Equals("yes-new-files"))
                {
                    RenameNewToCurrent(sFileScript);
                    RenameNewToCurrent(sFileBackup);
                }
                else if (sModified.Equals("yes"))
                {
                    if (IsAlreadyOpen())
                    {
                        throw TracingHelper.Error(TracingHelper.DATABASE_ALREADY_IN_USE);
                    }

                    // recovering after a crash (or forgot to close correctly)
                    RestoreBackup();

                    needbackup = true;
                }

                sModified = "yes";
                SaveProperties();

                cCache = new Cache(sFileCache);

                cCache.Open(false);
                RunScript();

                if (needbackup)
                {
                    Close(false);
                    sModified = "yes";
                    SaveProperties();
                    cCache.Open(false);
                }

                OpenScript();

                // this is a existing database
                return(newdata);
            }
        }