/// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte keyType, valueType;
            int count;
            if (!container.TryReadByte(out keyType)) return GetObjectResultTypes.NotEnoughData;
            if (!container.TryReadByte(out valueType)) return GetObjectResultTypes.NotEnoughData;
            if (!container.TryReadInt32(out count)) return GetObjectResultTypes.NotEnoughData;
            count = count.ToLittleEndian();
            Dictionary<string, Cell> value = new Dictionary<string, Cell>(count);
            for (int i = 0; i < count; i++)
            {
                int stringCount;
                if (!container.TryReadInt32(out stringCount)) return GetObjectResultTypes.NotEnoughData;
                stringCount = stringCount.ToLittleEndian();
                string keyContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out keyContent)) return GetObjectResultTypes.NotEnoughData;

                Cell valueContent;
                GetObjectResultTypes type = ThriftObjectEngine.TryGetObject(typeof(Cell), container, out valueContent, true);
                if (type != GetObjectResultTypes.Succeed) return type;
                value.Add(keyContent, valueContent);
            }
            result.SetValue(instance, value);
            return GetObjectResultTypes.Succeed;
        }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     int value;
     if(!container.TryReadInt32(out value)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, value.ToLittleEndian());
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     MessageIdentity identity;
     if(!container.TryReadMessageIdentity(out identity)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, identity);
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     byte value;
     if(!container.TryReadByte(out value)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, value);
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     int value;
     if(!container.TryReadInt32(out value)) return GetObjectResultTypes.NotEnoughData;
     value = value.ToLittleEndian();
     string content;
     if (!container.TryReadString(Encoding.UTF8, value, out content)) return GetObjectResultTypes.NotEnoughData;
     result.SetValue(instance, content);
     return GetObjectResultTypes.Succeed;
 }
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="container">网络数据容器</param>
 public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
 {
     byte type;
     int count;
     if (!container.TryReadByte(out type)) return GetObjectResultTypes.NotEnoughData;
     if (!container.TryReadInt32(out count)) return GetObjectResultTypes.NotEnoughData;
     count = count.ToLittleEndian();
     string[] value = new string[count];
     for (int i = 0; i < count; i++)
     {
         int length;
         if (!container.TryReadInt32(out length)) return GetObjectResultTypes.NotEnoughData;
         length = length.ToLittleEndian();
         string content;
         if (!container.TryReadString(Encoding.UTF8, length, out content)) return GetObjectResultTypes.NotEnoughData;
         value[i] = content;
     }
     result.SetValue(instance, value);
     return GetObjectResultTypes.Succeed;
 }
