public static IStoreManager GetStoreManager(StoreConfiguration storeConfiguration = null)
        {
            if (storeConfiguration == null)
            {
                storeConfiguration = StoreConfiguration.DefaultStoreConfiguration;
            }
            if (storeConfiguration.StoreManagerType != null)
            {
                return
                    (Activator.CreateInstance(storeConfiguration.StoreManagerType, storeConfiguration) as IStoreManager);
            }
#if BTREESTORE
#if SILVERLIGHT
            return(new IsolatedStorageStoreManager(storeConfiguration));
#else
            return(storeConfiguration.UseIsolatedStorage ? (IStoreManager) new IsolatedStorageStoreManager(storeConfiguration) : new FileStoreManager(storeConfiguration));
#endif
#else
#if WINDOWS_PHONE
            return(new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()));
#elif PORTABLE
            storeConfiguration.DisableBackgroundWrites = true;
            return(new BPlusTreeStoreManager(storeConfiguration, PlatformAdapter.Resolve <IPersistenceManager>()));
#else
            return(storeConfiguration.UseIsolatedStorage ? new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()) : new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new FilePersistenceManager()));
#endif
#endif
        }
        public static IStoreManager GetStoreManager(StoreConfiguration storeConfiguration = null)
        {
            if (storeConfiguration == null)
            {
                storeConfiguration = StoreConfiguration.DefaultStoreConfiguration;
            }
            if (storeConfiguration.StoreManagerType != null)
            {
                return
                    Activator.CreateInstance(storeConfiguration.StoreManagerType, storeConfiguration) as IStoreManager;
            }
#if BTREESTORE
#if SILVERLIGHT
            return new IsolatedStorageStoreManager(storeConfiguration);
#else
            return storeConfiguration.UseIsolatedStorage ? (IStoreManager) new IsolatedStorageStoreManager(storeConfiguration) : new FileStoreManager(storeConfiguration);
#endif
#else
#if WINDOWS_PHONE
            return  new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager());
#elif PORTABLE
            storeConfiguration.DisableBackgroundWrites = true;
            return new BPlusTreeStoreManager(storeConfiguration, PlatformAdapter.Resolve<IPersistenceManager>());
#else
            return storeConfiguration.UseIsolatedStorage ? new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()) : new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new FilePersistenceManager());
#endif
#endif


        }
        public static IStoreManager GetStoreManager(StoreConfiguration storeConfiguration = null)
        {
            if (storeConfiguration == null)
            {
                storeConfiguration = StoreConfiguration.DefaultStoreConfiguration;
            }
            if (storeConfiguration.StoreManagerType != null)
            {
                return
                    Activator.CreateInstance(storeConfiguration.StoreManagerType, storeConfiguration) as IStoreManager;
            }
#if BTREESTORE
#if SILVERLIGHT
            return new IsolatedStorageStoreManager(storeConfiguration);
#else
            return storeConfiguration.UseIsolatedStorage ? (IStoreManager) new IsolatedStorageStoreManager(storeConfiguration) : new FileStoreManager(storeConfiguration);
#endif
#else
#if WINDOWS_PHONE
            return  new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager());
#else
            return storeConfiguration.UseIsolatedStorage ? new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()) : new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new FilePersistenceManager());
#endif
#endif


        }
Example #4
0
        public void TestCreateNewMaster()
        {
            var pm = new FilePersistenceManager();
            var dirName = "TestCreateNewMaster1";
            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration {PersistenceType = PersistenceType.AppendOnly};
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            var storeId = mf.StoreId;
            mf = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.AppendOnly, mf.PersistenceType);

            dirName = "TestCreateNewMaster2";
            pm.CreateDirectory(dirName);
            storeConfig.PersistenceType = PersistenceType.Rewrite;
            storeSetId = Guid.NewGuid();
            mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            storeId = mf.StoreId;
            mf = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.Rewrite, mf.PersistenceType);

            // Enumerating commit points of a new master file should not throw an error
            Assert.AreEqual(0, mf.GetCommitPoints().Count());
        }
