Example #1
0
		public PropertyInfo FindAttachedModelProperty(PropertyInfo queryProperty, PropertyInfo[] modelProperties)
		{
			var queryPropertyName = queryProperty.Name;
			if (!queryPropertyName.EndsWith(Suffix)) return null;
			if (queryProperty.PropertyType.GetGenericTypeDefinition() != typeof (Range<>)) return null;
			return
				modelProperties.FirstOrDefault(modelProperty => queryPropertyName == modelProperty.Name + Suffix);
		}
Example #2
0
 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(ss => ss.Name == ckf);
     var ck = ckpi.GetValue(model, null) as bool?;
     var m = modelProps.FirstOrDefault(mm => mm.Name == vm.Name);
     Number = ((string)m.GetValue(model, null)).FmtFone();
     ReceiveText = ck ?? false;
 }
Example #3
0
 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(ss => ss.Name == ckf);
     var ck = ckpi.GetValue(model, null) as bool?;
     var m = modelProps.FirstOrDefault(mm => mm.Name == vm.Name);
     Debug.Assert(m != null, "m != null");
     Address = ((string)m.GetValue(model, null));
     Send = ck ?? false;
 }
Example #4
0
 public List<ChangeDetail> CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     var changes = new List<ChangeDetail>();
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(mm => mm.Name == ckf);
     if (track)
     {
         model.UpdateValue(changes, vm.Name, Number.GetDigits());
         model.UpdateValue(changes, ckf, ReceiveText);
         return changes;
     }
     var ci = modelProps.FirstOrDefault(ss => ss.Name == vm.Name);
     Debug.Assert(ci != null, "ci != null");
     ci.SetValue(model, Number.GetDigits(), null);
     ckpi.SetValue(model, ReceiveText, null);
     return changes;
 }
Example #5
0
        //savePropertyFromChildNode
        private void setPropertyFromXmlNode(XmlNode node, PropertyInfo[] properties)
        {
            var property = properties.FirstOrDefault(x => x.Name == node.Name);
            if (property != null && !String.IsNullOrEmpty(node.InnerText))
            {
                if (property.PropertyType == typeof(int)) { property.SetValue(this, int.Parse(node.InnerText), null); }
                if (property.PropertyType == typeof(String)) { property.SetValue(this, node.InnerText, null); }

            }
        }
        private bool TryFindAndCreateEnumProperties(
            Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties,
            List<Action> referenceResolutionListForCurrentType)
        {
            var typeClosureToTrack = new List<KeyValuePair<EdmProperty, PropertyInfo>>();

            foreach (
                var cspaceProperty in cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsEnumType(p.TypeUsage.EdmType)))
            {
                var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
                if (clrProperty != null)
                {
                    typeClosureToTrack.Add(new KeyValuePair<EdmProperty, PropertyInfo>(cspaceProperty, clrProperty));
                }
                else
                {
                    var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
                    SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                    return false;
                }
            }

            foreach (var typeToTrack in typeClosureToTrack)
            {
                TrackClosure(typeToTrack.Value.PropertyType);
                // prevent the lifting of these closure variables
                var ot = ospaceType;
                var cp = typeToTrack.Key;
                var clrp = typeToTrack.Value;
                referenceResolutionListForCurrentType.Add(() => CreateAndAddEnumProperty(type, ot, cp, clrp));
            }

            return true;
        }
 private bool TryFindAndCreatePrimitiveProperties(
     Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties)
 {
     foreach (
         var cspaceProperty in
             cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsPrimitiveType(p.TypeUsage.EdmType)))
     {
         var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
         if (clrProperty != null)
         {
             PrimitiveType propertyType;
             if (TryGetPrimitiveType(clrProperty.PropertyType, out propertyType))
             {
                 if (clrProperty.CanRead
                     && clrProperty.CanWrite)
                 {
                     AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
                 }
                 else
                 {
                     var message = Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
                         clrProperty.Name, type.FullName, type.Assembly.FullName);
                     SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                     return false;
                 }
             }
             else
             {
                 var message = Strings.Validator_OSpace_Convention_NonPrimitiveTypeProperty(
                     clrProperty.Name, type.FullName, clrProperty.PropertyType.FullName);
                 SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                 return false;
             }
         }
         else
         {
             var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
             SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
             return false;
         }
     }
     return true;
 }
        private bool TryFindNavigationProperties(
            Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties,
            List<Action> referenceResolutionListForCurrentType)
        {
            var typeClosureToTrack =
                new List<KeyValuePair<NavigationProperty, PropertyInfo>>();
            foreach (var cspaceProperty in cspaceType.GetDeclaredOnlyMembers<NavigationProperty>())
            {
                var clrProperty = clrProperties.FirstOrDefault(p => NonPrimitiveMemberMatchesByConvention(p, cspaceProperty));
                if (clrProperty != null)
                {
                    var needsSetter = cspaceProperty.ToEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many;
                    if (clrProperty.CanRead
                        && (!needsSetter || clrProperty.CanWrite))
                    {
                        typeClosureToTrack.Add(
                            new KeyValuePair<NavigationProperty, PropertyInfo>(
                                cspaceProperty, clrProperty));
                    }
                }
                else
                {
                    var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(
                        cspaceProperty.Name, type.FullName);
                    SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                    return false;
                }
            }

            foreach (var typeToTrack in typeClosureToTrack)
            {
                TrackClosure(typeToTrack.Value.PropertyType);

                // keep from lifting these closure variables
                var ct = cspaceType;
                var ot = ospaceType;
                var cp = typeToTrack.Key;
                var clrp = typeToTrack.Value;

                referenceResolutionListForCurrentType.Add(() => CreateAndAddNavigationProperty(ct, ot, cp, clrp));
            }

            return true;
        }
