CPE_learningsite
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
4cd176a439ea516368a5d8827cdf8726027259a6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
/* Developer: Tyler Allen Date Created: 08/24/2016 --------------------------------------------------- */ using System; using System.Collections.Generic; using System.Configuration; using System.Data.Linq; using System.Linq; using CPE.App.Notify.Extensions; using CPE.App.Notify.Models; using CPE.App.Notify.Models.Enums; namespace CPE.App.Notify.Helpers { public static class SessionHelper { private static readonly CPEWebDataContext _database = CPEWebDataContext.GetContext(); // Get meeting session public static MeetingSession getMeetingSession(int meetingSessionKey) { MeetingSession meetingSession = null; meetingSession = _database .MeetingSessions.FirstOrDefault(x => x.MeetingSessionKey == meetingSessionKey); return meetingSession.Log(key: meetingSessionKey); } // Get first meeting participant session public static MeetingParticipantSession getMeetingParticipantSession(int meetingParticipantSessionKey) { var meetingParticipantSession = _database .MeetingParticipantSessions.FirstOrDefault(x => x.MeetingParticipantSessionKey == meetingParticipantSessionKey) .Log(); return meetingParticipantSession.Log(key: meetingParticipantSessionKey); } // Get first meeting participant session public static MeetingParticipantSession getMeetingParticipantSession(int meetingSessionKey, long participantKey) { var meetingParticipantSession = _database .MeetingParticipantSessions .FirstOrDefault(mps => (mps.MeetingSessionKey == meetingSessionKey) && (mps.ParticipantKey == participantKey)); return meetingParticipantSession.Log(key: participantKey); } // Get meeting participant sessions public static List<MeetingParticipantSession> getMeetingParticipantSessions(int meetingSessionKey) { var listOfMeetingParticipantSessions = _database .MeetingParticipantSessions.Where(m => m.MeetingSessionKey == meetingSessionKey) .ToList(); return listOfMeetingParticipantSessions.Log(key: meetingSessionKey); } // Get participant purchase public static ParticipantPurchase getParticipantPurchase(long participantKey, long scoId) { var purchase = getParticipantPurchases(participantKey, scoId) .FirstOrDefault(); return purchase.Log(key: participantKey); } // Get participant purchase public static ParticipantPurchase getParticipantPurchase(long scoId, DispositionProcessingStates dispositionProcessingState) { var purchase = _database .ParticipantPurchases.FirstOrDefault(pp => (pp.MeetingSco == scoId) && (pp.DispositionProcessingState == (int) dispositionProcessingState)); return purchase.Log(key: scoId); } // Get participant purchase public static List<ParticipantPurchase> getParticipantPurchases(long participantKey, long scoId) { var purchases = _database .ParticipantPurchases .Where(pp => (pp.PrincipalID == participantKey) && (pp.MeetingSco == scoId)) .ToList(); return purchases.Log(key: participantKey); } // Get participant tracking results public static List<GetParticipantTrackingsResult> getParticipantTrackingResults(int meetingParticipantSessionKey) { var participantTrackings = _database .GetParticipantTrackings() .Where(pt => pt.MeetingParticipantSessionKey == meetingParticipantSessionKey) .ToList(); return participantTrackings.Log(key: meetingParticipantSessionKey); } // Get participant session data result public static ParticipantSessionsDataResult getParticipantSessionsDataResult(int meetingSessionKey, int meetingParticipantSessionKey) { var participantSessionDataResult = _database.ParticipantSessionsData(meetingSessionKey) .FirstOrDefault( psd => psd.MeetingParticipantSessionKey == meetingParticipantSessionKey); return participantSessionDataResult.Log(key: meetingSessionKey); } public static IQueryable<GetRecordingCandidatesResult> getRecordingCandidates(int? meetingSessionKey = null) { return _database.GetRecordingCandidates(meetingSessionKey).Log(key: meetingSessionKey); } /// <summary> /// </summary> /// <param name="meetingParticipantSession"></param> /// <param name="toEmail"></param> /// <param name="meetingSco"></param> /// <param name="purchaseDate"></param> /// <param name="purchaseTicket"></param> /// <returns></returns> private static ParticipantResults processEndOfMeetingSessionAdobeConnectResultsForParticipant(MeetingParticipantSession meetingParticipantSession, out string toEmail, out int meetingSco, out DateTime purchaseDate, out string purchaseTicket) { "Begin ProcessEndOfMeetingSessionAdobeConnectResultsForParticipant...".Log(key: meetingParticipantSession.MeetingParticipantSessionKey); $"ProcessEndOfMeetingSessionAdobeConnectResultsForParticipant received the meetingParticipantSession {meetingParticipantSession}".Log(LoggingLevels.Info, key: meetingParticipantSession.MeetingParticipantSessionKey); var result = ParticipantResults.Wonky; toEmail = null; meetingSco = -1; purchaseDate = DateTime.MinValue; purchaseTicket = null; var principalid = meetingParticipantSession.ParticipantKey; var meetingSessionKey = meetingParticipantSession.MeetingSessionKey; var meeting = meetingParticipantSession.MeetingSession; $"Meeting session was found {meeting}".Log(key: meetingParticipantSession.MeetingParticipantSessionKey); var scoId = meeting.SCO_ID; var participantTrackings = getParticipantTrackingResults(meetingParticipantSession.MeetingParticipantSessionKey) .ToList() .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); var participantSession = getParticipantSessionsDataResult(meetingSessionKey, meetingParticipantSession.MeetingParticipantSessionKey) .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); ParticipantPurchase purchase = null; if(participantSession != null) { purchase = getParticipantPurchase(principalid, scoId) .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); if(purchase == null) { result = ParticipantResults.Ineligible; } else { purchase.DispositionProcessingState = (int) DispositionProcessingStates.InProgress; _database.SubmitChanges(ConflictMode.ContinueOnConflict); toEmail = purchase.Email; meetingSco = purchase.MeetingSco; purchaseDate = purchase.PurchaseDate; purchaseTicket = purchase.Ticket; var minutesInSessionHour = 50; var meetingSession = _database.MeetingSessionsData() .FirstOrDefault(m => m.MeetingSessionKey == meetingSessionKey) .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); if(meetingSession != null) { double maxSessionTimePossibleRoundedDown = -1; if(meetingSession.ActualSessionTime != null) { // one of these integers needs to be cast to a double to get a double as an answer, that's how .NET math works. var maxSessionTimePossible = ((double) meetingSession.ActualSessionTime/minutesInSessionHour).Log(key: meetingParticipantSession.MeetingParticipantSessionKey); maxSessionTimePossibleRoundedDown = (Math.Floor(maxSessionTimePossible/.5)*.5).Log(key: meetingParticipantSession.MeetingParticipantSessionKey); } double sessionCreditRoundedDown = 0; if(participantSession.SessionCredit.HasValue) { var dbSessionCredit = Convert.ToDouble(participantSession.SessionCredit) .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); sessionCreditRoundedDown = (Math.Floor(dbSessionCredit/.5)*.5).Log(key: meetingParticipantSession.MeetingParticipantSessionKey); } var validCourseCreditsValues = ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';') .Select(double.Parse) .ToList() .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); //max credits cut list var mx = validCourseCreditsValues.BinarySearch(maxSessionTimePossibleRoundedDown); //find appropriate valid value for this course //user awarded no more than max possible credits for the course var arrayPosition = mx >= 0 ? mx : ~mx - 1; //...by rounding down var maxValidCourseCredit = validCourseCreditsValues[arrayPosition]; if(sessionCreditRoundedDown < 1) { purchase.Credits = 0; } else { if(sessionCreditRoundedDown > maxSessionTimePossibleRoundedDown) { purchase.Credits = maxSessionTimePossibleRoundedDown; } else if(sessionCreditRoundedDown > maxValidCourseCredit) { purchase.Credits = maxValidCourseCredit; } else { purchase.Credits = sessionCreditRoundedDown; } } var meetingDetail = _database.MeetingDetails.FirstOrDefault(m => m.MeetingKey == purchase.MeetingSco) .Log(key: meetingParticipantSession.MeetingParticipantSessionKey); purchase.Presenter = meetingDetail == null ? "" : meetingDetail.Instructor; // This value gets set on first login, which may not be the date the cerficate was earned on (this value gets displayed on the certificate). Ideally we would use the local user's time zone to figure the date. purchase.MeetingDate = DateTime.Now.Date; double sessionHeartbeatCountAsDouble = participantSession.SessionHeartbeatCount.GetValueOrDefault() .Log(message: "sessionHeartbeatCountAsDouble", key: meetingParticipantSession.MeetingParticipantSessionKey); double sessionEngagementCountAsDouble = participantSession.SessionEngagementCount.GetValueOrDefault() .Log(message: "sessionEngagementCountAsDouble", key: meetingParticipantSession.MeetingParticipantSessionKey); var percentComplete = (Math.Abs(Math.Abs(sessionHeartbeatCountAsDouble)) < 1 ? 1 : sessionEngagementCountAsDouble/sessionHeartbeatCountAsDouble).Log(message: "percentComplete", key: meetingParticipantSession.MeetingParticipantSessionKey); if((purchase.Credits >= 1.0) && (percentComplete >= .75)) //threshold for earning a certificate is 75% response rate { purchase.EarnedCertificate = true; result = ParticipantResults.Pass; } else { result = ParticipantResults.Fail; } purchase.DispositionProcessingState = (int) DispositionProcessingStates.Finished; _database.SubmitChanges(ConflictMode.ContinueOnConflict); } } } if(purchase == null) { result = ParticipantResults.Ineligible; } $"Participant result returned {result}".Log(key: meetingParticipantSession.MeetingParticipantSessionKey); "End ProcessEndOfMeetingSessionAdobeConnectResultsForParticipant...".Log(key: meetingParticipantSession.MeetingParticipantSessionKey); return result; } /// <summary> /// </summary> /// <param name="meetingSessionKey"></param> /// <param name="isUnitTest">Bypasses sending an email for testing purposes</param> public static bool StopSession(int meetingSessionKey, bool isUnitTest = false) { "Begin StopSession...".Log(key:meetingSessionKey); $"StopSession received the meetingSessionKey {meetingSessionKey}".Log(LoggingLevels.Info, key: meetingSessionKey); var boolResult = false; try { var meetingSession = getMeetingSession(meetingSessionKey) .Log(key: meetingSessionKey); if(meetingSession == null) { $"Meeting session was not found for key - {meetingSessionKey}".Log(LoggingLevels.Error, key: meetingSessionKey); } else { try { // Is there a need to write a test for this? var adobeHelper = new AdobeHelper(); if(adobeHelper.GetAdobeTransactions(meetingSession, _database)) { "Adobe transactions were found and processed".Log(key: meetingSessionKey); _database.SubmitChanges(ConflictMode.ContinueOnConflict); } else { "No Adobe transactions were found".Log(LoggingLevels.Warn, key: meetingSessionKey); } var listOfMeetingParticipantSessions = getMeetingParticipantSessions(meetingSession.MeetingSessionKey) .Log(key: meetingSessionKey); foreach (var meetingParticipantSession in listOfMeetingParticipantSessions) { var purchase = getParticipantPurchase(meetingParticipantSession.ParticipantKey, meetingSession.SCO_ID) .Log(key: meetingSessionKey); if(purchase != null) { "A purchase was found and will be processed for a certificate".Log(key: meetingSessionKey); string toEmail = null; var meetingSco = -1; DateTime purchaseDate; string purchaseTicket = null; "Begin ProcessEndOfMeetingSessionAdobeConnectResultsForParticipant...".Log(key: meetingSessionKey); var passFailResult = processEndOfMeetingSessionAdobeConnectResultsForParticipant(meetingParticipantSession, out toEmail, out meetingSco, out purchaseDate, out purchaseTicket); $"ProcessEndOfMeetingSessionAdobeConnectResultsForParticipant returned a result of {passFailResult}".Log(key: meetingSessionKey); switch (passFailResult) { case ParticipantResults.Ineligible: break; case ParticipantResults.Fail: "Begin SendFailNotice...".Log(key: meetingSessionKey); if(!isUnitTest) { toEmail.Log(key: meetingSessionKey); EmailCertificateHelper.SendFailNotice(toEmail); } "End SendFailNotice...".Log(key: meetingSessionKey); break; case ParticipantResults.Pass: "Begin SendWebcastCert...".Log(key: meetingSessionKey); if(!isUnitTest) { toEmail.Log(key: meetingSessionKey); EmailCertificateHelper.SendWebcastCert(toEmail, meetingSco, purchaseDate, purchaseTicket); } "End SendWebcastCert...".Log(key: meetingSessionKey); break; case ParticipantResults.Wonky: break; } } } } catch (Exception exception) { exception.Log(LoggingLevels.Fatal, key: meetingSessionKey); } } boolResult = true; } catch (Exception exception) { exception.Log(LoggingLevels.Fatal, key: meetingSessionKey); } "End StopSession...".Log(key: meetingSessionKey); return boolResult.Log(key: meetingSessionKey); } /// <summary> /// </summary> /// <param name="meetingParticipantSessionKey"></param> /// <param name="isUnitTest">Bypasses sending an email for testing purposes</param> public static bool ArchiveSession(int meetingParticipantSessionKey, bool isUnitTest = false) { "Begin ArchiveSession...".Log(key: meetingParticipantSessionKey); var boolResult = false; try { var meetingParticipantSession = getMeetingParticipantSession(meetingParticipantSessionKey) .Log(key: meetingParticipantSessionKey); var meetingSession = getMeetingSession(meetingParticipantSession.MeetingSessionKey) .Log(key: meetingParticipantSessionKey); var purchase = getParticipantPurchase(meetingParticipantSession.ParticipantKey, meetingSession.SCO_ID) .Log(key: meetingParticipantSessionKey); if(purchase != null) { // Is there a need to write a test for this? var adobeHelper = new AdobeHelper(); if(adobeHelper.GetAdobeTransactions(meetingSession, _database)) { "Adobe transactions were found and processed".Log(key: meetingParticipantSessionKey); _database.SubmitChanges(ConflictMode.ContinueOnConflict); } else { "No Adobe transactions were found".Log(LoggingLevels.Warn, key: meetingParticipantSessionKey); } string toEmail = null; var meetingSco = -1; var purchaseDate = DateTime.MinValue; string purchaseTicket = null; var passFailResult = processEndOfMeetingSessionAdobeConnectResultsForParticipant(meetingParticipantSession, out toEmail, out meetingSco, out purchaseDate, out purchaseTicket) .Log(key: meetingParticipantSessionKey); switch (passFailResult) { case ParticipantResults.Ineligible: break; case ParticipantResults.Fail: "Begin SendFailNotice...".Log(key: meetingParticipantSessionKey); if(!isUnitTest) { toEmail.Log(); EmailCertificateHelper.SendFailNotice(toEmail) .Log(key: meetingParticipantSessionKey); } "End SendFailNotice...".Log(key: meetingParticipantSessionKey); break; case ParticipantResults.Pass: "Begin SendWebcastCert...".Log(key: meetingParticipantSessionKey); if(!isUnitTest) { toEmail.Log(); EmailCertificateHelper.SendWebcastCert(toEmail, meetingSco, purchaseDate, purchaseTicket) .Log(key: meetingParticipantSessionKey); } "End SendWebcastCert...".Log(key: meetingParticipantSessionKey); break; case ParticipantResults.Wonky: break; } } boolResult = true; } catch (Exception exception) { exception.Log(LoggingLevels.Fatal, key: meetingParticipantSessionKey); } "End ArchiveSession...".Log(key: meetingParticipantSessionKey); return boolResult; } /// <summary> /// Pass a meeting session to process all recordings. /// </summary> /// <param name="meetingSessionKey"></param> /// <param name="isUnitTest"></param> /// <returns></returns> public static bool ArchiveSessionByMeetingSession(int meetingSessionKey, bool isUnitTest = false) { var returnResult = true; var sessions = getRecordingCandidates(meetingSessionKey); if(sessions.Any()) { foreach (var session in sessions) { if(!ArchiveSession(session.MeetingParticipantSessionKey, isUnitTest)) { returnResult = false; } } } return returnResult; } } } |
Commits for CPE_learningsiteCPE/CPE.App/CPE.App.Notify/Helpers/SessionHelper.cs
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |