Ejemplo n.º 1
0
        /// <inheritdoc />
        public void SetValue(string key, string value)
        {
            using (var scope = _scopeProvider.CreateScope())
            {
                scope.WriteLock(Cms.Core.Constants.Locks.KeyValues);

                var keyValue = _repository.Get(key);
                if (keyValue == null)
                {
                    keyValue = new KeyValue
                    {
                        Identifier = key,
                        Value      = value,
                        UpdateDate = DateTime.Now,
                    };
                }
                else
                {
                    keyValue.Value      = value;
                    keyValue.UpdateDate = DateTime.Now;
                }

                _repository.Save(keyValue);

                scope.Complete();
            }
        }
Ejemplo n.º 2
0
        public void CanSetAndGet()
        {
            IScopeProvider provider = ScopeProvider;

            // Insert new key/value
            using (IScope scope = provider.CreateScope())
            {
                var keyValue = new KeyValue
                {
                    Identifier = "foo",
                    Value      = "bar",
                    UpdateDate = DateTime.Now,
                };
                IKeyValueRepository repo = CreateRepository(provider);
                repo.Save(keyValue);
                scope.Complete();
            }

            // Retrieve key/value
            using (IScope scope = provider.CreateScope())
            {
                IKeyValueRepository repo     = CreateRepository(provider);
                IKeyValue           keyValue = repo.Get("foo");
                scope.Complete();

                Assert.AreEqual("bar", keyValue.Value);
            }

            // Update value
            using (IScope scope = provider.CreateScope())
            {
                IKeyValueRepository repo     = CreateRepository(provider);
                IKeyValue           keyValue = repo.Get("foo");
                keyValue.Value      = "buzz";
                keyValue.UpdateDate = DateTime.Now;
                repo.Save(keyValue);
                scope.Complete();
            }

            // Retrieve key/value again
            using (IScope scope = provider.CreateScope())
            {
                IKeyValueRepository repo     = CreateRepository(provider);
                IKeyValue           keyValue = repo.Get("foo");
                scope.Complete();

                Assert.AreEqual("buzz", keyValue.Value);
            }
        }