Example #1
0
        internal static void ToJson(fastCSharp.emit.jsonSerializer toJsoner, memberMapValue <valueType> value)
        {
            if (value.Value == null)
            {
                fastCSharp.web.ajax.WriteNull(toJsoner.CharStream);
            }
            else
            {
                memberMap memberMap = value.MemberMap;
                if (memberMap == null || memberMap.IsDefault)
                {
                    fastCSharp.emit.jsonSerializer.typeToJsoner <valueType> .ToJson(toJsoner, value.Value);
                }
                else
                {
                    fastCSharp.emit.jsonSerializer.config config = typePool <fastCSharp.emit.jsonSerializer.config> .Pop() ?? new fastCSharp.emit.jsonSerializer.config(), oldConfig = toJsoner.Config;

                    fastCSharp.emit.memberCopyer <fastCSharp.emit.jsonSerializer.config> .Copy(config, oldConfig);

                    (toJsoner.Config = config).MemberMap = memberMap;
                    try
                    {
                        fastCSharp.emit.jsonSerializer.typeToJsoner <valueType> .ToJson(toJsoner, value.Value);
                    }
                    finally
                    {
                        toJsoner.Config  = oldConfig;
                        config.MemberMap = null;
                        typePool <fastCSharp.emit.jsonSerializer.config> .PushNotNull(config);
                    }
                }
            }
        }
Example #2
0
 internal static void Serialize(fastCSharp.emit.dataSerializer serializer, memberMapValue <valueType> value)
 {
     if (value.Value == null)
     {
         serializer.Stream.Write(fastCSharp.emit.binarySerializer.NullValue);
     }
     else
     {
         memberMap memberMap = value.MemberMap;
         if (memberMap == null || memberMap.IsDefault)
         {
             fastCSharp.emit.dataSerializer.typeSerializer <valueType> .Serialize(serializer, value.Value);
         }
         else
         {
             memberMap oldMemberMap = serializer.MemberMap, currentMemberMap = serializer.CurrentMemberMap, jsonMemberMap = serializer.JsonMemberMap;
             serializer.MemberMap = memberMap;
             try
             {
                 fastCSharp.emit.dataSerializer.typeSerializer <valueType> .Serialize(serializer, value.Value);
             }
             finally
             {
                 serializer.MemberMap        = oldMemberMap;
                 serializer.CurrentMemberMap = currentMemberMap;
                 serializer.JsonMemberMap    = jsonMemberMap;
             }
         }
     }
 }
Example #3
0
        /// <summary>
        /// 加载日志修改对象
        /// </summary>
        /// <param name="value">修改的对象</param>
        /// <param name="key"></param>
        /// <param name="memberMap">修改对象成员位图</param>
        public void LoadUpdate(valueType value, keyType key, memberMap memberMap)
        {
            cacheValue cacheValue;

            if (tree.TryGetValue(key, out cacheValue))
            {
                fastCSharp.emit.memberCopyer <modelType> .Copy(cacheValue.Value, value, memberMap);
            }
        }
Example #4
0
            internal static bool RemoteTestCase()
            {
                typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null);
                using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer))
                {
                    if (server.Start())
                    {
                        using (memoryDatabaseModelTable <identity> .remote table = new memoryDatabaseModelTable <identity> .remote(new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer), cache = new identityArray <identity>()))
                        {
                            updateMember = table.CreateMemberMap().Append(value => value.Int);
                            cache.WaitLoad();
                            if (cache.Count == 0)
                            {
                                identity int1 = table.Insert(new identity {
                                    Int = 1, String = "A大A"
                                }, false);
                                identity intOld2 = new identity {
                                    Int = 2
                                };
                                identity int2 = table.Insert(intOld2);
                                identity int4 = table.Insert(new identity {
                                    Int = 4
                                });
                                if (int1 == null)
                                {
                                    return(false);
                                }
                                if (int2 == null)
                                {
                                    return(false);
                                }
                                if (int4 == null)
                                {
                                    return(false);
                                }

                                intOld2.Int = 3;
                                identity int3 = table.Update(intOld2, updateMember);
                                if (int3 == null)
                                {
                                    return(false);
                                }
                                identity delete = table.Delete(int4.Id);
                                if (delete == null)
                                {
                                    return(false);
                                }

                                return(check(table, false));
                            }
                            return(check(table, true));
                        }
                    }
                }
                return(false);
            }
Example #5
0
            internal static bool RemoteTestCase()
            {
                typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null);
                using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer))
                {
                    if (server.Start())
                    {
                        using (memoryDatabaseModelTable <primaryKey3, primaryKey> .remote table = new memoryDatabaseModelTable <primaryKey3, primaryKey> .remote(new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer), cache = new dictionary <primaryKey3, primaryKey>(), memoryDatabaseTable.serializeType.Json))
                        {
                            updateMember = table.CreateMemberMap().Append(value => value.Int);
                            cache.WaitLoad();
                            if (cache.Count == 0)
                            {
                                primaryKey3 int1 = table.Insert(new primaryKey3 {
                                    Key1 = 1, Key2 = "1", Key3 = Guid.NewGuid(), Int = 1, String = "A大A"
                                }, false);
                                primaryKey3 intOld2 = new primaryKey3 {
                                    Key1 = 2, Key2 = "2", Key3 = Guid.NewGuid(), Int = 2
                                };
                                primaryKey3 int2 = table.Insert(intOld2);
                                primaryKey3 int4 = table.Insert(new primaryKey3 {
                                    Key1 = 2, Key2 = "2", Key3 = Guid.NewGuid(), Int = 4
                                });
                                if (int1 == null)
                                {
                                    return(false);
                                }
                                if (int2 == null)
                                {
                                    return(false);
                                }
                                if (int4 == null)
                                {
                                    return(false);
                                }

                                intOld2.Int = 3;
                                primaryKey3 int3 = table.Update(intOld2, updateMember);
                                if (int3 == null)
                                {
                                    return(false);
                                }
                                primaryKey3 delete = table.Delete(int4);
                                if (delete == null)
                                {
                                    return(false);
                                }

                                return(check(table, false));
                            }
                            return(check(table, true));
                        }
                    }
                }
                return(false);
            }
Example #6
0
 /// <summary>
 /// 加载日志修改对象
 /// </summary>
 /// <param name="value">修改的对象</param>
 /// <param name="identity">自增值</param>
 /// <param name="memberMap">修改对象成员位图</param>
 public void LoadUpdate(valueType value, int identity, memberMap memberMap)
 {
     if ((uint)identity < (uint)array.Length)
     {
         valueType cacheValue = array[identity].Value;
         if (cacheValue != null)
         {
             fastCSharp.emit.memberCopyer <modelType> .Copy(cacheValue, value, memberMap);
         }
     }
 }
