Esempio n. 1
0
        /// <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();
            }
        }