History

TVA.ServiceProcess - Added new Trasfer command to ServiceHelper for uploading and downloading files from remote console. - Added new Files command to ServiceHelper for copying and moving files on the server.

Pinal Patel committed 10 years ago

Commit c8be7121 parent 4e21d082 files · +244 −15Browse files

Showing the changes to Source/Libraries/GSF.ServiceProcess/ClientHelper.cs (1 of 2 files). Show all

Unified · Split

Source/Libraries/GSF.ServiceProcess/ClientHelper.cs+59−3
@@ -49,14 +49,17 @@ · 48 unmodified lines
49//49//
50//******************************************************************************************************50//******************************************************************************************************
51 51
52using GSF.Communication;
53using GSF.Configuration;
54using GSF.Console;
55using GSF.IO;
52using System;56using System;
53using System.ComponentModel;57using System.ComponentModel;
54using System.Configuration;58using System.Configuration;
55using System.Drawing;59using System.Drawing;
60using System.IO;
56using System.Text;61using System.Text;
57using System.Threading;62using System.Threading;
58using GSF.Communication;
59using GSF.Configuration;
60 63
61namespace GSF.ServiceProcess64namespace 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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t