Esempio n. 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            var props = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(value.GetType());

            for (int i = 0; i < props.Count; i++)
            {
                var propEx = props[i];
                if (propEx == null || propEx.mustIgnoreMemberForClient)
                {
                    continue;
                }
                PropertyInfo prop      = propEx.prop;
                var          propValue = prop.GetValue(value, null);
                //We should not send in the json for an object, any property that is an stateobject
                //they should travel independenly
                //This check is important because we have properties
                if (!(propValue is IStateObject))
                {
                    writer.WritePropertyName(prop.Name);
                    serializer.Serialize(writer, propValue);
                }
            }
            writer.WriteEndObject();
        }
Esempio n. 2
0
        /// <summary>
        ///     Given the instance it tries to add the bit array to the dictionary of bit arrays
        ///     representing the state (modified or not) of the model properties.
        /// </summary>
        /// <param name="model">The instance of IChangesTrackeable</param>
        public void AddsBitArray(IStateObject model)
        {
            BitArray data;

            if (!bitArrays.TryGetValue(model, out data))
            {
                var props = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(model.GetType());
                bitArrays.Add(model, new BitArray(props.Count));
            }
            else
            {
                data.SetAll(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     It collects all the delta objects int the given instance
        /// </summary>
        /// <param name="instance">The instance</param>
        /// <returns>The changes found in the instance</returns>
        public object GetDeltas(IStateObject instance)
        {
            //  Arrayway
            BitArray bitArray;
            Delta    delta = null;

            // if model has been subscribed to any delta tracker
            if (bitArrays.TryGetValue(instance, out bitArray))
            {
                if (bitArray == null)
                {
                    return(null);
                }
                if (instance is IReturnWholeObjectAsDelta)
                {
                    return(instance);
                }
                var propertiesMatchingBitArrays = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(instance.GetType());
                var dataCount = bitArray.Count;
                for (var bitArrayPosition = 0; bitArrayPosition < dataCount; bitArrayPosition++)
                {
                    if (bitArray.Get(bitArrayPosition))
                    {
                        var propertyInfoEx = propertiesMatchingBitArrays[bitArrayPosition];
                        if (!propertyInfoEx.mustIgnoreMemberForClient)
                        {
                            object propValue = propertyInfoEx.prop.GetValue(instance);
                            if (delta == null)
                            {
                                delta = new Delta();
                            }
                            delta.Add(propertyInfoEx.prop.Name, propValue);
                        }
                    }
                }
            }
            if (delta != null)
            {
                //We are including the UniqueID in the delta
                if (delta.Count > 0)
                {
                    delta["UniqueID"] = instance.UniqueID;
                }
            }
            return(delta);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            Type valueType = value.GetType();

            if (writeTypeInfo)
            {
                writer.WritePropertyName("__type");

                string assemblyQualifiedName = valueType.AssemblyQualifiedName;
                writer.WriteValue(assemblyQualifiedName);
            }
            var propArr = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(valueType);

            for (var i = 0; i < propArr.Count; i++)
            {
                var propEx = propArr[i];
                if (propEx == null)
                {
                    continue;
                }
                var prop = propEx.prop;
                if (propEx.mustIgnoreMemberForClient)
                {
                    continue;
                }
                object propValue = null;
                try
                {
                    propValue = prop.GetValue(value, null);
                    writer.WritePropertyName(prop.Name);
                    serializer.Serialize(writer, propValue);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Problem while writing JSON for object of type " + valueType + " property " + prop.Name);
                    Debug.WriteLine("Error " + ex.Message);
                }
            }

            writer.WriteEndObject();
        }
        protected override List <MemberInfo> GetSerializableMembers(Type type)
        {
            if (TypeCacheUtils.IsAnStructType(type) ||
                (type == typeof(CurrentState)) ||
                (type == typeof(ViewsState)) ||
                (type == typeof(ClientCommand)))
            {
                return(base.GetSerializableMembers(type));
            }

            List <MemberInfo> props = new List <MemberInfo>();

            foreach (var propEx in TypePropertiesCache.GetArrayPropertiesOrderedByIndex(type))

            {
                if (propEx != null && !propEx.IsExcludedPropertyForSerialization(serverSide, skipUniqueId, skipObjectProperties))
                {
                    props.Add(propEx.prop);
                }
            }
            return(props);
        }