/// <summary> /// Serialiaztion of objects /// </summary> /// <param name="obj">Object to serialize</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(obj)) { return; } var ds = obj as DataSet; abstractHessianOutput.WriteMapBegin(obj.GetType().FullName); foreach (DataTable dt in ds.Tables) { abstractHessianOutput.WriteMapBegin(null); abstractHessianOutput.WriteString(dt.TableName); foreach (DataColumn column in dt.Columns) { abstractHessianOutput.WriteString(column.ColumnName); abstractHessianOutput.WriteString(column.DataType.FullName); } abstractHessianOutput.WriteMapEnd(); abstractHessianOutput.WriteMapBegin(null); foreach (DataRow dr in dt.Rows) { abstractHessianOutput.WriteMapBegin(null); foreach (object value in dr.ItemArray) { abstractHessianOutput.WriteObject(value); } abstractHessianOutput.WriteMapEnd(); } abstractHessianOutput.WriteMapEnd(); } abstractHessianOutput.WriteMapEnd(); }
///// <summary> ///// Serialiaztion of objects ///// </summary> ///// <param name="obj">Object to serialize</param> ///// <param name="abstractHessianOutput">HessianOutput - Instance</param> //public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) //{ // if (abstractHessianOutput.AddRef(obj)) // return; // Type type = obj.GetType(); // abstractHessianOutput.WriteMapBegin(type.FullName); // List<MemberInfo> serFields = GetSerializableFieldList(); // for (int i = 0; i < serFields.Count; i++) // { // MemberInfo field = serFields[i]; // //if (!field.CanWrite) continue; // if (field.GetCustomAttributes(typeof(IgnoreAttribute), true).Length > 0) continue; // abstractHessianOutput.WriteString(field.Name); // abstractHessianOutput.WriteObject(ReflectionUtils.GetMemberValue(field, obj)); // } // abstractHessianOutput.WriteMapEnd(); //} /// <summary> /// Serialiaztion of objects /// </summary> /// <param name="obj">Object to serialize</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(obj)) { return; } Type cl = obj.GetType(); int iref = abstractHessianOutput.WriteObjectBegin(cl.FullName); if (iref >= 0) { WriteInstance(obj, abstractHessianOutput); } else if (iref == -1) { writeDefinition20(abstractHessianOutput); abstractHessianOutput.WriteObjectBegin(cl.FullName); WriteInstance(obj, abstractHessianOutput); } else { WriteObject10(obj, abstractHessianOutput); } }
///// <summary> ///// Serialiaztion of objects ///// </summary> ///// <param name="obj">Object to serialize</param> ///// <param name="abstractHessianOutput">HessianOutput - Instance</param> //public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) //{ // if (abstractHessianOutput.AddRef(obj)) // return; // Type type = obj.GetType(); // abstractHessianOutput.WriteMapBegin(type.FullName); // List<MemberInfo> serFields = GetSerializableFieldList(); // for (int i = 0; i < serFields.Count; i++) // { // MemberInfo field = serFields[i]; // //if (!field.CanWrite) continue; // if (field.GetCustomAttributes(typeof(IgnoreAttribute), true).Length > 0) continue; // abstractHessianOutput.WriteString(field.Name); // abstractHessianOutput.WriteObject(ReflectionUtils.GetMemberValue(field, obj)); // } // abstractHessianOutput.WriteMapEnd(); //} /// <summary> /// Serialiaztion of objects /// </summary> /// <param name="obj">Object to serialize</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(obj)) { return; } Type cl = obj.GetType(); int iref = abstractHessianOutput.WriteObjectBegin(cl.FullName); SerializationInfo serializationInfo = new SerializationInfo(cl, new FormatterConverter()); ((ISerializable)obj).GetObjectData(serializationInfo, new StreamingContext()); if (iref >= 0) { WriteInstance(serializationInfo, abstractHessianOutput); } else if (iref == -1) { writeDefinition20(serializationInfo, abstractHessianOutput); abstractHessianOutput.WriteObjectBegin(cl.FullName); WriteInstance(serializationInfo, abstractHessianOutput); } else { WriteObject10(serializationInfo, abstractHessianOutput); } }
/// <summary> /// Serialiaztion of objects /// </summary> /// <param name="objData">Object to serialize</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object objData, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(objData)) { return; } if (objData == null) { abstractHessianOutput.WriteNull(); } else { int iref = abstractHessianOutput.WriteObjectBegin(PROT_GUID_TYPE); if (iref < -1) { abstractHessianOutput.WriteString("value"); abstractHessianOutput.WriteString(objData.ToString()); abstractHessianOutput.WriteMapEnd(); } else { if (iref == -1) { abstractHessianOutput.WriteClassFieldLength(1); abstractHessianOutput.WriteString("value"); abstractHessianOutput.WriteObjectBegin(PROT_GUID_TYPE); } abstractHessianOutput.WriteString(objData.ToString()); } } }
/// <summary> /// Writes map in the output stream /// </summary> /// <param name="obj"> Object to write</param> /// <param name="abstractHessianOutput">Instance of the hessian output</param> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(obj)) { return; } IDictionary dictionary = (IDictionary)obj; Type mapType = obj.GetType(); if (mapType.Equals(typeof(Hashtable))) { abstractHessianOutput.WriteMapBegin(null); } else { abstractHessianOutput.WriteMapBegin(mapType.Name); } IDictionaryEnumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { object objKey = enumerator.Key; abstractHessianOutput.WriteObject(objKey); object objValue = enumerator.Value; abstractHessianOutput.WriteObject(objValue); } abstractHessianOutput.WriteMapEnd(); }
/// <summary> /// Writes list objects (That extends from ICollection-Interfaces) /// </summary> /// <param name="objList">List object</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object objList, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(objList)) { return; } // TODO auch generische Listen schreiben ICollection collection = (ICollection)objList; Type type = objList.GetType(); if (type.Equals(typeof(ArrayList))) { abstractHessianOutput.WriteListBegin(collection.Count, null); } else { abstractHessianOutput.WriteListBegin(collection.Count, objList.GetType().FullName); } IEnumerator enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { Object value = enumerator.Current; abstractHessianOutput.WriteObject(value); } abstractHessianOutput.WriteListEnd(); }
/// <summary> /// Writes array object /// </summary> /// <param name="objArrayToWrite">Array - Instance to write</param> /// <param name="abstractHessianOutput">HessianOutput-Instance</param> public override void WriteObject(Object objArrayToWrite, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(objArrayToWrite)) { return; } System.Object[] array = (Object[])objArrayToWrite; bool hasEnd = abstractHessianOutput.WriteListBegin(array.Length, getArrayType(objArrayToWrite.GetType())); for (int i = 0; i < array.Length; i++) { abstractHessianOutput.WriteObject(array[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } }
/// <summary> /// Writes list objects (That extends from ICollection-Interfaces) /// </summary> /// <param name="objList">List object</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object objList, AbstractHessianOutput abstractHessianOutput) { if (abstractHessianOutput.AddRef(objList)) { return; } // TODO auch generische Listen schreiben IEnumerable collection = (IEnumerable)objList; bool hasEnd; if (objList is ArrayList) { hasEnd = abstractHessianOutput.WriteListBegin(((ICollection)objList).Count, objList.GetType().FullName); } else if (objList is ICollection) { hasEnd = abstractHessianOutput.WriteListBegin(((ICollection)objList).Count, objList.GetType().FullName); } else { hasEnd = abstractHessianOutput.WriteListBegin(-1, null); } IEnumerator enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { Object value = enumerator.Current; abstractHessianOutput.WriteObject(value); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } }
/// <summary> /// Serialiaztion of string valued objects /// </summary> /// <param name="obj">Object to serialize</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { if (obj == null) { abstractHessianOutput.WriteNull(); } else { if (abstractHessianOutput.AddRef(obj)) { return; } Type type = obj.GetType(); int iref = abstractHessianOutput.WriteObjectBegin(type.Name); if (iref < -1) { abstractHessianOutput.WriteString("value"); abstractHessianOutput.WriteString(obj.ToString()); abstractHessianOutput.WriteMapEnd(); } else { if (iref == -1) { abstractHessianOutput.WriteInt(1); abstractHessianOutput.WriteString("value"); abstractHessianOutput.WriteObjectBegin(type.Name); } abstractHessianOutput.WriteString(obj.ToString()); } } }
/// <summary> /// Writes primitive objects and arrayy of primitive objects /// </summary> /// <param name="obj">Object to write</param> /// <param name="abstractHessianOutput">HessianOutput - Instance</param> /// <exception cref="CHessianException"/> public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput) { switch (m_intCode) { case BOOLEAN: abstractHessianOutput.WriteBoolean(((bool)obj)); break; case BYTE: case SBYTE: case SHORT: case INTEGER: abstractHessianOutput.WriteInt(Convert.ToInt32(obj)); break; case LONG: abstractHessianOutput.WriteLong((long)obj); break; case FLOAT: abstractHessianOutput.WriteDouble(Convert.ToDouble(obj)); break; case DOUBLE: abstractHessianOutput.WriteDouble((double)obj); break; case CHARACTER: abstractHessianOutput.WriteInt((char)obj); break; case STRING: abstractHessianOutput.WriteString((string)obj); break; case DATE: DateTime dt = (DateTime)obj; const long timeShift = 62135596800000; long javaTime = dt.ToUniversalTime().Ticks / 10000 - timeShift; abstractHessianOutput.WriteUTCDate(javaTime); break; case INTEGER_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } int[] arrData = (int[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[int"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteInt(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case STRING_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } String[] arrData = (String[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[string"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteString(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case BOOLEAN_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } bool[] arrData = (bool[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[boolean"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteBoolean(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case BYTE_ARRAY: { byte[] arrData = (byte[])obj; abstractHessianOutput.WriteBytes(arrData, 0, arrData.Length); break; } case SBYTE_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } sbyte[] arrData = (sbyte[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[sbyte"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteInt(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case SHORT_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } short[] arrData = (short[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[short"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteInt(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case LONG_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } long[] arrData = (long[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[long"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteLong(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case FLOAT_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } float[] arrData = (float[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[float"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteDouble(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case DOUBLE_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } double[] arrData = (double[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[double"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteDouble(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } case CHARACTER_ARRAY: { char[] arrData = (char[])obj; abstractHessianOutput.WriteString(arrData, 0, arrData.Length); break; } case OBJECT_ARRAY: { if (abstractHessianOutput.AddRef(obj)) { return; } Object[] arrData = (Object[])obj; bool hasEnd = abstractHessianOutput.WriteListBegin(arrData.Length, "[object"); for (int i = 0; i < arrData.Length; i++) { abstractHessianOutput.WriteObject(arrData[i]); } if (hasEnd) { abstractHessianOutput.WriteListEnd(); } break; } default: throw new CHessianException(m_intCode + " " + obj.GetType().ToString()); } #endregion }