コード例 #1
0
 static KeyValueStorageConfiguration()
 {
     fns.Add("BPlus", (Path, Name, OutType) => {
         BPlusKeyValueStorage bpkvs = new BPlusKeyValueStorage(Path, Name);
         if (OutType == typeof(byte[]))
         {
             return(bpkvs);
         }
         if (OutType == typeof(byte[][]))
         {
             return(new Byte2EncodingKeyValueStorage(bpkvs));
         }
         if (OutType == typeof(string))
         {
             return(new StringEncodingKeyValueStorage(bpkvs));
         }
         throw new NotSupportedException();
     });
     fns.Add("LevelDB", (Path, Name, OutType) => {
         LevelDBKeyValueStorage lkvs = new LevelDBKeyValueStorage(Path);
         if (OutType == typeof(byte[]))
         {
             return(lkvs);
         }
         if (OutType == typeof(byte[][]))
         {
             return(new Byte2EncodingKeyValueStorage(lkvs));
         }
         if (OutType == typeof(string))
         {
             return(new StringEncodingKeyValueStorage(lkvs));
         }
         throw new NotSupportedException();
     });
 }
コード例 #2
0
        public KeyValueStorage <byte[]> GetStore(string name)
        {
            if (stores.ContainsKey(name))
            {
                return(stores [name]);
            }
            KeyValueStorage <byte[]> store = new LevelDBKeyValueStorage(path.CreatePath(name));

            System.IO.MemoryStream ms = new System.IO.MemoryStream(repositoryConfigurations.Get
                                                                       (System.Text.Encoding.Unicode.GetBytes(name)));
            System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(GenericUserRepositoryConfiguration));
            GenericUserRepositoryConfiguration     gurc = (GenericUserRepositoryConfiguration)xmls.Deserialize(ms);

            switch (gurc.EncryptionMehtod)
            {
            case  EncryptionMethod.AES:
                store = new AESEncryptingKeyValueStorage(store, symmetricKeys.Get(gurc.AESKeyID));
                stores.Add(name, store);
                return(store);

            case EncryptionMethod.RSA:
                store = new RSAEncryptingKeyValueStorage(store, rsa.Value);
                stores.Add(name, store);
                return(store);

            case EncryptionMethod.None:
                stores.Add(name, store);
                return(store);

            default:
                throw new NotSupportedException("Specified encryption method is not supported.");
            }
        }