aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-03 13:25:56 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-03 13:25:56 +0300
commitd02c08913ef27d23ff0ef714eb1e9008f9b29e17 (patch)
treec391f35e6ce6fdc55349baed74bc71ed46687292 /Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs
parentf2a27972ca652ef568e5eede22d86f9698a08cca (diff)
downloadTango-d02c08913ef27d23ff0ef714eb1e9008f9b29e17.tar.gz
Tango-d02c08913ef27d23ff0ef714eb1e9008f9b29e17.zip
Added absolute unhandled exception catching.
Improved exception handling for FileSystem upload.
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs')
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs217
1 files changed, 109 insertions, 108 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs
index 03de61dba..b623200d8 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs
@@ -659,154 +659,155 @@ namespace Tango.FSE.UI.FileSystem
LogManager.Log($"Compressing local folder to temporary zip file '{localSourcePath}'...");
ZipFile.CreateFromDirectory(originalPath, localSourcePath);
}
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, $"Error uploading local item '{sourceItem.Name}'.");
- _activeHandlers.Remove(handler);
- handler.RaiseFailed(ex);
- return;
- }
- long position = 0;
- bool webRtcFailed = false;
- int webRtcRetries = WEB_RTC_MAX_RETRIES;
- long dynamixMaxChunkSizeSignalR = MAX_CHUNK_SIZE;
- long dynamicMaxChunkSizeWebRTC = MIN_CHUNK_SIZE_WEB_RTC;
- bool isWebRTCChunkSizeFixed = false;
- LogManager.Log("Starting chunks download...");
- LogManager.Log($"WebRTC active: {(IsWebRtcAvailable && EnableWebRTC).ToStringYesNo()}.");
+ long position = 0;
+ bool webRtcFailed = false;
+ int webRtcRetries = WEB_RTC_MAX_RETRIES;
+ long dynamixMaxChunkSizeSignalR = MAX_CHUNK_SIZE;
+ long dynamicMaxChunkSizeWebRTC = MIN_CHUNK_SIZE_WEB_RTC;
+ bool isWebRTCChunkSizeFixed = false;
- using (FileStream fs = new FileStream(localSourcePath, FileMode.Open))
- {
- while (position < fs.Length && !aborted)
- {
- fs.Position = position;
+ LogManager.Log("Starting chunks download...");
+ LogManager.Log($"WebRTC active: {(IsWebRtcAvailable && EnableWebRTC).ToStringYesNo()}.");
- if (handler.IsPaused)
+ using (FileStream fs = new FileStream(localSourcePath, FileMode.Open))
+ {
+ while (position < fs.Length && !aborted)
{
- Thread.Sleep(1000);
- continue;
- }
+ fs.Position = position;
- try
- {
- ChunkUploadResponse response = null;
- ChunkUploadRequest request = new ChunkUploadRequest()
+ if (handler.IsPaused)
{
- OperationId = operationId,
- };
+ Thread.Sleep(1000);
+ continue;
+ }
- if (_webRtcTransporter != null && _webRtcTransporter.State == TransportComponentState.Connected && EnableWebRTC && !webRtcFailed && _machineProvider.ConnectionType == MachineConnectionTypes.SignalR)
+ try
{
- try
+ ChunkUploadResponse response = null;
+ ChunkUploadRequest request = new ChunkUploadRequest()
+ {
+ OperationId = operationId,
+ };
+
+ if (_webRtcTransporter != null && _webRtcTransporter.State == TransportComponentState.Connected && EnableWebRTC && !webRtcFailed && _machineProvider.ConnectionType == MachineConnectionTypes.SignalR)
+ {
+ try
+ {
+ byte[] data = new byte[Math.Min(dynamicMaxChunkSizeWebRTC, fs.Length - fs.Position)];
+ fs.Read(data, 0, data.Length);
+ request.Data = data;
+ request.IsCompleted = fs.Position == fs.Length;
+
+ response = await _webRtcTransporter.SendGenericRequest<ChunkUploadRequest, ChunkUploadResponse>(request, new TransportRequestConfig()
+ {
+ Timeout = request.IsCompleted ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(2),
+ Priority = QueuePriority.Low
+ });
+
+ if (!isWebRTCChunkSizeFixed)
+ {
+ dynamicMaxChunkSizeWebRTC = Math.Min(dynamicMaxChunkSizeWebRTC + 1024, MAX_CHUNK_SIZE_WEB_RTC);
+ }
+
+ webRtcRetries = WEB_RTC_MAX_RETRIES;
+ }
+ catch (Exception ex)
+ {
+ webRtcRetries--;
+
+ dynamicMaxChunkSizeWebRTC = Math.Max(dynamicMaxChunkSizeWebRTC - 1024, MIN_CHUNK_SIZE_WEB_RTC);
+ isWebRTCChunkSizeFixed = true;
+
+ if (webRtcRetries == 0)
+ {
+ webRtcFailed = true;
+ LogManager.Log(ex, $"WebRTC chunk upload for '{sourceItem.Name}' failed after {WEB_RTC_MAX_RETRIES} retries with exception:\n{ex.FlattenMessage()}\nFalling back to SignalR upload...");
+ }
+
+ continue;
+ }
+ }
+ else
{
- byte[] data = new byte[Math.Min(dynamicMaxChunkSizeWebRTC, fs.Length - fs.Position)];
+ byte[] data = new byte[Math.Min(dynamixMaxChunkSizeSignalR, fs.Length - fs.Position)];
fs.Read(data, 0, data.Length);
request.Data = data;
request.IsCompleted = fs.Position == fs.Length;
- response = await _webRtcTransporter.SendGenericRequest<ChunkUploadRequest, ChunkUploadResponse>(request, new TransportRequestConfig()
+ Stopwatch watch = new Stopwatch();
+ watch.Start();
+
+ response = await _machineProvider.MachineOperator.SendGenericRequest<ChunkUploadRequest, ChunkUploadResponse>(request, new TransportRequestConfig()
{
- Timeout = request.IsCompleted ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(2),
+ Timeout = request.IsCompleted ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(30),
Priority = QueuePriority.Low
});
- if (!isWebRTCChunkSizeFixed)
+ watch.Stop();
+
+ if (watch.Elapsed.TotalSeconds < 1)
{
- dynamicMaxChunkSizeWebRTC = Math.Min(dynamicMaxChunkSizeWebRTC + 1024, MAX_CHUNK_SIZE_WEB_RTC);
+ dynamixMaxChunkSizeSignalR += 1024 * 10;
}
-
- webRtcRetries = WEB_RTC_MAX_RETRIES;
- }
- catch (Exception ex)
- {
- webRtcRetries--;
-
- dynamicMaxChunkSizeWebRTC = Math.Max(dynamicMaxChunkSizeWebRTC - 1024, MIN_CHUNK_SIZE_WEB_RTC);
- isWebRTCChunkSizeFixed = true;
-
- if (webRtcRetries == 0)
+ else if (watch.Elapsed.TotalSeconds > 1)
{
- webRtcFailed = true;
- LogManager.Log(ex, $"WebRTC chunk upload for '{sourceItem.Name}' failed after {WEB_RTC_MAX_RETRIES} retries with exception:\n{ex.FlattenMessage()}\nFalling back to SignalR upload...");
+ dynamixMaxChunkSizeSignalR -= 1024 * 10;
}
- continue;
+ dynamixMaxChunkSizeSignalR = Math.Max(dynamixMaxChunkSizeSignalR, MIN_CHUNK_SIZE);
}
+
+ position = fs.Position;
+ handler.InvalidateProgress(position, fs.Length);
}
- else
+ catch (Exception ex)
{
- byte[] data = new byte[Math.Min(dynamixMaxChunkSizeSignalR, fs.Length - fs.Position)];
- fs.Read(data, 0, data.Length);
- request.Data = data;
- request.IsCompleted = fs.Position == fs.Length;
+ LogManager.Log(ex, $"Upload failed for '{sourceItem.Name}'.");
- Stopwatch watch = new Stopwatch();
- watch.Start();
+ _activeHandlers.Remove(handler);
+ handler.RaiseFailed(ex);
- response = await _machineProvider.MachineOperator.SendGenericRequest<ChunkUploadRequest, ChunkUploadResponse>(request, new TransportRequestConfig()
+ if (isFolder)
{
- Timeout = request.IsCompleted ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(30),
- Priority = QueuePriority.Low
- });
-
- watch.Stop();
-
- if (watch.Elapsed.TotalSeconds < 1)
- {
- dynamixMaxChunkSizeSignalR += 1024 * 10;
- }
- else if (watch.Elapsed.TotalSeconds > 1)
- {
- dynamixMaxChunkSizeSignalR -= 1024 * 10;
+ try
+ {
+ fs.Dispose();
+ LogManager.Log("Removing temporary zip file...");
+ File.Delete(localSourcePath);
+ }
+ catch { }
}
- dynamixMaxChunkSizeSignalR = Math.Max(dynamixMaxChunkSizeSignalR, MIN_CHUNK_SIZE);
+ return;
}
-
- position = fs.Position;
- handler.InvalidateProgress(position, fs.Length);
}
- catch (Exception ex)
- {
- LogManager.Log(ex, $"Upload failed for '{sourceItem.Name}'.");
- _activeHandlers.Remove(handler);
- handler.RaiseFailed(ex);
-
- if (isFolder)
- {
- try
- {
- fs.Dispose();
- LogManager.Log("Removing temporary zip file...");
- File.Delete(localSourcePath);
- }
- catch { }
- }
-
- return;
+ if (!aborted)
+ {
+ LogManager.Log($"Upload for '{sourceItem.Name}' completed successfully.");
+ handler.RaiseCompleted();
}
- }
-
- if (!aborted)
- {
- LogManager.Log($"Upload for '{sourceItem.Name}' completed successfully.");
- handler.RaiseCompleted();
- }
- if (isFolder)
- {
- try
+ if (isFolder)
{
- LogManager.Log("Removing temporary zip file...");
- File.Delete(localSourcePath);
+ try
+ {
+ LogManager.Log("Removing temporary zip file...");
+ File.Delete(localSourcePath);
+ }
+ catch { }
}
- catch { }
}
}
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error uploading local item '{sourceItem.Name}'.");
+ _activeHandlers.Remove(handler);
+ handler.RaiseFailed(ex);
+ return;
+ }
_activeHandlers.Remove(handler);
});