Ejemplo n.º 1
0
        /// <summary>
        /// Remove a relationship between two objects. This will remove the keys for each side of the relationship.
        /// </summary>
        /// <typeparam name="T">The type of the sorce object</typeparam>
        /// <typeparam name="U">The type of the related object</typeparam>
        /// <param name="store">The underlying store</param>
        /// <param name="keyT">The key of the source object</param>
        /// <param name="keyU">The key of the related object</param>
        /// <param name="transformer"></param>
        public static void RemoveRelationship <T, U>(this IKVStore store, Key keyT, Key keyU, ITypeStringTransformer transformer = null)
        {
            var tr = transformer ?? new ForeignKeyTypeStringTransformer();

            store.RemoveFromCollection(tr.TransformFor <T, U>(keyT), keyU.Value);
            store.RemoveFromCollection(tr.TransformFor <U, T>(keyU), keyT.Value);
        }
Ejemplo n.º 2
0
        public Key GenerateKey(IKVStore store)
        {
            var sequenceValue = store.GetNextSequenceValue(string.Format("{0}:i", ConceptualTableKeyPrefix));

            //todo : replace with customisable logic
            return(string.Format("{0}:{1}", ConceptualTableKeyPrefix, sequenceValue.ToString()));
        }
Ejemplo n.º 3
0
        public Queue(IKVStore store, string key)
        {
            _store = store;
            _key   = key;

            _idxStartKey = key + ":" + "iA";
            _idxEndKey   = key + ":" + "iB";
        }
