Example #1
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null)
            {
                return;
            }

            switch (persistency)
            {
            case MessageBufferPersistencyType.Volatile:
                MessageBuffer = new ListMessageBuffer();
                break;

            case MessageBufferPersistencyType.Persistent:
                try {
                    MessageBuffer = new Db4oMessageBuffer(
                        ProtocolManager.Session.Username,
                        ProtocolManager.Protocol,
                        ProtocolManager.NetworkID,
                        ID
                        );
                } catch (Exception ex) {
#if LOG4NET
                    _Logger.Error(
                        "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                        "exception, falling back to memory backend!", ex
                        );
#endif
                    MessageBuffer = new ListMessageBuffer();
                }
                break;
            }
        }
Example #2
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null)
            {
                return;
            }

            switch (persistency)
            {
            case MessageBufferPersistencyType.Volatile:
                MessageBuffer = new ListMessageBuffer();
                break;

            case MessageBufferPersistencyType.Persistent:
                try {
                    var start = DateTime.UtcNow;
                    MessageBuffer = new Db4oMessageBuffer(
                        ProtocolManager.Session.Username,
                        ProtocolManager.Protocol,
                        ProtocolManager.NetworkID,
                        ID
                        );
                    var stop = DateTime.UtcNow;
#if LOG4NET
                    _Logger.DebugFormat(
                        "InitMessageBuffer(): initializing " +
                        "Db4oMessageBuffer({0}, {1}, {2}, {3}) " +
                        "took: {4:0.00} ms",
                        ProtocolManager.Session.Username,
                        ProtocolManager.Protocol,
                        ProtocolManager.NetworkID,
                        ID,
                        (stop - start).TotalMilliseconds
                        );
#endif
                } catch (Exception ex) {
#if LOG4NET
                    _Logger.Error(
                        "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                        "exception, falling back to memory backend!", ex
                        );
#endif
                    MessageBuffer = new ListMessageBuffer();

                    var builder = new MessageBuilder();
                    builder.AppendEventPrefix();
                    builder.AppendErrorText(
                        _("Failed to open chat history for writing. " +
                          "Your chat history will not be preserved. " +
                          "Reason: {0}"),
                        ex.Message
                        );
                    MessageBuffer.Add(builder.ToMessage());
                }
                break;
            }
        }
Example #3
0
        public static int OptimizeAllBuffers(Db4oMessageBufferOptimizationTypes opts)
        {
            DateTime start = DateTime.UtcNow, stop;
            var      dbPath  = Platform.GetBuffersBasePath();
            var      dbFiles = Directory.GetFiles(dbPath, "*.db4o",
                                                  SearchOption.AllDirectories);

            foreach (var dbFile in dbFiles)
            {
#if LOG4NET
                Logger.Info(String.Format(_("Optimizing: {0}..."), dbFile));
#endif
                try {
                    using (var buffer = new Db4oMessageBuffer(dbFile)) {
                        buffer.AggressiveGC = false;
                        if ((opts & Db4oMessageBufferOptimizationTypes.Defrag) != 0)
                        {
                            buffer.CloseDatabase();
                            buffer.DefragDatabase();
                            buffer.InitDatabase();
                        }
                        if ((opts & Db4oMessageBufferOptimizationTypes.Index) != 0)
                        {
                            buffer.RebuildIndex();
                        }
                    }
                } catch (Exception ex) {
#if LOG4NET
                    Logger.Debug("OptimizeAllBuffers(): Failed to optimize: " +
                                 dbFile + " Exception: ", ex);
                    Logger.InfoFormat(_("Failed to optimize: {0}. Reason: {1}"),
                                      dbFile, ex.Message);
#endif
                }
            }
            stop = DateTime.UtcNow;
#if LOG4NET
            Logger.Debug(
                String.Format(
                    "OptimizeAllBuffers(): optimizing buffers took: {0:0} second(s)",
                    (stop - start).TotalSeconds
                    )
                );
#endif
            return(dbFiles.Length);
        }
