diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-15 18:12:34 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-15 18:12:34 +0300 |
| commit | d14eb378aa56a41a685bece5b2432313767e1902 (patch) | |
| tree | be5c0c6d7ee6fed3a79845cc22e3848cc013f6b9 /Software/Visual_Studio | |
| parent | 15f46cb9a0de56d751ed98674996358ee2c59066 (diff) | |
| download | Tango-d14eb378aa56a41a685bece5b2432313767e1902.tar.gz Tango-d14eb378aa56a41a685bece5b2432313767e1902.zip | |
Fixed machine studio crash when job upload fails.
Fixed machine studio crash when an exception occurs on RenderThreadMethod.
Diffstat (limited to 'Software/Visual_Studio')
| -rw-r--r-- | Software/Visual_Studio/SideChains/RealTimeGraphX-master/RealTimeGraphX/GraphController.cs | 184 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs | 50 |
2 files changed, 127 insertions, 107 deletions
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphX-master/RealTimeGraphX/GraphController.cs b/Software/Visual_Studio/SideChains/RealTimeGraphX-master/RealTimeGraphX/GraphController.cs index 9aabc649a..0331ab3eb 100644 --- a/Software/Visual_Studio/SideChains/RealTimeGraphX-master/RealTimeGraphX/GraphController.cs +++ b/Software/Visual_Studio/SideChains/RealTimeGraphX-master/RealTimeGraphX/GraphController.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Drawing; using RealTimeGraphX.EventArguments; using RealTimeGraphX.Renderers; +using System.Diagnostics; namespace RealTimeGraphX { @@ -216,124 +217,131 @@ namespace RealTimeGraphX { if (!IsPaused) { - var pending_list = _pending_series_collection.BlockDequeue(); - - foreach (var pending_series in pending_list) + try { - if (pending_series.IsClearSeries) - { - _pending_series_collection = new GraphDataQueue<List<PendingSeries>>(); - _to_render.Clear(); - break; - } + var pending_list = _pending_series_collection.BlockDequeue(); - if (_to_render.ContainsKey(pending_series.Series)) - { - var s = _to_render[pending_series.Series]; - s.XX.AddRange(pending_series.XX); - s.YY.AddRange(pending_series.YY); - } - else + foreach (var pending_series in pending_list) { - _to_render[pending_series.Series] = pending_series; - } - } - - if (DateTime.Now > _last_render_time.AddMilliseconds(RefreshRate.TotalMilliseconds) && _to_render.Count > 0) - { - GraphDataPoint min_x = _range.MaximumX - _range.MaximumX; - GraphDataPoint max_x = _range.MaximumX; - GraphDataPoint min_y = _range.MinimumY; - GraphDataPoint max_y = _range.MaximumY; - - min_x = _to_render.First().Value.XX.First(); - max_x = _to_render.First().Value.XX.Last(); + if (pending_series.IsClearSeries) + { + _pending_series_collection = new GraphDataQueue<List<PendingSeries>>(); + _to_render.Clear(); + break; + } - if (_range.AutoY) - { - min_y = _to_render.Select(x => x.Value).SelectMany(x => x.YY).Min(); - max_y = _to_render.Select(x => x.Value).SelectMany(x => x.YY).Max(); + if (_to_render.ContainsKey(pending_series.Series)) + { + var s = _to_render[pending_series.Series]; + s.XX.AddRange(pending_series.XX); + s.YY.AddRange(pending_series.YY); + } + else + { + _to_render[pending_series.Series] = pending_series; + } } - if (min_y == max_y) + if (DateTime.Now > _last_render_time.AddMilliseconds(RefreshRate.TotalMilliseconds) && _to_render.Count > 0) { - min_y = _range.MinimumY; - max_y = _range.MaximumY; - } + GraphDataPoint min_x = _range.MaximumX - _range.MaximumX; + GraphDataPoint max_x = _range.MaximumX; + GraphDataPoint min_y = _range.MinimumY; + GraphDataPoint max_y = _range.MaximumY; + + min_x = _to_render.First().Value.XX.First(); + max_x = _to_render.First().Value.XX.Last(); - EffectiveMinimumX = min_x; - EffectiveMaximumX = max_x; - EffectiveMinimumY = min_y; - EffectiveMaximumY = max_y; + if (_range.AutoY) + { + min_y = _to_render.Select(x => x.Value).SelectMany(x => x.YY).Min(); + max_y = _to_render.Select(x => x.Value).SelectMany(x => x.YY).Max(); + } - VirtualMinimumX = EffectiveMinimumX; - VirtualMaximumX = EffectiveMaximumX; - VirtualMinimumY = EffectiveMinimumY; - VirtualMaximumY = EffectiveMaximumY; + if (min_y == max_y) + { + min_y = _range.MinimumY; + max_y = _range.MaximumY; + } - _last_render_time = DateTime.Now; + EffectiveMinimumX = min_x; + EffectiveMaximumX = max_x; + EffectiveMinimumY = min_y; + EffectiveMaximumY = max_y; - if (Surface != null) - { - var surface_size = Surface.GetSize(); - var zoom_rect = Surface.GetZoomRect(); + VirtualMinimumX = EffectiveMinimumX; + VirtualMaximumX = EffectiveMaximumX; + VirtualMinimumY = EffectiveMinimumY; + VirtualMaximumY = EffectiveMaximumY; - Surface.BeginDraw(); + _last_render_time = DateTime.Now; - if (zoom_rect.Width > 0 && zoom_rect.Height > 0) + if (Surface != null) { - var zoom_rect_top_percentage = zoom_rect.Top / surface_size.Height; - var zoom_rect_bottom_percentage = zoom_rect.Bottom / surface_size.Height; - var zoom_rect_left_percentage = zoom_rect.Left / surface_size.Width; - var zoom_rect_right_percentage = zoom_rect.Right / surface_size.Width; + var surface_size = Surface.GetSize(); + var zoom_rect = Surface.GetZoomRect(); - VirtualMinimumY = EffectiveMaximumY - GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumY, EffectiveMaximumY, zoom_rect_bottom_percentage); - VirtualMaximumY = EffectiveMaximumY - GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumY, EffectiveMaximumY, zoom_rect_top_percentage); + Surface.BeginDraw(); - VirtualMinimumX = GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumX, EffectiveMaximumX, zoom_rect_left_percentage); - VirtualMaximumX = GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumX, EffectiveMaximumX, zoom_rect_right_percentage); + if (zoom_rect.Width > 0 && zoom_rect.Height > 0) + { + var zoom_rect_top_percentage = zoom_rect.Top / surface_size.Height; + var zoom_rect_bottom_percentage = zoom_rect.Bottom / surface_size.Height; + var zoom_rect_left_percentage = zoom_rect.Left / surface_size.Width; + var zoom_rect_right_percentage = zoom_rect.Right / surface_size.Width; - GraphTransform transform = new GraphTransform(); - var scale_x = (float)(surface_size.Width / zoom_rect.Width); - var scale_y = (float)(surface_size.Height / zoom_rect.Height); - var translate_x = (float)-zoom_rect.Left * scale_x; - var translate_y = (float)-zoom_rect.Top * scale_y; + VirtualMinimumY = EffectiveMaximumY - GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumY, EffectiveMaximumY, zoom_rect_bottom_percentage); + VirtualMaximumY = EffectiveMaximumY - GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumY, EffectiveMaximumY, zoom_rect_top_percentage); - transform = new GraphTransform(); - transform.TranslateX = translate_x; - transform.TranslateY = translate_y; - transform.ScaleX = scale_x; - transform.ScaleY = scale_y; + VirtualMinimumX = GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumX, EffectiveMaximumX, zoom_rect_left_percentage); + VirtualMaximumX = GraphDataPointHelper.ComputeAbsolutePosition(EffectiveMinimumX, EffectiveMaximumX, zoom_rect_right_percentage); - Surface.SetTransform(transform); - } + GraphTransform transform = new GraphTransform(); + var scale_x = (float)(surface_size.Width / zoom_rect.Width); + var scale_y = (float)(surface_size.Height / zoom_rect.Height); + var translate_x = (float)-zoom_rect.Left * scale_x; + var translate_y = (float)-zoom_rect.Top * scale_y; - List<Tuple<TDataSeries, IEnumerable<PointF>>> to_draw = new List<Tuple<TDataSeries, IEnumerable<PointF>>>(); + transform = new GraphTransform(); + transform.TranslateX = translate_x; + transform.TranslateY = translate_y; + transform.ScaleX = scale_x; + transform.ScaleY = scale_y; - var to_render = _to_render.Select(x => x.Value).ToList(); + Surface.SetTransform(transform); + } - foreach (var item in to_render) - { - var points = Renderer.Render(Surface, item.Series, _range, item.XX, item.YY, min_x, max_x, min_y, max_y); - to_draw.Add(new Tuple<TDataSeries, IEnumerable<PointF>>(item.Series, points)); - } + List<Tuple<TDataSeries, IEnumerable<PointF>>> to_draw = new List<Tuple<TDataSeries, IEnumerable<PointF>>>(); - for (int i = 0; i < to_draw.Count; i++) - { - if (to_draw[i].Item2.Count() > 2) + var to_render = _to_render.Select(x => x.Value).ToList(); + + foreach (var item in to_render) + { + var points = Renderer.Render(Surface, item.Series, _range, item.XX, item.YY, min_x, max_x, min_y, max_y); + to_draw.Add(new Tuple<TDataSeries, IEnumerable<PointF>>(item.Series, points)); + } + + for (int i = 0; i < to_draw.Count; i++) { - if (to_draw[i].Item1.IsVisible) + if (to_draw[i].Item2.Count() > 2) { - Renderer.Draw(Surface, to_draw[i].Item1, to_draw[i].Item2, i, to_draw.Count); + if (to_draw[i].Item1.IsVisible) + { + Renderer.Draw(Surface, to_draw[i].Item1, to_draw[i].Item2, i, to_draw.Count); + } } } + + Surface.EndDraw(); } - Surface.EndDraw(); + OnEffectiveRangeChanged(EffectiveMinimumX, EffectiveMaximumX, EffectiveMinimumY, EffectiveMaximumY); + OnVirtualRangeChanged(VirtualMinimumX, VirtualMaximumX, VirtualMinimumY, VirtualMaximumY); } - - OnEffectiveRangeChanged(EffectiveMinimumX, EffectiveMaximumX, EffectiveMinimumY, EffectiveMaximumY); - OnVirtualRangeChanged(VirtualMinimumX, VirtualMaximumX, VirtualMinimumY, VirtualMaximumY); + } + catch (Exception ex) + { + Debug.WriteLine($"Error in RealTimeGraphX:\n{ex.ToString()}"); } } else diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 0c0cd7adc..b25afd67d 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -1356,40 +1356,52 @@ namespace Tango.Integration.Operation ThreadFactory.StartNew(async () => { + Status = MachineStatuses.Printing; + RunningJob = originalJob; + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + if (JobUploadStrategy == JobUploadStrategy.JobDescriptionFile) { - request.JobTicket.Segments.Clear(); + try + { + request.JobTicket.Segments.Clear(); - JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); - MemoryStream ms = jobDescriptionFile.ToStream(); + JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); + MemoryStream ms = jobDescriptionFile.ToStream(); - var storage = CreateStorageManager(); + var storage = CreateStorageManager(); - var storageInfo = await storage.GetStorageDrive(); - var root_folder = await storage.GetRootFolder(); + var storageInfo = await storage.GetStorageDrive(); + var root_folder = await storage.GetRootFolder(); - var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); - if (existing_item != null) - { - await storage.DeleteItem(existing_item); - } + var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); + if (existing_item != null) + { + await storage.DeleteItem(existing_item); + } - String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); + String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); - await storage.UploadFileSync(job_file_path, ms); + await storage.UploadFileSync(job_file_path, ms); - ms.Dispose(); + ms.Dispose(); - request.JobTicket.JobDescriptionFile = job_file_path; + request.JobTicket.JobDescriptionFile = job_file_path; + } + catch (Exception ex) + { + Status = MachineStatuses.ReadyToDye; + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseFailed(ex); + LogRequestFailed(request, ex); + return; + } } LogRequestSent(request); bool responseLogged = false; - Status = MachineStatuses.Printing; - RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - SendContinuousRequest<JobRequest, JobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => { handler.RaiseStatusReceived(response.Message.Status); |
