コード例 #1
0
        public async Task ExampleUsage2()
        {
            var storeDir = EnvironmentV2.instance.GetOrAddTempFolder("KeyValueStoreTests").GetChildDir("ExampleUsage2Dir");

            storeDir.DeleteV2(); // Cleanup before tests if the test file exists
            string   myKey1 = "test123";
            MyClass1 x1     = new MyClass1()
            {
                myString1 = "Abc", myString2 = "Abc2"
            };
            {   // Create a fast memory store and combine it with a LiteDB store that is persisted to disk:
                IKeyValueStore store = new InMemoryKeyValueStore().WithFallbackStore(new FileBasedKeyValueStore(storeDir));
                await store.Set(myKey1, x1);

                MyClass1 x2 = await store.Get <MyClass1>(myKey1, null);

                Assert.Equal(x1.myString1, x2.myString1);
                Assert.Equal(x1.myString2, x2.myString2);
            }
            { // Create a second store and check that the changes were persisted:
                IKeyValueStore store2 = new FileBasedKeyValueStore(storeDir);
                Assert.True(await store2.ContainsKey(myKey1));
                MyClass1 x2 = await store2.Get <MyClass1>(myKey1, null);

                Assert.Equal(x1.myString1, x2.myString1);
                Assert.Equal(x1.myString2, x2.myString2);
                Assert.True(await store2.Remove(myKey1));
                Assert.False(await store2.ContainsKey(myKey1));
            }
        }
コード例 #2
0
        public static async Task <ProgressionSystem <FeatureFlag> > SetupWithGSheets(string apiKey, string sheetId, string sheetName)
        {
            var cachedFlags          = FileBasedKeyValueStore.New("FeatureFlags");
            var cachedFlagsLocalData = FileBasedKeyValueStore.New("FeatureFlags_LocalData");
            var googleSheetsStore    = new GoogleSheetsKeyValueStore(cachedFlags, apiKey, sheetId, sheetName);

            return(await Setup(new FeatureFlagStore(cachedFlagsLocalData, googleSheetsStore)));
        }
コード例 #3
0
ファイル: AppFlowToStore.cs プロジェクト: r8zbeh/cscore
 public AppFlowToStore(KeyValueStoreTypeAdapter <AppFlowEvent> store = null)
 {
     if (store == null)
     {
         store = FileBasedKeyValueStore.New(DEFAULT_FOLDER).GetTypeAdapter <AppFlowEvent>();
     }
     this.store = store;
 }
コード例 #4
0
ファイル: DefaultAppFlowImpl.cs プロジェクト: belzecue/cscore
        public DefaultAppFlowImpl(IKeyValueStore store = null)
        {
            this.store = store == null?FileBasedKeyValueStore.New("AppFlowEvents") : store;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            InternetStateManager.AddListener(this);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
コード例 #5
0
        public static NewsManager NewManagerViaGSheets(string apiKey, string sheetId, string sheetName)
        {
            var            newsDir            = EnvironmentV2.instance.GetOrAddTempFolder("NewsManagerCache");
            var            gSheetsCache       = new FileBasedKeyValueStore(newsDir.GetChildDir("GSheetsData"));
            var            newsLocalDataCache = new FileBasedKeyValueStore(newsDir.GetChildDir("LocalData"));
            IKeyValueStore newsStore          = new GoogleSheetsKeyValueStore(gSheetsCache, apiKey, sheetId, sheetName);

            return(new NewsManager(newsLocalDataCache.GetTypeAdapter <News.LocalData>(), newsStore.GetTypeAdapter <News>()));
        }
コード例 #6
0
        public async Task TestEnumSetAndGet2()
        {
            var f = EnvironmentV2.instance.GetOrAddTempFolder("TestEnumSetAndGet");

            f.DeleteV2();
            IKeyValueStore store  = new FileBasedKeyValueStore(f);
            string         myKey1 = "myKey1";
            MyEnum1        e1     = MyEnum1.state2;
            await store.Set(myKey1, e1);

            MyEnum1 e2 = await store.Get(myKey1, MyEnum1.state1);

            Assert.Equal(e1, e2);
        }
コード例 #7
0
ファイル: FeatureFlagTests.cs プロジェクト: r8zbeh/cscore
        public async Task TestDefaultProgressionSystemSetup()
        {
            // Get your key from https://console.developers.google.com/apis/credentials
            var apiKey = "AIzaSyCtcFQMgRIUHhSuXggm4BtXT4eZvUrBWN0";
            // https://docs.google.com/spreadsheets/d/1KBamVmgEUX-fyogMJ48TT6h2kAMKyWU1uBL5skCGRBM contains the sheetId:
            var sheetId              = "1KBamVmgEUX-fyogMJ48TT6h2kAMKyWU1uBL5skCGRBM";
            var sheetName            = "MySheet1"; // Has to match the sheet name
            var cachedFlags          = FileBasedKeyValueStore.New("FeatureFlags");
            var cachedFlagsLocalData = FileBasedKeyValueStore.New("FeatureFlags_LocalData");
            var googleSheetsStore    = new GoogleSheetsKeyValueStore(cachedFlags, apiKey, sheetId, sheetName);

            DefaultProgressionSystem.Setup(new TestFeatureFlagStore(cachedFlagsLocalData, googleSheetsStore));

            AppFlow.TrackEvent(EventConsts.catMethod, "Some event");
            Assert.False(await FeatureFlag.IsEnabled("MyFlag4"));
            Log.d("Now take a look at the folders in " + cachedFlags.folderForAllFiles.Parent.GetFullFileSystemPath());
        }
コード例 #8
0
        public async Task TestAppFlowToStore()
        {
            int eventCount = 1000;

            var s1 = Log.MethodEntered("InMemoryKeyValueStore");
            {
                IKeyValueStore store   = new InMemoryKeyValueStore();
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Log.MethodDone(s1, maxAllowedTimeInMs: 1000);
            }
            var s2 = Log.MethodEntered("InMemory FileSystem");
            {
                var            dir1    = EnvironmentV2.instance.GetNewInMemorySystem().GetChildDir("TestAppFlowToFiles");
                IKeyValueStore store   = new FileBasedKeyValueStore(dir1.CreateV2());
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Assert.Equal(eventCount, dir1.GetFiles().Count());
                Log.MethodDone(s2, maxAllowedTimeInMs: 10000);
            }
            var s3 = Log.MethodEntered("Real FileSystem");
            {
                var dir2 = EnvironmentV2.instance.GetRootTempFolder().GetChildDir("TestAppFlowToFiles");
                dir2.DeleteV2(); // Cleanup from last test
                IKeyValueStore store   = new FileBasedKeyValueStore(dir2.CreateV2());
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Assert.Equal(eventCount, dir2.GetFiles().Count());
                Log.MethodDone(s3, maxAllowedTimeInMs: 10000);
            }
            float ratioInMemVsReadFs = s2.ElapsedMilliseconds / (float)s3.ElapsedMilliseconds;

            Assert.True(0.01 < ratioInMemVsReadFs && ratioInMemVsReadFs < 1, $"s2={s2} > s3={s3}, ratioInMemVsReadFs={ratioInMemVsReadFs}");
        }
コード例 #9
0
ファイル: LocalAnalytics.cs プロジェクト: shoshiiran/cscore
 public LocalAnalytics(string dirName = DEFAULT_DIR)
     : this(new MutationObserverKeyValueStore().WithFallbackStore(FileBasedKeyValueStore.New(dirName)))
 {
 }