Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 4cd176 ... vs d90493 ... for /CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs

Diff revisions: vs.
  @@ -4,6 +4,7 @@
4 4 using System.Collections.Generic;
5 5 using System.Linq;
6 6 using System.Web;
7 + using Newtonsoft.Json;
7 8
8 9 namespace CPE.App.Api.Helpers
9 10 {
  @@ -13,10 +14,10 @@
13 14 {
14 15 // statement.Verb.Id=http://adlnet.gov/expapi/verbs/answered
15 16 // statement.Verb.Id=http://adlnet.gov/expapi/verbs/experienced
16 -
17 + var dtNow = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss");
17 18 if (statement.Verb.Id.IndexOf("passed")>-1)
18 19 {
19 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), statement.Verb.Id);
20 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}. statement={2}", dtNow, statement.Verb.Id, JsonConvert.SerializeObject(statement));
20 21
21 22 //parse statement to db variables
22 23 var email = statement.Actor.Mbox.Substring(7);
  @@ -24,15 +25,40 @@
24 25 var lname = statement.Actor.Name.Substring(statement.Actor.Name.LastIndexOf(" ") + 1);
25 26 var courseUrl = statement.Object.Id.Substring(statement.Object.Id.LastIndexOf("/") + 1);
26 27 var courseName = statement.Object.Definition.Name.EnUs;
28 + bool done;
27 29
28 30 //cpe has test data with multiple, currently valid purchases of the same course for one user, which causes problems but is not a real-world problem.
29 31 //elucidat tracks all users globally by email address so a tincan statement won't identify a specific purchase here
30 32 //unless we create unique email addy (e.g. email+ticket@mail.com) when originally logging them in to content
31 - var course = BaseController.Database.PurchasedCourses.FirstOrDefault(c => c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate == null);
33 + var course = BaseController.Database.PurchasedCourses.FirstOrDefault(c =>
34 + c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate == null);
32 35 if (course == null)
33 36 {
34 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, cert already earned email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName);
37 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action 1, cert already earned email={1} courseName={2}", dtNow, email, courseName);
35 38 //no action, cert already earned
39 + //try
40 + //{
41 + // course = BaseController.Database.PurchasedCourses.FirstOrDefault(c => c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate!=null);
42 + // if (course == null)
43 + // {
44 + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, course == null, select courseName={1} from db with CertificateDate.", dtNow, courseName);
45 + // }
46 +
47 + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, select courseName={1} from db with CertificateDate. course={2}", dtNow, courseName, JsonConvert.SerializeObject(course));
48 +
49 + // done = SendEmailHelper.SendCertificateEmail(course);
50 +
51 + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, send courseName={1} from db to email={2} successfully", dtNow, courseName, email);
52 + //}
53 + //catch (Exception exception)
54 + //{
55 + // var innerException = "";
56 + // if (exception.InnerException != null) innerException = exception.InnerException.ToString();
57 + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString()+ innerException);
58 + //}
59 +
60 + //Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", dtNow, email, courseName);
61 +
36 62 return true;
37 63 }
38 64
  @@ -43,12 +69,12 @@
43 69 }
44 70 catch (Exception exception)
45 71 {
46 - Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName, exception.ToString());
72 + Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString());
47 73 }
48 74
49 - var done = SendEmailHelper.SendCertificateEmail(course);
75 + done = SendEmailHelper.SendCertificateEmail(course);
50 76
51 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName);
77 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", dtNow, email, courseName);
52 78
53 79 //umm why am i not returning done here?
54 80 return true;
  @@ -57,7 +83,7 @@
57 83
58 84 if (statement.Verb.Id.IndexOf("failed") > -1)
59 85 {
60 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), statement.Verb.Id);
86 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}. statement={2}", dtNow, statement.Verb.Id, JsonConvert.SerializeObject(statement));
61 87
62 88 //parse statement to db variables
63 89 var email = statement.Actor.Mbox.Substring(7);
  @@ -76,7 +102,7 @@
76 102 return true;
77 103 }
78 104
79 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} course.Ticket={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), course.Ticket);
105 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} course.Ticket={1}", dtNow, course.Ticket);
80 106
81 107 if (!course.FailedAttempts.HasValue)
82 108 {
  @@ -89,10 +115,10 @@
89 115 }
90 116 catch (Exception exception)
91 117 {
92 - Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName, exception.ToString());
118 + Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString());
93 119 }
94 120
95 - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} failure recorded email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName);
121 + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} failure recorded email={1} courseName={2}", dtNow, email, courseName);
96 122
97 123 return true;
98 124 }