コード例 #1
0
        /// <summary>
        /// Setup and return the Virtual Cache
        /// </summary>
        /// <param name="ObjectCacheID"></param>
        /// <returns></returns>
        public ISortedDictionary <int, Person> GetObjectCache(int ObjectCacheID)
        {
            string CacheFilename  = "OFile" + ObjectCacheID.ToString();
            string ServerPath     = "SopBin\\";
            string ServerFilename = "OServer.dta";

            Sop.IFile f  = null;
            string    fn = string.Format("{0}{1}.{2}", ServerPath, CacheFilename, ObjectServer.DefaultFileExtension);

            if (server == null)
            {
                server = Sop.ObjectServer.OpenWithTransaction(string.Format("{0}{1}", ServerPath, ServerFilename),
                                                              new Preferences {
                    MemoryExtenderMode = true
                });
            }

            f = server.FileSet[CacheFilename];
            if (f == null)
            {
                f = server.FileSet.Add(CacheFilename, fn);
            }
            IStoreFactory sf = new StoreFactory();

            return(sf.Get <int, Person>(f.Store, "VirtualCache"));
        }
コード例 #2
0
        private void ClearLogs()
        {
            if (LogCollection == null)
            {
                return;
            }
            var lc = LogCollection;  //).GetLogSequence();

            Sop.IFile targetFile     = null;
            var       logsForRemoval = new List <BackupDataLogKey>(lc.Count);

            foreach (var de in lc)
            {
                var key = (BackupDataLogKey)de.Key;
                if (targetFile == null || targetFile.Filename != key.SourceFilename)
                {
                    targetFile = Server.GetFile(key.SourceFilename);
                }
                if (targetFile != null)
                {
                    logsForRemoval.Add(key);
                }
            }
            foreach (BackupDataLogKey k in logsForRemoval)
            {
                lc.Remove(k);
            }
        }
コード例 #3
0
ファイル: PeopleDirectory.cs プロジェクト: kouweizhong/Sop
        /// <summary>
        /// Sample code for managing People and their Addresses
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: PeopleDirectory demo started...", DateTime.Now);

            // create Server (open the data file) and begin a transaction...
            using (var Server = new ObjectServer("SopBin\\OServer.dta", true))
            {
                IStoreFactory sf = new StoreFactory();
                PeopleStore       = sf.Get <long, Person>(Server.SystemFile.Store, "People");
                PeopleStoreByName = sf.Get <PersonKey, long>(Server.SystemFile.Store, "PeopleByName", new PersonComparer());

                string    AddressFilename = "oFile2";
                Sop.IFile f = Server.GetFile(AddressFilename);
                if (f == null)
                {
                    f = Server.FileSet.Add(AddressFilename);
                }
                AddressStore          = sf.Get <long, Address>(f.Store, "Addresses");
                AddressStoreByAddress = sf.Get <AddressKey, long>(f.Store, "AddressesByAddress", new AddressComparer());

                if (PeopleStore.Count == 0)
                {
                    Populate();
                }
                else
                {
                    Console.WriteLine("Processing {0} records", PeopleStore.Count * 4);
                    ReadAll();
                }
                // when code reaches here, 'no exception happened, 'just commit the transaction.
                Server.Commit();
            }   // if error occurred, transaction will be rolled back automatically.

            Console.WriteLine("{0}: PeopleDirectory demo ended...", DateTime.Now);
        }