Example #4
0
 public static int OptimizeAllBuffers(Db4oMessageBufferOptimizationTypes opts)
 {
     DateTime start = DateTime.UtcNow, stop;
     var dbPath = Platform.GetBuffersBasePath();
     var dbFiles = Directory.GetFiles(dbPath, "*.db4o",
                                      SearchOption.AllDirectories);
     foreach (var dbFile in dbFiles) {
     #if LOG4NET
         Logger.Info(String.Format(_("Optimizing: {0}..."), dbFile));
     #endif
         try {
             using (var buffer = new Db4oMessageBuffer(dbFile)) {
                 buffer.AggressiveGC = false;
                 if ((opts & Db4oMessageBufferOptimizationTypes.Defrag) != 0) {
                     buffer.CloseDatabase();
                     buffer.DefragDatabase();
                     buffer.InitDatabase();
                 }
                 if ((opts & Db4oMessageBufferOptimizationTypes.Index) != 0) {
                     buffer.RebuildIndex();
                 }
             }
         } catch (Exception ex) {
     #if LOG4NET
             Logger.Debug("OptimizeAllBuffers(): Failed to optimize: " +
                          dbFile + " Exception: ", ex);
             Logger.InfoFormat(_("Failed to optimize: {0}. Reason: {1}"),
                               dbFile, ex.Message);
     #endif
         }
     }
     stop = DateTime.UtcNow;
     #if LOG4NET
     Logger.Debug(
         String.Format(
             "OptimizeAllBuffers(): optimizing buffers took: {0:0} second(s)",
             (stop - start).TotalSeconds
         )
     );
     #endif
     return dbFiles.Length;
 }
Example #5
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null) {
                return;
            }

            switch (persistency) {
                case MessageBufferPersistencyType.Volatile:
                    MessageBuffer = new ListMessageBuffer();
                    break;
                case MessageBufferPersistencyType.Persistent:
                    try {
                        var start = DateTime.UtcNow;
                        MessageBuffer = new Db4oMessageBuffer(
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID
                        );
                        var stop = DateTime.UtcNow;
            #if LOG4NET
                        _Logger.DebugFormat(
                            "InitMessageBuffer(): initializing " +
                            "Db4oMessageBuffer({0}, {1}, {2}, {3}) " +
                            "took: {4:0.00} ms",
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID,
                            (stop - start).TotalMilliseconds
                        );
            #endif
                    } catch (Exception ex) {
            #if LOG4NET
                        _Logger.Error(
                            "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                            "exception, falling back to memory backend!", ex
                        );
            #endif
                        MessageBuffer = new ListMessageBuffer();

                        var builder = new MessageBuilder();
                        builder.AppendEventPrefix();
                        builder.AppendErrorText(
                            _("Failed to open chat history for writing. " +
                              "Your chat history will not be preserved. " +
                              "Reason: {0}"),
                            ex.Message
                        );
                        MessageBuffer.Add(builder.ToMessage());
                    }
                    break;
            }
        }
Example #6
0
 public static int OptimizeAllBuffers()
 {
     DateTime start = DateTime.UtcNow, stop;
     var dbPath = Platform.GetBuffersBasePath();
     var dbFiles = Directory.GetFiles(dbPath, "*.db4o",
                                      SearchOption.AllDirectories);
     foreach (var dbFile in dbFiles) {
     #if LOG4NET
         Logger.Info(String.Format(_("Optimizing: {0}..."), dbFile));
     #endif
         using (var buffer = new Db4oMessageBuffer(dbFile)) {
             buffer.AggressiveGC = false;
             buffer.CloseDatabase();
             buffer.DefragDatabase();
             buffer.InitDatabase();
             buffer.RebuildIndex();
         }
     }
     stop = DateTime.UtcNow;
     #if LOG4NET
     Logger.Debug(
         String.Format(
             "OptimizeAllBuffers(): optimizing buffers took: {0:0.0} ms",
             (stop - start).TotalMilliseconds
         )
     );
     #endif
     return dbFiles.Length;
 }
Example #7
0
 public void Reopen()
 {
     Buffer.Dispose();
     Buffer = new Db4oMessageBuffer("testuser", "testprot", "testnet", "testchat");
     Enumerator();
 }
Example #8
0
        public void InitMessageBuffer(MessageBufferPersistencyType persistency)
        {
            Trace.Call(persistency);

            if (MessageBuffer != null) {
                return;
            }

            switch (persistency) {
                case MessageBufferPersistencyType.Volatile:
                    MessageBuffer = new ListMessageBuffer();
                    break;
                case MessageBufferPersistencyType.Persistent:
                    try {
                        MessageBuffer = new Db4oMessageBuffer(
                            ProtocolManager.Session.Username,
                            ProtocolManager.Protocol,
                            ProtocolManager.NetworkID,
                            ID
                        );
                    } catch (Exception ex) {
            #if LOG4NET
                        _Logger.Error(
                            "InitMessageBuffer(): Db4oMessageBuffer() threw " +
                            "exception, falling back to memory backend!", ex
                        );
            #endif
                        MessageBuffer = new ListMessageBuffer();
                    }
                    break;
            }
        }
 public void Reopen()
 {
     Buffer.Dispose();
     Buffer = new Db4oMessageBuffer("testuser", "testprot", "testnet", "testchat");
     Enumerator();
 }