コード例 #1
0
        public static async Task <(IStore store, StoreError err)> Load(int cacheSize, string path, ILogger logger)
        {
            logger = logger.AddNamedContext("LocalDbStore");
            logger.Verbose("Load store");

            var db = new DBreezeEngine(new DBreezeConfiguration
            {
                DBreezeDataFolderName = path
            });

            var store = new LocalDbStore(
                null,
                null,
                db,
                path,
                logger
                );

            using (var tx = store.BeginTx())
            {
                var(participants, err) = await store.DbGetParticipants();

                if (err != null)
                {
                    return(null, err);
                }

                var inmemStore = new InmemStore(participants, cacheSize, logger);

                //read roots from db and put them in InmemStore
                var roots = new Dictionary <string, Root>();
                foreach (var p in participants)
                {
                    Root root;
                    (root, err) = await store.DbGetRoot(p.Key);

                    if (err != null)
                    {
                        return(null, err);
                    }

                    roots[p.Key] = root;
                }



                err = inmemStore.Reset(roots);
                if (err != null)
                {
                    return(null, err);
                }

                store.participants = participants;
                store.InMemStore   = inmemStore;

                tx.Commit();
            }

            return(store, null);
        }
コード例 #2
0
        //LoadBadgerStore creates a Store from an existing database
        public static async Task <(IStore store, StoreError err)> New(Dictionary <string, int> participants, int cacheSize, string path, ILogger logger)
        {
            logger = logger.AddNamedContext("LocalDbStore");
            logger.Verbose("New store");

            var inmemStore = new InmemStore(participants, cacheSize, logger);
            var db         = new DBreezeEngine(new DBreezeConfiguration
            {
                //Storage =  DBreezeConfiguration.eStorage.MEMORY,
                DBreezeDataFolderName = path
            });

            var store = new LocalDbStore(
                participants,
                inmemStore,
                db,
                path,
                logger
                );

            using (var tx = store.BeginTx())
            {
                var err = await store.DbSetParticipants(participants);

                if (err != null)
                {
                    return(null, err);
                }

                err = await store.DbSetRoots(inmemStore.Roots);

                if (err != null)
                {
                    return(null, err);
                }
                tx.Commit();
            }

            return(store, null);
        }