コード例 #4
0
ファイル: MemoryExtender.cs プロジェクト: kouweizhong/Sop
        /// <summary>
        /// Setups and returns the Virtual Cache
        /// </summary>
        /// <param name="ObjectCacheID"></param>
        /// <returns></returns>
        public ISortedDictionaryOnDisk GetObjectCache(int ObjectCacheID)
        {
            Sop.IFile f  = null;
            string    fn = CacheFilename + ObjectCacheID.ToString();

            if (server == null)
            {
                server = Sop.ObjectServer.OpenWithTransaction(string.Format("{0}{1}", ServerPath, ServerFilename),
                                                              // memory extender mode will cause SOP data file get deleted upon restart
                                                              new Preferences {
                    MemoryExtenderMode = true
                });
            }
            if (!server.FileSet.Contains(fn))
            {
                f = server.FileSet.Add(fn);
            }
            else
            {
                f = server.FileSet[fn];
            }
            if (f != null)
            {
                return(f.Store);
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Sample code for managing People and their Addresses
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: PeopleDirectory demo started...", DateTime.Now);

            IStoreFactory sf = new StoreFactory();

            PeopleStore       = sf.Get <long, Person>(Server.SystemFile.Store, "People");
            PeopleStoreByName = sf.Get <PersonKey, long>(Server.SystemFile.Store, "PeopleByName", new PersonComparer());

            string AddressFilename = "oFile2";

            Sop.IFile f = Server.GetFile(AddressFilename);
            if (f == null)
            {
                f = Server.FileSet.Add(AddressFilename);
            }
            AddressStore          = sf.Get <long, Address>(f.Store, "Addresses");
            AddressStoreByAddress = sf.Get <AddressKey, long>(f.Store, "AddressesByAddress", new AddressComparer());

            if (PeopleStore.Count == 0)
            {
                Populate();
            }
            else
            {
                Console.WriteLine("Processing {0} records", PeopleStore.Count * 4);
                ReadAll();
            }
            PeopleStore.Transaction.Commit();
            Console.WriteLine("{0}: PeopleDirectory demo ended...", DateTime.Now);
        }
コード例 #6
0
        /// <summary>
        /// Shows how to use two Object Servers with separate transaction for each.
        /// </summary>
        public static void Run()
        {
            string CacheFilename = "OFile.dta";
            //** ObjectServer1 is to be physically stored in ...\Sop1 folder
            string ServerPath1 = "SopBin\\Sop1\\";
            //** ObjectServer2 is to be physically stored in ...\Sop2 folder
            string ServerPath2    = "SopBin\\Sop2\\";
            string ServerFilename = "OServer.dta";

            //** create 1st ObjectServer & its transaction
            ObjectServer server = Sop.ObjectServer.OpenWithTransaction(string.Format("{0}{1}", ServerPath1, ServerFilename),
                                                                       new Preferences());

            //** create 2nd ObjectServer & its transaction
            string       ServerFilename2 = "OServer2.dta";
            string       sfullpath2      = string.Format("{0}{1}", ServerPath2, ServerFilename2);
            ObjectServer server2         = Sop.ObjectServer.OpenWithTransaction(sfullpath2);

            string fn  = string.Format("{0}{1}{2}", ServerPath1, 1, CacheFilename);
            string fn2 = string.Format("{0}{1}{2}", ServerPath2, 2, CacheFilename);

            Sop.IFile f = server.FileSet[CacheFilename];
            if (f == null)
            {
                f = server.FileSet.Add(CacheFilename, fn);
            }

            IStoreFactory sf = new StoreFactory();
            ISortedDictionary <int, Person>
            store = sf.Get <int, Person>(f.Store, "VirtualCache");

            Sop.IFile f2 = server2.FileSet[CacheFilename];
            if (f2 == null)
            {
                f2 = server2.FileSet.Add(CacheFilename, fn2);
            }
            ISortedDictionary <int, Person>
            store2 = sf.Get <int, Person>(f2.Store, "VirtualCache");

            //** insert records
            Console.WriteLine("Start Insertion then Validation of records & their sequence...");

            object o  = store.Transaction;
            object o2 = store2.Transaction;

            InsertRecords(store, 20003, "Store1");
            ReadRecords(store, 20003, "Store1");
            store.Transaction.Rollback();

            InsertRecords(store2, 20501, "Store2");
            ReadRecords(store2, 20501, "Store2");
            store2.Transaction.Rollback();

            Console.WriteLine("Done...");
        }
コード例 #7
0
ファイル: MultipleFiles.cs プロジェクト: kouweizhong/Sop
        public ISortedDictionary <int, T> GetObjectStore <T>(string StoreName, string NameOfFile, string Filename)
            where T : new()
        {
            Sop.IFile f = Server.GetFile(NameOfFile);
            if (f == null)
            {
                f = Server.FileSet.Add(NameOfFile, Filename);
            }
            IStoreFactory sf = new StoreFactory();

            return(sf.Get <int, T>(f.Store, StoreName));
        }
コード例 #8
0
        /// <summary>
        /// Sample code for managing People and their Addresses using the "IPersistent"
        /// interface as method to save said objects to SOP DB.
        /// NOTE: this yields optimal disk usage as you control up to byte level what
        /// info to save. BUT schema (for Person and Address)
        /// versioning(not shown) needs to be managed by the application code.
        /// Xml Serialized objects has advantage on schema versioning as .Net's
        /// Xml Serialization supports versioning built-in. BUT it isn't hard to
        /// implement IPersistent schema versioning.
        ///
        /// Also, this demo shows SOP managing about 1 million records (250K records on 4 tables)
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: PeopleDirectoryUsingIPersistent demo started...", DateTime.Now);

            //"SopBin\\OServer.dta"
            using (var Server = new ObjectServer(null,
                                                 true, new Profile()
            {
                BTreeSlotLength = 200
            }))
            {
                IStoreFactory sf = new StoreFactory();
                PeopleStore       = sf.GetPersistentValue <long, Person>(Server.SystemFile.Store, "People");
                PeopleStoreByName = sf.GetPersistentKey <PersonKey, long>(Server.SystemFile.Store, "PeopleByName", new PersonComparer());

                string    AddressFilename = "oFile2";
                Sop.IFile f = Server.GetFile(AddressFilename);
                if (f == null)
                {
                    f = Server.FileSet.Add(AddressFilename);
                }
                AddressStore          = sf.GetPersistentValue <long, Address>(f.Store, "Addresses");
                AddressStoreByAddress = sf.GetPersistentKey <AddressKey, long>(f.Store, "AddressesByAddress", new AddressComparer());

                if (PeopleStore.Count == 0)
                {
                    Populate();
                }
                else
                {
                    Console.WriteLine("Processing {0} records", PeopleStore.Count * 4);
                    ReadAll();
                }
                Server.Commit();
            }
            Console.WriteLine("{0}: PeopleDirectoryUsingIPersistent demo ended...", DateTime.Now);
        }
コード例 #9
0
ファイル: TransactionBase.cs プロジェクト: kouweizhong/Sop
 public virtual Sop.ISortedDictionaryOnDisk CreateCollection(Sop.IFile file, IComparer comparer, string name,
                                                             bool isDataInKeySegment)
 {
     return(OnDisk.ObjectServer.CreateDictionaryOnDisk((OnDisk.File.IFile)file,
                                                       comparer, name, isDataInKeySegment));
 }
コード例 #10
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
 Sop.IFile Sop.IFileSet.Add(Sop.IFile f)
 {
     return((IFile)this.Add((IFile)f));
 }
コード例 #11
0
ファイル: FileSet.cs プロジェクト: kouweizhong/Sop
 public bool Contains(Sop.IFile f)
 {
     return(Contains((Sop.Client.IFile)f));
 }