Ejemplo n.º 4
0
 public KvLoginProvider(IKVStore store, string namespacePrefix = "ULP:", IRandomCharacterGenerator characterGen = null, IHasher hasher = null, IStringVerifier usernameVerifier = null, IStringVerifier passwordVerifier = null)
 {
     _store            = new KeyTransformKVStore(store, new PrefixTransformer(namespacePrefix));
     _usernameVerifier = usernameVerifier ?? new NullStringVerifier();
     _passwordVerifier = passwordVerifier ?? new NullStringVerifier();
     _characterGen     = characterGen ?? new SimpleRandomCharacterGenerator();
     _hasher           = hasher ?? new Md5HasherWithSalt();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieves all objects of type U and their retrospective keys whence given the key for type T
        /// </summary>
        /// <typeparam name="T">The type of the sorce object</typeparam>
        /// <typeparam name="U">The type of the related object</typeparam>
        /// <param name="store">The underlying store</param>
        /// <param name="keyT">The key of the source object</param>
        /// <param name="transformer"></param>
        /// <returns></returns>
        public static IEnumerable <KeyValuePair <string, U> > GetRelatedFor <T, U>(this IKVStore store, Key keyT,
                                                                                   ITypeStringTransformer transformer = null)
        {
            var tr = transformer ?? new ForeignKeyTypeStringTransformer();

            var keys = store.GetRelatedKeysFor <T, U>(keyT);

            return(keys.Select(key => new KeyValuePair <string, U>(key, store.Get <U>(key))));
        }
Ejemplo n.º 6
0
        public KeyWithRelationship GetRelationshipFor <T>(IKVStore store, Key key)
        {
            string relationshipSuffix;

            if (_foreignTypeAliases.TryGetValue(typeof(T), out relationshipSuffix))
            {
                return(new KeyWithRelationship(key, new KVForeignKeyStoreRelationshipProvider(store, relationshipSuffix)));
            }

            return(null);
        }
Ejemplo n.º 7
0
        public IEnumerable <KeyWithRelationship> BuildKeyRelationships <T>(IKVStore underlyingStore, Key key)
        {
            IObjectTypeSchema objectTypeSchema;

            if (!_schemaObjects.TryGetValue(typeof(T), out objectTypeSchema))
            {
                throw new InvalidOperationException("No object schema available for " + typeof(T));
            }

            return(objectTypeSchema.BuildKeyRelationships(underlyingStore, key));
        }
Ejemplo n.º 8
0
        public void Remove <T>(IKey foreignKey, IKVStore store, IStoreSchema schema)
        {
            IObjectTypeSchema thisObjectSchema = schema.GetObjectSchema <T>();

            var relationships = thisObjectSchema.BuildKeyRelationships(store, Key);

            foreach (var relationship in relationships)
            {
                relationship.Remove(this);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Clears all relationships in both directtions between two types of objects connected to the source key.
        /// </summary>
        /// <typeparam name="T">The type of the sorce object</typeparam>
        /// <typeparam name="U">The type of the related object</typeparam>
        /// <param name="store">The underlying store</param>
        /// <param name="keyT">The key of the source object</param>
        /// <param name="transformer"></param>
        public static void ClearRelationships <T, U>(this IKVStore store, Key keyT,
                                                     ITypeStringTransformer transformer = null)
        {
            var tr = transformer ?? new ForeignKeyTypeStringTransformer();

            var keys = store.GetRelatedKeysFor <T, U>(keyT, tr);

            foreach (var keyU in keys)
            {
                store.RemoveRelationship <T, U>(keyT, keyU, tr);
            }
        }
Ejemplo n.º 10
0
        public DualIndexStoreEnumerator(IKVStore store, string key)
        {
            _store = store;
            _key   = key;

            string _idxStartKey = key + ":" + "iA";
            string _idxEndKey   = key + ":" + "iB";

            _startIdx = GetSeqValue(_idxStartKey);
            _endIdx   = GetSeqValue(_idxEndKey);

            _enumeratorIdx = _startIdx;
        }
Ejemplo n.º 11
0
        public void TestInit()
        {
            var r = new ExtensionNode();

            r.Key = "0a0c".HexToBytes();
            var b  = new BranchNode();
            var l1 = new ExtensionNode();

            l1.Key = new byte[] { 0x01 };
            var l2 = new ExtensionNode();

            l2.Key = new byte[] { 0x09 };
            var v1 = new LeafNode();

            v1.Value = "abcd".HexToBytes();
            var v2 = new LeafNode();

            v2.Value = "2222".HexToBytes();
            var v3 = new LeafNode();

            v3.Value = Encoding.ASCII.GetBytes("hello");
            var h1 = new HashNode();

            h1.Hash = v3.GetHash();
            var l3 = new ExtensionNode();

            l3.Next = h1;
            l3.Key  = "0e".HexToBytes();


            r.Next         = b;
            b.Children[0]  = l1;
            l1.Next        = v1;
            b.Children[9]  = l2;
            l2.Next        = v2;
            b.Children[10] = l3;
            root           = r;
            var store = new MemoryStore();
            var db    = new MPTDb(store);

            this.rootHash = root.GetHash();
            db.Put(r);
            db.Put(b);
            db.Put(l1);
            db.Put(l2);
            db.Put(l3);
            db.Put(v1);
            db.Put(v2);
            db.Put(v3);
            this.mptdb = store;
        }
Ejemplo n.º 12
0
 public IEnumerable <KeyWithRelationship> BuildKeyRelationships(IKVStore store, Key key)
 {
     return(_foreignTypeAliases.Select(
                s => new KeyWithRelationship(key, new KVForeignKeyStoreRelationshipProvider(store, s.Value))));
 }
Ejemplo n.º 13
0
 public static KVProfileProvider <StrDictProfile> GetStringDictProfile(IKVStore store)
 {
     return(new KVProfileProvider <StrDictProfile>(store));
 }
Ejemplo n.º 14
0
 public MPTDb(IKVStore store) : base(store)
 {
     this.store = store;
 }
Ejemplo n.º 15
0
 public KVStoreTest(ITestOutputHelper output, ServiceFixture_MySql fixture)
 {
     _output  = output;
     _kvStore = fixture.ServiceProvider.GetRequiredService <IKVStore>();
 }
Ejemplo n.º 16
0
 public MPTTrie(UInt256 root, IKVStore store) : base(root, store)
 {
     this.db = new MPTDb(store);
 }
Ejemplo n.º 17
0
 public KeyTransformKVStore(IKVStore underlyingStore, IStringTransformer transformer = null)
 {
     _store       = underlyingStore;
     _transformer = transformer ?? new NullStringTransformer();
 }
Ejemplo n.º 18
0
 public TypesafeKVStore(IKVStore underlyingStore, ITypeStringTransformer generator = null)
     : base(underlyingStore)
 {
     _generator = generator ?? new TypeStringTransformer(null);
 }
 public LazySetKeyValueStore(IKVStore underlyingStore)
 {
     _store = underlyingStore;
 }
Ejemplo n.º 20
0
 public UserLoginControlRepo(IKVStore kvStore) : base(kvStore)
 {
 }
Ejemplo n.º 21
0
 public KVProfileProvider(IKVStore store, string namespacePrefix = "UPP:")
 {
     _store = new KeyTransformKVStore(store, new PrefixTransformer(namespacePrefix));
 }
Ejemplo n.º 22
0
 public KvRoleProvider(IKVStore store, string namespacePrefix = "URP:")
 {
     _store          = new KeyTransformKVStore(store, new PrefixTransformer(namespacePrefix));
     _usersToRolesFK = new KVForeignKeyStoreRelationshipProvider(_store, "Roles");
     _rolesToUsersFK = new KVForeignKeyStoreRelationshipProvider(_store, "Users");
 }
Ejemplo n.º 23
0
 public KVRelationalStore(IKVStore store, IStoreSchema schema)
 {
     _store  = store;
     _schema = schema;
 }
Ejemplo n.º 24
0
 public LoggingKVStore(IKVStore underlyingStore, IKVLogger logger)
 {
     _store  = underlyingStore;
     _logger = logger;
 }
Ejemplo n.º 25
0
 protected KVStoreRepository(IKVStore kVStore)
 {
     KVStore = kVStore;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets all the related keys to objects of type U connected to keyT. This can be used in either direction
        /// </summary>
        /// <typeparam name="T">The type of the sorce object</typeparam>
        /// <typeparam name="U">The type of the related object</typeparam>
        /// <param name="store">The underlying store</param>
        /// <param name="keyT">The key of the source object</param>
        /// <param name="transformer"></param>
        /// <returns></returns>
        public static IEnumerable <string> GetRelatedKeysFor <T, U>(this IKVStore store, Key keyT, ITypeStringTransformer transformer = null)
        {
            var tr = transformer ?? new ForeignKeyTypeStringTransformer();

            return(store.GetCollection <string>(tr.TransformFor <T, U>(keyT)).Distinct());
        }
 /// <summary>
 /// Maintains a relationship of a key to a number of 'foreign key references' by creating an extra tracker key defined by itself and the suffix
 /// </summary>
 /// <param name="store">The underlying store to read to and write from</param>
 /// <param name="relationshipSuffixCollection">If there are more than 1 conceptual foreign key references,
 /// this can be used to isolate the target collection types, so links to multiple conceptual 'tables' are not confused</param>
 /// <param name="relationshipSuffix">This will be used as a suffix in the tracker key so it is uniquely identifiable back to the source key. Normally the default is sufficient</param>
 public KVForeignKeyStoreRelationshipProvider(IKVStore store, string relationshipSuffixCollection = null)
 {
     _store = new KeyTransformKVStore(store, new SuffixTransformer(relationshipSuffix + relationshipSuffixCollection));
 }