Пример #7
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte value;

            if (!container.TryReadByte(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }
Пример #8
0
        /// <summary>
        ///     将一个元数据转换为特定类型的对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="target">特定的对象</param>
        /// <param name="container">网络数据容器</param>
        /// <param name="value">如果解析成功, 则此字段为解析成功后的值</param>
        /// <param name="isInnerObject">
        ///     是否为内部对象
        ///     <para>* 如果此值被设置为false(默认值), 则会对当前类型尝试解析MessageIdentity字段</para>
        /// </param>
        /// <returns>返回一个解析后的状态</returns>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        /// <exception cref="Exception">转换失败</exception>
        public static GetObjectResultTypes TryGetObject <T>(Type target, INetworkDataContainer container, out T value, bool isInnerObject = false)
        {
            value = default(T);
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            Dictionary <short, GetObjectAnalyseResult> result = Analyser.GetObjectAnalyser.Analyse(target);

            if (result == null)
            {
                return(GetObjectResultTypes.UnknownObjectType);
            }
            GetObjectResultTypes tmpFieldParsingResult;
            //create instance for new obj.
            Object       instance     = Activator.CreateInstance(target);
            ThriftObject thriftObject = instance as ThriftObject;

            if (thriftObject == null)
            {
                throw new Exception("Cannot convert target object to Intellect Object! #type: " + target.FullName);
            }

            #region Data Parsing.

            GetObjectAnalyseResult analyzeResult;
            if (!isInnerObject)
            {
                #region Message Identity.

                if (!result.TryGetValue(-1, out analyzeResult))
                {
                    throw new Exception("#Lost Thrift protocol object processor which it can handles type of MessageIdentity");
                }
                if (analyzeResult.HasCacheFinished)
                {
                    if ((tmpFieldParsingResult = analyzeResult.CacheProcess(instance, analyzeResult, container)) != GetObjectResultTypes.Succeed)
                    {
                        container.ResetOffset();
                        return(tmpFieldParsingResult);
                    }
                }
                else
                {
                    IThriftTypeProcessor processor = ThriftTypeProcessorMapping.Instance.GetProcessor(analyzeResult.Property.PropertyType);
                    if (processor == null)
                    {
                        throw new Exception("#Lost Thrift protocol object processor which it can handles type of MessageIdentity");
                    }
                    analyzeResult.CacheProcess     = processor.Process;
                    analyzeResult.HasEnoughData    = processor.HasEnoughData;
                    analyzeResult.HasCacheFinished = true;
                    if ((tmpFieldParsingResult = analyzeResult.CacheProcess(instance, analyzeResult, container)) != GetObjectResultTypes.Succeed)
                    {
                        container.ResetOffset();
                        return(tmpFieldParsingResult);
                    }
                }

                #endregion
            }

            while (true)
            {
                byte pType;
                //get property type.
                if (!container.TryReadByte(out pType))
                {
                    container.ResetOffset();
                    return(GetObjectResultTypes.NotEnoughData);
                }
                PropertyTypes propertyType = (PropertyTypes)pType;
                //succeed parsing binary data to a Thrift protocol object by finding Thrift protocol's STOP flag.
                if (propertyType == PropertyTypes.Stop)
                {
                    value = (T)instance;
                    return(GetObjectResultTypes.Succeed);
                }
                //get id.
                short id;
                if (!container.TryReadInt16(out id))
                {
                    container.ResetOffset();
                    return(GetObjectResultTypes.NotEnoughData);
                }
                id = id.ToLittleEndian();
                //get analyze result.
                if (!result.TryGetValue(id, out analyzeResult))
                {
                    throw new Exception(string.Format("Illegal data contract, non-exists id! #id: {0} \r\n#Formatted MSG info: {1}, data: \r\n{2}", id, instance, container.Dump()));
                }
                //set current property value to the target object.
                if ((tmpFieldParsingResult = InstanceHelper.SetInstance(thriftObject, analyzeResult, container)) != GetObjectResultTypes.Succeed)
                {
                    container.ResetOffset();
                    return(tmpFieldParsingResult);
                }
            }

            #endregion
        }
Пример #9
0
 /// <summary>
 ///     将一个元数据转换为特定类型的对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="container">网络数据容器</param>
 /// <param name="value">如果解析成功, 则此字段为解析成功后的值</param>
 /// <returns>返回一个解析后的状态</returns>
 /// <exception cref="ArgumentNullException">参数不能为空</exception>
 /// <exception cref="Exception">转换失败</exception>
 public static GetObjectResultTypes TryGetObject <T>(INetworkDataContainer container, out T value)
 {
     return(TryGetObject(typeof(T), container, out value));
 }
Пример #10
0
 /// <summary>
 ///     ��Ԫ����ת��Ϊ�������ͻ�����
 /// </summary>
 /// <param name="instance">Ŀ�����</param>
 /// <param name="result">�������</param>
 /// <param name="container">������������</param>
 public abstract GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container);
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            MessageIdentity identity;

            if (!container.TryReadMessageIdentity(out identity))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, identity);
            return(GetObjectResultTypes.Succeed);
        }
Пример #12
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="instance">目标对象</param>
 /// <param name="result">分析结果</param>
 /// <param name="container">网络数据容器</param>
 public abstract GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container);
Пример #13
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            int value;

            if (!container.TryReadInt32(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, value.ToLittleEndian());
            return(GetObjectResultTypes.Succeed);
        }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     _container.Dispose();
     _container = null;
 }
