void DecryptMember(object target, MemberInfo property)
        {
            var encryptedValue = property.GetValue(target);

            if (encryptedValue == null)
                return;

            if (EncryptionService == null)
                throw new InvalidOperationException(
                    String.Format("Cannot decrypt field {0} because no encryption service was configured.", property.Name));

            if (encryptedValue is WireEncryptedString)
                Decrypt((WireEncryptedString)encryptedValue);
            else
            {
                property.SetValue(target, DecryptUserSpecifiedProperty(encryptedValue));
            }

            Log.Debug(property.Name + " decrypted successfully");
        }
        void DecryptMember(object target, MemberInfo property)
        {
            var encryptedValue = property.GetValue(target);

            if (encryptedValue == null)
            {
                return;
            }

            var wireEncryptedString = encryptedValue as WireEncryptedString;
            if (wireEncryptedString != null)
            {
                Decrypt(wireEncryptedString);
            }
            else
            {
                property.SetValue(target, DecryptUserSpecifiedProperty(encryptedValue));
            }

            Log.Debug(property.Name + " decrypted successfully");
        }
        void EncryptMember(object target, MemberInfo member)
        {
            var valueToEncrypt = member.GetValue(target);

            if (valueToEncrypt == null)
            {
                return;
            }

            var wireEncryptedString = valueToEncrypt as WireEncryptedString;
            if (wireEncryptedString != null)
            {
                var encryptedString = wireEncryptedString;
                EncryptWireEncryptedString(encryptedString);

                //we clear the properties to avoid having the extra data serialized
                encryptedString.EncryptedBase64Value = null;
                encryptedString.Base64Iv = null;
            }
            else
            {
                member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
            }

            Log.Debug(member.Name + " encrypted successfully");
        }
        void EncryptMember(object target, MemberInfo member)
        {
            var valueToEncrypt = member.GetValue(target);

            if (valueToEncrypt == null)
                return;

            if (EncryptionService == null)
                throw new InvalidOperationException(
                    String.Format("Cannot encrypt field {0} because no encryption service was configured.",
                                  member.Name));

            if (valueToEncrypt is WireEncryptedString)
            {
                var encryptedString = (WireEncryptedString)valueToEncrypt;
                EncryptWireEncryptedString(encryptedString);

                if (!ConfigureEncryption.EnsureCompatibilityWithNSB2)
                {
                    //we clear the properties to avoid having the extra data serialized
                    encryptedString.EncryptedBase64Value = null;
                    encryptedString.Base64Iv = null;
                }
            }
            else
            {
                member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
            }

            Log.Debug(member.Name + " encrypted successfully");
        }
        void DecryptMember(object target, MemberInfo property)
        {
            var encryptedValue = property.GetValue(target);

            if (encryptedValue == null)
            {
                return;
            }

            if (EncryptionService == null)
            {
                throw new Exception(String.Format("Cannot decrypt field {0} because no encryption service was configured.", property.Name));
            }

            var wireEncryptedString = encryptedValue as WireEncryptedString;
            if (wireEncryptedString != null)
            {
                Decrypt(wireEncryptedString);
            }
            else
            {
                property.SetValue(target, DecryptUserSpecifiedProperty(encryptedValue));
            }

            Log.Debug(property.Name + " decrypted successfully");
        }
        void EncryptMember(object target, MemberInfo member)
        {
            var valueToEncrypt = member.GetValue(target);

            if (valueToEncrypt == null)
            {
                return;
            }

            if (EncryptionService == null)
            {
                throw new Exception(String.Format("Cannot encrypt field {0} because no encryption service was configured.",member.Name));
            }

            var wireEncryptedString = valueToEncrypt as WireEncryptedString;
            if (wireEncryptedString != null)
            {
                var encryptedString = wireEncryptedString;
                EncryptWireEncryptedString(encryptedString);

                //we clear the properties to avoid having the extra data serialized
                encryptedString.EncryptedBase64Value = null;
                encryptedString.Base64Iv = null;
            }
            else
            {
                member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
            }

            Log.Debug(member.Name + " encrypted successfully");
        }
