예제 #1
0
        public static void SaveViewModel(SecureSettingsViewModel model)
        {
            PropertyInfo[] properties = model.GetType().GetProperties();

            SecureSettings.SetConnectionValue("IdenityConnection", model.IdenityConnection);

            foreach (var prop in properties)
            {
                DisplayNameAttribute attr = (DisplayNameAttribute)Attribute.GetCustomAttribute(prop, typeof(DisplayNameAttribute));

                if (attr != null && attr.DisplayName != "IdenityConnection")
                {
                    string value = (string)prop.GetValue(model);

                    SecureSettings.SetValue(attr.DisplayName, value);

                }

            }
        }
예제 #2
0
        public static SecureSettingsViewModel CreateViewModel()
        {
            var model = new SecureSettingsViewModel();
            model.IdenityConnection = SecureSettings.GetConnectionValue("IdenityConnection");

            foreach (string key in ConfigurationManager.AppSettings)
            {

                string value = ConfigurationManager.AppSettings[key];

                PropertyInfo[] properties = model.GetType().GetProperties();

                foreach (var prop in properties)
                {
                    DisplayNameAttribute attr = (DisplayNameAttribute)Attribute.GetCustomAttribute(prop, typeof(DisplayNameAttribute));

                    if (attr.DisplayName == key)
                    {
                        EncryptionAttribute attrEncryption = (EncryptionAttribute)Attribute.GetCustomAttribute(prop, typeof(EncryptionAttribute));
                        if (attrEncryption != null) value = SecureSettings.GetValue(key);
                        prop.SetValue(model, value);
                    }

                }
            }
            return model;
        }