blob: f223e873bb13bc0e9639e9af784a168984aae352 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.DI;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.FileSystem;
using Tango.FSE.Common.RemoteJobUpload;
using Tango.PPC.Shared.RemoteJobUpload;
using Tango.Transport;
namespace Tango.FSE.UI.RemoteJobUpload
{
/// <summary>
/// The default remote job upload provider.
/// </summary>
/// <seealso cref="Tango.FSE.Common.RemoteJobUpload.IRemoteJobUploadProvider" />
public class DefaultRemoteJobUploadProvider : ExtendedObject, IRemoteJobUploadProvider
{
[TangoInject]
private IMachineProvider MachineProvider { get; set; }
[TangoInject]
private IFileSystemProvider FileSystemProvider { get; set; }
/// <summary>
/// Uploads the specified job file to the remote connected machine.
/// </summary>
/// <param name="filePath">The job file path.</param>
/// <param name="jobType">Remote job type.</param>
/// <param name="name">Optional job name</param>
/// <returns></returns>
public async Task UploadJob(string filePath, RemoteJobUploadType jobType, String name = null)
{
LogManager.Log($"Uploading job '{filePath}' to the remote machine...");
var uploadResponse = await MachineProvider.MachineOperator.SendGenericRequest<RemoteJobUploadRequest, RemoteJobUploadResponse>(new RemoteJobUploadRequest()
{
Type = jobType,
Name = name ?? Path.GetFileNameWithoutExtension(filePath)
}, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(30) });
var handler = await FileSystemProvider.Upload(filePath, uploadResponse.TargetFilePath, true);
var status = await handler.WaitForCompletion();
if (status != FileSystemHandlerStatus.Completed)
{
throw handler.FailedException;
}
var completedResponse = await MachineProvider.MachineOperator.SendGenericRequest<RemoteJobUploadCompletedRequest, RemoteJobUploadCompletedResponse>(new RemoteJobUploadCompletedRequest()
{
ID = uploadResponse.ID
}, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(30) });
if (completedResponse.Error.IsNotNullOrEmpty())
{
throw new OperationCanceledException(completedResponse.Error);
}
LogManager.Log($"Job upload '{filePath}' completed successfully.");
}
}
}
|