Пример #15
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            int value;

            if (!container.TryReadInt32(out value))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            value = value.ToLittleEndian();
            string content;

            if (!container.TryReadString(Encoding.UTF8, value, out content))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            result.SetValue(instance, content);
            return(GetObjectResultTypes.Succeed);
        }
Пример #16
0
        /// <summary>
        ///     设置字段实例
        /// </summary>
        /// <param name="instance">对象实例</param>
        /// <param name="analyseResult">字段临时解析结构</param>
        /// <param name="container">网络数据容器</param>
        public static GetObjectResultTypes SetInstance(object instance, GetObjectAnalyseResult analyseResult, INetworkDataContainer container)
        {
            GetObjectAnalyseResult analyze = analyseResult;

            //热处理判断
            if (analyze.HasCacheFinished) return analyze.CacheProcess(instance, analyseResult, container);

            #region 普通类型判断

            IThriftTypeProcessor intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
            if (intellectTypeProcessor != null)
            {
                //添加热缓存
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess = processor.Process;
                analyze.HasEnoughData = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            #region 枚举类型判断

            //枚举类型
            if (analyze.Property.PropertyType.IsEnum)
            {
                Type enumType = Enum.GetUnderlyingType(analyze.Property.PropertyType);
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(enumType);
                if (intellectTypeProcessor == null) throw new Exception("Cannot support this enum type! #type: " + analyze.Property.PropertyType);
                //添加热处理
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess = processor.Process;
                analyze.HasEnoughData = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            #region 可空类型判断

            Type innerType;
            if ((innerType = Nullable.GetUnderlyingType(analyze.Property.PropertyType)) != null)
            {
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(innerType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.CacheProcess = processor.Process;
                    analyze.HasEnoughData = processor.HasEnoughData;
                    analyze.HasCacheFinished = true;
                    return analyze.CacheProcess(instance, analyseResult, container);
                }
                throw new Exception("Cannot find compatible processor, #type: " + analyze.Property.PropertyType);
            }

            #endregion

            #region Thrift类型的判断

            //Thrift对象的判断
            if (analyze.Property.PropertyType.IsClass && analyze.Property.PropertyType.GetInterface(Consts.ThriftObjectFullName) != null)
            {
                //添加热缓存
                analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                {
                    GetObjectResultTypes r;
                    ThriftObject tobj;
                    if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType, innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed) return r;
                    innerAnalyseResult.SetValue(innerInstance, tobj);
                    return GetObjectResultTypes.Succeed;
                };
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container); ;
            }

            #endregion

            #region 数组的判断

            if (analyze.Property.PropertyType.IsArray)
            {
                Type elementType = analyze.Property.PropertyType.GetElementType();
                intellectTypeProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.HasEnoughData = processor.HasEnoughData;
                    analyze.CacheProcess = processor.Process;
                    analyze.HasCacheFinished = true;
                    return analyze.CacheProcess(instance, analyseResult, container);
                }
                if (elementType.IsSubclassOf(typeof (ThriftObject)))
                {
                    #region IntellectObject type array processor.

                    //add HOT cache.
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                    {
                        if(!innerContainer.CheckEnoughSize(5)) return GetObjectResultTypes.NotEnoughData;
                        byte tmpData;
                        int arrLen;
                        if (!innerContainer.TryReadByte(out tmpData)) return GetObjectResultTypes.NotEnoughData;
                        PropertyTypes arrElementType = (PropertyTypes)tmpData;
                        if (!innerContainer.TryReadInt32(out arrLen)) return GetObjectResultTypes.NotEnoughData;
                        arrLen = arrLen.ToLittleEndian();
                        Func<int, ThriftObject[]> func = ThriftObjectArrayHelper.GetFunc<ThriftObject>(analyze.Property.PropertyType);
                        ThriftObject[] array = func(arrLen);
                        for (int i = 0; i < arrLen; i++)
                        {
                            GetObjectResultTypes r;
                            ThriftObject tobj;
                            if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType.GetElementType(), innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed) return r;
                            array[i] = tobj;
                        }
                        innerAnalyseResult.SetValue(innerInstance, array);
                        return GetObjectResultTypes.Succeed;
                    };

                    #endregion
                }
                else throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                analyze.HasCacheFinished = true;
                return analyze.CacheProcess(instance, analyseResult, container);
            }

            #endregion

            throw new Exception("Cannot support this data type: " + analyze.Property.PropertyType);
        }
