Esempio n. 1
0
 private static ResourceInstanceComplexProperty ConvertComplexPayloadObjectToComplexProperty(ResourceProperty rp, PayloadComplexProperty payloadComplexProperty)
 {
     List<ResourceInstanceProperty> properties = new List<ResourceInstanceProperty>();
     foreach (ResourceProperty childProperty in (rp.Type as ComplexType).Properties.OfType<ResourceProperty>())
     {
         if (childProperty.IsComplexType)
         {
             PayloadComplexProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadComplexProperty;
             properties.Add(ConvertComplexPayloadObjectToComplexProperty(childProperty, fromPayload));
         }
         else
         {
             PayloadSimpleProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadSimpleProperty;
             if (fromPayload != null)
             {
                 ResourceInstanceProperty newProperty = null;
                 object val = CommonPayload.DeserializeStringToObject(fromPayload.Value, childProperty.Type.ClrType, false, fromPayload.ParentObject.Format);
                 newProperty = new ResourceInstanceSimpleProperty(childProperty.Name, new NodeValue(val, childProperty.Type));
                 properties.Add(newProperty);
             }
         }
     }
     ComplexResourceInstance complexResourceInstance = new ComplexResourceInstance(rp.Type.Name, properties.ToArray());
     return new ResourceInstanceComplexProperty(rp.Type.Name, rp.Name, complexResourceInstance);
 }
Esempio n. 2
0
        internal static KeyedResourceInstance CreateKeyedResourceInstanceFromPayloadObject(ResourceContainer container, ResourceType resourceType, PayloadObject payloadObject)
        {
            List<ResourceInstanceProperty> properties = new List<ResourceInstanceProperty>();
            List<ResourceInstanceProperty> keyProperties = new List<ResourceInstanceProperty>();

            foreach (ResourceProperty property in resourceType.Properties.OfType<ResourceProperty>())
            {
                if (property.IsNavigation)
                    continue;

                if (property.IsComplexType)
                {
                    PayloadComplexProperty fromPayload = payloadObject[property.Name] as PayloadComplexProperty;
                    properties.Add(ConvertComplexPayloadObjectToComplexProperty(property, fromPayload));
                }
                else
                {
                    string stringValue;
                    if (payloadObject.PayloadProperties.Any(p => p.Name == property.Name))
                    {
                        PayloadSimpleProperty fromPayload = payloadObject[property.Name] as PayloadSimpleProperty;
                        stringValue = fromPayload.Value;
                    }
                    else
                    {
                        if (!payloadObject.CustomEpmMappedProperties.TryGetValue(property.Name, out stringValue))
                            stringValue = null;
                    }

                    ResourceInstanceProperty newProperty = null;
                    object val = CommonPayload.DeserializeStringToObject(stringValue, property.Type.ClrType, false, payloadObject.Format);
                    newProperty = new ResourceInstanceSimpleProperty(property.Name, new NodeValue(val, property.Type));

                    if (property.PrimaryKey != null)
                        keyProperties.Add(newProperty);
                    else
                        properties.Add(newProperty);
                }
            }

            ResourceInstanceKey key = new ResourceInstanceKey(container, resourceType, keyProperties.ToArray());
            return new KeyedResourceInstance(key, properties.ToArray());

        }
Esempio n. 3
0
 private static List<ResourceInstanceProperty> CloneObjectToResourceInstanceProperties(IEnumerable<ResourceProperty> properties, object o)
 {
     List<ResourceInstanceProperty> instanceProperties = new List<ResourceInstanceProperty>();
     foreach (ResourceProperty resProperty in properties)
     {
         if (resProperty.IsNavigation)
             continue;
         object propertyObject = o.GetType().InvokeMember(resProperty.Name, System.Reflection.BindingFlags.GetProperty, null, o, new object[] { });
         ResourceInstanceProperty resourceInstanceProperty = null;
         if (resProperty.Type is ComplexType)
         {
             ComplexResourceInstance complexInstance = CloneObjectToComplexResourceInstance(resProperty.Type as ComplexType, propertyObject);
             resourceInstanceProperty = new ResourceInstanceComplexProperty(resProperty.Type.Name, resProperty.Name, complexInstance);
         }
         else
         {
             resourceInstanceProperty = new ResourceInstanceSimpleProperty(resProperty.Name, new NodeValue(propertyObject, resProperty.Type));
         }
         instanceProperties.Add(resourceInstanceProperty);
     }
     return instanceProperties;
 }
Esempio n. 4
0
 public static ComplexResourceInstance CreateComplexResourceInstance(ComplexType type)
 {
     List<ResourceInstanceProperty> instanceProperties = new List<ResourceInstanceProperty>();
     foreach (ResourceProperty childProperty in type.Properties)
     {
         ResourceInstanceProperty resourceInstanceProperty = null;
         if (childProperty.IsComplexType)
         {
             resourceInstanceProperty = new ResourceInstanceComplexProperty(childProperty.Type.Name, childProperty.Name, CreateComplexResourceInstance((ComplexType)childProperty.Type));
         }
         else
         {
             NodeValue nodeValue = Resource.CreateValue(childProperty);
             resourceInstanceProperty = new ResourceInstanceSimpleProperty(childProperty.Name, nodeValue);
         }
         instanceProperties.Add(resourceInstanceProperty);
     }
     ComplexResourceInstance complexInstance = new ComplexResourceInstance(type.Name, instanceProperties.ToArray());
     return complexInstance;
 }
        public void VisitResourceInstanceSimpleProperty(ResourceInstanceSimpleProperty simplePropertyNode, XmlElement parentNode)
        {
            XmlElement simplePropertyElement = null;

            simplePropertyElement = CreateDataWebElement(simplePropertyNode.Name);
            
            if (simplePropertyNode.IncludeTypeMetadataHint)
            {
                XmlAttribute typeAttribute = CreateDataMetadataAttribute("type");
#if !ClientSKUFramework

                if (simplePropertyNode.ClrType == typeof(byte[]) || simplePropertyNode.ClrType == typeof(System.Data.Linq.Binary))
                    typeAttribute.Value = "Edm.Binary";
                else
#endif
                    typeAttribute.Value = simplePropertyNode.ClrType.ToString().Replace("System.", "Edm.");
                simplePropertyElement.Attributes.Append(typeAttribute);
            }
            //TODO, need to do the correct serialization per type
            //TODO: What do we do if null?
            if (simplePropertyNode.PropertyValue != null)
            {
                string xmlValue = TypeData.XmlValueFromObject(simplePropertyNode.PropertyValue);
                simplePropertyElement.InnerText = xmlValue;
                if (simplePropertyNode.PropertyValue is string)
                {
                    if ((simplePropertyNode.PropertyValue as string).ToCharArray().Any(c => Char.IsWhiteSpace(c)))
                    {
                        XmlAttribute space = document.CreateAttribute("xml", "space", null);
                        space.Value = "preserve";
                        simplePropertyElement.Attributes.Append(space);
                    }
                }
            }
            else
            {
                XmlAttribute isnullAttribute = CreateDataWebMetadataAttribute("null");
                isnullAttribute.Value = "true";
                simplePropertyElement.Attributes.Append(isnullAttribute);
            }

            if (parentNode == null)
            {
                AddNamespacesToTopElement(simplePropertyElement);
                document.AppendChild(simplePropertyElement);
            }
            else
            {
                parentNode.AppendChild(simplePropertyElement);
            }

        }
Esempio n. 6
0
 private void ModifyProperty(ResourceInstanceSimpleProperty property, RowComplexType newResource)
 {
     newResource.Properties[property.Name] = property.PropertyValue;
 }