private DownloadOrPatchResponse downloadOrPatch(byte[] bytes, string command) { if (command == null) { throw new ArgumentNullException("command"); } lock (this.m_sendAndReceive_Lock) // don't allow other communication to interrupt { var response1 = sendAndReceive(command + " " + bytes.Length); var commandResponse1 = new DownloadOrPatchResponse(response1); if (commandResponse1.Success && commandResponse1.Bytes == bytes.Length) { // it's now ready to accept a binary program (expecting the length we gave it above) var response2 = sendAndReceive(bytes); var commandResponse2 = new DownloadOrPatchResponse(response2); if (commandResponse2.Success && commandResponse2.Bytes == bytes.Length) { return(commandResponse2); } else if (!commandResponse2.Success) { throw new ProtocolException("Download/patch failed."); } else { throw new ProtocolException("Tried to download/patch " + bytes.Length + " bytes but runtime responded that " + commandResponse2.Bytes + " bytes were downloaded/patched."); } } else if (!commandResponse1.Success) { throw new ProtocolException("Download/patch failed."); } else { throw new ProtocolException("Tried to download/patch " + bytes.Length + " bytes but runtime responded that " + commandResponse1.Bytes + " were expected to be downloaded/patched."); } } }
private DownloadOrPatchResponse downloadOrPatch(byte[] bytes, string command) { if (command == null) throw new ArgumentNullException("command"); lock (this.m_sendAndReceive_Lock) // don't allow other communication to interrupt { var response1 = sendAndReceive(command + " " + bytes.Length); var commandResponse1 = new DownloadOrPatchResponse(response1); if (commandResponse1.Success && commandResponse1.Bytes == bytes.Length) { // it's now ready to accept a binary program (expecting the length we gave it above) var response2 = sendAndReceive(bytes); var commandResponse2 = new DownloadOrPatchResponse(response2); if (commandResponse2.Success && commandResponse2.Bytes == bytes.Length) { return commandResponse2; } else if (!commandResponse2.Success) { throw new ProtocolException("Download/patch failed."); } else { throw new ProtocolException("Tried to download/patch " + bytes.Length + " bytes but runtime responded that " + commandResponse2.Bytes + " bytes were downloaded/patched."); } } else if (!commandResponse1.Success) { throw new ProtocolException("Download/patch failed."); } else { throw new ProtocolException("Tried to download/patch " + bytes.Length + " bytes but runtime responded that " + commandResponse1.Bytes + " were expected to be downloaded/patched."); } } }