コード例 #1
0
        /// <summary>
        /// 从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param><param name="data">元数据</param>
        /// <returns>
        /// 返回转换后的第三方客户数据
        /// </returns>
        /// <exception cref="N:KJFramework.Exception">转换失败</exception>
        public override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            unsafe
            {
                fixed(byte *pData = data)
                {
                    IPEndPoint iep = new IPEndPoint(new IPAddress(BitConverter.GetBytes(*(int *)pData)), *(int *)(pData + 4));

                    return(iep);
                }
            }
        }
コード例 #2
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     if (attribute == null)
     {
         throw new System.Exception("非法的智能属性标签。");
     }
     if (attribute.IsRequire && data == null)
     {
         throw new System.Exception("无法处理非法的类型值。");
     }
     return(BitConverter.ToSingle(data, 0));
 }
コード例 #3
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>返回转换后的第三方客户数据</returns>
        /// <exception cref="Exception">转换失败</exception>
        public override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            if (attribute == null)
            {
                throw new System.Exception("非法的智能属性标签。");
            }
            if (attribute.IsRequire && data == null)
            {
                throw new System.Exception("无法处理非法的类型值。");
            }
            long ticks = BitConverter.ToInt64(data, 0);

            return(new DateTime(ticks));
        }
コード例 #4
0
        /// <summary>
        /// 从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>
        /// 返回转换后的第三方客户数据
        /// </returns>
        /// <exception cref="N:KJFramework.Exception">转换失败</exception>
        public override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            TransactionIdentityTypes identityType = (TransactionIdentityTypes)data[0];

            if (identityType == TransactionIdentityTypes.TCP)
            {
                return(TCPTransactionIdentity.Deserialize(data, 0, data.Length));
            }
            if (identityType == TransactionIdentityTypes.NamedPipe)
            {
                return(NamedPipeTransactionIdentity.Deserialize(data, 0, data.Length));
            }
            throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identityType));
        }
コード例 #5
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            IPEndPoint value = analyseResult.GetValue <IPEndPoint>(target);

            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteIPEndPoint(value);
        }
コード例 #6
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     if (attribute == null)
     {
         throw new System.Exception("非法的智能属性标签。");
     }
     if (attribute.IsRequire && data == null)
     {
         throw new System.Exception("无法处理非法的类型值。");
     }
     unsafe
     {
         fixed(byte *pByte = data) return(*(decimal *)pByte);
     }
 }
コード例 #7
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>返回转换后的第三方客户数据</returns>
        /// <exception cref="Exception">转换失败</exception>
        public unsafe override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            TimeSpan[] array = new TimeSpan[data.Length / Size.TimeSpan];
            fixed(byte *pByte = data)
            {
                TimeSpan *pData = (TimeSpan *)pByte;

                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = *pData++;
                }
            }

            return(array);
        }
コード例 #8
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>返回转换后的第三方客户数据</returns>
        /// <exception cref="Exception">转换失败</exception>
        public unsafe override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            ulong[] array = new ulong[data.Length / Size.UInt64];
            fixed(byte *pByte = data)
            {
                ulong *pData = (ulong *)pByte;

                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = *pData++;
                }
            }

            return(array);
        }
コード例 #9
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>返回转换后的第三方客户数据</returns>
        /// <exception cref="Exception">转换失败</exception>
        public unsafe override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            short[] array = new short[data.Length / Size.Int16];
            fixed(byte *pByte = data)
            {
                short *pData = (short *)pByte;

                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = *pData++;
                }
            }

            return(array);
        }
コード例 #10
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute");
     }
     if (attribute.IsRequire && data == null)
     {
         throw new System.Exception("Cannot process a required value, because current binary data is null! #attr id: " + attribute.Id);
     }
     if (data == null || data.Length == 0)
     {
         return(null);
     }
     return(new Blob(data));
 }
コード例 #11
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Color value = analyseResult.GetValue <Color>(target);

            if (value == null || value.Data == null)
            {
                if (attribute.IsRequire)
                {
                    if (attribute.IsRequire)
                    {
                        throw new Exception(string.Format("#Currently property data is required! Id: {0}", attribute.Id));
                    }
                }
                return;
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteMemory(value.Data, 0U, (uint)value.Data.Length);
        }
コード例 #12
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     if (attribute == null)
     {
         throw new System.Exception("非法的智能属性标签。");
     }
     if (attribute.IsRequire && data == null)
     {
         throw new System.Exception("无法处理非法的类型值。");
     }
     //x86
     if (Size.IntPtr == 4)
     {
         return(new IntPtr(BitConverter.ToInt32(data, 0)));
     }
     //x64
     return(new IntPtr(BitConverter.ToInt64(data, 0)));
 }
コード例 #13
0
        /// <summary>
        ///     从元数据转换为第三方客户数据
        /// </summary>
        /// <param name="attribute">当前字段标注的属性</param>
        /// <param name="data">元数据</param>
        /// <returns>返回转换后的第三方客户数据</returns>
        /// <exception cref="Exception">转换失败</exception>
        public override object Process(IntellectPropertyAttribute attribute, byte[] data)
        {
            int    offset = 4;
            ushort len;

            string[] array = new string[BitConverter.ToInt32(data, 0)];
            for (int i = 0; i < array.Length; i++)
            {
                len     = BitConverter.ToUInt16(data, offset);
                offset += 2;
                if (len == 0)
                {
                    continue;
                }
                array[i] = Encoding.UTF8.GetString(data, offset, len);
                offset  += len;
            }
            return(array);
        }
