예제 #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
        /// <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
        /// <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
        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
 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));
 }