diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs index 7d4aa154e..1f09023cb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs @@ -45,7 +45,6 @@ namespace Tango.PPC.UI.Printing /// <returns></returns> public async Task<JobHandler> Print(Job job, ObservablesContext context) { - JobHandler handler = null; #if STUBPRINT @@ -66,9 +65,25 @@ namespace Tango.PPC.UI.Printing { try { + job.JobStatus = JobStatuses.Completed; + + if (!context.IsDisposed) + { + await context.SaveChangesAsync(); + } + else + { + using (var newContext = ObservablesContext.CreateDefault()) + { + var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); + if (newJob != null) + { + newJob.JobStatus = JobStatuses.Completed; + await newContext.SaveChangesAsync(); + } + } + } - job.JobStatus = BL.Enumerations.JobStatuses.Completed; - await context.SaveChangesAsync(); RaiseJobSaved(job); } catch (Exception ex) @@ -76,12 +91,12 @@ namespace Tango.PPC.UI.Printing LogManager.Log(ex, "Error occurred after job printing completed."); } }; - handler.Canceled += async (x, e) => + handler.Canceled += (x, e) => { try { //No change in status ! - await context.SaveChangesAsync(); + //await context.SaveChangesAsync(); RaiseJobSaved(job); } catch (Exception ex) @@ -94,8 +109,25 @@ namespace Tango.PPC.UI.Printing try { - job.JobStatus = BL.Enumerations.JobStatuses.Disrupted; - await context.SaveChangesAsync(); + job.JobStatus = JobStatuses.Disrupted; + + if (!context.IsDisposed) + { + await context.SaveChangesAsync(); + } + else + { + using (var newContext = ObservablesContext.CreateDefault()) + { + var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); + if (newJob != null) + { + newJob.JobStatus = JobStatuses.Disrupted; + await newContext.SaveChangesAsync(); + } + } + } + RaiseJobSaved(job); } catch (Exception ex) |
