X-Git-Url: https://xp-dev.com/git/CPE_learningsite/blobdiff_plain/4cd176a439ea516368a5d8827cdf8726027259a6..d90493cf2f1f435b060f3ae01600f05f801f24a8:/CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs diff --git a/CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs b/CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs index 7e7a0e7..9629fc7 100644 --- a/CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs +++ b/CPE/CPE.App/CPE.App.Api/Helpers/TinCanHelper.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Web; +using Newtonsoft.Json; namespace CPE.App.Api.Helpers { @@ -13,10 +14,10 @@ namespace CPE.App.Api.Helpers { // statement.Verb.Id=http://adlnet.gov/expapi/verbs/answered // statement.Verb.Id=http://adlnet.gov/expapi/verbs/experienced - + var dtNow = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"); if (statement.Verb.Id.IndexOf("passed")>-1) { - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), statement.Verb.Id); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}. statement={2}", dtNow, statement.Verb.Id, JsonConvert.SerializeObject(statement)); //parse statement to db variables var email = statement.Actor.Mbox.Substring(7); @@ -24,15 +25,40 @@ namespace CPE.App.Api.Helpers var lname = statement.Actor.Name.Substring(statement.Actor.Name.LastIndexOf(" ") + 1); var courseUrl = statement.Object.Id.Substring(statement.Object.Id.LastIndexOf("/") + 1); var courseName = statement.Object.Definition.Name.EnUs; + bool done; //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. //elucidat tracks all users globally by email address so a tincan statement won't identify a specific purchase here //unless we create unique email addy (e.g. email+ticket@mail.com) when originally logging them in to content - var course = BaseController.Database.PurchasedCourses.FirstOrDefault(c => c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate == null); + var course = BaseController.Database.PurchasedCourses.FirstOrDefault(c => + c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate == null); if (course == null) { - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, cert already earned email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action 1, cert already earned email={1} courseName={2}", dtNow, email, courseName); //no action, cert already earned + //try + //{ + // course = BaseController.Database.PurchasedCourses.FirstOrDefault(c => c.Email == email && c.ContentUrl == courseUrl && c.CertificateDate!=null); + // if (course == null) + // { + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, course == null, select courseName={1} from db with CertificateDate.", dtNow, courseName); + // } + + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, select courseName={1} from db with CertificateDate. course={2}", dtNow, courseName, JsonConvert.SerializeObject(course)); + + // done = SendEmailHelper.SendCertificateEmail(course); + + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} no action, send courseName={1} from db to email={2} successfully", dtNow, courseName, email); + //} + //catch (Exception exception) + //{ + // var innerException = ""; + // if (exception.InnerException != null) innerException = exception.InnerException.ToString(); + // Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString()+ innerException); + //} + + //Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", dtNow, email, courseName); + return true; } @@ -43,12 +69,12 @@ namespace CPE.App.Api.Helpers } catch (Exception exception) { - Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName, exception.ToString()); + Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString()); } - var done = SendEmailHelper.SendCertificateEmail(course); + done = SendEmailHelper.SendCertificateEmail(course); - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", dtNow, email, courseName); //umm why am i not returning done here? return true; @@ -57,7 +83,7 @@ namespace CPE.App.Api.Helpers if (statement.Verb.Id.IndexOf("failed") > -1) { - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), statement.Verb.Id); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} statement.Verb.Id={1}. statement={2}", dtNow, statement.Verb.Id, JsonConvert.SerializeObject(statement)); //parse statement to db variables var email = statement.Actor.Mbox.Substring(7); @@ -76,7 +102,7 @@ namespace CPE.App.Api.Helpers return true; } - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} course.Ticket={1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), course.Ticket); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} course.Ticket={1}", dtNow, course.Ticket); if (!course.FailedAttempts.HasValue) { @@ -89,10 +115,10 @@ namespace CPE.App.Api.Helpers } catch (Exception exception) { - Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName, exception.ToString()); + Utilities.LogWrapper.Error("[TinCanHelper][HandleStatement] {0} email={1} courseName={2} exception={3}", dtNow, email, courseName, exception.ToString()); } - Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} failure recorded email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName); + Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} failure recorded email={1} courseName={2}", dtNow, email, courseName); return true; }