private void StrToMS(RichTextBox txtBox, bool withArr, bool Run) { ScriptToRCP.ArrCnt = 0; if (Run == true) { string s; string[] sa; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(txtBox.Text)); TextReader reader = new StreamReader(ms, Encoding.ASCII); s = reader.ReadToEnd(); s.Trim(); s = s.Replace(" ", ""); s = s.ToLower(); try { if (s.Length != 0) { if (s[s.Length - 1] == ',') { s = s.Substring(0, s.LastIndexOf(',')); } } else { return; } } catch { return; } sa = s.Split(new char[] { '\r', '\n' }); for (int i = 0; i < sa.Length; i++) { if (sa[i] != "") { string[] ss; ss = sa[i].Split(new char[] { ',', ' ' }); RCPBuilder valClass = (RCPBuilder)ScriptToRCP.ht[ss[0]]; try { if (ss.Length == 1) { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP()); } else if (ss.Length == 2) { try { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP(Convert.ToUInt16(ss[1]))); } catch (GetSleepException) { //System.Threading.Thread.Sleep(UInt16.Parse(ss[1])); Thread.Sleep(UInt16.Parse(ss[1])); } // If the ss[1] is not a number, FormatException will be generated by above method } else { throw new FormatException(); } } catch (FormatException) { StringBuilder sb = new StringBuilder(); for (int j = 1; j < ss.Length; j++) { sb.Append(ss[j] + ","); } try { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP(sb.ToString())); } catch (NotImplementedException) { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Thread.Sleep(50); } } }
private void StrToMS(RichTextBox txtBox, bool withArr) { ScriptToRCP.ArrCnt = 0; string s; string[] sa; StreamWriter sw = new StreamWriter(FormScriptEditor.CommonScriptPath + "\\Gen\\" + (withArr?"rCPGen_withArray.txt":"rCPGen.txt")); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(txtBox.Text)); TextReader reader = new StreamReader(ms, Encoding.ASCII); s = reader.ReadToEnd(); s.Trim(); s = s.Replace(" ", ""); s = s.ToLower(); if (s.Length == 0) { sw.Close(); return; } if (s[s.Length - 1] == ',') { s = s.Substring(0, s.LastIndexOf(',')); } sa = s.Split(new char[] { '\r', '\n' }); for (int i = 0; i < sa.Length; i++) { if (sa[i] != "") { string[] ss; ss = sa[i].Split(new char[] { ',', ' ' }); RCPBuilder valClass = (RCPBuilder)ScriptToRCP.ht[ss[0]]; try { if (ss.Length == 1) { sw.WriteLine(valClass.ByteArrToString(valClass.CmdToRCP(), withArr)); } else if (ss.Length == 2) { try { sw.WriteLine(valClass.ByteArrToString(valClass.CmdToRCP(Convert.ToUInt16(ss[1])), withArr)); } catch (GetSleepException) { continue; } } else { throw new FormatException(); } } catch (FormatException) { StringBuilder sb = new StringBuilder(); for (int j = 1; j < ss.Length; j++) { sb.Append(ss[j] + ","); } try { sw.WriteLine(valClass.ByteArrToString(valClass.CmdToRCP(sb.ToString()), withArr)); } catch (NotImplementedException) { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } sw.Close(); this.toolStripStatusLabelGen.Text = FormScriptEditor.CommonScriptPath + "\\Gen\\" + (withArr?"rCPGen_withArray.txt":"rCPGen.txt"); }
public void ParseScript() { try { if (this.WholeScript != "") { string s = this.WholeScript.Trim(); s = s.Replace(" ", ""); string[] ss; ss = s.Split(new char[] { ',', ' ' }); RCPBuilder valClass = (RCPBuilder)ScriptToRCP.ht[ss[0]]; try { if (ss.Length == 1) { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP()); } else if (ss.Length == 2) { try { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP(Convert.ToUInt16(ss[1]))); } catch (GetSleepException) { Thread.Sleep(UInt16.Parse(ss[1])); } // If the ss[1] is not a number, FormatException will be generated by above method } else { throw new FormatException(); } } catch (FormatException) { StringBuilder sb = new StringBuilder(); for (int j = 1; j < ss.Length; j++) { sb.Append(ss[j] + ","); } try { RcpProtocol.Instance.SendBytePkt(valClass.CmdToRCP(sb.ToString())); } catch (NotImplementedException) { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (GetSleepException) { Thread.Sleep(UInt16.Parse(ss[1])); } catch { MessageBox.Show("Syntax Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { } }