public FiddlerBodyMatch(FiddlerUriMatchMode matchMode, string matchData) //: base(matchMode, matchUri) { if (String.IsNullOrEmpty(matchData) && matchMode != FiddlerUriMatchMode.AllPass) { throw new Exception("empty data is illegal for this mode"); } if (matchData.StartsWith("<hex>")) { if (matchMode == FiddlerUriMatchMode.Regex) { throw new Exception("Regex can not use hex mode"); } MatchBodyBytes = MyBytes.HexStringToByte(matchData.Remove(0, "<hex>".Length), HexDecimal.hex16); if ((MatchBodyBytes == null || MatchBodyBytes.Length == 0) && matchMode != FiddlerUriMatchMode.AllPass) { throw new Exception("empty data is illegal for this mode"); } MatchMode = matchMode; MatchUri = string.Format("<hex>{0}", BitConverter.ToString(MatchBodyBytes)); } else { MatchMode = matchMode; MatchUri = matchData; } }
static void Main(string[] args) { TestChilkat(); DoMyTest(); byte[] clientHello = MyBytes.HexStringToByte("16030100c6010000c2030351adaa772a453edd1c42c48e85d98c671e1619b06fa8a88641f27b43d2797a3c00001c5a5ac02bc02fc02cc030cca9cca8c013c014009c009d002f0035000a0100007daaaa0000ff0100010000000014001200000f642e62616977616e6469616e2e636e0017000000230000000d00140012040308040401050308050501080606010201000500050100000000001200000010000e000c02683208687474702f312e3175500000000b00020100000a000a0008aaaa001d001700187a7a000100", HexaDecimal.hex16, ShowHexMode.@null); TLSPacket.TLSPlaintext tp = new TLSPacket.TLSPlaintext(TLSPacket.TLSContentType.Handshake, new TLSPacket.ProtocolVersion(0x03, 0x03)); TLSPacket.ClientHello ch = new TLSPacket.ClientHello("d.baiwandian.cn"); clientHello = tp.CreateRawData(ch.GetProtocolRawData()); Console.ReadLine(); MyTLS myTLS = new MyTLS(); myTLS.Connect(); Console.WriteLine("enter to say [ Handshake - Client Hello ]"); Console.ReadLine(); myTLS.SendData(clientHello); Console.ReadLine(); myTLS.Dispose(); Console.WriteLine("enter to exti"); Console.ReadLine(); }
public void TestMethod_HexStringToByte() { string testData_1 = " 0x01 0x02 0x03 0x04 0x05 0x06 0x06 0x00 0xff 0xff"; byte[] result = MyBytes.HexStringToByte(testData_1, HexaDecimal.hex16, ShowHexMode.spitSpace0x); Console.WriteLine(MyBytes.ByteToHexString(result, HexaDecimal.hex2, ShowHexMode.spitSpace0b)); Console.WriteLine(MyBytes.ByteToHexString(result, HexaDecimal.hex10, ShowHexMode.spitSpace0d)); Console.WriteLine(MyBytes.ByteToHexString(result, HexaDecimal.hex16, ShowHexMode.spitSpace0x)); }
/// <summary> /// 获取运算后的值,掉用此法的该版本的重载将会改变涉及到的staticData数据的游标 /// </summary> /// <param name="yourActuatorStaticDataCollection">可用staticData集合</param> /// <param name="yourDataResultCollection">返回对所有staticData数据运算后的结果列表</param> /// <param name="errorMessage">错误消息(如果没有错误则为null)(在获取参数化数据产生错误后因对当前case设置警示)</param> /// <returns>运算结果</returns> public string GetTargetContentData(ActuatorStaticDataCollection yourActuatorStaticDataCollection, NameValueCollection yourDataResultCollection, out string errorMessage) { string myTargetContentData = contentData; errorMessage = null; if (hasParameter) { myTargetContentData = ParameterizationContentHelper.GetCurrentParametersData(contentData, MyConfiguration.ParametersDataSplitStr, yourActuatorStaticDataCollection, yourDataResultCollection, out errorMessage); } if (encodetype != ParameterizationContentEncodingType.encode_default) { switch (encodetype) { //base64 case ParameterizationContentEncodingType.encode_base64: myTargetContentData = Convert.ToBase64String(Encoding.UTF8.GetBytes(myTargetContentData)); break; case ParameterizationContentEncodingType.decode_base64: try { myTargetContentData = Encoding.UTF8.GetString(Convert.FromBase64String(myTargetContentData)); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; //hex 16 case ParameterizationContentEncodingType.encode_hex16: myTargetContentData = MyBytes.StringToHexString(myTargetContentData); break; case ParameterizationContentEncodingType.decode_hex16: try { byte[] nowBytes = MyBytes.HexStringToByte(myTargetContentData, HexDecimal.hex16, ShowHexMode.space); myTargetContentData = Encoding.UTF8.GetString(nowBytes); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; //hex 2 case ParameterizationContentEncodingType.encode_hex2: myTargetContentData = MyBytes.StringToHexString(myTargetContentData, Encoding.UTF8, HexDecimal.hex2, ShowHexMode.space); break; case ParameterizationContentEncodingType.decode_hex2: try { byte[] nowBytes = MyBytes.HexStringToByte(myTargetContentData, HexDecimal.hex2, ShowHexMode.space); myTargetContentData = Encoding.UTF8.GetString(nowBytes); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; default: errorMessage = "[getTargetContentData] unknow or not supported this encodetype"; break; } } return(myTargetContentData); }
private void bt_publish_Click(object sender, EventArgs e) { if (session == null) { ShowError("not conection"); return; } if (tb_sendTopic.Text == "") { MessageBox.Show("please put in topic or queues ", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } IMessageProducer prod; try { prod = cb_sendTopicQueues.SelectedIndex == 0 ? session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(tb_sendTopic.Text)) : session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(tb_sendTopic.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { } IMessage msg; if (cb_sendTextByte.SelectedIndex == 0) { msg = prod.CreateTextMessage(); ((ITextMessage)msg).Text = rtb_dataToSend.Text; } else { msg = prod.CreateBytesMessage(); try { ((IBytesMessage)msg).Content = MyBytes.HexStringToByte(rtb_dataToSend.Text, HexaDecimal.hex16, ShowHexMode.space); } catch (Exception ex) { MessageBox.Show(ex.Message, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } int sendNum = 1; try { sendNum = int.Parse(tb_sendCount.Text); } catch { tb_sendCount.Text = "1"; } for (int i = 0; i < sendNum; i++) { prod.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); } prod.Dispose(); ShowState("published"); tb_sendTopic.AutoCompleteCustomSource.Add(tb_sendTopic.Text); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); //向UI推送执行过程信息 Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; //处理执行错误(执行器无法执行的错误) Action <string> DealExecutiveError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.com) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyComExecutionContent nowExecutionContent = yourExecutionContent as MyComExecutionContent; myResult.caseProtocol = CaseProtocol.com; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); StringBuilder tempCaseOutContent = new StringBuilder(); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[com]Executive···", caseId)); #region Send if (nowExecutionContent.isSend) { string nowComData = nowExecutionContent.comContentToSend.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (tempError != null) { DealExecutiveError(string.Format("this case get static data errer with [{0}]", nowExecutionContent.comContentToSend.GetTargetContentData())); tempCaseOutContent.AppendLine("error with static data"); } else { byte[] nowSendBytes; if (nowExecutionContent.comSendEncoding == null) { try { nowSendBytes = MyBytes.HexStringToByte(nowComData, HexaDecimal.hex16, ShowHexMode.space); } catch { nowSendBytes = null; } } else { try { nowSendBytes = nowExecutionContent.comSendEncoding.GetBytes(nowComData); } catch { nowSendBytes = null; } } if (nowSendBytes == null) { DealExecutiveError(string.Format("can not change data to bytes with [{0}]", nowExecutionContent.comContentToSend.GetTargetContentData())); tempCaseOutContent.AppendLine("error with com data"); } else { if (mySerialPort.Send(nowSendBytes)) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, "send sucess"); tempCaseOutContent.AppendLine("send sucess"); } else { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, mySerialPort.ErroerMessage); tempCaseOutContent.AppendLine(mySerialPort.ErroerMessage); } } } } #endregion #region receive if (nowExecutionContent.isReceive) { if (nowExecutionContent.comSleepTime > 0) { System.Threading.Thread.Sleep(nowExecutionContent.comSleepTime); } byte[] recweiveBytes = mySerialPort.ReadAllBytes(); if (recweiveBytes != null) { string receiveStr; if (nowExecutionContent.comReceiveEncoding == null) { receiveStr = MyBytes.ByteToHexString(recweiveBytes, HexaDecimal.hex16, ShowHexMode.space); } else { try { receiveStr = nowExecutionContent.comReceiveEncoding.GetString(recweiveBytes); } catch { receiveStr = null; } } if (receiveStr != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, receiveStr); tempCaseOutContent.AppendLine(receiveStr); } else { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, string.Format("can not Encoding your data with {0}", MyBytes.ByteToHexString(recweiveBytes, HexaDecimal.hex16, ShowHexMode.space))); tempCaseOutContent.AppendLine("[error]receive data error can not encoding receive data"); } } } #endregion myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); myResult.backContent = tempCaseOutContent.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealExecutiveError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }