private void parseJson(AutoCSer.Json.Parser parser) { if (MemberMap == null) { MemberMap = new MemberMap <memberMapType>(); } parser.MemberMap = MemberMap; if (Value == null) { valueType poolValue = Value = MemberMapValueLinkPool <valueType> .Pop(); try { AutoCSer.Json.TypeParser <valueType> .Parse(parser, ref Value); } finally { if (poolValue != Value) { MemberMapValueLinkPool <valueType> .PushNotNull(poolValue); } } } else { memberMapType parseValue = Value; AutoCSer.Json.TypeParser <memberMapType> .Parse(parser, ref parseValue); } }
/// <summary> /// 日志流数据处理 /// </summary> /// <param name="data"></param> /// <returns></returns> private bool onLog(ref Log <valueType, modelType> .Data data) { valueType value = data.Value.Value; int identity = getKey(value); switch (data.Type) { case LogType.Insert: if (identity >= array.Length) { array.ToSize(identity + 1); } if (array[identity] == null) { ++Count; } if (identity > maxIdentity) { maxIdentity = identity; } custom.Insert(array[identity] = value); return(true); case LogType.Update: if (identity < array.Length) { valueType clientValue = array[identity]; if (clientValue != null) { MemberMap <modelType> memberMap = data.Value.MemberMap; custom.Update(clientValue, value, memberMap); AutoCSer.MemberCopy.Copyer <modelType> .Copy(clientValue, value, memberMap); } } MemberMapValueLinkPool <valueType> .PushNotNull(value); return(true); case LogType.Delete: MemberMapValueLinkPool <valueType> .PushNotNull(value); if (identity < array.Length) { valueType clientValue = array[identity]; if (clientValue != null) { array[identity] = null; --Count; custom.Delete(clientValue); } } return(true); } return(false); }
private void deSerialize(AutoCSer.BinarySerialize.DeSerializer deSerializer) { if (deSerializer.CheckNullValue() == 0) { Value = default(valueType); } else { MemberMap oldMemberMap = deSerializer.MemberMap; deSerializer.MemberMap = MemberMap; try { if (Value == null) { valueType poolValue = Value = MemberMapValueLinkPool <valueType> .Pop(); try { AutoCSer.BinarySerialize.TypeDeSerializer <valueType> .DeSerialize(deSerializer, ref Value); } finally { if (poolValue != Value) { MemberMapValueLinkPool <valueType> .PushNotNull(poolValue); } } } else { memberMapType parseValue = Value; AutoCSer.BinarySerialize.TypeDeSerializer <memberMapType> .DeSerialize(deSerializer, ref parseValue); } } finally { MemberMap = (MemberMap <memberMapType>)deSerializer.MemberMap; deSerializer.MemberMap = oldMemberMap; } } }
/// <summary> /// 日志流数据处理 /// </summary> /// <param name="data"></param> /// <returns></returns> private bool onLog(ref Log <valueType, modelType> .Data data) { valueType value = data.Value.Value, clientValue; keyType key = getKey(value); switch (data.Type) { case LogType.Insert: if (dictionary.TryGetValue(key, out clientValue)) { dictionary[key] = value; } else { dictionary.Add(key, value); } custom.Insert(value); return(true); case LogType.Update: if (dictionary.TryGetValue(key, out clientValue)) { MemberMap <modelType> memberMap = data.Value.MemberMap; custom.Update(clientValue, value, memberMap); AutoCSer.MemberCopy.Copyer <modelType> .Copy(clientValue, value, memberMap); } MemberMapValueLinkPool <valueType> .PushNotNull(value); return(true); case LogType.Delete: MemberMapValueLinkPool <valueType> .PushNotNull(value); if (dictionary.TryGetValue(key, out clientValue)) { custom.Delete(clientValue); } return(true); } return(false); }
/// <summary> /// 日志流数据 /// </summary> /// <param name="data"></param> private void onLog(AutoCSer.Net.TcpServer.ReturnValue <Log <valueType, modelType> .Data> data) { if (isError == 0) { if (data.Type == Net.TcpServer.ReturnType.Success) { try { valueType value = data.Value.Value.Value; RandomKey <keyType> key = getKey(data.Value.Value.Value); KeyValue <valueType, EventWaitHandle> queueValue; switch (data.Value.Type) { case LogType.Insert: Monitor.Enter(logLock); if (queue.TryGetOnly(key, out queueValue)) { queue.SetOnly(key, new KeyValue <valueType, EventWaitHandle>(value, null)); Monitor.Exit(logLock); } else { try { queue.Set(ref key, new KeyValue <valueType, EventWaitHandle>(value, null)); if (queue.Count > maxCount) { queue.UnsafePopNode(); } } finally { Monitor.Exit(logLock); } } return; case LogType.Update: Monitor.Enter(logLock); if (queue.TryGetOnly(key, out queueValue)) { if (queueValue.Value == null) { try { AutoCSer.MemberCopy.Copyer <modelType> .Copy(queueValue.Key, value, data.Value.Value.MemberMap); } finally { Monitor.Exit(logLock); } if (data.Value.Value.MemberMap == null && !isErrorMemberMap) { isErrorMemberMap = true; log.add(AutoCSer.Log.LogType.Warn, "客户端缓存数据缺少成员位图信息 " + typeof(valueType).fullName()); } return; } queue.Remove(ref key, out queueValue); } Monitor.Exit(logLock); MemberMapValueLinkPool <valueType> .PushNotNull(value); return; case LogType.Delete: MemberMapValueLinkPool <valueType> .PushNotNull(value); Monitor.Enter(logLock); queue.Remove(ref key, out queueValue); Monitor.Exit(logLock); return; } } catch (Exception error) { log.add(AutoCSer.Log.LogType.Error, error); } } this.error(); } }