コード例 #14
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string value = isArrayElement ? (string)target : analyseResult.GetValue <string>(target);

            if (value == null)
            {
                if (!attribute.IsRequire || isArrayElement)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            if (!isArrayElement)
            {
                proxy.WriteByte((byte)attribute.Id);
                proxy.WriteInt32(Encoding.UTF8.GetByteCount(value));
            }
            proxy.WriteString(value);
        }
コード例 #15
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            Blob value = analyseResult.GetValue <Blob>(target);

            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            byte[] data = value.Compress();
            if (data == null)
            {
                throw new UnexpectedValueException(string.Format(ExceptionMessage.EX_UNEXPRECTED_VALUE, attribute.Id, analyseResult.Property.Name));
            }
            proxy.WriteByte((byte)attribute.Id);
            proxy.WriteInt32(data.Length);
            proxy.WriteMemory(data, 0U, (uint)data.Length);
        }
コード例 #16
0
        /// <summary>
        /// 从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        /// <param name="isNullable">是否为可空字段标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            TransactionIdentity identity = analyseResult.GetValue <TransactionIdentity>(target);

            if (identity == null)
            {
                return;
            }
            if (identity.IdentityType == TransactionIdentityTypes.TCP)
            {
                TCPTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (TCPTransactionIdentity)identity, proxy);
            }
            else if (identity.IdentityType == TransactionIdentityTypes.NamedPipe)
            {
                NamedPipeTransactionIdentity.Serialize((byte)attribute.Id, IdentitySerializationTypes.IntellectObject, (NamedPipeTransactionIdentity)identity, proxy);
            }
            else
            {
                throw new NotSupportedException(string.Format("#We were not support current type of Transaction-Identity yet! {0}", identity.IdentityType));
            }
        }
コード例 #17
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     if (data == null || data.Length == 0)
     {
         return(null);
     }
     IPEndPoint[] array = new IPEndPoint[data.Length / Size.IPEndPoint];
     unsafe
     {
         int innerOffset = 0;
         fixed(byte *pByte = data)
         {
             for (int i = 0; i < array.Length; i++)
             {
                 array[i]     = new IPEndPoint(new IPAddress(BitConverter.GetBytes(*(int *)(pByte + innerOffset))), *(int *)(pByte + innerOffset + 4));
                 innerOffset += (int)Size.IPEndPoint;
             }
         }
     }
     return(array);
 }
コード例 #18
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            string[] value = analyseResult.GetValue <string[]>(target);
            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            //id(1) + total length(4) + rank(4)
            proxy.WriteByte((byte)attribute.Id);
            MemoryPosition position = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteInt32(value.Length);
            if (value.Length == 0)
            {
                proxy.WriteBackInt32(position, 4);
                return;
            }
            for (int i = 0; i < value.Length; i++)
            {
                string elementValue = value[i];
                if (string.IsNullOrEmpty(elementValue))
                {
                    proxy.WriteUInt16(0);
                }
                else
                {
                    byte[] elementData = Encoding.UTF8.GetBytes(elementValue);
                    proxy.WriteUInt16((ushort)elementData.Length);
                    proxy.WriteMemory(elementData, 0U, (uint)elementData.Length);
                }
            }
            MemoryPosition endPosition = proxy.GetPosition();

            proxy.WriteBackInt32(position, MemoryPosition.CalcLength(proxy.SegmentCount, position, endPosition) - 4);
        }
コード例 #19
0
        /// <summary>
        ///     从第三方客户数据转换为元数据
        /// </summary>
        /// <param name="proxy">内存片段代理器</param>
        /// <param name="attribute">字段属性</param>
        /// <param name="analyseResult">分析结果</param>
        /// <param name="target">目标对象实例</param>
        /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
        public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false)
        {
            short[] value = analyseResult.GetValue <short[]>(target);
            if (value == null)
            {
                if (!attribute.IsRequire)
                {
                    return;
                }
                throw new PropertyNullValueException(string.Format(ExceptionMessage.EX_PROPERTY_VALUE, attribute.Id, analyseResult.Property.Name, analyseResult.Property.PropertyType));
            }
            //id(1) + total length(4) + rank(4)
            proxy.WriteByte((byte)attribute.Id);
            MemoryPosition position = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteInt32(value.Length);
            if (value.Length == 0)
            {
                proxy.WriteBackInt32(position, 4);
                return;
            }
            if (value.Length > 10)
            {
                unsafe
                {
                    fixed(short *pByte = value) proxy.WriteMemory(pByte, (uint)(value.Length * Size.Int16));
                }
            }
            else
            {
                for (int i = 0; i < value.Length; i++)
                {
                    proxy.WriteInt16(value[i]);
                }
            }
            proxy.WriteBackInt32(position, (int)(value.Length * Size.Int16 + 4));
        }
コード例 #20
0
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     throw new NotSupportedException("Cannot use this method, because current type doesn't supported.");
 }
コード例 #21
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public override object Process(IntellectPropertyAttribute attribute, byte[] data)
 {
     return(new Guid(data));
 }
コード例 #22
0
 /// <summary>
 ///     从第三方客户数据转换为元数据
 /// </summary>
 /// <param name="proxy">内存片段代理器</param>
 /// <param name="attribute">字段属性</param>
 /// <param name="analyseResult">分析结果</param>
 /// <param name="target">目标对象实例</param>
 /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param>
 /// <param name="isNullable">是否为可空字段标示</param>
 public abstract void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false);
コード例 #23
0
 /// <summary>
 ///     从元数据转换为第三方客户数据
 /// </summary>
 /// <param name="attribute">当前字段标注的属性</param>
 /// <param name="data">元数据</param>
 /// <returns>返回转换后的第三方客户数据</returns>
 /// <exception cref="Exception">转换失败</exception>
 public abstract object Process(IntellectPropertyAttribute attribute, byte[] data);