public void DeleteContainer()
 {
     if (mutex.Wait(TimeSpan.FromSeconds(DefaultTime)))
     {
         _persistentDictionary.Dispose();
         _persistentDictionary = null;
         PersistentDictionaryFile.DeleteFiles(_path);
         mutex.Release();
     }
 }
Example #2
0
        public void Dispose()
        {
            if (_persistentDictionary != null && !_disposing)
            {
                _disposing = true;

                var databasePath = _persistentDictionary.Database;

                _persistentDictionary.Dispose();
                _persistentDictionary = null;

                PersistentDictionaryFile.DeleteFiles(databasePath);

                try
                {
                    if (Directory.Exists(_path))
                    {
                        Directory.Delete(_path, true);
                    }
                }
                catch (Exception)
                {
                    // swallow the error that we couldn't clean the directory for now.
                }
            }

            // force the Esent store to be cleaned out of memory
            GC.Collect(2, GCCollectionMode.Forced);
        }
Example #3
0
        protected override void Dispose(bool disposing)
        {
            if (_targetStorage != null)
            {
                try
                {
                    // Save the system reflection database, if newly created...
                    if (_isSystem)
                    {
                        if (!_isExisted)
                        {
                            // Add some metadata...
                            _targetStorage["$DataCount$"] = _count.ToString();
                        }
                    }

                    _targetStorage.Dispose();
                    _targetStorage = null;

                    // For the non-system reflection database, delete after use...
                    if (!_isSystem)
                    {
                        if (!String.IsNullOrEmpty(_dataSourceDir) &&
                            Directory.Exists(_dataSourceDir))
                        {
                            PersistentDictionaryFile.DeleteFiles(_dataSourceDir);
                        }
                    }
                }
                catch
                {
                }
            }
        }
Example #4
0
        public void VerifyCreateDictionaryFromConfigSet()
        {
            const string DictionaryLocation = "ConfigSetDictionary";
            string       dictionaryFilename = Path.Combine(DictionaryLocation, "configsetDict.edb");
            var          config             = new DatabaseConfig()
            {
                DatabasePageSize = 32 * 1024,
                DatabaseFilename = dictionaryFilename,
                SystemPath       = DictionaryLocation,
                LogFilePath      = DictionaryLocation,
                TempPath         = DictionaryLocation,
                TableClass1Name  = "_test_",
            };

            var pd = new PersistentDictionary <int, Guid?>(config);

            for (int i = 0; i < 256; i++)
            {
                pd[i] = Guid.NewGuid();
            }

            Assert.AreEqual(pd.Database.Config.DatabasePageSize, 32 * 1024);
            Assert.AreEqual(pd.Database.Config.TableClass1Name, "_test_");

            pd.Dispose();

            Assert.IsTrue(File.Exists(dictionaryFilename));
            Cleanup.DeleteDirectoryWithRetry(DictionaryLocation);
        }
Example #5
0
        public void VerifyCreateDictionaryFromDirectoryAndConfigSet()
        {
            const string DictionaryLocation = "ConfigSetDictionary";
            var          config             = new DatabaseConfig()
            {
                DatabasePageSize = 32 * 1024,
                TableClass1Name  = "_test_",
            };

            var pd = new PersistentDictionary <int, Guid?>(DictionaryLocation, config);

            for (int i = 0; i < 256; i++)
            {
                pd[i] = Guid.NewGuid();
            }

            Assert.AreEqual(pd.Database.Config.DatabasePageSize, 32 * 1024);
            Assert.AreEqual(pd.Database.Config.TableClass1Name, "_test_");

            pd.Dispose();

            Assert.IsTrue(Directory.Exists(DictionaryLocation));
            Assert.AreEqual(DictionaryLocation, pd.DatabasePath);
            Cleanup.DeleteDirectoryWithRetry(DictionaryLocation);
        }
