aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs')
-rw-r--r--Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs114
1 files changed, 66 insertions, 48 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs
index 5dd975463..7db7433fa 100644
--- a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs
+++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs
@@ -5,7 +5,6 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
-using System.Threading;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;
@@ -89,6 +88,37 @@ namespace Tango.Integration.Storage
#endregion
+ #region Protected Methods
+
+ /// <summary>
+ /// Logs the request sent.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ protected void LogRequestSent(IMessage message)
+ {
+ LogManager.Log(String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString()), LogCategory.Debug);
+ }
+
+ /// <summary>
+ /// Logs the request failed.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ protected void LogRequestFailed(IMessage message, Exception ex)
+ {
+ LogManager.Log(String.Format("Request failed '{0}'...{1}{2}{1}{3}", message.GetType().Name, Environment.NewLine, message.ToJsonString(), ex.ToString()), LogCategory.Error);
+ }
+
+ /// <summary>
+ /// Logs the response received.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ protected void LogResponseReceived(IMessage message)
+ {
+ LogManager.Log(String.Format("Response received '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString()), LogCategory.Debug);
+ }
+
+ #endregion
+
#region Public Methods
/// <summary>
@@ -104,10 +134,11 @@ namespace Tango.Integration.Storage
try
{
- response = await _transporter.SendRequest<GetStorageInfoRequest, GetStorageInfoResponse>(request, new TransportRequestConfig() { ShouldLog = true });
+ response = await _transporter.SendRequest<GetStorageInfoRequest, GetStorageInfoResponse>(request);
}
catch (Exception ex)
{
+ LogRequestFailed(request, ex);
throw ex;
}
@@ -158,10 +189,11 @@ namespace Tango.Integration.Storage
try
{
- response = await _transporter.SendRequest<GetFilesRequest, GetFilesResponse>(request, new TransportRequestConfig() { ShouldLog = true });
+ response = await _transporter.SendRequest<GetFilesRequest, GetFilesResponse>(request);
}
catch (Exception ex)
{
+ LogRequestFailed(request, ex);
throw ex;
}
@@ -214,7 +246,7 @@ namespace Tango.Integration.Storage
request.Path = path;
request.Length = stream.Length;
- var fileUploadResponse = await _transporter.SendRequest<FileUploadRequest, FileUploadResponse>(request, new TransportRequestConfig() { ShouldLog = true });
+ var fileUploadResponse = await _transporter.SendRequest<FileUploadRequest, FileUploadResponse>(request);
String uploadId = fileUploadResponse.Message.UploadID;
long max_length = fileUploadResponse.Message.MaxChunkLength;
@@ -246,31 +278,24 @@ namespace Tango.Integration.Storage
{
if (!canceled)
{
- if (!handler.IsPaused)
- {
- byte[] buffer = new byte[Math.Min(max_length, stream.Length - stream.Position)];
- stream.Read(buffer, 0, buffer.Length);
+ byte[] buffer = new byte[Math.Min(max_length, stream.Length - stream.Position)];
+ stream.Read(buffer, 0, buffer.Length);
- FileChunkUploadRequest chunk = new FileChunkUploadRequest();
- chunk.UploadID = uploadId;
- chunk.Path = path;
- chunk.Buffer = ByteString.CopyFrom(buffer);
+ FileChunkUploadRequest chunk = new FileChunkUploadRequest();
+ chunk.UploadID = uploadId;
+ chunk.Path = path;
+ chunk.Buffer = ByteString.CopyFrom(buffer);
- var chunk_response = _transporter.SendRequest<FileChunkUploadRequest, FileChunkUploadResponse>(chunk, new TransportRequestConfig() { Priority = QueuePriority.Low }).Result;
+ var chunk_response = _transporter.SendRequest<FileChunkUploadRequest, FileChunkUploadResponse>(chunk).Result;
- if (chunk_response.Message.IsCanceled)
- {
- canceled = true;
- handler.RaiseFailed(new IOException("The storage device controller has canceled the current upload."));
- return;
- }
-
- handler.Current = stream.Position;
- }
- else
+ if (chunk_response.Message.IsCanceled)
{
- Thread.Sleep(100);
+ canceled = true;
+ handler.RaiseFailed(new IOException("The storage device controller has canceled the current upload."));
+ return;
}
+
+ handler.Current = stream.Position;
}
else
{
@@ -337,7 +362,7 @@ namespace Tango.Integration.Storage
FileDownloadRequest request = new FileDownloadRequest();
request.FileName = file.Path;
- var fileDownloadResponse = await _transporter.SendRequest<FileDownloadRequest, FileDownloadResponse>(request, new TransportRequestConfig() { ShouldLog = true });
+ var fileDownloadResponse = await _transporter.SendRequest<FileDownloadRequest, FileDownloadResponse>(request);
String download_id = fileDownloadResponse.Message.DownloadID;
long max_length = fileDownloadResponse.Message.MaxChunkLength;
@@ -358,32 +383,25 @@ namespace Tango.Integration.Storage
{
if (!canceled)
{
- if (!handler.IsPaused)
- {
- FileChunkDownloadRequest chunk = new FileChunkDownloadRequest();
- chunk.DownloadID = download_id;
- chunk.FileName = file.Path;
- chunk.Position = stream.Length;
+ FileChunkDownloadRequest chunk = new FileChunkDownloadRequest();
+ chunk.DownloadID = download_id;
+ chunk.FileName = file.Path;
+ chunk.Position = stream.Length;
- var chunk_response = _transporter.SendRequest<FileChunkDownloadRequest, FileChunkDownloadResponse>(chunk, new TransportRequestConfig() { Priority = QueuePriority.Low }).Result;
+ var chunk_response = _transporter.SendRequest<FileChunkDownloadRequest, FileChunkDownloadResponse>(chunk).Result;
- if (chunk_response.Message.IsCanceled)
- {
- canceled = true;
- handler.RaiseFailed(new IOException("The storage device controller has canceled the current download."));
- return;
- }
+ if (chunk_response.Message.IsCanceled)
+ {
+ canceled = true;
+ handler.RaiseFailed(new IOException("The storage device controller has canceled the current download."));
+ return;
+ }
- byte[] buffer = chunk_response.Message.Buffer.ToByteArray();
- stream.Write(buffer, 0, buffer.Length);
+ byte[] buffer = chunk_response.Message.Buffer.ToByteArray();
+ stream.Write(buffer, 0, buffer.Length);
- handler.Current = stream.Length;
- }
- else
- {
- Thread.Sleep(100);
- }
+ handler.Current = stream.Length;
}
else
{
@@ -418,7 +436,7 @@ namespace Tango.Integration.Storage
{
Path = item.Path,
Attribute = item.Attribute,
- }, new TransportRequestConfig() { ShouldLog = true });
+ });
}
/// <summary>
@@ -432,7 +450,7 @@ namespace Tango.Integration.Storage
{
Path = path,
Attribute = FileAttribute.Directory,
- }, new TransportRequestConfig() { ShouldLog = true });
+ });
}
#endregion