public StateBucketService(ISettingsStore store) { var converter = new StateBucketConverter(); bool loading = false; var writer = _cache.Connect() .ToCollection() .Select(buckets => converter.Convert(buckets.ToArray())) .Subscribe(state => { if (loading) return; store.Save(SettingStoreKey, state); }); //TODO: Make this error proof var initialState = store.Load(SettingStoreKey); var initialBuckets = converter.Convert(initialState); try { loading = true; _cache.AddOrUpdate(initialBuckets); } finally { loading = false; } _cleanUp = new CompositeDisposable(writer, _cache); }
public void WriteState() { var converter = new StateBucketConverter(); var buckets = new[] { new StateBucket("TestType1","123",new State(1,"SomeThingOrOther"), DateTime.Now.AddMinutes(-1)), new StateBucket("TestType2","124",new State(1,"Type 2 State"), DateTime.Now), }; var state = converter.Convert(buckets); var restored = converter.Convert(state); buckets.ShouldBeEquivalentTo(restored); }
public void WriteState() { var converter = new StateBucketConverter(); var buckets = new[] { new StateBucket("TestType1", "123", new State(1, "SomeThingOrOther"), DateTime.Now.AddMinutes(-1)), new StateBucket("TestType2", "124", new State(1, "Type 2 State"), DateTime.Now), }; var state = converter.Convert(buckets); var restored = converter.Convert(state); buckets.ShouldBeEquivalentTo(restored); }