Esempio n. 7
0
		private IRoot CreateEnumerableRoot(Theme theme, MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			var rootAttribute = member.GetCustomAttribute<RootAttribute>();
			var listAttribute = member.GetCustomAttribute<ListAttribute>();
			var viewAttribute = member.GetCustomAttribute<ViewAttribute>();

			Type elementType = listAttribute.ElementType;
			
			if (elementType == null)
			{
				elementType = rootAttribute.ElementType;
			}

			SetDefaultConverter(view, member, "DataContext", new EnumerableConverter(), null, bindings);
			
			var items = (IEnumerable)member.GetValue(view);
			if (items == null)
				throw new ArgumentNullException(member.Name, string.Format("Member of class {1} must have a value.", view.GetType().Name));

			var genericType = items.GetType().GetGenericArguments().SingleOrDefault();

			var isUIView = typeof(UIView).IsAssignableFrom(genericType);
 
			var section = CreateEnumSection(theme, member, items, null, true, bindings);

			var root = new RootElement(caption) { section };
			root.Opaque = false;
			root.ViewBinding.MemberInfo = member;
			root.DataContext = items;
			root.ViewBinding.DataContextCode = DataContextCode.Enumerable;

			if (isUIView)
			{
				root.ViewBinding.ViewType = genericType;
				root.ViewBinding.DataContextCode = DataContextCode.ViewEnumerable;
			}
			else if (viewAttribute != null && viewAttribute.ViewType != null)
			{
				root.ViewBinding.ViewType = viewAttribute.ViewType;
				root.ViewBinding.DataContextCode = DataContextCode.ViewEnumerable;
			}

			if (rootAttribute != null && rootAttribute.ViewType != null)
			{
				root.ViewBinding.ViewType = rootAttribute.ViewType;
				root.ViewBinding.DataContextCode = DataContextCode.ViewEnumerable;
			}

			if (listAttribute != null)
			{
				root.ViewBinding.ViewType = listAttribute.ViewType ?? root.ViewBinding.ViewType;
			}
		
			root.Theme.CellStyle = GetCellStyle(member, UITableViewCellStyle.Value1);
			
			return root;
		}
Esempio n. 8
0
		private ISection CreateEnumCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);
			
			object context = view;
			var dataContext = view as IDataContext;

			if (dataContext != null)
			{
				context = dataContext.DataContext;
			}
			
			SetDefaultConverter(view, member, "DataContext", new EnumCollectionConverter(), null, bindings);

			member = GetMemberFromDataContext(member, ref context);

			var csection = new Section() { IsMultiselect = true, Opaque = false };

			var collection = member.GetValue(view);
			if (collection == null)
			{
				var collectionType = typeof(EnumCollection<>);
				var enumType = memberType.GetGenericArguments().FirstOrDefault();
				Type[] generic = { enumType };

				collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
				member.SetValue(view, collection);
			}

			var index = 0;
			var items = (EnumCollection)collection;
			foreach (var item in items.Items)
			{
				var checkboxElement = new CheckboxElement(item.Description) 
				{ 
					Item = item, 
					Index = index, 
					DataContext = item.IsChecked, 
					Group = item.GroupName
				};

				csection.Add(checkboxElement);				
				index++;
			}
			
			csection.DataContext = memberType;
			csection.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

			return csection;
		}
Esempio n. 9
0
		private ISection GetSectionElementForMember(Theme theme, object view, MemberInfo member, List<Binding> bindings)
		{
			var caption = GetCaption(member);
			Type memberType = GetTypeForMember(member);
			ISection section = null;
			var isMultiselect = member.GetCustomAttribute<MultiSelectionAttribute>() != null;
			var isSelect = member.GetCustomAttribute<SelectionAttribute>() != null;

			if (memberType.IsEnum)
			{
				SetDefaultConverter(view, member, "DataContext", new EnumConverter(), memberType, bindings);
	
				var pop = member.GetCustomAttribute<PopOnSelectionAttribute>() != null;
				
				var currentValue = member.GetValue(view);
				var enumValues = Enum.GetValues(memberType);

				section = CreateEnumSection(theme, member, enumValues, currentValue, pop, bindings);
			}
			else if (typeof(EnumCollection).IsAssignableFrom(memberType))
			{
				section = CreateEnumCollectionSection(member, caption, view, bindings);
			}
			else if (isMultiselect)
			{
				section = CreateMultiselectCollectionSection(member, caption, view, bindings);
			}
			else if (isSelect)
			{
				section = CreateSelectCollectionSection(member, caption, view, bindings);
			}

			return section;
		}
