public static Type GetValueType(this MessageValueType me) { if (me == MessageValueType.Raw) { return(typeof(Byte[])); } return(Type.GetType($"System.{me.ToString()}")); }
public void SetMessageValue(EventInfo eventInfo, string value, string messageValue, string messageValueType, string identifier) { MessageValueHandler handler = new MessageValueHandler(); MessageValue rawMessageValue = (MessageValue)GetStringAsEnum <MessageValue>(messageValue); MessageValueType rawMessageValueType = (MessageValueType)GetStringAsEnum <MessageValueType>(messageValueType); VariableString rawIdentifier = (identifier == null) ? null : VariableString.GetAsVariableString(identifier, false); handler.SetValue(eventInfo, rawMessageValue, rawMessageValueType, rawIdentifier, value); }
public static MethodInfo GetConverterMethod(this MessageValueType me) { switch (me) { case MessageValueType.Raw: return(ConvertersInfo.GetBytesMethod); case MessageValueType.Boolean: return(ConvertersInfo.GetBooleanMethod); case MessageValueType.SByte: return(ConvertersInfo.GetSByteMethod); case MessageValueType.Byte: return(ConvertersInfo.GetByteMethod); case MessageValueType.Int16: return(ConvertersInfo.GetInt16Method); case MessageValueType.UInt16: return(ConvertersInfo.GetUInt16Method); case MessageValueType.Int32: return(ConvertersInfo.GetInt32Method); case MessageValueType.UInt32: return(ConvertersInfo.GetUInt32Method); case MessageValueType.Int64: return(ConvertersInfo.GetInt64Method); case MessageValueType.UInt64: return(ConvertersInfo.GetUInt64Method); case MessageValueType.Single: return(ConvertersInfo.GetSingleMethod); case MessageValueType.Double: return(ConvertersInfo.GetDoubleMethod); case MessageValueType.String: return(ConvertersInfo.GetStringMethod); default: return(null); } }
public static Func <Byte[], Object> GetConvertMethod(this MessageValueType me) { switch (me) { case MessageValueType.Raw: return(ConvertersInfo.GetBytes); case MessageValueType.Boolean: return(ConvertersInfo.GetBoolean); case MessageValueType.SByte: return(ConvertersInfo.GetSByte); case MessageValueType.Byte: return(ConvertersInfo.GetByte); case MessageValueType.Int16: return(ConvertersInfo.GetInt16); case MessageValueType.UInt16: return(ConvertersInfo.GetUInt16); case MessageValueType.Int32: return(ConvertersInfo.GetInt32); case MessageValueType.UInt32: return(ConvertersInfo.GetUInt32); case MessageValueType.Int64: return(ConvertersInfo.GetInt64); case MessageValueType.UInt64: return(ConvertersInfo.GetUInt64); case MessageValueType.Single: return(ConvertersInfo.GetSingle); case MessageValueType.Double: return(ConvertersInfo.GetDouble); case MessageValueType.String: return(ConvertersInfo.GetString); default: return(null); } }
public static Func <Object, Byte[]> GetConvertBackMethod(this MessageValueType me) { switch (me) { case MessageValueType.Boolean: return((e) => { var val = Boolean.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.SByte: return((e) => { var val = SByte.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Byte: return((e) => { var val = Byte.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Int16: return((e) => { var val = Int16.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.UInt16: return((e) => { var val = UInt16.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Int32: return((e) => { var val = Int32.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.UInt32: return((e) => { var val = UInt32.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Int64: return((e) => { var val = Int64.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.UInt64: return((e) => { var val = UInt64.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Single: return((e) => { var val = Single.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.Double: return((e) => { var val = Double.Parse((String)e); return ToBytesConverter.GetBytes(val); }); case MessageValueType.String: return((e) => { var val = (String)e; return ToBytesConverter.GetBytes(val); }); default: return(null); } }
public MessageValue(StringField sf) { m_valueType = MessageValueType.String; m_stringValue = StringField.GetStringValue(sf); }
public MessageValue(string s) { m_valueType = MessageValueType.String; m_stringValue = s; }
public MessageValue(int i) { m_valueType = MessageValueType.Int; m_intValue = i; }
public string GetValue(EventInfo eventInfo, MessageValue messageValue, MessageValueType valueType, VariableString identifier = null) { _httpMessageParser.TextEncoding = eventInfo.ProxyConnection.ProxyInfo.DefaultEncoding; string value = null; switch (messageValue) { case MessageValue.DataDirection: value = eventInfo.Direction.ToString(); break; case MessageValue.HttpBody: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { value = httpMessage.Body.ToString(); if (valueType != MessageValueType.Text && identifier != null) { switch (valueType) { case MessageValueType.Json: value = value?.GetJsonValue(identifier.GetText(eventInfo.Variables)); break; case MessageValueType.Xml: value = value?.GetXmlValue(identifier.GetText(eventInfo.Variables)); break; } } } } break; case MessageValue.HttpHeader: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null && identifier != null) { value = httpMessage.Headers.GetOrDefault(identifier.GetText(eventInfo.Variables)) ?? string.Empty; } } break; case MessageValue.HttpHeaders: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { value = httpMessage.Headers.ToString(); } } break; case MessageValue.HttpMethod: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { value = (httpMessage.StatusLine as HttpRequestStatusLine)?.Method; } } break; case MessageValue.HttpRequestUri: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { value = (httpMessage.StatusLine as HttpRequestStatusLine)?.Uri; } } break; case MessageValue.LocalAddress: value = eventInfo.ProxyConnection.OriginChannel.LocalEndpoint.Address.ToString(); break; case MessageValue.LocalPort: value = eventInfo.ProxyConnection.OriginChannel.LocalEndpoint.Port.ToString(); break; case MessageValue.SourceRemoteAddress: if (eventInfo.ProxyConnection.HasOriginConnection) { value = eventInfo.ProxyConnection.OriginChannel.RemoteEndpoint.Address.ToString(); } break; case MessageValue.SourceRemotePort: value = eventInfo.ProxyConnection.OriginChannel.RemoteEndpoint.Port.ToString(); break; case MessageValue.DestinationRemoteAddress: if (eventInfo.ProxyConnection.HasTargetConnection) { value = eventInfo.ProxyConnection.TargetChannel.RemoteEndpoint.Address.ToString(); } break; case MessageValue.DestinationRemotePort: if (eventInfo.ProxyConnection.HasTargetConnection) { value = eventInfo.ProxyConnection.TargetChannel.RemoteEndpoint.Port.ToString(); } break; case MessageValue.Protocol: value = eventInfo.Message?.Protocol?.ToString(); break; case MessageValue.HttpVersion: { HttpStatusLine requestStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine; if (requestStatusLine is HttpRequestStatusLine) { value = (requestStatusLine as HttpRequestStatusLine)?.Version; } else { value = (requestStatusLine as HttpResponseStatusLine)?.Version; } } break; case MessageValue.HttpStatusLine: value = (eventInfo.Message as HttpMessage)?.StatusLine?.ToString(); break; case MessageValue.HttpStatusCode: value = ((eventInfo.Message as HttpMessage)?.StatusLine as HttpResponseStatusLine)?.StatusCode.ToString(); break; case MessageValue.HttpStatusMessage: value = ((eventInfo.Message as HttpMessage)?.StatusLine as HttpResponseStatusLine)?.StatusMessage.ToString(); break; case MessageValue.Message: value = eventInfo.Message?.ToString(); if (valueType != MessageValueType.Text && identifier != null) { switch (valueType) { case MessageValueType.Json: value = value?.GetJsonValue(identifier.GetText(eventInfo.Variables)); break; case MessageValueType.Xml: value = value?.GetXmlValue(identifier.GetText(eventInfo.Variables)); break; } } break; } return(value ?? string.Empty); }
public void SetValue(EventInfo eventInfo, MessageValue messageValue, MessageValueType valueType, VariableString identifier, string replacementText) { switch (messageValue) { case MessageValue.DataDirection: { DataDirection dataDirection; if (Enum.TryParse(replacementText, out dataDirection)) { eventInfo.Direction = dataDirection; } } break; case MessageValue.HttpBody: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { if (valueType != MessageValueType.Text && identifier != null) { switch (valueType) { case MessageValueType.Json: replacementText = httpMessage.Body.Text.SetJsonValue(identifier.GetText(eventInfo.Variables), replacementText); break; case MessageValueType.Xml: replacementText = httpMessage.Body.Text.SetXmlValue(identifier.GetText(eventInfo.Variables), replacementText); break; } } httpMessage.Body = new HttpBody() { Text = replacementText }; if (GeneralSettings.AutoUpdateContentLength) { if (httpMessage.Headers.Contains("Content-Length")) { httpMessage.Headers["Content-Length"] = httpMessage.Body.Text.Length.ToString(); } } } } break; case MessageValue.HttpHeader: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null && identifier != null) { httpMessage.Headers[identifier.GetText(eventInfo.Variables)] = replacementText; } } break; case MessageValue.HttpHeaders: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { _httpHeadersParser.Parse(eventInfo, replacementText, true); } } break; case MessageValue.HttpStatusLine: { HttpMessage httpMessage = eventInfo.Message as HttpMessage; if (httpMessage != null) { HttpStatusLine newHttpStatusLine = _httpStatusLineParser.Parse(replacementText); httpMessage.StatusLine = newHttpStatusLine; } } break; case MessageValue.HttpMethod: { HttpRequestStatusLine httpStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine as HttpRequestStatusLine; if (httpStatusLine != null) { httpStatusLine.Method = replacementText; } } break; case MessageValue.HttpRequestUri: { HttpRequestStatusLine httpStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine as HttpRequestStatusLine; if (httpStatusLine != null) { httpStatusLine.Uri = replacementText; } } break; case MessageValue.HttpStatusMessage: { HttpResponseStatusLine httpStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine as HttpResponseStatusLine; if (httpStatusLine != null) { httpStatusLine.StatusMessage = replacementText; } } break; case MessageValue.HttpVersion: { HttpStatusLine httpStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine; if (httpStatusLine != null) { httpStatusLine.Version = replacementText; } } break; case MessageValue.HttpStatusCode: { HttpResponseStatusLine httpStatusLine = (eventInfo.Message as HttpMessage)?.StatusLine as HttpResponseStatusLine; if (httpStatusLine != null) { int replacementVal; if (int.TryParse(replacementText, out replacementVal)) { httpStatusLine.StatusCode = replacementVal; } } } break; case MessageValue.Message: { if (eventInfo.Message is HttpMessage) { HttpMessage newMessage = _httpMessageParser.Parse(replacementText, true).Item2; if (newMessage != null) { eventInfo.Message = newMessage; } } else if (eventInfo.Message != null) { eventInfo.Message.ResetCheckedEntity(HttpMessage.EntityFlag); if (valueType != MessageValueType.Text && identifier != null) { switch (valueType) { case MessageValueType.Json: replacementText = eventInfo.Message.ToString().SetJsonValue(identifier.GetText(eventInfo.Variables), replacementText); break; case MessageValueType.Xml: replacementText = eventInfo.Message.ToString().SetXmlValue(identifier.GetText(eventInfo.Variables), replacementText); break; } } eventInfo.Message.RawText = replacementText + eventInfo.Message.Delimiter; } } break; } }
private MessageValue(object value, MessageValueType type) { ValueType = type; _value = value; }