Пример #17
0
        /// <summary>
        ///     设置字段实例
        /// </summary>
        /// <param name="instance">对象实例</param>
        /// <param name="analyseResult">字段临时解析结构</param>
        /// <param name="container">网络数据容器</param>
        public static GetObjectResultTypes SetInstance(object instance, GetObjectAnalyseResult analyseResult, INetworkDataContainer container)
        {
            GetObjectAnalyseResult analyze = analyseResult;

            //热处理判断
            if (analyze.HasCacheFinished)
            {
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #region 普通类型判断

            IThriftTypeProcessor intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
            if (intellectTypeProcessor != null)
            {
                //添加热缓存
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess     = processor.Process;
                analyze.HasEnoughData    = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            #region 枚举类型判断

            //枚举类型
            if (analyze.Property.PropertyType.IsEnum)
            {
                Type enumType = Enum.GetUnderlyingType(analyze.Property.PropertyType);
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(enumType);
                if (intellectTypeProcessor == null)
                {
                    throw new Exception("Cannot support this enum type! #type: " + analyze.Property.PropertyType);
                }
                //添加热处理
                IThriftTypeProcessor processor = intellectTypeProcessor;
                analyze.CacheProcess     = processor.Process;
                analyze.HasEnoughData    = processor.HasEnoughData;
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            #region 可空类型判断

            Type innerType;
            if ((innerType = Nullable.GetUnderlyingType(analyze.Property.PropertyType)) != null)
            {
                intellectTypeProcessor = ThriftTypeProcessorMapping.Instance.GetProcessor(innerType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.CacheProcess     = processor.Process;
                    analyze.HasEnoughData    = processor.HasEnoughData;
                    analyze.HasCacheFinished = true;
                    return(analyze.CacheProcess(instance, analyseResult, container));
                }
                throw new Exception("Cannot find compatible processor, #type: " + analyze.Property.PropertyType);
            }

            #endregion

            #region Thrift类型的判断

            //Thrift对象的判断
            if (analyze.Property.PropertyType.IsClass && analyze.Property.PropertyType.GetInterface(Consts.ThriftObjectFullName) != null)
            {
                //添加热缓存
                analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                {
                    GetObjectResultTypes r;
                    ThriftObject         tobj;
                    if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType, innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed)
                    {
                        return(r);
                    }
                    innerAnalyseResult.SetValue(innerInstance, tobj);
                    return(GetObjectResultTypes.Succeed);
                };
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));;
            }

            #endregion

            #region 数组的判断

            if (analyze.Property.PropertyType.IsArray)
            {
                Type elementType = analyze.Property.PropertyType.GetElementType();
                intellectTypeProcessor = ArrayTypeProcessorMapping.Instance.GetProcessor(analyze.Property.PropertyType);
                if (intellectTypeProcessor != null)
                {
                    //添加热缓存
                    IThriftTypeProcessor processor = intellectTypeProcessor;
                    analyze.HasEnoughData    = processor.HasEnoughData;
                    analyze.CacheProcess     = processor.Process;
                    analyze.HasCacheFinished = true;
                    return(analyze.CacheProcess(instance, analyseResult, container));
                }
                if (elementType.IsSubclassOf(typeof(ThriftObject)))
                {
                    #region IntellectObject type array processor.

                    //add HOT cache.
                    analyze.CacheProcess = delegate(object innerInstance, GetObjectAnalyseResult innerAnalyseResult, INetworkDataContainer innerContainer)
                    {
                        if (!innerContainer.CheckEnoughSize(5))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        byte tmpData;
                        int  arrLen;
                        if (!innerContainer.TryReadByte(out tmpData))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        PropertyTypes arrElementType = (PropertyTypes)tmpData;
                        if (!innerContainer.TryReadInt32(out arrLen))
                        {
                            return(GetObjectResultTypes.NotEnoughData);
                        }
                        arrLen = arrLen.ToLittleEndian();
                        Func <int, ThriftObject[]> func  = ThriftObjectArrayHelper.GetFunc <ThriftObject>(analyze.Property.PropertyType);
                        ThriftObject[]             array = func(arrLen);
                        for (int i = 0; i < arrLen; i++)
                        {
                            GetObjectResultTypes r;
                            ThriftObject         tobj;
                            if ((r = ThriftObjectEngine.TryGetObject(innerAnalyseResult.Property.PropertyType.GetElementType(), innerContainer, out tobj, true)) != GetObjectResultTypes.Succeed)
                            {
                                return(r);
                            }
                            array[i] = tobj;
                        }
                        innerAnalyseResult.SetValue(innerInstance, array);
                        return(GetObjectResultTypes.Succeed);
                    };

                    #endregion
                }
                else
                {
                    throw new NotSupportedException(string.Format(ExceptionMessage.EX_NOT_SUPPORTED_VALUE, analyseResult.Attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
                }
                analyze.HasCacheFinished = true;
                return(analyze.CacheProcess(instance, analyseResult, container));
            }

            #endregion

            throw new Exception("Cannot support this data type: " + analyze.Property.PropertyType);
        }
Пример #18
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte keyType, valueType;
            int  count;

            if (!container.TryReadByte(out keyType))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadByte(out valueType))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadInt32(out count))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            count = count.ToLittleEndian();
            Dictionary <string, string> value = new Dictionary <string, string>(count);

            for (int i = 0; i < count; i++)
            {
                int stringCount;
                if (!container.TryReadInt32(out stringCount))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                stringCount = stringCount.ToLittleEndian();
                string keyContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out keyContent))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }

                if (!container.TryReadInt32(out stringCount))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                stringCount = stringCount.ToLittleEndian();
                string valueContent;
                if (!container.TryReadString(Encoding.UTF8, stringCount, out valueContent))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                value.Add(keyContent, valueContent);
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }
Пример #19
0
 /// <summary>
 ///    ���Լ��һ�µ�ǰ����Ҫ���������ݿ��ó����Ƿ���������͵Ľ�������
 ///    <para>* �˷���ֻ�е�ExpectedDataSize = -1ʱ�Żᱻ����</para>
 /// </summary>
 /// <param name="container">������������</param>
 /// <returns></returns>
 public virtual bool HasEnoughData(INetworkDataContainer container)
 {
     return true;
 }