Example #7
0
            /// <summary>
            /// 对象对比
            /// </summary>
            /// <param name="left"></param>
            /// <param name="right"></param>
            /// <param name="memberMap"></param>
            /// <returns></returns>
            private bool equalsValue(valueType left, valueType right, memberMap memberMap)
            {
                object leftObject = left, rightObject = right;

                foreach (field field in fields)
                {
                    if (memberMap.UnsafeIsMember(field.MemberIndex) && !field.Equals(field.Field.GetValue(leftObject), field.Field.GetValue(rightObject)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
Example #8
0
 /// <summary>
 /// 对象对比
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="memberMap"></param>
 /// <returns></returns>
 private bool equals(valueType left, valueType right, memberMap memberMap)
 {
     if (object.ReferenceEquals(left, right))
     {
         return(true);
     }
     foreach (field field in fields)
     {
         if (memberMap.UnsafeIsMember(field.MemberIndex) && !field.Equals(field.Field.GetValue(left), field.Field.GetValue(right)))
         {
             return(false);
         }
     }
     return(true);
 }
Example #9
0
            internal static bool TestCase()
            {
                using (memoryDatabaseModelTable <identity> table = new memoryDatabaseModelTable <identity>(cache = new identityArray <identity>(), memoryDatabaseTable.serializeType.Index, "localIdentity"))
                {
                    updateMember = table.CreateMemberMap().Append(value => value.Int);
                    cache.WaitLoad();
                    if (cache.Count == 0)
                    {
                        identity int1 = table.Insert(new identity {
                            Int = 1, String = "A大A"
                        }, false);
                        identity intOld2 = new identity {
                            Int = 2
                        };
                        identity int2 = table.Insert(intOld2);
                        identity int4 = table.Insert(new identity {
                            Int = 4
                        });
                        if (int1 == null)
                        {
                            return(false);
                        }
                        if (int2 == null)
                        {
                            return(false);
                        }
                        if (int4 == null)
                        {
                            return(false);
                        }

                        intOld2.Int = 3;
                        identity int3 = table.Update(intOld2, updateMember);
                        if (int3 == null)
                        {
                            return(false);
                        }
                        identity delete = table.Delete(int4.Id);
                        if (delete == null)
                        {
                            return(false);
                        }

                        return(check(table, false));
                    }
                    return(check(table, true));
                }
            }
Example #10
0
            internal static bool TestCase()
            {
                using (memoryDatabaseModelTable <primaryKey3, primaryKey> table = new memoryDatabaseModelTable <primaryKey3, primaryKey>(cache = new dictionary <primaryKey3, primaryKey>(), memoryDatabaseTable.serializeType.Json, "localPrimaryKey3"))
                {
                    updateMember = table.CreateMemberMap().Append(value => value.Int);
                    cache.WaitLoad();
                    if (cache.Count == 0)
                    {
                        primaryKey3 int1 = table.Insert(new primaryKey3 {
                            Key1 = 1, Key2 = "1", Key3 = Guid.NewGuid(), Int = 1, String = "A大A"
                        }, false);
                        primaryKey3 intOld2 = new primaryKey3 {
                            Key1 = 2, Key2 = "2", Key3 = Guid.NewGuid(), Int = 2
                        };
                        primaryKey3 int2 = table.Insert(intOld2);
                        primaryKey3 int4 = table.Insert(new primaryKey3 {
                            Key1 = 2, Key2 = "2", Key3 = Guid.NewGuid(), Int = 4
                        });
                        if (int1 == null)
                        {
                            return(false);
                        }
                        if (int2 == null)
                        {
                            return(false);
                        }
                        if (int4 == null)
                        {
                            return(false);
                        }

                        intOld2.Int = 3;
                        primaryKey3 int3 = table.Update(intOld2, updateMember);
                        if (int3 == null)
                        {
                            return(false);
                        }
                        primaryKey3 delete = table.Delete(int4);
                        if (delete == null)
                        {
                            return(false);
                        }

                        return(check(table, false));
                    }
                    return(check(table, true));
                }
            }
Example #11
0
            internal static bool TestCase()
            {
                using (memoryDatabaseModelTable <primaryKey, int> table = new memoryDatabaseModelTable <primaryKey, int>(cache = new fastCSharp.memoryDatabase.cache.searchTree <primaryKey, int>(), memoryDatabaseTable.serializeType.Data, "localPrimaryKey"))
                {
                    updateMember = table.CreateMemberMap().Append(value => value.Int);
                    cache.WaitLoad();
                    if (cache.Count == 0)
                    {
                        primaryKey int1 = table.Insert(new primaryKey {
                            Key = 1, Int = 1, String = "A大A"
                        }, false);
                        primaryKey intOld2 = new primaryKey {
                            Key = 2, Int = 2
                        };
                        primaryKey int2 = table.Insert(intOld2);
                        primaryKey int4 = table.Insert(new primaryKey {
                            Key = 3, Int = 4
                        });
                        if (int1 == null)
                        {
                            return(false);
                        }
                        if (int2 == null)
                        {
                            return(false);
                        }
                        if (int4 == null)
                        {
                            return(false);
                        }

                        intOld2.Int = 3;
                        primaryKey int3 = table.Update(intOld2, updateMember);
                        if (int3 == null)
                        {
                            return(false);
                        }
                        primaryKey delete = table.Delete(int4.Key);
                        if (delete == null)
                        {
                            return(false);
                        }

                        return(check(table, false));
                    }
                    return(check(table, true));
                }
            }
Example #12
0
            private static void deSerialize(fastCSharp.emit.dataDeSerializer deSerializer, ref deSerializePool value)
            {
                if (deSerializer.CheckNull() == 0)
                {
                    value.Value = default(valueType);
                }
                else
                {
                    memberMap oldMemberMap = deSerializer.MemberMap;
                    deSerializer.MemberMap = value.MemberMap;
                    try
                    {
                        if (value.Value == null)
                        {
                            valueType poolValue = value.Value = typePool <valueType> .Pop();

                            try
                            {
                                fastCSharp.emit.dataDeSerializer.typeDeSerializer <valueType> .DeSerialize(deSerializer, ref value.Value);
                            }
                            finally
                            {
                                if (poolValue != value.Value)
                                {
                                    typePool <valueType> .PushOnly(poolValue);
                                }
                            }
                        }
                        else
                        {
                            memberMapType parseValue = value.Value;
                            fastCSharp.emit.dataDeSerializer.typeDeSerializer <memberMapType> .DeSerialize(deSerializer, ref parseValue);
                        }
                    }
                    finally
                    {
                        value.MemberMap        = (memberMap <memberMapType>)deSerializer.MemberMap;
                        deSerializer.MemberMap = oldMemberMap;
                    }
                }
            }
Example #13
0
 private static void deSerialize(fastCSharp.emit.dataDeSerializer deSerializer, ref memberMapValue <valueType> value)
 {
     if (deSerializer.CheckNull() == 0)
     {
         value.Value = default(valueType);
     }
     else
     {
         memberMap oldMemberMap = deSerializer.MemberMap;
         deSerializer.MemberMap = value.MemberMap;
         try
         {
             fastCSharp.emit.dataDeSerializer.typeDeSerializer <valueType> .DeSerialize(deSerializer, ref value.Value);
         }
         finally
         {
             value.MemberMap        = deSerializer.MemberMap;
             deSerializer.MemberMap = oldMemberMap;
         }
     }
 }
Example #14
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        /// <param name="memberMap">更新数据成员</param>
        protected void onUpdated(valueType value, valueType oldValue, memberMap memberMap)
        {
            keyType oldKey = getKey(oldValue), newKey = getKey(value);

            if (newKey.Equals(oldKey))
            {
                valueKeyType oldValueKey = getValueKey(oldValue), newValueKey = getValueKey(value);
                if (!oldValueKey.Equals(newValueKey))
                {
                    targetType target = getValue(newKey);
                    if (target == null)
                    {
                        log.Error.Add(typeof(valueType).FullName + " 没有找到缓存目标对象 " + newKey.ToString(), new System.Diagnostics.StackFrame(), true);
                    }
                    else
                    {
                        Dictionary <valueKeyType, valueType> dictionary = getMember(target);
                        if (dictionary != null)
                        {
                            if (dictionary.Remove(oldValueKey))
                            {
                                dictionary.Add(newValueKey, value);
                                return;
                            }
                            dictionary.Add(newValueKey, value);
                        }
                        log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                    }
                }
            }
            else
            {
                onInserted(value, newKey);
                onDeleted(value, oldKey);
            }
        }
Example #15
0
 /// <summary>
 /// 对象序列化
 /// </summary>
 /// <typeparam name="valueType">对象类型</typeparam>
 /// <param name="stream">内存数据流</param>
 /// <param name="value">数据对象</param>
 /// <param name="filter">成员选择,默认为公共字段成员</param>
 /// <param name="memberMap">成员位图</param>
 public static void Get <valueType>(unmanagedStream stream, valueType value
                                    , code.memberFilters filter = code.memberFilters.InstanceField, memberMap <valueType> memberMap = default(memberMap <valueType>))
 {
     dataSerialize <valueType> .Get(stream, value, filter, memberMap);
 }
Example #16
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="value">更新后的数据</param>
 /// <param name="oldValue">更新前的数据</param>
 /// <param name="memberMap">更新数据成员</param>
 private void onUpdated(object value, object oldValue, memberMap memberMap)
 {
     onUpdated((valueType)value, (valueType)oldValue, memberMap);
 }
Example #17
0
 /// <summary>
 /// 对象成员复制
 /// </summary>
 /// <param name="value">目标对象</param>
 /// <param name="copyValue">被复制对象</param>
 /// <param name="filter">成员选择</param>
 /// <param name="memberMap">成员位图</param>
 public static valueType Copy(valueType value, valueType copyValue
                              , code.memberFilters filter = code.memberFilters.InstanceField, memberMap <valueType> memberMap = default(memberMap <valueType>))
 {
     if (isStruct)
     {
         return(memberGroup.CopyValue(value, copyValue, filter, memberMap));
     }
     else
     {
         if (value == null || copyValue == null)
         {
             log.Error.Throw(log.exceptionType.Null);
         }
         memberGroup.Copy(value, copyValue, filter, memberMap);
         return(value);
     }
 }
Example #18
0
 /// <summary>
 /// 复制成员数据
 /// </summary>
 /// <typeparam name="valueType">表格绑定类型</typeparam>
 /// <typeparam name="memberType">数据成员类型</typeparam>
 /// <param name="value">缓存数据</param>
 /// <param name="newValue">更新后的新数据</param>
 /// <param name="memberMap">更新成员位图</param>
 private static void copyReflection <valueType>(valueType value, valueType newValue, memberMap <valueType> memberMap)
 {
     fastCSharp.setup.cSharp.copy <valueType> .Copy(value, newValue, setup.memberFilter.Instance, memberMap);
 }
Example #19
0
 /// <summary>
 /// 对象反序列化
 /// </summary>
 /// <typeparam name="valueType">对象类型</typeparam>
 /// <param name="value">目标对象</param>
 /// <param name="data">序列化数据</param>
 /// <param name="endIndex">数据结束位置</param>
 /// <param name="memberMap">成员位图</param>
 /// <param name="memberIndexs">自定义成员位图索引</param>
 /// <returns>是否成功</returns>
 public static bool Get <valueType>(ref valueType value, subArray <byte> data, out int endIndex, out memberMap <valueType> memberMap, int[] memberIndexs)
 {
     return(deSerialize <valueType> .Get(ref value, data, out endIndex, out memberMap, memberIndexs));
 }
Example #20
0
 /// <summary>
 /// 用户更新事件
 /// </summary>
 /// <param name="value"></param>
 private void onUserChange(user value, user oldValue, memberMap memberMap)
 {
     context.Post(onUserChange, user.Table.Cache.GetArray());
 }