Example #5
0
        public static IStoreManager GetStoreManager(StoreConfiguration storeConfiguration = null)
        {
            if (storeConfiguration == null)
            {
                storeConfiguration = StoreConfiguration.DefaultStoreConfiguration;
            }
            if (storeConfiguration.StoreManagerType != null)
            {
                return
                    (Activator.CreateInstance(storeConfiguration.StoreManagerType, storeConfiguration) as IStoreManager);
            }
#if BTREESTORE
#if SILVERLIGHT
            return(new IsolatedStorageStoreManager(storeConfiguration));
#else
            return(storeConfiguration.UseIsolatedStorage ? (IStoreManager) new IsolatedStorageStoreManager(storeConfiguration) : new FileStoreManager(storeConfiguration));
#endif
#else
#if WINDOWS_PHONE
            return(new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()));
#else
            return(storeConfiguration.UseIsolatedStorage ? new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new IsolatedStoragePersistanceManager()) : new BPlusTreeStore.BPlusTreeStoreManager(storeConfiguration, new FilePersistenceManager()));
#endif
#endif
        }
Example #6
0
 public ServerCore(string baseLocation, ICache queryCache, PersistenceType persistenceType)
 {
     Logging.LogInfo("ServerCore Initialised {0}", baseLocation);
     _baseLocation = baseLocation;
     _stores = new Dictionary<string, StoreWorker>();
     var configuration = new StoreConfiguration {PersistenceType = persistenceType};
     _storeManager = StoreManagerFactory.GetStoreManager(configuration);
     _queryCache = queryCache;
 }
Example #7
0
        /*
         * public MasterFile(IPersistenceManager persistenceManager, string directoryPath)
         * {
         *  _persistenceManager = persistenceManager;
         *  _directoryPath = directoryPath;
         *  _masterFilePath = Path.Combine(directoryPath, MasterFileName);
         *  if (!File.Exists(_masterFilePath))
         *  {
         *      throw new StoreManagerException(directoryPath, "Master file not found");
         *  }
         *  try
         *  {
         *      using (var stream = _persistenceManager.GetInputStream(_masterFilePath))
         *      {
         *          Load(stream);
         *      }
         *  }
         *  catch (StoreManagerException)
         *  {
         *      throw;
         *  }
         *  catch (Exception ex)
         *  {
         *      throw new StoreManagerException(directoryPath,
         *                                      String.Format("Cannot read master file. Cause: {0}", ex.Message));
         *  }
         * }
         */

        private MasterFile(IPersistenceManager persistenceManager, string directoryPath, string masterFilePath,
                           StoreConfiguration storeConfiguration, Guid storeSetId)
        {
            _persistenceManager = persistenceManager;
            _directoryPath      = directoryPath;
            _masterFilePath     = masterFilePath;
            StoreType           = StoreType.Standard;
            PersistenceType     = storeConfiguration.PersistenceType;
            StoreFormatVersion  = CurrentStoreFormatVersion;
            StoreSetId          = storeSetId;
            StoreId             = Guid.NewGuid();
        }
Example #8
0
 public static MasterFile Create(IPersistenceManager persistenceManager, string directoryPath,
                                 StoreConfiguration storeConfiguration, Guid storeSetId)
 {
     var masterFilePath = Path.Combine(directoryPath, MasterFileName);
     if (persistenceManager.FileExists(masterFilePath))
     {
         throw new StoreManagerException(directoryPath, "Master file already exists");
     }
     persistenceManager.CreateFile(masterFilePath);
     using (var stream = persistenceManager.GetOutputStream(masterFilePath, FileMode.Open))
     {
         var newMaster = new MasterFile(persistenceManager, directoryPath, masterFilePath, storeConfiguration,
                                        storeSetId);
         newMaster.Save(stream);
         return newMaster;
     }
 }
