Skip to content

Commit 97d5a2d

Browse files
author
Shujaat
committed
- A few sanity checks in UploadExamDialog
- log files are now created by date and separate for MultiDF and HFQApp
1 parent 733de79 commit 97d5a2d

9 files changed

+75
-46
lines changed

HFQOApp/HFQOApp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<UpdateRequired>false</UpdateRequired>
2828
<MapFileExtensions>true</MapFileExtensions>
2929
<ApplicationRevision>1</ApplicationRevision>
30-
<ApplicationVersion>1.8.8.%2a</ApplicationVersion>
30+
<ApplicationVersion>1.8.11.%2a</ApplicationVersion>
3131
<UseApplicationTrust>false</UseApplicationTrust>
3232
<PublishWizardCompleted>true</PublishWizardCompleted>
3333
<BootstrapperEnabled>true</BootstrapperEnabled>

HFQOVM/HFQVM.cs

+40-29
Original file line numberDiff line numberDiff line change
@@ -213,43 +213,56 @@ private void UploadQueuedSnapshots()
213213
while (_QueuedSnapshots.Count > 0)
214214
{
215215
var snap = _QueuedSnapshots.First();
216-
_QueuedSnapshots.Remove(snap.Key);
216+
var ImageFileName = snap.Key;
217217

218-
ViewModelLocator.Logger.Info($"Uploading snapshot {snap.Key}");
219-
ViewModelLocator.DataService.UploadSnapshot(_DownloadId.Value, snap.Value.ToUniversalTime(), snap.Key).ContinueWith(t =>
218+
_QueuedSnapshots.Remove(ImageFileName);
219+
220+
if (System.IO.File.Exists(ImageFileName))
220221
{
221-
if (t.IsCompleted && !t.IsFaulted)
222+
ViewModelLocator.Logger.Info($"Uploading snapshot {ImageFileName}");
223+
ViewModelLocator.DataService.UploadSnapshot(_DownloadId.Value, snap.Value.ToUniversalTime(), ImageFileName).ContinueWith(t =>
222224
{
223-
if (t.Result)
225+
if (t.IsCompleted && !t.IsFaulted)
224226
{
225-
try
227+
if (t.Result)
226228
{
227-
ViewModelLocator.Logger.Info("Upload success. Deleting local snapshot file.");
229+
try
230+
{
231+
ViewModelLocator.Logger.Info("Upload success. Deleting local snapshot file.");
228232

229-
//and remove the image file from the disk
230-
File.Delete(snap.Key);
233+
//and remove the image file from the disk
234+
File.Delete(ImageFileName);
231235

232-
WriteToCache();
233-
}
234-
catch (Exception ee)
235-
{
236-
ViewModelLocator.Logger.Warn(ee, "Could not delete snapshot from local cache.");
236+
WriteToCache();
237+
}
238+
catch (Exception ee)
239+
{
240+
ViewModelLocator.Logger.Warn(ee, "Could not delete snapshot from local cache.");
241+
}
237242
}
238243
}
239-
}
240-
else
241-
{
242-
if (t.Exception == null)
243-
ViewModelLocator.Logger.Error($"Snapshot upload failed. Download Id: {_DownloadId}, Image File: {snap.Key}");
244244
else
245-
ViewModelLocator.Logger.Error(t.Exception, $"Snapshot upload failed. Download Id: {_DownloadId}, Image File: {snap.Key}");
245+
{
246+
if (t.Exception == null)
247+
ViewModelLocator.Logger.Error($"Snapshot upload failed. Download Id: {_DownloadId}, Image File: {ImageFileName}");
248+
else
249+
{
250+
ViewModelLocator.Logger.Error(t.Exception, $"Snapshot upload failed. Download Id: {_DownloadId}, Image File: {ImageFileName}");
251+
}
246252

247-
//if a snapshot fails, add it back to the queue.
248-
FailedToUploadSnapshots.Add(snap.Key, snap.Value);
253+
//if a snapshot fails, add it back to the queue.
254+
FailedToUploadSnapshots.Add(ImageFileName, snap.Value);
249255

250-
WriteToCache();
251-
}
252-
}).Wait();
256+
WriteToCache();
257+
}
258+
}).Wait();
259+
}
260+
else
261+
{
262+
//Image file no longer exists on the disk. We'll ignore it and proceed to update our local cache. This will remove the image file entry from cache.
263+
ViewModelLocator.Logger.Error($"Snapshot file does not exist on disk. Download Id: {_DownloadId}, Image File: {ImageFileName}");
264+
WriteToCache();
265+
}
253266
}
254267
}
255268

@@ -265,8 +278,6 @@ private void UploadQueuedSnapshots()
265278

266279
foreach (var failed in FailedToUploadSnapshots)
267280
_QueuedSnapshots.Add(failed.Key, failed.Value);
268-
269-
ViewModelLocator.DialogService.ShowMessage("Some snapshots could not be uploaded. HFQApp will try to upload them again shortly. See your HFQ log file for details.", true);
270281
}
271282
}
272283
}
@@ -473,7 +484,7 @@ public RelayCommand OpenExamCommand
473484

474485
ViewModelLocator.Auth.IsCommunicating = true;
475486

