protected override void DeserializeRequestBody(ITypeReader typeReader)
 {
     ServerIdentity = typeReader.Read <ServerIdentity>();
     Name           = typeReader.ReadString();
     Region         = typeReader.ReadString();
     PeersCount     = typeReader.ReadInt();
     HttpPort       = typeReader.ReadUShort();
     HttpsPort      = typeReader.ReadUShort();
 }
Exemplo n.º 2
0
        public override Instance ReadChildInstance(string name, Type childType)
        {
            ITypeReader <XmlNode> reader = TypeReaderFactory.GetReader(childType);

            if (reader == null)
            {
                return(base.ReadChildInstance(name, childType));
            }

            XmlElement element = _element[name];

            return(element == null ? null : reader.Read(element, childType));
        }
Exemplo n.º 3
0
        public DateTime?SaveSession(Guid userId, string sessionId, int sessionTimeOut, bool removeSession)
        {
            DateTime?expiration = null;

            using (ITypeReader reader = QueryReader(null, _dbConnName, StoredProcedure.SaveUserSession, userId, sessionId, sessionTimeOut, removeSession))
            {
                while (reader.Read())
                {
                    expiration = reader.GetDate("ExpirationDate");
                }
            }
            return(expiration);
        }
Exemplo n.º 4
0
        public override Instance ReadChildInstance(string name, PluginGraph graph, Type childType)
        {
            ITypeReader reader = TypeReaderFactory.GetReader(childType);

            if (reader == null)
            {
                return(base.ReadChildInstance(name, graph, childType));
            }

            XmlElement element = getChildNode(name);

            return(element == null ? null : reader.Read(element, childType));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the specified stream.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="format">The format.</param>
        public object Load(Type type, Stream stream, IFormat format)
        {
            ITypeReader reader = this.GetReader(type);

            if (reader.BypassFormat)
            {
                format = Format.None;
            }

            using (IFormatReader formatReader = format.CreateReader(stream))
            {
                return(reader.Read(formatReader));
            }
        }
Exemplo n.º 6
0
        public string[] ValidateUser(string userName)
        {
            using (ITypeReader reader = QueryReader(null, _dbConnName, StoredProcedure.CheckUserValid, userName))
            {
                if (reader.Read())
                {
                    string condition        = reader.GetString("Condition");
                    string message          = reader.GetString("Message");
                    string daysToExpiration = reader.GetInt("DaysTillPasswordExpiration").ToString();
                    return(new string[] { condition, message, daysToExpiration });
                }

                else
                {
                    return new string[] { }
                };
            }
        }
Exemplo n.º 7
0
    static object CreateObj(TypeData td, BinaryReader bin)
    {
        Type t    = td.ClassType;
        int  size = (int)(bin.BaseStream.Length - bin.BaseStream.Position);

        if (size < td.Size / td.ArrayCount)
        {
            LogMgr.Log("字节流的长度小于类的长度, Bytes Size:" + bin.BaseStream.Length.ToString() + ", Class Size:" + (td.Size / td.ArrayCount).ToString());
            return(null);
        }
        object obj = Activator.CreateInstance(t);

        if (obj == null)
        {
            return(null);
        }

        for (int i = 0; i < td.Fields.Length; ++i)
        {
            TypeData curData = td.Fields[i];
            if (curData.Handle.FieldType.IsPrimitive)
            {
                ITypeReader iReader = TypeReaderMapping.GetReaderFromHash(curData.HashCode);
                curData.Handle.SetValue(obj, iReader.Read(bin, 0));
            }
            else if (curData.Handle.FieldType.IsArray)
            {
                if (curData.VarType)
                {
                    //变长
                    int curSize = (int)(bin.BaseStream.Length - bin.BaseStream.Position);
                    if (curData.VarType && (curSize % curData.OrgSize != 0))
                    {
                        LogMgr.Log("字节长度不是变长类型的整数倍, Bytes Size:" + curSize.ToString() + ", Class Size:" + td.OrgSize.ToString());
                        return(null);
                    }
                    if (curSize > 0)
                    {
                        curSize /= curData.OrgSize;
                        if (curData.ClassType.IsPrimitive)
                        {
                            ITypeReader iReader = TypeReaderMapping.GetReaderFromHash(curData.HashCode);
                            curData.Handle.SetValue(obj, iReader.Read(bin, curSize));
                        }
                        else
                        {
                            object[] arr = (object[])Array.CreateInstance(curData.ClassType, curSize);
                            for (int j = 0; j < curSize; ++j)
                            {
                                arr[j] = CreateObj(curData, bin);
                                if (arr[j] == null)
                                {
                                    return(null);
                                }
                            }
                            curData.Handle.SetValue(obj, arr);
                        }
                    }
                }
                else
                {
                    //固定长度
                    if (curData.ClassType.IsPrimitive)
                    {
                        ITypeReader iReader = TypeReaderMapping.GetReaderFromHash(curData.HashCode);
                        curData.Handle.SetValue(obj, iReader.Read(bin, curData.ArrayCount));
                    }
                    else
                    {
                        object[] arr = (object[])Array.CreateInstance(curData.ClassType, curData.ArrayCount);
                        for (int j = 0; j < curData.ArrayCount; ++j)
                        {
                            arr[j] = CreateObj(curData, bin);
                            if (arr[j] == null)
                            {
                                return(null);
                            }
                        }
                        curData.Handle.SetValue(obj, arr);
                    }
                }
            }
            else if (curData.HashCode == TypeMapping.STRING_HASH)
            {
                ITypeReader iReader = TypeReaderMapping.GetReaderFromHash(curData.HashCode);
                if (curData.VarType)
                {
                    int curSize = (int)(bin.BaseStream.Length - bin.BaseStream.Position);
                    if (curSize % 2 != 0)
                    {
                        LogMgr.Log("字符串长度不是字符的整数倍:" + curSize.ToString());
                        return(null);
                    }
                    if (curSize > 0)
                    {
                        curData.Handle.SetValue(obj, iReader.Read(bin, curSize / 2));
                    }
                }
                else
                {
                    curData.Handle.SetValue(obj, iReader.Read(bin, curData.ArrayCount));
                }
            }
            else if (curData.Handle.FieldType.IsClass /*|| curData.FieldHandle.FieldType.IsValueType*/)
            {
                object subObj = CreateObj(curData, bin);
                if (subObj == null)
                {
                    return(null);
                }
                curData.Handle.SetValue(obj, subObj);
            }
            else
            {
                LogMgr.Log("未知的类型:" + curData.Handle.FieldType.ToString());
                return(null);
            }
        }
        return(obj);
    }
Exemplo n.º 8
0
 public static T ReadNullable <T>(this ITypeReader reader) where T : class, ISerializable, new()
 {
     return(reader.ReadBool() ? reader.Read <T>() : default);
Exemplo n.º 9
0
 protected override void DeserializeRequestBody(ITypeReader typeReader)
 {
     ServerIdentity = typeReader.Read <ServerIdentity>();
 }