Example #9
0
        public static MasterFile Create(IPersistenceManager persistenceManager, string directoryPath,
                                        StoreConfiguration storeConfiguration, Guid storeSetId)
        {
            var masterFilePath = Path.Combine(directoryPath, MasterFileName);

            if (persistenceManager.FileExists(masterFilePath))
            {
                throw new StoreManagerException(directoryPath, "Master file already exists");
            }
            persistenceManager.CreateFile(masterFilePath);
            using (var stream = persistenceManager.GetOutputStream(masterFilePath, FileMode.Open))
            {
                var newMaster = new MasterFile(persistenceManager, directoryPath, masterFilePath, storeConfiguration,
                                               storeSetId);
                newMaster.Save(stream);
                return(newMaster);
            }
        }
Example #10
0
        public void TestAppendCommitPoint()
        {
            var pm = new FilePersistenceManager();
            const string dirName = "TestAppendCommitPoint";
            EnsureEmptyDirectory(pm, dirName);

            var storeConfig = new StoreConfiguration {PersistenceType = PersistenceType.AppendOnly};
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time = DateTime.UtcNow;
            Guid commit1JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time = DateTime.UtcNow;
            Guid commit2JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, allCommits[0].CommitNumber);
            Assert.AreEqual(2ul, allCommits[0].LocationOffset);
            Assert.AreEqual(commit2JobId, allCommits[0].JobId);
            Assert.AreEqual(commit2Time.Ticks, allCommits[0].CommitTime.Ticks);

            Assert.AreEqual(1ul, allCommits[1].CommitNumber);
            Assert.AreEqual(1ul, allCommits[1].LocationOffset);
            Assert.AreEqual(commit1JobId, allCommits[1].JobId);
            Assert.AreEqual(commit1Time.Ticks, allCommits[1].CommitTime.Ticks);

            var lastCommit = mf.GetLatestCommitPoint();
            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);

        }
Example #11
0
        /*
        public MasterFile(IPersistenceManager persistenceManager, string directoryPath)
        {
            _persistenceManager = persistenceManager;
            _directoryPath = directoryPath;
            _masterFilePath = Path.Combine(directoryPath, MasterFileName);
            if (!File.Exists(_masterFilePath))
            {
                throw new StoreManagerException(directoryPath, "Master file not found");
            }
            try
            {
                using (var stream = _persistenceManager.GetInputStream(_masterFilePath))
                {
                    Load(stream);
                }
            }
            catch (StoreManagerException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new StoreManagerException(directoryPath,
                                                String.Format("Cannot read master file. Cause: {0}", ex.Message));
            }
        }
         */

        private MasterFile(IPersistenceManager persistenceManager, string directoryPath, string masterFilePath,
                           StoreConfiguration storeConfiguration, Guid storeSetId)
        {
            _persistenceManager = persistenceManager;
            _directoryPath = directoryPath;
            _masterFilePath = masterFilePath;
            StoreType = StoreType.Standard;
            PersistenceType = storeConfiguration.PersistenceType;
            StoreFormatVersion = CurrentStoreFormatVersion;
            StoreSetId = storeSetId;
            StoreId = Guid.NewGuid();
        }
 public AzureStoreManager(StoreConfiguration storeConfiguration) : base(storeConfiguration, new AzurePersistenceManager())
 {
     
 }
Example #13
0
        public void TestCorruptCommitPoint()
        {
            var pm = new FilePersistenceManager();
            var dirName = "TestCorruptCommitPoint";
            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration { PersistenceType = PersistenceType.AppendOnly };
            var storeSetId = Guid.NewGuid();
            var mf = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time = DateTime.UtcNow;
            Guid commit1JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time = DateTime.UtcNow;
            Guid commit2JobId = Guid.NewGuid();
            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);

            using (var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-250, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in one half of commit point should not cause a problem
            mf = MasterFile.Open(pm, dirName);
            var lastCommit = mf.GetLatestCommitPoint();
            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);

            using(var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-120, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in both halves of commit point should force a rewind to previous commit point
            mf = MasterFile.Open(pm, dirName);
            lastCommit = mf.GetLatestCommitPoint();
            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(1, allCommits.Count);

            Assert.AreEqual(1ul, lastCommit.CommitNumber);
            Assert.AreEqual(1ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit1JobId, lastCommit.JobId);
            Assert.AreEqual(commit1Time.Ticks, lastCommit.CommitTime.Ticks);

        }