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
4949 //
5050 //******************************************************************************************************
5151
52+using GSF.Communication;
53+using GSF.Configuration;
54+using GSF.Console;
55+using GSF.IO;
5256 using System;
5357 using System.ComponentModel;
5458 using System.Configuration;
5559 using System.Drawing;
60+using System.IO;
5661 using System.Text;
5762 using System.Threading;
58−using GSF.Communication;
59−using GSF.Configuration;
6063
6164 namespace GSF.ServiceProcess
6265 {
@@ -550,7 +553,31 @@ namespace GSF.ServiceProcess · 487 unmodified lines
550553 /// <param name="request"><see cref="ClientRequest"/> object to be sent.</param>
551554 public void SendRequest(ClientRequest request)
552555 {
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+ }
554581 }
555582
556583 /// <summary>
@@ -834,6 +861,35 @@ namespace GSF.ServiceProcess · 277 unmodified lines
834861 break;
835862 }
836863 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;
837893 default:
838894 OnReceivedServiceResponse(response);
839895 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