示例#1
0
        private JNode ExportAspect(StructuralAspect aspect, IEnumerable <DataProperty> dps)
        {
            var jn = new JNode();

            dps.ForEach((dp) => {
                var propName = dp.Name;
                var value    = aspect.GetRawValue(propName);
                var co       = value as IComplexObject;
                if (co != null)
                {
                    var complexAspect = co.ComplexAspect;
                    jn.AddJNode(propName, ExportAspect(complexAspect, complexAspect.ComplexType.DataProperties));
                }
                else
                {
                    if (value != dp.DefaultValue)
                    {
                        jn.AddPrimitive(propName, value);
                    }
                }
            });
            if (aspect is ComplexAspect)
            {
                var complexAspectNode = ExportComplexAspectInfo((ComplexAspect)aspect);
                jn.AddJNode("complexAspect", complexAspectNode);
            }
            else
            {
                var entityAspectNode = ExportEntityAspectInfo((EntityAspect)aspect);
                jn.AddJNode("entityAspect", entityAspectNode);
            }
            return(jn);
        }
示例#2
0
        private JNode BuildOriginalValuesMapNode(StructuralAspect aspect, NamingConvention nc)
        {
            var ovMap = aspect.OriginalValuesMap.ToDictionary(kvp => nc.ClientPropertyNameToServer(kvp.Key), kvp => kvp.Value);
            var cps   = aspect is EntityAspect
        ? ((EntityAspect)aspect).EntityType.ComplexProperties
        : ((ComplexAspect)aspect).ComplexType.ComplexProperties;

            cps.ForEach(cp => {
                var co         = aspect.GetValue(cp.Name);
                var serverName = nc.ClientPropertyNameToServer(cp.Name);
                if (cp.IsScalar)
                {
                    var ovmNode       = BuildOriginalValuesMapNode(((IComplexObject)co).ComplexAspect, nc);
                    ovMap[serverName] = ovmNode;
                }
                else
                {
                    var ovmNodes      = ((IEnumerable)co).Cast <IComplexObject>().Select(co2 => BuildOriginalValuesMapNode(co2.ComplexAspect, nc));
                    ovMap[serverName] = JNode.ToJArray(ovmNodes);
                }
            });
            var result = JNode.BuildMapNode(ovMap);

            return(result);
        }
示例#3
0
        private static void UpdateOriginalValues(StructuralAspect targetAspect, JNode jNode)
        {
            var stType     = targetAspect.StructuralType;
            var aspectNode = jNode.GetJNode(stType.IsEntityType ? "entityAspect" : "complexAspect");

            if (aspectNode == null)
            {
                return;               // aspect node can be null in a complexAspect with no originalValues
            }
            var originalValuesMap = aspectNode.GetMap("originalValuesMap", pn => stType.GetDataProperty(pn).ClrType);

            if (originalValuesMap != null)
            {
                targetAspect._originalValuesMap = new BackupValuesMap(originalValuesMap);
            }
        }
示例#4
0
        private JNode DataToJNode(StructuralAspect aspect)
        {
            var jn    = new JNode();
            var stype = aspect.StructuralType;

            stype.DataProperties.ForEach(dp => {
                var val = aspect.GetValue(dp.Name);
                // handle nonscalar dps
                if (dp.IsComplexProperty)
                {
                    jn.AddJNode(dp.NameOnServer, DataToJNode(((IComplexObject)val).ComplexAspect));
                }
                else
                {
                    jn.AddPrimitive(dp.NameOnServer, val, dp.DefaultValue);
                }
            });
            return(jn);
        }