public void SetObject(object o) { if (o == null) { amqpMessage.BodySection = MessageSupport.NULL_AMQP_VALUE_BODY; } else if (IsNMSObjectTypeSupported(o)) { object value = null; if (o is IList) { value = ConversionSupport.ListToAmqp(o as IList); } else if (o is IPrimitiveMap) { value = ConversionSupport.NMSMapToAmqp(o as IPrimitiveMap); } else { value = o; } // to copy the object being set encode a message then decode and take body Amqp.Message copy = new Amqp.Message(value); ByteBuffer buffer = copy.Encode(); copy = Message.Decode(buffer); amqpMessage.BodySection = new AmqpValue { Value = copy.Body }; } else { throw new ArgumentException("Encoding unexpected object type: " + o.GetType().Name); } }
public override string ToString() { string result = string.Format("{0}:\n", this.GetType()); result += string.Format("inner amqp message: \n{0}\n", AMQPMessageCloak.ToString(message)); result += "NMS Fields = [\n"; foreach (MemberInfo info in this.GetType().GetMembers()) { if (info is PropertyInfo) { PropertyInfo prop = info as PropertyInfo; if (prop.GetGetMethod(true).IsPublic) { try { Object val = prop.GetValue(this, null); if (val is IPrimitiveMap) { result += prop.Name + " = " + ConversionSupport.ToString(val as IPrimitiveMap) + ",\n"; } else { result += string.Format("{0} = {1},\n", prop.Name, val); } }catch (TargetInvocationException tie) { Tracer.InfoFormat("Failed to invoke Member field accessor: {0}, cause: {1}", prop.Name, tie); } } } } result = result.Substring(0, result.Length - 2) + "\n]"; return(result); }
public override string ToString() { string result = base.ToString(); if (this.map != null) { result += string.Format("\nMessage Body: {0}\n", ConversionSupport.ToString(this.map)); } return(result); }
/// <summary> /// Sets associate value to the underlying map implementation. /// </summary> /// <param name="key">Key to associated value.</param> /// <param name="value">Value to set.</param> protected override void SetObjectProperty(string key, object value) { object objval = value; if (objval is IDictionary) { objval = ConversionSupport.MapToAmqp(value as IDictionary); } else if (objval is IList || objval is IList <object> ) { objval = ConversionSupport.ListToAmqp(value as IList); } this.value[key] = objval; }
protected virtual void CheckValidType(Object value) { if (value != null && !(value is IList) && !(value is IDictionary)) { Type type = value.GetType(); if (type.IsInstanceOfType(typeof(Object)) || (!type.IsPrimitive && !type.IsValueType && !type.IsAssignableFrom(typeof(string))) || (!ConversionSupport.IsNMSType(value)) ) { throw new NMSException("Invalid type: " + type.Name + " for value: " + value); } } }
public bool ReadBoolean() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); bool result; object value = cloak.Peek(); if (value == null) { result = Convert.ToBoolean(value); } else { result = ConversionSupport.ConvertNMSType <bool>(value); } cloak.Pop(); return(result); }
public string ReadString() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); string result; object value = cloak.Peek(); if (value == null) { result = Convert.ToString(null); } else { result = ConversionSupport.ConvertNMSType <string>(value); } cloak.Pop(); return(result); }
public float ReadSingle() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); float result; object value = cloak.Peek(); if (value == null) { result = Convert.ToSingle(null); } else { result = ConversionSupport.ConvertNMSType <float>(value); } cloak.Pop(); return(result); }
public int ReadInt32() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); int result; object value = cloak.Peek(); if (value == null) { result = Convert.ToInt32(null); } else { result = ConversionSupport.ConvertNMSType <int>(value); } cloak.Pop(); return(result); }
public double ReadDouble() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); double result; object value = cloak.Peek(); if (value == null) { result = Convert.ToDouble(null); } else { result = ConversionSupport.ConvertNMSType <double>(value); } cloak.Pop(); return(result); }
public char ReadChar() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); char result; object value = cloak.Peek(); if (value == null) { throw new NullReferenceException("Cannot convert NULL value to char."); } else { result = ConversionSupport.ConvertNMSType <char>(value); } cloak.Pop(); return(result); }
public void WriteObject(object value) { FailIfReadOnlyMsgBody(); if (value == null) { cloak.Put(value); } else if (value is byte[]) { WriteBytes(value as byte[]); } else if (ConversionSupport.IsNMSType(value)) { cloak.Put(value); } else { throw NMSExceptionSupport.CreateMessageFormatException(new Exception("Unsupported Object type: " + value.GetType().Name)); } }
public object ReadObject() { FailIfWriteOnlyMsgBody(); FailIfBytesInBuffer(); object result = null; object value = null; try { value = cloak.Peek(); if (value == null) { result = null; } else if (value is byte[]) { byte[] buffer = value as byte[]; result = new byte[buffer.Length]; Array.Copy(buffer, 0, result as byte[], 0, buffer.Length); } else if (ConversionSupport.IsNMSType(value)) { result = value; } } catch (EndOfStreamException eos) { throw NMSExceptionSupport.CreateMessageEOFException(eos); } catch (IOException ioe) { throw NMSExceptionSupport.CreateMessageFormatException(ioe); } catch (Exception e) { Tracer.InfoFormat("Unexpected exception caught reading Object stream. Exception = {0}", e); throw NMSExceptionSupport.Create("Unexpected exception caught reading Object stream.", e); } cloak.Pop(); return(result); }
private bool IsNMSObjectTypeSupported(object o) { return(ConversionSupport.IsNMSType(o) || o is List || o is Map || o is IPrimitiveMap || o is IList); }