Example #6
0
        public void VerifyCreateDictionaryFromConfigSetWithTermFlags()
        {
            const string DictionaryLocation = "ConfigSetDictForTermFlags";
            string       dictionaryFilename = Path.Combine(DictionaryLocation, "ConfigSetDict.edb");
            var          config             = new DatabaseConfig()
            {
                SystemPath        = DictionaryLocation,
                LogFilePath       = DictionaryLocation,
                TempPath          = DictionaryLocation,
                DatabaseFilename  = dictionaryFilename,
                TableClass1Name   = "_testX_",
                DatabaseStopFlags = Windows7Grbits.Dirty,
            };

            using (var pd = new PersistentDictionary <int, Guid?>(config))
            {
                for (int i = 0; i < 256; i++)
                {
                    pd[i] = Guid.NewGuid();
                }

                Assert.IsTrue(File.Exists(dictionaryFilename));

                pd.Dispose();
            }

            JET_dbstate dbstate = GetDbState(dictionaryFilename);

            Console.WriteLine("Dbstate after TermDirty: {0}", dbstate);
            Assert.AreEqual(JET_dbstate.DirtyShutdown, dbstate);

            Cleanup.DeleteDirectoryWithRetry(DictionaryLocation);
        }
Example #7
0
        protected override void Dispose(bool disposing)
        {
            if (_indexedDocument != null)
            {
                try
                {
                    // Save the system reflection database, if newly created...
                    _indexedDocument.Dispose();
                    _indexedDocument = null;

                    // For the non-system reflection database, delete after use...
                    if (!_isSystem)
                    {
                        if (!String.IsNullOrEmpty(_indexedDataDir) &&
                            Directory.Exists(_indexedDataDir))
                        {
                            PersistentDictionaryFile.DeleteFiles(_indexedDataDir);
                        }
                    }
                }
                catch
                {
                }
            }
        }
Example #8
0
        public void VerifyNewPersistentDictionaryHasUpgradedGlobalsTable()
        {
            string directory = InteropApiTests.SetupHelper.CreateRandomDirectory();

            var dict = new PersistentDictionary <ulong, bool>(directory);

            dict.Dispose();
            Assert.IsTrue(this.CheckGlobalsTableIsUpgrdaded(directory));
        }
Example #9
0
        internal void Clear()
        {
            string path = _Library.DatabasePath;

            Flush();
            _Library.Dispose();
            PersistentDictionaryFile.DeleteFiles(path);
            _Library = new PersistentDictionary <TKey, TValue>(path);
        }
Example #10
0
        public void VerifyOpenFailsOnMismatchedValueTypes()
        {
            const string DictionaryLocation = "IntIntDictionary";
            var          dict = new PersistentDictionary <int, int>(DictionaryLocation);

            dict.Dispose();
            var wrongDict = new PersistentDictionary <int, string>(DictionaryLocation);

            Cleanup.DeleteDirectoryWithRetry(DictionaryLocation);
        }
Example #11
0
        public void VerifyDeleteRemovesDatabaseFiles()
        {
            const string DictionaryLocation = "DictionaryToDelete";
            var          dict = new PersistentDictionary <ulong, bool>(DictionaryLocation);

            dict.Dispose();
            Assert.IsTrue(PersistentDictionaryFile.Exists(DictionaryLocation));
            PersistentDictionaryFile.DeleteFiles(DictionaryLocation);
            Assert.IsFalse(PersistentDictionaryFile.Exists(DictionaryLocation));
            Directory.Delete(DictionaryLocation, false);
        }
Example #12
0
        //=====================================================================

        /// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            if (!base.IsDisposed)
            {
                if (index != null)
                {
                    index.Dispose();
                }

                base.Dispose(disposing);
            }
        }
Example #13
0
        public bool Run(BuildContext context)
        {
            _context = context;
            _logger  = context.Logger;

            BuildSettings settings = context.Settings;

            FormatChm format =
                settings.Formats[BuildFormatType.HtmlHelp1] as FormatChm;

            if (format == null)
            {
                throw new BuildException(
                          "FormatChmHelper: The build format is not available.");
            }

            string dataDir = Path.Combine(_options.OutputDirectory, "Data");

            try
            {
                _plusTree    = new PersistentDictionary <string, string>(dataDir);
                _indentCount = 0;

                WriteHtmls();
                WriteHhk();
                if (_hasToc)
                {
                    WriteHhc();
                }
                WriteHhp();

                return(true);
            }
            catch (System.Exception ex)
            {
                if (_logger != null)
                {
                    _logger.WriteLine(ex, BuildLoggerLevel.Error);
                }

                return(false);
            }
            finally
            {
                if (_plusTree != null)
                {
                    _plusTree.Dispose();
                }
            }
        }
 private void Dispose(bool disposing)
 {
     if (_databaseMsdnUrls != null)
     {
         try
         {
             _databaseMsdnUrls.Dispose();
             _databaseMsdnUrls = null;
         }
         catch
         {
         }
     }
 }
