|
|
@@ -103,13 +103,21 @@ namespace BulkPrinting
|
|
103
|
103
|
if (ex.Response != null)
|
|
104
|
104
|
{
|
|
105
|
105
|
var response = ex.Response;
|
|
106
|
|
- var stream = response.GetResponseStream();
|
|
107
|
|
- var reader = new StreamReader(stream);
|
|
108
|
|
- var message = reader.ReadToEnd();
|
|
109
|
|
- MaxException MaxError = JsonConvert.DeserializeObject<MaxException>(message);
|
|
110
|
|
- if (MaxError.Code != null)
|
|
|
106
|
+ HttpStatusCode? status = (response as HttpWebResponse)?.StatusCode;
|
|
|
107
|
+ if (status.HasValue && (status.Value == HttpStatusCode.InternalServerError))
|
|
111
|
108
|
{
|
|
112
|
|
- MessageBox.Show("Error " + MaxError.Code.ToString() + ": " + MaxError.Error, "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
109
|
+ var stream = response.GetResponseStream();
|
|
|
110
|
+ var reader = new StreamReader(stream);
|
|
|
111
|
+ var message = reader.ReadToEnd();
|
|
|
112
|
+ MaxException MaxError = JsonConvert.DeserializeObject<MaxException>(message);
|
|
|
113
|
+ if (MaxError.Code != null)
|
|
|
114
|
+ {
|
|
|
115
|
+ MessageBox.Show("Error " + MaxError.Code.ToString() + ": " + MaxError.Error, "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
116
|
+ }
|
|
|
117
|
+ else
|
|
|
118
|
+ {
|
|
|
119
|
+ MessageBox.Show("Login Failed. Please try again.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
120
|
+ }
|
|
113
|
121
|
}
|
|
114
|
122
|
else
|
|
115
|
123
|
{
|
|
|
@@ -172,7 +180,7 @@ namespace BulkPrinting
|
|
172
|
180
|
{
|
|
173
|
181
|
Result = default(R);
|
|
174
|
182
|
}
|
|
175
|
|
- else
|
|
|
183
|
+ else if (status.HasValue && (status == HttpStatusCode.InternalServerError))
|
|
176
|
184
|
{
|
|
177
|
185
|
var stream = response.GetResponseStream();
|
|
178
|
186
|
var reader = new StreamReader(stream);
|
|
|
@@ -182,6 +190,14 @@ namespace BulkPrinting
|
|
182
|
190
|
{
|
|
183
|
191
|
MessageBox.Show("Error " + MaxError.Code.ToString() + ": " + MaxError.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
184
|
192
|
}
|
|
|
193
|
+ else
|
|
|
194
|
+ {
|
|
|
195
|
+ MessageBox.Show(MaxError.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
196
|
+ }
|
|
|
197
|
+ }
|
|
|
198
|
+ else
|
|
|
199
|
+ {
|
|
|
200
|
+ MessageBox.Show("The server encountered an unexpected error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
185
|
201
|
}
|
|
186
|
202
|
}
|
|
187
|
203
|
return false;
|
|
|
@@ -472,6 +488,7 @@ namespace BulkPrinting
|
|
472
|
488
|
var ExportEvent = new EventLog();
|
|
473
|
489
|
ExportEvent.EventType = VendorEvent.VendorEventType.PrintVoucher;
|
|
474
|
490
|
ExportEvent.VoucherId = PrintedVoucher.VoucherId;
|
|
|
491
|
+ ExportEvent.BatchId = BatchId;
|
|
475
|
492
|
ExportEvent.Retry = IsReprint;
|
|
476
|
493
|
LogEvents.Add(ExportEvent);
|
|
477
|
494
|
}
|
|
|
@@ -623,15 +640,18 @@ namespace BulkPrinting
|
|
623
|
640
|
|
|
624
|
641
|
public static void TriggerLogDownload()
|
|
625
|
642
|
{
|
|
|
643
|
+#if ! SIMULATE_HDD_SERIAL
|
|
626
|
644
|
if (Globals.LogDownloader == null)
|
|
627
|
645
|
{
|
|
628
|
646
|
Globals.LogDownloader = new LogDownloader(Globals.DB);
|
|
629
|
647
|
Globals.LogDownloader.Start();
|
|
630
|
648
|
}
|
|
|
649
|
+#endif
|
|
631
|
650
|
}
|
|
632
|
651
|
|
|
633
|
652
|
public static void TriggerLogUpload()
|
|
634
|
653
|
{
|
|
|
654
|
+#if ! SIMULATE_HDD_SERIAL
|
|
635
|
655
|
if (Globals.LogUploader == null)
|
|
636
|
656
|
{
|
|
637
|
657
|
Globals.LogUploader = new LogUploader(Globals.DB);
|
|
|
@@ -641,27 +661,138 @@ namespace BulkPrinting
|
|
641
|
661
|
{
|
|
642
|
662
|
Globals.LogUploader.TriggerUpload();
|
|
643
|
663
|
}
|
|
|
664
|
+#endif
|
|
|
665
|
+ }
|
|
|
666
|
+
|
|
|
667
|
+ public static void CreateEventCountUpdateQueryParameters(SQLiteCommand command)
|
|
|
668
|
+ {
|
|
|
669
|
+ command.Parameters.AddWithValue("@Id", null);
|
|
|
670
|
+ command.Parameters.AddWithValue("@PrintCountDelta", null);
|
|
|
671
|
+ command.Parameters.AddWithValue("@ReprintCountDelta", null);
|
|
|
672
|
+ command.Parameters.AddWithValue("@ExportCountDelta", null);
|
|
|
673
|
+ command.Parameters.AddWithValue("@ReExportCountDelta", null);
|
|
|
674
|
+ }
|
|
|
675
|
+
|
|
|
676
|
+ public static void ExecuteEventCountUpdateQuery(SQLiteCommand command, int id,
|
|
|
677
|
+ int printCountDelta, int reprintCountDelta, int exportCountDelta, int reExportCountDelta)
|
|
|
678
|
+ {
|
|
|
679
|
+ command.Parameters["@Id"].Value = id;
|
|
|
680
|
+ command.Parameters["@PrintCountDelta"].Value = printCountDelta;
|
|
|
681
|
+ command.Parameters["@ReprintCountDelta"].Value = reprintCountDelta;
|
|
|
682
|
+ command.Parameters["@ExportCountDelta"].Value = exportCountDelta;
|
|
|
683
|
+ command.Parameters["@ReExportCountDelta"].Value = reExportCountDelta;
|
|
|
684
|
+ command.ExecuteNonQuery();
|
|
|
685
|
+ }
|
|
|
686
|
+
|
|
|
687
|
+ public static SQLiteCommand CreateVoucherEventCountUpdateCommand(DBHelper db, SQLiteTransaction trans)
|
|
|
688
|
+ {
|
|
|
689
|
+ var command = db.CreateCommand(
|
|
|
690
|
+ "UPDATE Voucher SET " +
|
|
|
691
|
+ "PrintCount=PrintCount+@PrintCountDelta," +
|
|
|
692
|
+ "ReprintCount=ReprintCount+@ReprintCountDelta," +
|
|
|
693
|
+ "ExportCount=ExportCount+@ExportCountDelta," +
|
|
|
694
|
+ "ReExportCount=ReExportCount+@ReExportCountDelta " +
|
|
|
695
|
+ "WHERE Id=@Id",
|
|
|
696
|
+ trans);
|
|
|
697
|
+ CreateEventCountUpdateQueryParameters(command);
|
|
|
698
|
+ return command;
|
|
|
699
|
+ }
|
|
|
700
|
+
|
|
|
701
|
+ public static bool CalculateEventCountDeltas(VendorEvent.VendorEventType eventType, bool retry,
|
|
|
702
|
+ out int printCountDelta, out int reprintCountDelta, out int exportCountDelta, out int reExportCountDelta)
|
|
|
703
|
+ {
|
|
|
704
|
+ printCountDelta = 0;
|
|
|
705
|
+ reprintCountDelta = 0;
|
|
|
706
|
+ exportCountDelta = 0;
|
|
|
707
|
+ reExportCountDelta = 0;
|
|
|
708
|
+
|
|
|
709
|
+ if (eventType == VendorEvent.VendorEventType.PrintVoucher)
|
|
|
710
|
+ {
|
|
|
711
|
+ if (retry)
|
|
|
712
|
+ {
|
|
|
713
|
+ reprintCountDelta++;
|
|
|
714
|
+ }
|
|
|
715
|
+ else
|
|
|
716
|
+ {
|
|
|
717
|
+ printCountDelta++;
|
|
|
718
|
+ }
|
|
|
719
|
+ return true;
|
|
|
720
|
+ }
|
|
|
721
|
+ else if (eventType == VendorEvent.VendorEventType.ExportVoucher)
|
|
|
722
|
+ {
|
|
|
723
|
+ if (retry)
|
|
|
724
|
+ {
|
|
|
725
|
+ reExportCountDelta++;
|
|
|
726
|
+ }
|
|
|
727
|
+ else
|
|
|
728
|
+ {
|
|
|
729
|
+ exportCountDelta++;
|
|
|
730
|
+ }
|
|
|
731
|
+ return true;
|
|
|
732
|
+ }
|
|
|
733
|
+ return false;
|
|
|
734
|
+ }
|
|
|
735
|
+
|
|
|
736
|
+ public static SQLiteCommand CreateBatchEventCountUpdateCommand(DBHelper db, SQLiteTransaction trans)
|
|
|
737
|
+ {
|
|
|
738
|
+ var command = db.CreateCommand(
|
|
|
739
|
+ "UPDATE Batch SET " +
|
|
|
740
|
+ "PrintCount=PrintCount+@PrintCountDelta," +
|
|
|
741
|
+ "ReprintCount=ReprintCount+@ReprintCountDelta," +
|
|
|
742
|
+ "ExportCount=ExportCount+@ExportCountDelta," +
|
|
|
743
|
+ "ReExportCount=ReExportCount+@ReExportCountDelta " +
|
|
|
744
|
+ "WHERE Id=@Id",
|
|
|
745
|
+ trans);
|
|
|
746
|
+ CreateEventCountUpdateQueryParameters(command);
|
|
|
747
|
+ return command;
|
|
644
|
748
|
}
|
|
645
|
749
|
|
|
646
|
750
|
public static void LogBulkEvents(DBHelper db, List<EventLog> EventLogs)
|
|
647
|
751
|
{
|
|
648
|
|
- string Sql = "INSERT INTO Logs (UserId, VoucherId, EventDate, EventType, Retry) VALUES (@userid, @voucherid, @eventdate, @eventtype, @retry)";
|
|
|
752
|
+ string Sql = "INSERT INTO Logs (UserId, VoucherId, EventDate, EventType, Retry, Summarised) " +
|
|
|
753
|
+ "VALUES (@userid, @voucherid, @eventdate, @eventtype, @retry, 1)";
|
|
649
|
754
|
|
|
650
|
755
|
lock (db.WriteLock)
|
|
651
|
756
|
{
|
|
652
|
757
|
using (var trans = db.BeginTransaction())
|
|
653
|
758
|
{
|
|
654
|
|
- using (var Command = db.CreateCommand(Sql, trans))
|
|
|
759
|
+ using (var insertLogsCommand = db.CreateCommand(Sql, trans))
|
|
|
760
|
+ using (var updateVoucherCommand = CreateVoucherEventCountUpdateCommand(db, trans))
|
|
|
761
|
+ using (var updateBatchCommand = CreateBatchEventCountUpdateCommand(db, trans))
|
|
655
|
762
|
{
|
|
656
|
763
|
foreach (var EventLog in EventLogs)
|
|
657
|
764
|
{
|
|
658
|
|
- Command.Parameters.Clear();
|
|
659
|
|
- Command.Parameters.AddWithValue("@userid", Globals.SessionData.Credentials.Payload.User.Id);
|
|
660
|
|
- Command.Parameters.AddWithValue("@voucherid", EventLog.VoucherId);
|
|
661
|
|
- Command.Parameters.AddWithValue("@eventdate", DateTime.UtcNow);
|
|
662
|
|
- Command.Parameters.AddWithValue("@eventtype", EventLog.EventType);
|
|
663
|
|
- Command.Parameters.AddWithValue("@retry", EventLog.Retry);
|
|
664
|
|
- Command.ExecuteNonQuery();
|
|
|
765
|
+ insertLogsCommand.Parameters.Clear();
|
|
|
766
|
+ insertLogsCommand.Parameters.AddWithValue("@userid", Globals.SessionData.Credentials.Payload.User.Id);
|
|
|
767
|
+ insertLogsCommand.Parameters.AddWithValue("@voucherid", EventLog.VoucherId);
|
|
|
768
|
+ insertLogsCommand.Parameters.AddWithValue("@eventdate", DateTime.UtcNow);
|
|
|
769
|
+ insertLogsCommand.Parameters.AddWithValue("@eventtype", EventLog.EventType);
|
|
|
770
|
+ insertLogsCommand.Parameters.AddWithValue("@retry", EventLog.Retry);
|
|
|
771
|
+ insertLogsCommand.ExecuteNonQuery();
|
|
|
772
|
+
|
|
|
773
|
+ if (EventLog.VoucherId.HasValue)
|
|
|
774
|
+ {
|
|
|
775
|
+ if (! EventLog.BatchId.HasValue)
|
|
|
776
|
+ {
|
|
|
777
|
+ throw new Exception("Event log entry is missing a batch ID");
|
|
|
778
|
+ }
|
|
|
779
|
+
|
|
|
780
|
+ int printCountDelta, reprintCountDelta, exportCountDelta, reExportCountDelta;
|
|
|
781
|
+ if (CalculateEventCountDeltas(
|
|
|
782
|
+ EventLog.EventType,
|
|
|
783
|
+ EventLog.Retry,
|
|
|
784
|
+ out printCountDelta,
|
|
|
785
|
+ out reprintCountDelta,
|
|
|
786
|
+ out exportCountDelta,
|
|
|
787
|
+ out reExportCountDelta))
|
|
|
788
|
+ {
|
|
|
789
|
+ ExecuteEventCountUpdateQuery(updateVoucherCommand, EventLog.VoucherId.Value,
|
|
|
790
|
+ printCountDelta, reprintCountDelta, exportCountDelta, reExportCountDelta);
|
|
|
791
|
+
|
|
|
792
|
+ ExecuteEventCountUpdateQuery(updateBatchCommand, EventLog.BatchId.Value,
|
|
|
793
|
+ printCountDelta, reprintCountDelta, exportCountDelta, reExportCountDelta);
|
|
|
794
|
+ }
|
|
|
795
|
+ }
|
|
665
|
796
|
}
|
|
666
|
797
|
}
|
|
667
|
798
|
trans.Commit();
|
|
|
@@ -674,16 +805,18 @@ namespace BulkPrinting
|
|
674
|
805
|
}
|
|
675
|
806
|
}
|
|
676
|
807
|
|
|
677
|
|
- public static void LogEvent(DBHelper db, VendorEvent.VendorEventType EventType, int? VoucherId = null, bool Retry = false)
|
|
|
808
|
+ public static void LogEvent(DBHelper db, VendorEvent.VendorEventType EventType)
|
|
678
|
809
|
{
|
|
|
810
|
+ // Not for voucher-related events. If you add support for individual voucher events, please update print counts,
|
|
|
811
|
+ // etc., as in LogBulkEvents.
|
|
679
|
812
|
db.ExecuteNonQuery(
|
|
680
|
|
- "INSERT INTO Logs (UserId, VoucherId, EventDate, EventType, Retry) " +
|
|
681
|
|
- "VALUES (@userid, @voucherid, @eventdate, @eventtype, @retry)",
|
|
|
813
|
+ "INSERT INTO Logs (UserId, VoucherId, EventDate, EventType, Retry, Summarised) " +
|
|
|
814
|
+ "VALUES (@userid, @voucherid, @eventdate, @eventtype, @retry, 1)",
|
|
682
|
815
|
new SQLiteParameter("@userid", Globals.SessionData.Credentials.Payload.User.Id),
|
|
683
|
|
- new SQLiteParameter("@voucherid", VoucherId),
|
|
|
816
|
+ new SQLiteParameter("@voucherid", null),
|
|
684
|
817
|
new SQLiteParameter("@eventdate", DateTime.UtcNow),
|
|
685
|
818
|
new SQLiteParameter("@eventtype", EventType),
|
|
686
|
|
- new SQLiteParameter("@retry", Retry));
|
|
|
819
|
+ new SQLiteParameter("@retry", false));
|
|
687
|
820
|
if (Globals.SessionMode == SessionModes.Online)
|
|
688
|
821
|
{
|
|
689
|
822
|
TriggerLogUpload();
|