476-
ViewModelLocator.Logger.Error($"Downloading Exam for Access ID: '{_SelectedAccess.access_id}");
487+
ViewModelLocator.Logger.Info($"Downloading Exam for Access ID: '{_SelectedAccess.access_id}");
477488

478489
MasterFile MF = null;
479490

@@ -573,7 +584,7 @@ public RelayCommand OpenLogFileCommand
573584
{
574585
Process.Start(new ProcessStartInfo()
575586
{
576-
FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HFQApp\activity.log"),
587+
FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HFQApp\"),
577588
UseShellExecute = true
578589
});
579590
},

HFQOVM/ViewModelLocator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static ViewModelLocator()
1919
if (!System.IO.Directory.Exists(LogDir))
2020
System.IO.Directory.CreateDirectory(LogDir);
2121

22-
InitLogger("${specialfolder:folder=ApplicationData}/HFQApp/activity.log");
22+
InitLogger("${specialfolder:folder=ApplicationData}/HFQApp/");
2323
}
2424

2525
App = "HFQApp";

HFQOViews/HFQPane.xaml.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,32 @@ private void SearchBox_KeyDown(object sender, KeyEventArgs e)
3838
{
3939
if (e.Key == Key.Enter)
4040
{
41-
//Refresh filtering
42-
QAs.Refresh();
41+
if (QAs != null)
42+
{
43+
//Refresh filtering
44+
QAs.Refresh();
45+
}
46+
else
47+
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
4348
}
4449
}
4550

4651
private void SearchButton_Click(object sender, RoutedEventArgs e)
4752
{
4853
//Refresh filtering
49-
QAs.Refresh();
54+
if(QAs != null)
55+
QAs.Refresh();
56+
else
57+
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
5058
}
5159

5260
private void ClearButton_Click(object sender, RoutedEventArgs e)
5361
{
5462
SearchBox.Text = "";
5563

5664
//Refresh filtering
57-
QAs.Refresh();
65+
if (QAs != null)
66+
QAs.Refresh();
5867
}
5968

6069
private void CollectionViewSource_Filter(object sender, System.Windows.Data.FilterEventArgs e)

MultiDF.VM/ViewModelLocator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static ViewModelLocator()
2121
if (!System.IO.Directory.Exists(LogDir))
2222
System.IO.Directory.CreateDirectory(LogDir);
2323

24-
InitLogger("${specialfolder:folder=ApplicationData}/MultiDF/activity.log");
24+
InitLogger("${specialfolder:folder=ApplicationData}/MultiDF/");
2525
}
2626

2727
App = "MultiDF";

MultiDF.Views/UploadExamDialog.xaml.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,31 @@ private void ClearButton_Click(object sender, RoutedEventArgs e)
9696
SearchBox.Text = "";
9797

9898
//Refresh filtering
99-
QAs.Refresh();
99+
if (QAs != null)
100+
QAs.Refresh();
100101
}
101102

102103
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
103104
{
104105
if (e.Key == Key.Enter)
105106
{
106-
//Refresh filtering
107-
QAs.Refresh();
107+
if (QAs != null)
108+
{
109+
//Refresh filtering
110+
QAs.Refresh();
111+
}
112+
else
113+
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
108114
}
109115
}
110116

111117
private void SearchButton_Click(object sender, RoutedEventArgs e)
112118
{
113119
//Refresh filtering
114-
QAs.Refresh();
120+
if (QAs != null)
121+
QAs.Refresh();
122+
else
123+
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
115124
}
116125

117126
private void CollectionViewSource_Filter(object sender, System.Windows.Data.FilterEventArgs e)

SharedAssemblyInfo_HFQ.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
// You can specify all the values or you can default the Build and Revision Numbers
2727
// by using the '*' as shown below:
2828
// [assembly: AssemblyVersion("1.0.*")]
29-
[assembly: AssemblyVersion("1.8.8")]
30-
[assembly: AssemblyFileVersion("1.8.8")]
29+
[assembly: AssemblyVersion("1.8.11")]
30+
[assembly: AssemblyFileVersion("1.8.11")]

VMBase/AuthVM.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public RelayCommand LogoutCommand
146146
});
147147
});
148148
},
149-
() => _IsLoggedIn
149+
() => IsLoggedIn
150150
);
151151
}
152152

VMBase/ViewModelLocatorBase.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ public static void Cleanup()
7676
/// </summary>
7777
public static Logger Logger => LogManager.GetLogger("MultiDFLogger");
7878

79-
protected static void InitLogger(string logPath)
79+
protected static void InitLogger(string logFolder)
8080
{
8181
// Step 1. Create configuration object
8282
var config = new LoggingConfiguration();
8383

8484
// Step 2. Create target log file
8585
var fileTarget = new FileTarget("MultiDFLogger")
8686
{
87-
FileName = logPath,
88-
Layout = "${longdate} ${level} ${message} ${exception}"
87+
FileName = logFolder + "${shortdate}.log",
88+
Layout = "${longdate} ${level} ${message} ${exception}"
8989
};
9090
config.AddTarget(fileTarget);
9191

0 commit comments

Comments
 (0)