/// <summary> /// Handles the message. /// </summary> /// <param name="message">The message.</param> /// <exception cref="System.ArgumentNullException"> /// ticketUuid /// or /// gameTitle /// or /// recallData /// </exception> public void HandleMessage(ITextMessage message) { Logger.Debug("Entered HandleMessage"); if (null == message) { throw new ArgumentNullException("message"); } var ticketUuid = message.Properties.GetString(MessageKeys.TicketMessageKey); var gameTitle = message.Properties.GetString(MessageKeys.GameTitleMessageKey); var casino = message.Properties.GetString(MessageKeys.CasinoNameMessageKey); var gamePlayedAt = message.Properties.GetLong(MessageKeys.GamePlayTimeMessageKey); var recallData = message.Text; var ticketIdOk = true; var gameTitleOk = true; var recallDataOk = true; var casinoOk = true; var gamePlayedAtOk = true; var numBadParams = 0; if (string.IsNullOrWhiteSpace(ticketUuid)) { ticketIdOk = false; ++numBadParams; } if (string.IsNullOrWhiteSpace(gameTitle)) { gameTitleOk = false; ++numBadParams; } else { if (!Directory.Exists(GameDirectoryPath + @"\" + Regex.Replace(gameTitle, @"\s+", string.Empty))) { gameTitleOk = false; ++numBadParams; } } if (string.IsNullOrWhiteSpace(recallData)) { recallDataOk = false; ++numBadParams; } if (string.IsNullOrWhiteSpace(casino)) { casinoOk = false; ++numBadParams; } if (0 > gamePlayedAt) { gamePlayedAtOk = false; ++numBadParams; } if (0 < numBadParams) { MsgProducer.NotifyJobFailed(ticketUuid); var errMsg = "Invalid message payload: "; var badParams = string.Empty; if (!ticketIdOk) { badParams += "ticketUuid"; } if (!gameTitleOk) { if (!string.IsNullOrWhiteSpace(badParams)) { badParams += "/"; } badParams += "gameTitle"; } if (!recallDataOk) { if (!string.IsNullOrWhiteSpace(badParams)) { badParams += "/"; } badParams += "recallData"; } if (!casinoOk) { if (!string.IsNullOrWhiteSpace(badParams)) { badParams += "/"; } badParams += "casino"; } if (!gamePlayedAtOk) { if (!string.IsNullOrWhiteSpace(badParams)) { badParams += "/"; } badParams += "gamePlayedAt"; } var value = numBadParams > 1 ? "values" : "value"; errMsg += $"{badParams} {value} must be non-null and non-empty"; throw new ArgumentException(errMsg); } Logger.DebugFormat( "HandleMessage - ticketUuid={0} casino={3} gameTitle={1} gamePlayedTime={4} recallData={2}", ticketUuid, gameTitle, recallData, casino, gamePlayedAt); VideoRecordingService.RecordVideo(ticketUuid, casino, gameTitle, gamePlayedAt, recallData); }
public void RecordVideo(string ticketId, string casino, string gameTitle, long gamePlayedAt, string gameRecallData) { try { MsgProducer.UpdateJobStatus(ticketId, TicketStatus.Recording); Logger.DebugFormat( "Entered VideoRecordingService.RecordVideo - ticketId={0} casino={3} gameTitle={1} gameRecallData={2}", ticketId, gameTitle, gameRecallData, casino); // clean up any mp4 files left in video recording directory foreach ( var mp4File in Directory.GetFiles(VideoRecordDirectoryPath).Where(mp4File => mp4File.EndsWith(".mp4"))) { File.Delete(mp4File); } // write game share recallData to file for reading by Air Game exe at run-time var normalizedGameTitle = Regex.Replace(gameTitle, @"\s+", string.Empty); var gameShareRecallData = new FileInfo(GameDirectoryPath + @"\" + normalizedGameTitle + @"\" + GameRecallDataFile); if (gameShareRecallData.Exists) { gameShareRecallData.Delete(); } using (var gsrdTextWriter = gameShareRecallData.CreateText()) { gsrdTextWriter.Write(gameRecallData); } // start up the video recording app Recorder.PowerOn(); Thread.Sleep(800); // start up the Air Game Exe as a separate process RunAirGameProc(normalizedGameTitle); // get the mp4 recording as a byte[] and send message to VideoUploader // service with this byte[] as payload var videoBytes = FinalizeVideo(); MsgProducer.UpdateJobStatus(ticketId, TicketStatus.Recorded, videoBytes); MsgProducer.UploadVideo(ticketId, casino, gameTitle, gamePlayedAt, videoBytes); } catch (RecordVideoException) { throw; } catch (Exception ex) { Logger.WarnFormat("Exception caught: {0}" + Environment.NewLine + "{1}", ex.Message, ex.StackTrace); throw new RecordVideoException("Failed to Record Video", ex); } finally { Logger.Trace("In finally"); try { // clean up any mp4 files left in video recording directory foreach ( var mp4File in Directory.GetFiles(VideoRecordDirectoryPath).Where(mp4File => mp4File.EndsWith(".mp4"))) { File.Delete(mp4File); } // clean up Game Share recallData file from this recording session var gameShareRecallData = new FileInfo(GameDirectoryPath + @"\" + gameTitle + @"\" + GameRecallDataFile); if (gameShareRecallData.Exists) { gameShareRecallData.Delete(); } } catch (Exception ex) { Logger.WarnFormat("Exception caught: {0}" + Environment.NewLine + "{1}", ex.Message, ex.StackTrace); } } }