Пример #20
0
 /// <summary>
 ///    尝试检查一下当前所需要解析的数据可用长度是否满足此类型的解析需求
 ///    <para>* 此方法只有当ExpectedDataSize = -1时才会被调用</para>
 /// </summary>
 /// <param name="container">网络数据容器</param>
 /// <returns></returns>
 public virtual bool HasEnoughData(INetworkDataContainer container)
 {
     return(true);
 }
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="instance">目标对象</param>
        /// <param name="result">分析结果</param>
        /// <param name="container">网络数据容器</param>
        public override GetObjectResultTypes Process(object instance, GetObjectAnalyseResult result, INetworkDataContainer container)
        {
            byte type;
            int  count;

            if (!container.TryReadByte(out type))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            if (!container.TryReadInt32(out count))
            {
                return(GetObjectResultTypes.NotEnoughData);
            }
            count = count.ToLittleEndian();
            string[] value = new string[count];
            for (int i = 0; i < count; i++)
            {
                int length;
                if (!container.TryReadInt32(out length))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                length = length.ToLittleEndian();
                string content;
                if (!container.TryReadString(Encoding.UTF8, length, out content))
                {
                    return(GetObjectResultTypes.NotEnoughData);
                }
                value[i] = content;
            }
            result.SetValue(instance, value);
            return(GetObjectResultTypes.Succeed);
        }