Showing the changes to Source/Libraries/GSF.ServiceProcess/ClientHelper.cs (1 of 2 files). Show all
Unified · Split
| @@ -49,14 +49,17 @@ · 48 unmodified lines | |||
| 49 | // | 49 | // |
| 50 | //****************************************************************************************************** | 50 | //****************************************************************************************************** |
| 51 | 51 | ||
| 52 | using GSF.Communication; | ||
| 53 | using GSF.Configuration; | ||
| 54 | using GSF.Console; | ||
| 55 | using GSF.IO; | ||
| 52 | using System; | 56 | using System; |
| 53 | using System.ComponentModel; | 57 | using System.ComponentModel; |
| 54 | using System.Configuration; | 58 | using System.Configuration; |
| 55 | using System.Drawing; | 59 | using System.Drawing; |
| 60 | using System.IO; | ||
| 56 | using System.Text; | 61 | using System.Text; |
| 57 | using System.Threading; | 62 | using System.Threading; |
| 58 | using GSF.Communication; | ||
| 59 | using GSF.Configuration; | ||
| 60 | 63 | ||
| 61 | namespace GSF.ServiceProcess | 64 | namespace GSF.ServiceProcess |
| 62 | { | 65 | { |
| @@ -550,7 +553,31 @@ namespace GSF.ServiceProcess · 487 unmodified lines | |||
| 550 | /// <param name="request"><see cref="ClientRequest"/> object to be sent.</param> | 553 | /// <param name="request"><see cref="ClientRequest"/> object to be sent.</param> |
| 551 | public void SendRequest(ClientRequest request) | 554 | public void SendRequest(ClientRequest request) |
| 552 | { | 555 | { |
| 553 | m_remotingClient.SendAsync(request); | 556 | try |
| 557 | { | ||
| 558 | // Intercept TRANSFER requests for uploads. | ||
| 559 | if (request.Command == "TRANSFER" && request.Arguments.Exists("upload")) | ||
| 560 | { | ||
| 561 | string source = FilePath.GetAbsolutePath(request.Arguments["orderedarg1"]); | ||
| 562 | if (File.Exists(source)) | ||
| 563 | { | ||
| 564 | // Attach the file content. | ||
| 565 | request.Attachments.Add(File.ReadAllBytes(source)); | ||
| 566 | } | ||
| 567 | else | ||
| 568 | { | ||
| 569 | // File does not exist. | ||
| 570 | throw new FileNotFoundException(string.Format("File '{0}' does not exist", source)); | ||
| 571 | } | ||
| 572 | } | ||
| 573 | |||
| 574 | // Pass the request along. | ||
| 575 | m_remotingClient.SendAsync(request); | ||
| 576 | } | ||
| 577 | catch (Exception ex) | ||
| 578 | { | ||
| 579 | UpdateStatus(UpdateType.Alarm, "Error processing request - {0}", ex.Message); | ||
| 580 | } | ||
| 554 | } | 581 | } |
| 555 | 582 | ||
| 556 | /// <summary> | 583 | /// <summary> |
| @@ -834,6 +861,35 @@ namespace GSF.ServiceProcess · 277 unmodified lines | |||
| 834 | break; | 861 | break; |
| 835 | } | 862 | } |
| 836 | break; | 863 | break; |
| 864 | case "TRANSFER:SUCCESS": | ||
| 865 | if (response.Attachments.Count == 2) | ||
| 866 | { | ||
| 867 | // Extract data from response. | ||
| 868 | byte[] content = (byte[])response.Attachments[0]; | ||
| 869 | Arguments arguments = (Arguments)response.Attachments[1]; | ||
| 870 | string target = arguments["orderedarg2"]; | ||
| 871 | bool overwrite = arguments.Exists("overwrite"); | ||
| 872 | |||
| 873 | target = FilePath.GetAbsolutePath(target); | ||
| 874 | if (!File.Exists(target) || overwrite) | ||
| 875 | { | ||
| 876 | // Save the received file. | ||
| 877 | UpdateStatus(UpdateType.Information, "Saving file '{0}'...\r\n\r\n", target); | ||
| 878 | File.WriteAllBytes(target, content); | ||
| 879 | UpdateStatus(UpdateType.Information, "File '{0}' saved successfully.\r\n\r\n", target); | ||
| 880 | } | ||
| 881 | else | ||
| 882 | { | ||
| 883 | // File exists and cannot be overwritten. | ||
| 884 | UpdateStatus(UpdateType.Alarm, "File '{0}' already exists.\r\n\r\n", target); | ||
| 885 | } | ||
| 886 | } | ||
| 887 | else | ||
| 888 | { | ||
| 889 | // Response is malformed. | ||
| 890 | UpdateStatus(UpdateType.Alarm, "{0} response is malformed.\r\n\r\n", response.Type); | ||
| 891 | } | ||
| 892 | break; | ||
| 837 | default: | 893 | default: |
| 838 | OnReceivedServiceResponse(response); | 894 | OnReceivedServiceResponse(response); |
| 839 | break; | 895 | break; |