/// <summary> /// Do a ZModem upload into the scratchpad then show the scratchpad size afterwards. /// </summary> /// <param name="buffer">The I/O buffer</param> private void UploadCommand(LineBuffer buffer) { buffer.WriteLine("Zmodem upload (to abort ^X^X^X^X^X)"); string scratchFileName = Path.GetTempFileName(); ZModem.ZModem zModem = new ZModem.ZModem(buffer.Stream) { Filename = scratchFileName }; bool success = zModem.Receive(); buffer.WriteLine(success ? "Upload succeeded" : "Upload failed"); _scratch.Clear(); if (success) { using (FileStream fileStream = new FileStream(scratchFileName, FileMode.Open)) { byte[] rawScratchpad = new byte[fileStream.Length]; fileStream.Read(rawScratchpad, 0, (int)fileStream.Length); _scratch.Append(new StringBuilder(Encoding.ASCII.GetString(rawScratchpad))); } File.Delete(scratchFileName); } ShowScratchpadSize(buffer); }
/// <summary> /// Do a ZModem download of the scratchpad and optionally delete the scratchpad /// after a successful completion. /// </summary> /// <param name="buffer">Output buffer</param> private void DownloadCommand(LineBuffer buffer) { buffer.WriteLine("Zmodem download started... (to abort ^X^X^X^X^X)"); buffer.WriteLine(string.Format("Filesize {0} bytes, estimated time at 2880 cps : 1 sec", _scratch.Length)); string scratchFileName = Path.GetTempFileName(); using (FileStream fileStream = new FileStream(scratchFileName, FileMode.Create)) { ASCIIEncoding encoder = new ASCIIEncoding(); byte[] rawScratchpad = encoder.GetBytes(_scratch.ToString()); fileStream.Write(rawScratchpad, 0, rawScratchpad.Length); } ZModem.ZModem zModem = new ZModem.ZModem(buffer.Stream) { Filename = scratchFileName }; bool success = zModem.Send(); buffer.WriteLine(success ? "Download succeeded" : "Download failed"); if (success) { buffer.WriteString("OK to delete the downloaded scratchpad-file? (y/n)? N\b"); string yesNoResponse = buffer.ReadLine(); if (yesNoResponse.Trim() == "Y") { _scratch.Clear(); } } File.Delete(scratchFileName); }
/// <summary> /// Do a ZModem download of the scratchpad and optionally delete the scratchpad /// after a successful completion. /// </summary> /// <param name="buffer">Output buffer</param> private void DownloadCommand(LineBuffer buffer) { buffer.WriteLine("Zmodem download started... (to abort ^X^X^X^X^X)"); buffer.WriteLine(string.Format("Filesize {0} bytes, estimated time at 2880 cps : 1 sec", _scratch.Length)); string scratchFileName = Path.GetTempFileName(); using (FileStream fileStream = new FileStream(scratchFileName, FileMode.Create)) { ASCIIEncoding encoder = new ASCIIEncoding(); byte[] rawScratchpad = encoder.GetBytes(_scratch.ToString()); fileStream.Write(rawScratchpad, 0, rawScratchpad.Length); } ZModem.ZModem zModem = new ZModem.ZModem(buffer.Stream) {Filename = scratchFileName}; bool success = zModem.Send(); buffer.WriteLine(success ? "Download succeeded" : "Download failed"); if (success) { buffer.WriteString("OK to delete the downloaded scratchpad-file? (y/n)? N\b"); string yesNoResponse = buffer.ReadLine(); if (yesNoResponse.Trim() == "Y") { _scratch.Clear(); } } File.Delete(scratchFileName); }