public object[] Get(object content)
        {
            var type = content.GetType();

            if (!CachedKeys.ContainsKey(type))
            {
                var context = ContextProvider.GetFor(type);
                CachedKeys[type] = context.Context.Model.FindEntityType(type).FindPrimaryKey().Properties.Select(p => p.PropertyInfo).ToList().AsReadOnly();
            }

            return(CachedKeys[type].Select(p => p.GetValue(content)).ToArray());
        }
        public void Set(IEnumerable <object> keyValues, object content)
        {
            var type = content.GetType();

            if (!CachedKeys.ContainsKey(type))
            {
                var context = ContextProvider.GetFor(content.GetType());
                CachedKeys[type] = context.Context.Model.FindEntityType(content.GetType()).FindPrimaryKey().Properties.Select(p => p.PropertyInfo).ToList().AsReadOnly();
            }

            for (var i = 0; i < CachedKeys[type].Count(); i++)
            {
                CachedKeys[type].ElementAt(i).SetValue(content, keyValues.ElementAt(i));
            }
        }
Example #3
0
        //protected IVEncryptor(string method, string password, bool oneTimeAuth, bool isUdp)
        //    :base(method,password,oneTimeAuth,isUdp){

        //    //InitKey();
        //}

        //protected abstract Dictionary<string, IVEncryptorInfo> GetCiphers();

        private void InitKey()
        {
            string k = Method + ":" + Password;

            _ciphers = GetCiphers();

            if (!_ciphers.TryGetValue(Method, out _cipherInfo))
            {
                throw new ArgumentException($"method({Method}) not found");
            }
            _keyLen       = _cipherInfo.KeySize;
            _ivLen        = _cipherInfo.IVSize;
            _innerLibName = _cipherInfo.InnerLibName;
            _key          = CachedKeys.GetOrAdd(k, (nk) =>
            {
                byte[] passBuf = Encoding.UTF8.GetBytes(Password);
                byte[] key     = new byte[32];
                BytesToKey(passBuf, key);
                return(key);
            });
        }
Example #4
0
        public void Initialize()
        {
            if (!CachedKeys.Any())
            {
                var allKeys = Enum.GetValues(typeof(Keys));
                foreach (var key in allKeys)
                {
                    var name = Enum.GetName(typeof(Keys), key);
                    //hardcode begin
                    if (CachedKeys.ContainsKey(name))
                    {
                        name = name + " (2)";
                    }
                    if (CachedKeys.ContainsKey(name))
                    {
                        name = name.Replace("(2)", "(3)");
                    }
                    if (CachedKeys.ContainsKey(name))
                    {
                        name = name.Replace("(3)", "(4)");
                    }
                    if (CachedKeys.ContainsKey(name))
                    {
                        name = name.Replace("(4)", "(5)");
                    }
                    if (CachedKeys.ContainsKey(name))
                    {
                        name = name.Replace("(5)", "(6)");
                    }
                    //hardcode end
                    CachedKeys.Add(name, (Keys)key);
                }
            }

            var valueType = new StateValueType();

            valueType.AcceptedValues = CachedKeys.Select(x => x.Key).ToArray();
            this.ValueType           = valueType;
        }
 public void ClearCache()
 {
     CachedKeys.ToList().ForEach(k => _translationsCache.Remove(RemoveKey(k)));
     ClearKeys();
 }