Esempio n. 10
0
		private IElement GetElementForMember(Theme theme, UIView view, MemberInfo member, List<Binding> bindings)
		{
			string caption = GetCaption(member);
			IElement element = null;

			var orderAttribute = member.GetCustomAttribute<OrderAttribute>();

			Type memberType = GetTypeForMember(member);

			if (!(member is MethodInfo))
			{
				var defaultValue = member.GetCustomAttribute<DefaultValueAttribute>();
				if (defaultValue != null)
				{
					var propertyInfo = member as PropertyInfo;
					var fieldInfo = member as FieldInfo;
					if (propertyInfo != null && propertyInfo.CanWrite)
					{
						propertyInfo.SetValue(view, defaultValue.Value, null);
					}
					
					if (fieldInfo != null)
					{
						fieldInfo.SetValue(view, defaultValue.Value);
					}
				}

			}
			
			// get a single element
			if(_ElementPropertyMap.ContainsKey(memberType))
			{
				element = _ElementPropertyMap[memberType](member, caption, view, bindings);
			}
			
			if (typeof(IElement).IsAssignableFrom(memberType))
			{
				var memberValue = member.GetValue(view) as IElement;
				if (memberValue == null)
				{
					memberValue = Activator.CreateInstance(memberType) as IElement;
				}
				if (memberValue != null)
				{
					memberValue.Caption = caption;
				}

				element = memberValue;
			}

			if (element == null)
			{
				element = GetRootElementForMember(theme, view, member, bindings);
			}
			
			if (orderAttribute != null && element != null)
				element.Order = orderAttribute.Order;
			
			var dataContext = view as IDataContext;
			if (dataContext != null && element.DataContext == null)
			{
				element.DataContext = dataContext.DataContext;
			}

			return element;
		}
Esempio n. 11
0
		private IElement CreateIntElement(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			IElement element = null;

			var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
			string placeholder = null;
			var keyboardType = UIKeyboardType.NumberPad;

			if(entryAttribute != null)
			{
				placeholder = entryAttribute.Placeholder;
				if(entryAttribute.KeyboardType != UIKeyboardType.Default)
					keyboardType = entryAttribute.KeyboardType;

				element = new EntryElement(caption) { Placeholder = placeholder, KeyboardType = keyboardType};
			}
			else
			{
				element = new StringElement(caption) { DataContext = member.GetValue(view).ToString() };
			}

			SetDefaultConverter(view, member, "DataContext", new IntConverter(), null, bindings);

			return element;
		}
Esempio n. 12
0
 private void UpdateItem(ObjectOrValueNode node, MemberInfo info)
 {
     var newInstance = info.GetValue(node.Instance, null);
     if (newInstance == null)
     {
         node.Members[info] = null;
     }
     else
     {
         var newItem = RegisterItem(newInstance, node);
         node.Members[info] = newItem;
     }
 }
Esempio n. 13
0
		public IElement CreateEnumRoot(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);
			var currentValue = (int)member.GetValue(view);

			SetDefaultConverter(member, "Value", new EnumConverter() { PropertyType = memberType }, bindings);
			
			var pop = member.GetCustomAttribute<PopOnSelectionAttribute>() != null;
			var enumValues = Enum.GetValues(memberType);
			var csection = CreateEnumSection(Root, enumValues, currentValue, pop);

			var element = new RootElement(caption) { csection };
			element.Caption = caption;
			element.ViewBinding.DataContext = memberType;
			element.ViewBinding.DataContextCode = DataContextCode.Enum;
			element.Opaque = false;
			element.Theme = Theme.CreateTheme(Root.Theme); 
			element.Theme.CellStyle = UITableViewCellStyle.Value1;

			var radioGroup = new RadioGroup(memberType.FullName, currentValue) { EnumType = memberType };
			((IRoot)element).Groups.Add(radioGroup);

			return element;
		}