Example #15
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <remarks>CFI, 2012-03-10</remarks>
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            values.Flush();
            values.Dispose();

            lifetime.Flush();
            lifetime.Dispose();

            IsDisposed = true;
        }
Example #16
0
        public void VerifyConstructorCanCopyDictionary()
        {
            const string DictionaryLocation = "CopiedDictionary";
            var          expected           = new Dictionary <int, Guid?>();

            for (int i = 0; i < 256; ++i)
            {
                expected[i] = Guid.NewGuid();
            }

            var actual = new PersistentDictionary <int, Guid?>(expected, DictionaryLocation);

            DictionaryAssert.AreEqual(expected, actual);
            actual.Dispose();
            Cleanup.DeleteDirectoryWithRetry(DictionaryLocation);
        }
Example #17
0
        public void VerifyDeleteRemovesReservedLogs()
        {
            const string DictionaryLocation = "DictionaryToDelete";
            const string ReservedLog        = @"DictionaryToDelete\res1.log";
            var          dict = new PersistentDictionary <ulong, bool>(DictionaryLocation);

            dict.Dispose();
            if (!File.Exists(ReservedLog))
            {
                File.WriteAllText(ReservedLog, "VerifyDeleteRemovesDatabaseFiles");
            }

            Assert.IsTrue(PersistentDictionaryFile.Exists(DictionaryLocation));
            PersistentDictionaryFile.DeleteFiles(DictionaryLocation);
            Assert.IsFalse(PersistentDictionaryFile.Exists(DictionaryLocation));
            Directory.Delete(DictionaryLocation, false);
        }
Example #18
0
        public bool Run(BuildContext context)
        {
            _context = context;
            _logger  = context.Logger;

            BuildSettings settings = context.Settings;

            string dataDir = Path.Combine(_options.OutputDirectory, "Data");

            try
            {
                _plusTree = new PersistentDictionary <string, string>(dataDir);

                WriteHtmls();
                if (!WriteHhk())
                {
                    return(false);
                }
                if (!WriteToc())
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.WriteLine(ex, BuildLoggerLevel.Error);
                }

                return(false);
            }
            finally
            {
                if (_plusTree != null)
                {
                    _plusTree.Dispose();
                }
            }
        }
