Skip to content

Commit

Permalink
Fix NRE and additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sshulik committed Jun 6, 2017
1 parent 91fe79f commit 43f7605
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions AutoPrintr/AutoPrintr/ViewModels/JobsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class JobsViewModel : BaseViewModel
{
#region Properties
private readonly IWindowsServiceClient _windowsServiceClient;
private readonly ILoggerService _loggingService;

public ObservableCollection<Job> Jobs { get; private set; }

Expand Down Expand Up @@ -44,10 +45,12 @@ public DocumentType? SelectedDocumentType

#region Constructors
public JobsViewModel(INavigationService navigationService,
IWindowsServiceClient windowsServiceClient)
IWindowsServiceClient windowsServiceClient,
ILoggerService loggingService)
: base(navigationService)
{
_windowsServiceClient = windowsServiceClient;
_loggingService = loggingService;

JobStates = Enum.GetValues(typeof(JobState))
.OfType<JobState?>()
Expand Down Expand Up @@ -89,26 +92,36 @@ public void NavigatedFrom()

private async void LoadJobs()
{
ShowBusyControl();
try
{
ShowBusyControl();

Jobs.Clear();

Jobs.Clear();
var jobs = (await _windowsServiceClient.GetJobsAsync())?
.Where(x => x != null)
.Where(x => SelectedJobState.HasValue ? x.State == SelectedJobState.Value : true)
.Where(x => SelectedDocumentType.HasValue ? x.Document.Type == SelectedDocumentType.Value : true)
.OrderByDescending(x => x.UpdatedOn);

var jobs = (await _windowsServiceClient.GetJobsAsync())?
.Where(x => SelectedJobState.HasValue ? x.State == SelectedJobState.Value : true)
.Where(x => SelectedDocumentType.HasValue ? x.Document.Type == SelectedDocumentType.Value : true)
.OrderByDescending(x => x.UpdatedOn);
if (jobs == null)
{
ShowMessageControl("Jobs cannot be loaded, the AutoPrintr service is not available. Please run the service and try again");
HideBusyControl();
return;
}

if (jobs == null)
foreach (var job in jobs)
Jobs.Add(job);
}
catch (Exception e)
{
_loggingService?.WriteError(e);
}
finally
{
ShowMessageControl("Jobs cannot be loaded, the AutoPrintr service is not available. Please run the service and try again");
HideBusyControl();
return;
}

foreach (var job in jobs)
Jobs.Add(job);

HideBusyControl();
}

private void JobChanged(Job job)
Expand Down

0 comments on commit 43f7605

Please sign in to comment.