using System; using System.Linq; using System.Xml; using CPE.App.Web.Connect; using CPE.App.Web.Models; using CPE.App.Web.Code; namespace CPE.App.Web { public static class adobe { public static void GetAdobeTransactions(MeetingSession meetingSession, CPEWebDataContext context) { Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("Parameters: meetingSession.MeetingSessionKey = {0} meetingSession.EndDate.HasValue = {1}", meetingSession.MeetingSessionKey, meetingSession.EndDate.HasValue)); int adobeTransactionsAdded = 0; if (!meetingSession.EndDate.HasValue) return; string login = "support@intesolv.com"; string password = "Cp3!nC"; string url = "http://cpeonline.adobeconnect.com"; int accountId = 1050997608; Session session = Login.UserLogin(login, password, url, accountId); if (session == null) { Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("session == null; meetingSession.MeetingSessionKey = {0}", meetingSession.MeetingSessionKey)); return; } var oldRecords = context.AdobeTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey); //string dateCreatedFilter = meetingSession.StartDate.AddHours(-6).ToString("yyyy-MM-ddThh:mm:00.000-04:00"); // Striping the time is way easier than trying to use the correct time zone, even though the results may be different //string dateCreatedFilter = meetingSession.StartDate.AddHours(-6).ToString("yyyy-MM-ddThh:mm"); // This sometimes fails, so adobe asked us to format the date differently string dateCreatedFilter = meetingSession.StartDate.AddHours(-6).ToString("yyyy-MM-dd"); // https://cpeonline.adobeconnect.com/api/xml?action=report-bulk-consolidated-transactions&filter-sco-id=1091486528&filter-gt-date-created=2014-06-23T8:00 var request = new Connect.Request(session, "report-bulk-consolidated-transactions"); request.Parameters.Add("filter-sco-id", meetingSession.SCO_ID.ToString()); request.Parameters.Add("filter-gt-date-created", dateCreatedFilter); Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("Before report-bulk-consolidated-transactions. meetingSession.MeetingSessionKey = {0} ScoIdFilter = {1} dateCreatedFilter = {2}", meetingSession.MeetingSessionKey, meetingSession.SCO_ID.ToString(), dateCreatedFilter)); if (request.Execute() && request.Status == Status.OK) { // Tyler Allen -- 08/27/2016 // The transaction is getting locked due to other transaction working on the same row. try { context.AdobeTransactions.DeleteAllOnSubmit(oldRecords); var xml = request.XmlResults; var nodes = xml.SelectNodes("//row"); foreach (XmlNode node in nodes) { var dateString = node.SelectSingleNode("date-created") .InnerText; var offSetString = dateString.Substring(dateString.Length - 6, 6); var offSet = int.Parse(offSetString.Substring(1, 2)); dateString = dateString.Replace(offSetString, ""); var dateStart = DateTime.Parse(dateString) .AddHours(offSet); var transaction = new AdobeTransaction() { Created = DateTime.UtcNow, Principal_ID = int.Parse(node.Attributes["principal-id"].Value), MeetingSessionKey = meetingSession.MeetingSessionKey, StartDate = dateStart, EndDate = (node.SelectSingleNode("date-closed") == null) ? ((meetingSession.EndDate.HasValue) ? meetingSession.EndDate.Value : DateTime.UtcNow) : DateTime.Parse(node.SelectSingleNode("date-closed").InnerText.Replace(offSetString, "")).AddHours(offSet) }; string dateClosedForLogging = "null"; if (node.SelectSingleNode("date-closed") != null) { dateClosedForLogging = node.SelectSingleNode("date-closed").InnerText; } Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("Before Insert. meetingSession.MeetingSessionKey = {0} Principal_ID = {1} dateCreated = {2} dateClosed = {3}", meetingSession.MeetingSessionKey, transaction.Principal_ID, node.SelectSingleNode("date-created").InnerText, dateClosedForLogging)); context.AdobeTransactions.InsertOnSubmit(transaction); adobeTransactionsAdded++; } context.SubmitChanges(); } catch (Exception exception) { Console.WriteLine(exception); } var adobeTransactionsForMeeting = context.AdobeTransactions.Where(at => at.MeetingSessionKey == meetingSession.MeetingSessionKey).OrderByDescending(at => at.AdobeTransactionKey).ToList(); if (adobeTransactionsForMeeting.Count > 1) { Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("After Insert. meetingSession.MeetingSessionKey = {0} Max AdobeTransactionKey = {1}", meetingSession.MeetingSessionKey, adobeTransactionsForMeeting.First().AdobeTransactionKey)); } else { Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("After Insert. meetingSession.MeetingSessionKey = {0} No AdobeTransactions found.", meetingSession.MeetingSessionKey)); } } else { Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("Execute failed. meetingSession.MeetingSessionKey = {0} request.Status = {1} request.XmlResults = [{2}] request.Url = {3}", meetingSession.MeetingSessionKey, request.Status, request.XmlResults.InnerXml, request.Url)); // Retry? } Extensions.LogServiceCall("[adobe][GetAdobeTransactions]", String.Format("End meetingSession.MeetingSessionKey = {0} adobeTransactionsAdded = {1}", meetingSession.MeetingSessionKey, adobeTransactionsAdded)); } public static void GetAdobeCertificateTransactions(MeetingSession meetingSession, CPEWebDataContext context) { Extensions.LogServiceCall("[adobe][GetAdobeCertificateTransactions]", String.Format("Parameters: meetingSession.MeetingSessionKey = {0} meetingSession.EndDate.HasValue = {1}", meetingSession.MeetingSessionKey, meetingSession.EndDate.HasValue)); int adobeCertificateTransactionsAdded = 0; if (!meetingSession.EndDate.HasValue) return; string login = "support@intesolv.com"; string password = "Cp3!nC"; string url = "http://cpeonline.adobeconnect.com"; int accountId = 1050997608; Session session = Login.UserLogin(login, password, url, accountId); if (session == null) return; var oldRecords = context.AdobeCertificateTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey); context.AdobeCertificateTransactions.DeleteAllOnSubmit(oldRecords); // https://cpeonline.adobeconnect.com/api/xml?action=report-bulk-objects&filter-sco-id=1091486528 var request = new Connect.Request(session, "report-bulk-objects"); request.Parameters.Add("filter-sco-id", meetingSession.SCO_ID.ToString()); if (request.Execute() && request.Status == Status.OK) { var xml = request.XmlResults; var nodes = xml.SelectNodes("//row"); foreach (XmlNode node in nodes) { var description = node.SelectSingleNode("description") .InnerText; string[] fields = description.Split('|'); string presenter = fields.FirstOrDefault(p => p.Contains("Presenter")); presenter = presenter?.Substring(presenter.IndexOf('=') + 1); string fos = fields.FirstOrDefault(f => f.Contains("FOS") || f.Contains("Field of Study")); fos = fos?.Substring(fos.IndexOf('=') + 1); var transaction = new AdobeCertificateTransaction() { Created = DateTime.UtcNow, MeetingSessionKey = meetingSession.MeetingSessionKey, Fos = fos, Presenter = presenter }; context.AdobeCertificateTransactions.InsertOnSubmit(transaction); adobeCertificateTransactionsAdded++; } } Extensions.LogServiceCall("[adobe][GetAdobeCertificateTransactions]", String.Format("End meetingSession.MeetingSessionKey = {0} adobeCertificateTransactionsAdded = {1}", meetingSession.MeetingSessionKey, adobeCertificateTransactionsAdded)); } } }