Example #19
0
        public static void MigratePrevServerGroups(string name)
        {
            lock (MigratePrevServerGroupsLock)
            {
                var directory = string.Format(@"{0}\{1}\PrevServerGroups", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'PrevServerGroups' data.");

                    var oldDictionary = new PersistentDictionary <uint, string>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            oldDictionaryEntry.Value.Split(';').Select(int.Parse).ForEach(oldServerGroup =>
                            {
                                database.PreviousServerGroup.AddObject(new PreviousServerGroup
                                {
                                    Id = Guid.NewGuid(),
                                    ClientDatabaseId = (int)oldDictionaryEntry.Key,
                                    ServerGroup      = oldServerGroup,
                                    Creation         = DateTime.UtcNow
                                });
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'PrevServerGroups' data.");
                }
            }
        }
Example #20
0
        public static void MigrateModerates(string name)
        {
            lock (MigrateModeratesLock)
            {
                var directory = string.Format(@"{0}\{1}\Moderates", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Moderates' data.");

                    var oldDictionary = new PersistentDictionary <string, ModeratedClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Moderate.AddObject(new Moderate
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId    = (int)oldDictionaryEntry.Value.User,
                                ModeratorDatabaseId = (int)oldDictionaryEntry.Value.Moderator,
                                ServerGroup         = (int)oldDictionaryEntry.Value.ServerGroup,
                                Type     = (byte)oldDictionaryEntry.Value.Type,
                                Creation = oldDictionaryEntry.Value.Moderated
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Moderates' data.");
                }
            }
        }
Example #21
0
        public static void MigrateSticky(string name)
        {
            lock (MigrateStickyLock)
            {
                var directory = string.Format(@"{0}\{1}\Sticky", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Sticky' data.");

                    var oldDictionary = new PersistentDictionary <Guid, StickyClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Sticky.AddObject(new Sticky
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Value.ClientDatabaseId,
                                ChannelId        = (int)oldDictionaryEntry.Value.ChannelId,
                                StickTime        = (int)oldDictionaryEntry.Value.StickTime,
                                Creation         = oldDictionaryEntry.Value.Creation
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Sticky' data.");
                }
            }
        }
Example #22
0
        public static void MigrateTimes(string name)
        {
            lock (MigrateTimesLock)
            {
                var directory = string.Format(@"{0}\{1}\Times", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Times' data.");

                    var oldDictionary = new PersistentDictionary <string, TimeClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Time.AddObject(new Time
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Value.User,
                                Joined           = oldDictionaryEntry.Value.Joined,
                                Disconnected     = oldDictionaryEntry.Value.Disconnected,
                                TotalMinutes     = (oldDictionaryEntry.Value.Disconnected - oldDictionaryEntry.Value.Joined).TotalMinutes
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Times' data.");
                }
            }
        }
Example #23
0
        protected override void Dispose(bool disposing)
        {
            if (_targetStorage != null)
            {
                try
                {
                    _targetStorage.Dispose();
                    _targetStorage = null;

                    // For the non-system reflection database, delete after use...
                    if (!_isSystem)
                    {
                        if (!String.IsNullOrEmpty(_targetDataDir) &&
                            Directory.Exists(_targetDataDir))
                        {
                            PersistentDictionaryFile.DeleteFiles(_targetDataDir);
                        }
                    }
                }
                catch
                {
                }
            }
        }
Example #24
0
        public static void MigrateSeen(string name)
        {
            lock (MigrateSeenLock)
            {
                var directory = string.Format(@"{0}\{1}\Seen", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Seen' data.");

                    var oldDictionary = new PersistentDictionary <uint, DateTime>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Seen.AddObject(new Seen
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Key,
                                LastSeen         = oldDictionaryEntry.Value
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Seen' data.");
                }
            }
        }
 public void Dispose()
 {
     _persistentDictionary.Dispose();
     _persistentDictionary = null;
     GC.Collect();
 }
 public void Dispose()
 {
     FlushChanges();
     _backingStore.Dispose();
 }
Example #27
0
 public void Dispose() => _directory.Dispose();
Example #28
0
 public void Dispose()
 {
     _persistedDictionary.Dispose();
 }
        private void CheckDataIndex()
        {
            if (!PersistentDictionaryFile.Exists(_dataDir))
            {
                return;
            }

            FileInfo info = new FileInfo(Path.Combine(_dataDir,
                                                      DataSource.DatabaseFileName));

            if (!info.Exists)
            {
                return;
            }

            // Get the total file size in MB...
            long fileSize = info.Length / 1024;

            if (fileSize < 1)
            {
                return;
            }

            PersistentDictionary <string, string> storage = null;

            try
            {
                storage = new PersistentDictionary <string, string>(_dataDir);
                int indexCount = storage.Count;
                if (indexCount > 0)
                {
                    return;
                }
            }
            finally
            {
                if (storage != null)
                {
                    storage.Dispose();
                    storage = null;
                }
            }

            try
            {
                // It is possible the database is corrupted, try fixing it...

                // Perform a defragmentation of the PersistentDictionary.edb database
                Process process = new Process();

                ProcessStartInfo startInfo = process.StartInfo;

                startInfo.FileName = "esentutl.exe";
                //startInfo.Arguments = "-d " + "PersistentDictionary.edb" + " -o";
                startInfo.Arguments              = "/d " + "PersistentDictionary.edb";
                startInfo.UseShellExecute        = false;
                startInfo.CreateNoWindow         = true;
                startInfo.WorkingDirectory       = _dataDir;
                startInfo.RedirectStandardOutput = false;

                // Now, start the process - there will still not be output till...
                process.Start();
                // We must wait for the process to complete...
                process.WaitForExit();
                int exitCode = process.ExitCode;
                process.Close();
                if (exitCode != 0)
                {
                    return;
                }

                string[] logFiles = Directory.GetFiles(_dataDir, "*.log",
                                                       SearchOption.TopDirectoryOnly);
                if (logFiles != null)
                {
                    for (int i = 0; i < logFiles.Length; i++)
                    {
                        File.Delete(logFiles[i]);
                    }
                }
            }
            catch
            {
            }
        }