Example #9
0
 public void CopyFromModel(PropertyInfo vm, object existing, object model, PropertyInfo[] modelProps)
 {
     string altname = vm.Name + "Id";
     var fiattr = vm.GetAttribute<FieldInfoAttribute>();
     if (fiattr != null && fiattr.IdField.HasValue())
         altname = fiattr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     var midvalue = mid.GetValue(model, null);
     if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
         Value = midvalue.ToInt().ToString();
     else if (midvalue == null)
         Value = null;
     else if (mid.PropertyType.Name == "CodeInfo")
         Value = ((CodeInfo) midvalue).Value;
     else
         Value = midvalue.ToString();
     var cinfo = midvalue as CodeInfo;
     if (cinfo == null && existing != null)
         cinfo = existing as CodeInfo;
     if (items == null && cinfo != null && cinfo.items != null)
         items = cinfo.items;
     Name = vm.Name;
 }
Example #10
0
        public List<ChangeDetail> CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
        {
            var changes = new List<ChangeDetail>();
            string altname = vm.Name + "Id";
            var attr = vm.GetAttribute<FieldInfoAttribute>();
            if (attr != null && attr.IdField.HasValue())
                altname = attr.IdField;
            var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);

            if (mid == null)
                return changes;

            if (mid.PropertyType.Name == "CodeInfo")
            {
                Util.SetPropertyEx(model, vm.Name + ".Value", Value == "0" ? null : Value);
            }
            else
            {
                if (track)
                {
                    if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
                        if (Value == "0")
                            model.UpdateValue(changes, altname, null);
                        else
                            model.UpdateValue(changes, altname, Value.ToInt());
                    return changes;
                }
                mid.SetPropertyFromText(model, Value == "0" ? null : Value);
            }

            return changes;
        }
Example #11
0
 public string CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     string altname = vm.Name + "Id";
     var attr = vm.GetAttribute<FieldInfoAttribute>();
     if (attr != null && attr.IdField.HasValue())
         altname = attr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     if (mid == null)
         return string.Empty;
     if (track)
     {
         var changes = new StringBuilder();
         if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
             if (Value == "0")
                 model.UpdateValue(changes, altname, null);
             else
                 model.UpdateValue(changes, altname, Value.ToInt());
         return changes.ToString();
     }
     mid.SetPropertyFromText(model, Value);
     return string.Empty;
 }
Example #12
0
 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     string altname = vm.Name + "Id";
     var fiattr = vm.GetAttribute<FieldInfoAttribute>();
     if (fiattr != null && fiattr.IdField.HasValue())
         altname = fiattr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     var midvalue = mid.GetValue(model, null);
     if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
         Value = midvalue.ToInt().ToString();
     else if (midvalue == null)
         Value = null;
     else
         Value = midvalue.ToString();
     Name = vm.Name;
 }
Example #13
0
		public PropertyInfo FindAttachedModelProperty(PropertyInfo queryProperty, PropertyInfo[] modelProperties)
		{
			var queryPropertyName = queryProperty.Name;
			if (!queryPropertyName.EndsWith(Suffix)) return null;
			if (!TypeUtils.IsBaseEntityQuery(queryProperty.PropertyType)) return null;
			return modelProperties.FirstOrDefault(modelProperty => modelProperty.Name + Suffix == queryPropertyName);
		}
Example #14
0
 public string CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(mm => mm.Name == ckf);
     if (track)
     {
         var changes = new StringBuilder();
         model.UpdateValue(changes, vm.Name, Address);
         model.UpdateValue(changes, ckf, Send);
         return changes.ToString();
     }
     var ci = modelProps.FirstOrDefault(ss => ss.Name == vm.Name);
     Debug.Assert(ci != null, "ci != null");
     ci.SetValue(model, Address, null);
     ckpi.SetValue(model, Send, null);
     return string.Empty;
 }
Example #15
0
    /// <summary>
    /// If command has a ListParameter, assign unmatched  values from <c>numbered</c> to it.
    /// </summary>
    /// <param name="cmd">The command</param>
    /// <param name="properties">The command properties</param>
    /// <param name="numbered">Unmatched parameteres from ExtractParameters call</param>
    private void AssignListParameter(ICommand cmd, PropertyInfo[] properties, string[] numbered)
    {
      var listProperty = properties.FirstOrDefault(p => CommandInspector.GetListParameter(p) != null);
      if (listProperty == null)
        return;

      var numberedParameters = properties.Select(CommandInspector.GetNumberedParameter)
                         .Where(p => p != null)
                         .Select(p => p.Number);

      int numberedParametersToSkip = (numberedParameters.Any()) ? numberedParameters.Max() + 1 : 0;
      var list = numbered.Skip(numberedParametersToSkip).ToList();
      list = (from element in list
        select Parser.PerformSubstitution(_context, element)).ToList();
#if NET45
      listProperty.SetValue(cmd, list);
#else
      listProperty.SetValue(cmd, list, null);
#endif
    }