void CopyCurrentRuleToClipboard() { if (CurrentRule != null) { MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); CurrentRule.Write(sw); sw.Flush(); ms.Position = 0; using (StreamReader reader = new StreamReader(ms, Encoding.ASCII)) { string contents = reader.ReadToEnd(); if (!String.IsNullOrEmpty(contents)) { //Need to make sure corrupt rules don't get pasted. System.Security.Cryptography.SHA256Managed c = new System.Security.Cryptography.SHA256Managed(); System.Text.UTF8Encoding e = new UTF8Encoding(); byte[] rep = e.GetBytes(contents); string hashstr = Convert.ToBase64String(c.ComputeHash(rep)); Clipboard.SetText(hashstr + "#" + contents); } } } }
public void Write(CountedStreamWriter inf) { foreach (IUTLFileBlockHandler h in FileBlocks) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); h.Write(sw); sw.Flush(); inf.WriteLine(h.BlockTypeID); inf.WriteLine(((int)sw.Count).ToString(System.Globalization.CultureInfo.InvariantCulture)); ms.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(ms); inf.Write(sr.ReadToEnd()); } }
private void toolStripButton1_Click(object sender, EventArgs e) { if (CurrentRule != null) { MemoryStream ms = new System.IO.MemoryStream(); CountedStreamWriter sw = new CountedStreamWriter(ms); CurrentRule.Write(sw); sw.Flush(); ms.Position = 0; using (StreamReader reader = new StreamReader(ms, Encoding.ASCII)) { string contents = reader.ReadToEnd(); if (!String.IsNullOrEmpty(contents)) { Clipboard.SetText(contents); } } } }