Exemplo n.º 1
0
 /// <summary>Perform an external backup, compressing all files into a single ZIP archive.</summary>
 /// <param name="serializer"></param>
 /// <param name="stm">Destination backup stream</param>
 /// <param name="compressionLevel">Compression level</param>
 public static void ExternalBackup(this EseSerializer serializer, Stream stm, CompressionLevel compressionLevel)
 {
     using (ZipArchive archive = new ZipArchive(stm, ZipArchiveMode.Create, false))
     {
         BackupDatabaseImpl(serializer, archive, CompressionLevel.Optimal);
     }
 }
Exemplo n.º 2
0
 /// <summary>Perform streaming backup.</summary>
 /// <param name="serializer"></param>
 /// <param name="dest">Destination folder</param>
 public static void StreamingBackup(this EseSerializer serializer, string dest)
 {
     if (!Directory.Exists(dest))
     {
         Directory.CreateDirectory(dest);
     }
     Api.JetBackupInstance(serializer.idInstance, dest, BackupGrbit.None, progress);
 }
Exemplo n.º 3
0
        public SerializerSession(EseSerializer _ser)
        {
            m_serializer = _ser;
            Api.JetBeginSession(serializer.idInstance, out m_idSession, null, null);
            Api.JetAttachDatabase(m_idSession, serializer.pathDatabase, AttachDatabaseGrbit.None);
            Api.JetOpenDatabase(m_idSession, serializer.pathDatabase, null, out m_idDatabase, OpenDatabaseGrbit.None);

            this.setThread();
        }
Exemplo n.º 4
0
        /// <summary></summary>
        public void Dispose()
        {
            lock ( syncRoot )
            {
                // Close all sessions.
                var lSessions = m_allSessions.ToList();
                for (int i = lSessions.Count - 1; i >= 0; i--)
                {
                    // Every CloseSession may fail e.g. with JET_err.SessionContextNotSetByThisThread if it runs a transaction.
                    try
                    {
                        var sess = lSessions[i];
                        if (0 == i)
                        {
                            sess.DisposeLastSession();
                        }
                        else
                        {
                            sess.Dispose();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        TraceWarning("SessionPool.Dispose - unable to close a session: " + ex.ToString());
                    }
                }
                m_allSessions.Clear();
                m_freeSessions.Clear();

                // Close the database.
                if (null != m_serializer)
                {
                    try
                    {
                        m_serializer.Dispose();
                    }
                    catch (System.Exception ex)
                    {
                        TraceWarning("SessionPool.Dispose - unable to dispose a serializer: " + ex.ToString());
                    }

                    m_serializer = null;
                }

                if (null != m_semaphore)
                {
                    m_semaphore.Dispose();
                    m_semaphore = null;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>Construct the session pool.</summary>
        /// <remarks>You should only create a single instance of this class.</remarks>
        /// <param name="settings">Database settings.</param>
        /// <param name="arrTypes">The array of record types.
        /// In every session returned by this pool, the corresponding tables will be already opened for you.</param>
        public SessionPool(EsentDatabase.Settings settings, params Type[] arrTypes)
        {
            folderDatabase = settings.databasePath;

            m_serializer = new EseSerializer(settings, arrTypes.Length, null);

            SessionLimit = Math.Max(settings.maxConcurrentSessions, 0);

            if (SessionLimit > 0)
            {
                m_semaphore = new Semaphore(SessionLimit, SessionLimit);
            }

            m_allSessions = new HashSet <SerializerSession>();

            m_freeSessions = new Stack <SerializerSession>();

            m_recordTypes = arrTypes.ToList();

            m_serializer.EnsureDatabaseExists();
        }
Exemplo n.º 6
0
        static void BackupDatabaseImpl(EseSerializer serializer, ZipArchive destination, CompressionLevel level)
        {
            // Start the backup process
            Api.JetBeginExternalBackupInstance(serializer.idInstance, BeginExternalBackupGrbit.None);

            byte[] buff = new byte[iBuffSize];

            // Database files that should become part of the backup file set
            BackupFiles(serializer.idInstance, destination, level, buff, Api.JetGetAttachInfoInstance);

            // Database patch files and transaction log files that should become part of the backup file set
            BackupFiles(serializer.idInstance, destination, level, buff, Api.JetGetLogInfoInstance);

            // For some mysterious reason, including zero-length patch file enables the backup to be restored with JetRestoreInstance API.
            string patchName = Path.ChangeExtension(serializer.FileName, "pat");

            destination.CreateEntry(patchName);

            // Delete any transaction log files that will no longer be needed once the current backup completes successfully.
            Api.JetTruncateLogInstance(serializer.idInstance);

            // End an external backup session
            Api.JetEndExternalBackupInstance(serializer.idInstance);
        }
Exemplo n.º 7
0
 /// <summary>Restore a streaming backup.</summary>
 /// <param name="src">Source backup folder</param>
 /// <param name="settings"></param>
 public static void StreamingRestore(string src, EsentDatabase.Settings settings)
 {
     using (EseSerializer ser = new EseSerializer(settings, 0))
         Api.JetRestoreInstance(ser.idInstance, src, settings.databasePath, progress);
 }
Exemplo n.º 8
0
 /// <summary>Perform an external backup, compressing all files into a single ZIP archive.</summary>
 /// <param name="serializer"></param>
 /// <param name="stm">The ZIP archive will be written to this stream.</param>
 public static void ExternalBackup(this EseSerializer serializer, Stream stm)
 {
     ExternalBackup(serializer, stm, CompressionLevel.Optimal);
 }