public HpaFileUpload(SendFileType imageType, string filePath) { _imageType = imageType; _filePath = filePath; // file name FileName = Path.GetFileName(filePath); switch (imageType) { case SendFileType.Banner: { if (!FileName.Equals(BANNER_FILENAME, StringComparison.OrdinalIgnoreCase)) { throw new ApiException("The filename for banners must be BANNER.JPG."); } } break; case SendFileType.Logo: { if (!FileName.Equals(LOGO_FILENAME, StringComparison.OrdinalIgnoreCase)) { throw new ApiException("The filename for banners must be IDLELOGO.JPG."); } } break; default: { throw new ApiException("Unknown send file type."); } } // file size _buffer = File.ReadAllBytes(filePath); _hexData = BitConverter.ToString(_buffer).Replace("-", ""); }
public IDeviceResponse SendFile(SendFileType imageType, string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ApiException("Filename is required for SendFile."); } // load the file var fileUpload = new HpaFileUpload(imageType, filePath); // build the initial message var builder = new HpaAdminBuilder(HPA_MSG_ID.SENDFILE) { KeepAlive = true } .Set("FileName", fileUpload.FileName) .Set("FileSize", fileUpload.FileSize) .Set("MultipleMessage", "1"); var response = _controller.SendAdminMessage <SipSendFileResponse>(builder); if (response.DeviceResponseCode.Equals("00")) { IEnumerable <string> fileParts = fileUpload.GetFileParts(response.MaxDataSize / 5); foreach (var filePart in fileParts) { string multipleMessage = (filePart.Equals(fileParts.Last())) ? "0" : "1"; var dataResponse = _controller.SendAdminMessage <SipSendFileResponse>( new HpaAdminBuilder(HPA_MSG_ID.SENDFILE) { KeepAlive = (multipleMessage.Equals("1")), AwaitResponse = (multipleMessage.Equals("0")) } .Set("FileData", filePart) .Set("MultipleMessage", multipleMessage) ); if (dataResponse != null) { response = dataResponse; } } return(response); } else { throw new ApiException(string.Format("Failed to upload file: {0}", response.DeviceResponseText)); } }
public virtual IDeviceResponse SendFile(SendFileType fileType, string filePath) { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); }