Esempio n. 1
0
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            String name = null;

            while (!abstractHessianInput.IsEnd())
            {
                string key = abstractHessianInput.ReadString();

                if (key.Equals("name"))
                {
                    name = abstractHessianInput.ReadString();
                }
                else
                {
                    abstractHessianInput.ReadObject();
                }
            }

            abstractHessianInput.ReadMapEnd();

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

            Object obj = Enum.Parse(m_type, name);

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
Esempio n. 2
0
        private Object ReadGenericLengthList(AbstractHessianInput abstractHessianInput, int intListLength)
        {
            Type[] args     = m_type.GetGenericArguments();
            Type   itemType = args[0];
            Type   listType = null;

            if (m_type.Namespace.StartsWith("System") || m_type.IsInterface)
            {
                listType = typeof(System.Collections.Generic.List <>).MakeGenericType(itemType);
            }
            else
            {
                listType = m_type;
            }

            object list = Activator.CreateInstance(listType);

            abstractHessianInput.AddRef(list);

            while (intListLength > 0)
            {
                object item = abstractHessianInput.ReadObject(itemType);
                listType.InvokeMember("Add", BindingFlags.InvokeMethod, null, list, new object[] { item });
                intListLength--;
            }
            return(list);
        }
        public Object ReadObject(AbstractHessianInput abstractHessianInput, object obj, string[] fieldNames)
        {
            try
            {
                SerializationInfo serializationInfo = new SerializationInfo(m_type, new FormatterConverter());

                foreach (var fieldName in fieldNames)
                {
                    serializationInfo.AddValue(fieldName, abstractHessianInput.ReadObject());
                }

                obj = Instantiate(serializationInfo);

                int iref = abstractHessianInput.AddRef(obj);

                Object resolve = Resolve(abstractHessianInput, obj);

                if (obj != resolve)
                {
                    abstractHessianInput.SetRef(iref, resolve);
                }

                return(resolve);
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CHessianException(obj.GetType().FullName + ":" + e, e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Reads date
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput - Instance</param>
        /// <param name="fields"></param>
        public override object ReadObject(AbstractHessianInput abstractHessianInput, object[] fields)
        {
            String[] fieldNames = (String[])fields;
            String   name       = null;

            for (int i = 0; i < fieldNames.Length; i++)
            {
                if ("name".Equals(fieldNames[i]))
                {
                    name = abstractHessianInput.ReadString();
                }
                else
                {
                    abstractHessianInput.ReadObject();
                }
            }

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

            Object obj = Enum.Parse(m_type, name);

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            string value = null;

            while (!abstractHessianInput.IsEnd())
            {
                string key = abstractHessianInput.ReadString();
                if (key.Equals("value"))
                {
                    value = abstractHessianInput.ReadString();
                }
                else
                {
                    abstractHessianInput.ReadObject();
                }
            }

            abstractHessianInput.ReadMapEnd();

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

            object obj = decimal.Parse(value);

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
        public Object ReadObject(AbstractHessianInput abstractHessianInput, Object obj, FieldDeserializer[] fields)
        {
            try
            {
                int iref = abstractHessianInput.AddRef(obj);

                foreach (FieldDeserializer reader in fields)
                {
                    reader.Deserialize(abstractHessianInput, obj);
                }

                Object resolve = Resolve(abstractHessianInput, obj);

                if (obj != resolve)
                {
                    abstractHessianInput.SetRef(iref, resolve);
                }

                return(resolve);
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CHessianException(m_type.FullName + ":" + e.Message, e);
            }
        }
        /// <summary>
        /// Reads date
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput - Instance</param>
        /// <param name="fields"></param>
        public override object ReadObject(AbstractHessianInput abstractHessianInput, object[] fields)
        {
            String[] fieldNames = (string[])fields;

            String value = null;

            for (int i = 0; i < fieldNames.Length; i++)
            {
                if ("value".Equals(fieldNames[i]))
                {
                    value = abstractHessianInput.ReadString();
                }
                else
                {
                    abstractHessianInput.ReadObject();
                }
            }
            if (value == null)
            {
                return(null);
            }

            object obj = decimal.Parse(value);

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            string value = null;

            while (!abstractHessianInput.IsEnd())
            {
                string key = abstractHessianInput.ReadString();
                if (key.Equals("value"))
                {
                    value = abstractHessianInput.ReadString();
                }
                else
                {
                    abstractHessianInput.ReadObject();
                }
            }

            abstractHessianInput.ReadMapEnd();

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

            object obj = new System.Globalization.CultureInfo(value);

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
Esempio n. 9
0
        /// <summary>
        /// Reads map from input
        /// </summary>
        /// <param name="abstractHessianInput">Input stream</param>
        /// <returns>Read map or null</returns>
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            IDictionary dictionary = null;

            if ((m_type == null) || (m_type.IsInterface && typeof(IDictionary).IsAssignableFrom(m_type)))
            {
                dictionary = new Hashtable();
            }
            else if (m_type.Equals(typeof(Hashtable)))
            {
                dictionary = new Hashtable();
            }
            else
            {
                dictionary = (IDictionary)Activator.CreateInstance(m_type);
                //dictionary = new Hashtable();
            }
            abstractHessianInput.AddRef(dictionary);
            while (!abstractHessianInput.IsEnd())
            {
                dictionary.Add(abstractHessianInput.ReadObject(), abstractHessianInput.ReadObject());
            }
            abstractHessianInput.ReadEnd();
            return(dictionary);
        }
        /// <summary>
        /// Reads string valued object
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput Instance</param>
        /// <returns>Read string valued object</returns>
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            String strInitValue = null;

            while (!abstractHessianInput.IsEnd())
            {
                string strKey   = abstractHessianInput.ReadString();
                string strValue = abstractHessianInput.ReadString();

                if (strKey.Equals("value"))
                {
                    strInitValue = strValue;
                }
            }

            abstractHessianInput.ReadMapEnd();

            if (strInitValue == null)
            {
                throw new IOException(m_type.FullName + " expects name.");
            }

            try
            {
                return(m_constructor.Invoke(new Object[] { strInitValue }));
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new IOException(e.ToString());
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Reads the object as a map. (Hashtable)
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput instance to read from</param>
        /// <param name="strType">Type of the map (can be null)</param>
        /// <returns>Object read from stream</returns>
        public Object ReadMap(AbstractHessianInput abstractHessianInput, string strType)
        {
            AbstractDeserializer abstractDeserializer = GetDeserializer(strType);

            if (abstractDeserializer == null)
            {
                abstractDeserializer = new CMapDeserializer(typeof(Hashtable));
            }
            return(abstractDeserializer.ReadMap(abstractHessianInput));
        }
Esempio n. 12
0
        /// <summary>
        /// Reads the array.
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput</param>
        /// <param name="intLength">Length of data</param>
        /// <returns>Array data</returns>
        public override Object ReadList(AbstractHessianInput abstractHessianInput, int intLength)
        {
            if (intLength >= 0)
            {
                Object[] arrResult = createArray(intLength);

                abstractHessianInput.AddRef(arrResult);

                if (m_componentType != null)
                {
                    for (int i = 0; i < arrResult.Length; i++)
                    {
                        arrResult[i] = abstractHessianInput.ReadObject(m_componentType);
                    }
                }
                else
                {
                    for (int i = 0; i < arrResult.Length; i++)
                    {
                        arrResult[i] = abstractHessianInput.ReadObject();
                    }
                }

                abstractHessianInput.ReadListEnd();
                return(arrResult);
            }
            else
            {
                ArrayList colList = new ArrayList();
                abstractHessianInput.AddRef(colList);
                if (m_componentType != null)
                {
                    while (!abstractHessianInput.IsEnd())
                    {
                        colList.Add(abstractHessianInput.ReadObject(m_componentType));
                    }
                }
                else
                {
                    while (!abstractHessianInput.IsEnd())
                    {
                        colList.Add(abstractHessianInput.ReadObject());
                    }
                }

                abstractHessianInput.ReadListEnd();

                Object[] arrResult = createArray(colList.Count);
                for (int i = 0; i < arrResult.Length; i++)
                {
                    arrResult[i] = colList[i];
                }
                return(arrResult);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Reads list.
 /// </summary>
 /// <param name="abstractHessianInput">HessianInput - Instance</param>
 /// <param name="intListLength">Length of the list</param>
 /// <returns>Return value is always an ArrayList - Instance,
 /// apart from StringCollection - Instances</returns>
 public override System.Object ReadList(AbstractHessianInput abstractHessianInput, int intListLength)
 {
     if (m_type != null && IsGenericList(m_type))
     {
         return(ReadGenericList(abstractHessianInput));
     }
     else
     {
         return(ReadUntypedList(abstractHessianInput));
     }
 }
Esempio n. 14
0
        private Object ReadUntypedList(AbstractHessianInput abstractHessianInput)
        {
            IList listResult = new ArrayList();

            abstractHessianInput.AddRef(listResult);
            while (!abstractHessianInput.IsEnd())
            {
                listResult.Add(abstractHessianInput.ReadObject());
            }
            abstractHessianInput.ReadEnd();
            return(listResult);
        }
Esempio n. 15
0
        private Object ReadUntypedLengthList(AbstractHessianInput abstractHessianInput, int intListLength)
        {
            IList listResult = new ArrayList();

            abstractHessianInput.AddRef(listResult);
            while (intListLength > 0)
            {
                listResult.Add(abstractHessianInput.ReadObject());
                intListLength--;
            }
            return(listResult);
        }
Esempio n. 16
0
        /// <summary>
        /// Reads map
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput to read from</param>
        /// <returns>Read object or null</returns>
        public override object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            var ds    = new DataSet();
            int refer = abstractHessianInput.AddRef(ds);

            while (!abstractHessianInput.IsEnd())
            {
                var dt = new DataTable();
                if (abstractHessianInput.ReadMapStart() == CHessian2Constants.BC_MAP)
                {
                    abstractHessianInput.ReadType();
                }
                dt.TableName = abstractHessianInput.ReadString();
                while (!abstractHessianInput.IsEnd())
                {
                    var columnName   = abstractHessianInput.ReadString();
                    var typeFullName = abstractHessianInput.ReadString();
                    var type         = Type.GetType(typeFullName);
                    dt.Columns.Add(new DataColumn(columnName, type));
                }
                abstractHessianInput.ReadEnd();

                if (abstractHessianInput.ReadMapStart() == CHessian2Constants.BC_MAP)
                {
                    abstractHessianInput.ReadType();
                }
                while (!abstractHessianInput.IsEnd())
                {
                    ArrayList objects = new ArrayList();
                    if (abstractHessianInput.ReadMapStart() == CHessian2Constants.BC_MAP)
                    {
                        abstractHessianInput.ReadType();
                    }
                    while (!abstractHessianInput.IsEnd())
                    {
                        var obj = abstractHessianInput.ReadObject();
                        objects.Add(obj);
                    }
                    abstractHessianInput.ReadEnd();
                    var row = dt.NewRow();
                    row.ItemArray = objects.ToArray();
                    dt.Rows.Add(row);
                }
                abstractHessianInput.ReadEnd();
                ds.Tables.Add(dt);
            }
            abstractHessianInput.ReadEnd();
            return(ds);
        }
Esempio n. 17
0
        /// <summary>
        /// Reads the map
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput-Instance to read from</param>
        /// <returns>Read map</returns>
        /// <exception cref="CHessianException"/>
        public virtual object ReadMap(AbstractHessianInput abstractHessianInput)
        {
            Object obj = abstractHessianInput.ReadObject();

            String className = this.GetType().Name;

            if (obj != null)
            {
                throw error(className + ": unexpected object " + obj.GetType().Name + " (" + obj + ")");
            }
            else
            {
                throw error(className + ": unexpected null value");
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Reads the array.
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput</param>
        /// <param name="intLength">Length of data</param>
        /// <param name="strType">Type of the array objects</param>
        /// <returns>Array data</returns>
        public Object ReadList(AbstractHessianInput abstractHessianInput, int intLength, string strType)
        {
            AbstractDeserializer abstractDeserializer = GetDeserializer(strType);

            if (abstractDeserializer != null)
            {
                return(abstractDeserializer.ReadList(abstractHessianInput, intLength));
            }
            else
            {
                return(new CEnumerableDeserializer(typeof(ArrayList)).ReadList(
                           abstractHessianInput,
                           intLength));
            }
        }
 public override Object ReadObject(AbstractHessianInput abstractHessianInput, string[] fieldNames)
 {
     try
     {
         return(ReadObject(abstractHessianInput, null, fieldNames));
     }
     catch (IOException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new CHessianException(m_type.FullName + ":" + e.Message, e);
     }
 }
 public override Object ReadMap(AbstractHessianInput abstractHessianInput)
 {
     try
     {
         return(ReadMap(abstractHessianInput, null));
     }
     catch (IOException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new CHessianException(m_type.FullName + ":" + e.Message, e);
     }
 }
Esempio n. 21
0
        public override Object ReadObject(AbstractHessianInput abstractHessianInput, Object[] fields)
        {
            String[]    fieldNames = (String[])fields;
            IDictionary map        = (IDictionary)Activator.CreateInstance(m_type);

            int iref = abstractHessianInput.AddRef(map);

            for (int i = 0; i < fieldNames.Length; i++)
            {
                String name = fieldNames[i];
                map.Add(name, abstractHessianInput.ReadObject());
            }

            return(map);
        }
Esempio n. 22
0
        /// <summary>
        /// Reads object
        /// </summary>
        /// <param name="abstractHessianInput">Instance of AbstractHessianInput</param>
        /// <returns>Object that was read</returns>
        public override object ReadObject(AbstractHessianInput abstractHessianInput)
        {
            int intCode = abstractHessianInput.ReadListStart();

            switch (intCode)
            {
            case CHessianProtocolConstants.PROT_NULL:
                return(null);

            case CHessianProtocolConstants.PROT_REF_TYPE:
                return(abstractHessianInput.ReadRef());
            }
            int intLength = abstractHessianInput.ReadLength();

            return(ReadList(abstractHessianInput, intLength));
        }
        public override Object ReadObject(AbstractHessianInput abstractHessianInput, Object[] fields)
        {
            try
            {
                Object obj = Instantiate();

                return(ReadObject(abstractHessianInput, obj, (FieldDeserializer[])fields));
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CHessianException(m_type.FullName + ":" + e.Message, e);
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Reads objects as list
        /// <see cref="ReadList(AbstractHessianInput,int)"/>
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput - Instance</param>
        /// <returns>List instance</returns>
        public override object ReadObject(AbstractHessianInput abstractHessianInput)
        {
            int intCode = abstractHessianInput.ReadListStart();

            switch (intCode)
            {
            case CHessianInput.PROT_NULL:
                return(null);

            case CHessianInput.PROT_REF_TYPE:
                return(abstractHessianInput.ReadRef());
            }
            String strType   = abstractHessianInput.ReadType();
            int    intLength = abstractHessianInput.ReadLength();

            return(ReadList(abstractHessianInput, intLength));
        }
Esempio n. 25
0
        private Object ReadGenericList(AbstractHessianInput abstractHessianInput)
        {
            Type[] args     = m_type.GetGenericArguments();
            Type   itemType = args[0];
            Type   listType = typeof(System.Collections.Generic.List <>).MakeGenericType(itemType);

            object list = Activator.CreateInstance(listType);

            abstractHessianInput.AddRef(list);

            while (!abstractHessianInput.IsEnd())
            {
                object item = abstractHessianInput.ReadObject(itemType);
                listType.InvokeMember("Add", BindingFlags.InvokeMethod, null, list, new object[] { item });
            }
            abstractHessianInput.ReadEnd();
            return(list);
        }
        protected Object Resolve(AbstractHessianInput abstractHessianInput, Object obj)
        {
            // if there's a readResolve method, call it
            //        try
            //        {
            //            if (_readResolve != null)
            //                return _readResolve.invoke(obj, new Object[0]);
            //        }
            //        catch (InvocationTargetException e)
            //        {
            //            if (e.getCause() instanceof Exception)
            //throw (Exception)e.getCause();
            //else
            //throw e;
            //        }

            return(obj);
        }
Esempio n. 27
0
        /// <summary>
        /// Reads map from input
        /// </summary>
        /// <param name="abstractHessianInput">Input stream</param>
        /// <returns>Read map or null</returns>
        public override object ReadObject(AbstractHessianInput abstractHessianInput)
        {
            //Read map start
            int code = abstractHessianInput.ReadMapStart();

            switch (code)
            {
            case CHessianProtocolConstants.PROT_NULL:
                return(null);

            case CHessianProtocolConstants.PROT_REF_TYPE:
                return(abstractHessianInput.ReadRef());

            case 'r':
                throw new CHessianException("remote type is not implemented!");
            }
            return(ReadMap(abstractHessianInput));
        }
        public Object ReadMap(AbstractHessianInput abstractHessianInput, Object obj)
        {
            try
            {
                int iref = abstractHessianInput.AddRef(obj);

                while (!abstractHessianInput.IsEnd())
                {
                    Object key = abstractHessianInput.ReadObject();

                    FieldDeserializer deser = (FieldDeserializer)_fieldMap[key];

                    if (deser != null)
                    {
                        deser.Deserialize(abstractHessianInput, obj);
                    }
                    else
                    {
                        abstractHessianInput.ReadObject();
                    }
                }

                abstractHessianInput.ReadMapEnd();

                Object resolve = Resolve(abstractHessianInput, obj);

                if (obj != resolve)
                {
                    abstractHessianInput.SetRef(iref, resolve);
                }

                return(resolve);
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CHessianException(e.Message);
            }
        }
        /// <summary>
        /// Reads date
        /// </summary>
        /// <param name="abstractHessianInput">HessianInput - Instance</param>
        /// <param name="fields"></param>
        public override object ReadObject(AbstractHessianInput abstractHessianInput, object[] fields)
        {
            String[] fieldNames = (string[])fields;

            //String value = null;

            //for (int i = 0; i < fieldNames.Length; i++)
            //{
            //    if ("value".Equals(fieldNames[i]))
            //        value = abstractHessianInput.ReadString();
            //    else
            //        abstractHessianInput.ReadObject();
            //}
            //if (value == null)
            //    return null;

            object obj = DBNull.Value;

            abstractHessianInput.AddRef(obj);

            return(obj);
        }
        public Object ReadObject(AbstractHessianInput abstractHessianInput, Object obj, string[] fieldNames)
        {
            try
            {
                int iref = abstractHessianInput.AddRef(obj);

                foreach (var fieldName in fieldNames)
                {
                    FieldDeserializer reader = (FieldDeserializer)_fieldMap[fieldName];

                    if (reader != null)
                    {
                        reader.Deserialize(abstractHessianInput, obj);
                    }
                    else
                    {
                        abstractHessianInput.ReadObject();
                    }
                }

                Object resolve = Resolve(abstractHessianInput, obj);

                if (obj != resolve)
                {
                    abstractHessianInput.SetRef(iref, resolve);
                }

                return(resolve);
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CHessianException(obj.GetType().FullName + ":" + e, e);
            }
        }