3 Date Created: 08/24/2016
4 ---------------------------------------------------
8 using System.Configuration;
11 using CPE.App.Notify.Extensions;
12 using CPE.App.Notify.Models;
13 using CPE.App.Notify.Models.Enums;
14 using IBS.Connect.API;
15 using IBS.Connect.API.Enums;
16 using Action = IBS.Connect.API.Action;
18 namespace CPE.App.Notify.Helpers {
21 public class AdobeHelper {
22 private Session _adobeConnectSession;
26 /// <returns></returns>
27 private Session getAdobeConnectSession() {
28 if(_adobeConnectSession == null) {
30 string password = null;
32 long? accountId = null;
34 login = ConfigurationManager.AppSettings["Adobe_Login"];
35 password = ConfigurationManager.AppSettings["Adobe_Password"];
36 url = ConfigurationManager.AppSettings["Adobe_Url"];
37 accountId = int.Parse(ConfigurationManager.AppSettings["Adobe_AccountId"]);
38 } catch (Exception exception) {
39 exception.Log(LoggingLevels.Fatal);
42 var connectSession = new Session(new Uri(url)) {
43 AccountId = accountId,
47 if(connectSession.Login()) {
48 _adobeConnectSession = connectSession;
51 return _adobeConnectSession;
56 /// <param name="meetingSession"></param>
57 /// <param name="context"></param>
58 /// <returns></returns>
59 public bool GetAdobeTransactions(MeetingSession meetingSession, CPEWebDataContext context) {
60 var boolResult = false;
62 // Test if the session has ended.
63 if(!meetingSession.EndDate.HasValue) {
67 // Get an Adobe Connect session and test for valid session.
68 var connectSession = getAdobeConnectSession();
69 if(connectSession == null) {
74 // Get the transaction for the meeting session from Adobe Connect
75 var dateCreatedFilter = meetingSession.StartDate.AddHours(-6)
76 .ToString("yyyy-MM-dd");
77 var request = new Request {
79 new Action("report-bulk-consolidated-transactions") {
83 Value = meetingSession.SCO_ID
86 Field = "date-created",
87 FilterModifier = FilterModifiers.GreaterThan,
88 Value = dateCreatedFilter
94 request.ActionsXml.Log();
95 request.ExecuteUrl.Log();
96 var response = request.Execute(connectSession);
97 response.Status.Log();
98 response.XmlString.Log();
99 if(response.Status == ResponseStatus.OK) {
100 // Delete the old records that are no longer valid
101 var oldRecords = context.AdobeTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey);
102 context.AdobeTransactions.DeleteAllOnSubmit(oldRecords);
104 var xml = response.Xml;
105 var nodes = xml.SelectNodes("//row");
106 foreach (XmlNode node in nodes) {
108 var dateString = node.SelectSingleNode("date-created")
110 var offSetString = dateString.Substring(dateString.Length - 6, 6);
111 var offSet = int.Parse(offSetString.Substring(1, 2));
112 dateString = dateString.Replace(offSetString, "");
113 var dateStart = DateTime.Parse(dateString)
115 var transaction = new AdobeTransaction {
116 Created = DateTime.UtcNow,
117 Principal_ID = int.Parse(node.Attributes["principal-id"].Value),
118 MeetingSessionKey = meetingSession.MeetingSessionKey,
119 StartDate = dateStart,
120 EndDate = node.SelectSingleNode("date-closed") == null ? (meetingSession.EndDate ?? DateTime.UtcNow) : DateTime.Parse(node.SelectSingleNode("date-closed")
121 .InnerText.Replace(offSetString, ""))
125 context.AdobeTransactions.InsertOnSubmit(transaction);
127 context.SubmitChanges();
135 /// <param name="meetingSession"></param>
136 /// <param name="context"></param>
137 /// <returns></returns>
138 public bool GetAdobeCertificateTransactions(MeetingSession meetingSession, CPEWebDataContext context) {
139 var boolResult = false;
141 if(!meetingSession.EndDate.HasValue) {
145 var connectSession = getAdobeConnectSession();
146 if(connectSession == null) {
150 var oldRecords = context.AdobeCertificateTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey);
151 context.AdobeCertificateTransactions.DeleteAllOnSubmit(oldRecords);
153 var request = new Request {
155 new Action("report-bulk-objects") {
159 Value = meetingSession.SCO_ID
165 request.ActionsXml.Log();
166 request.ExecuteUrl.Log();
167 var response = request.Execute(connectSession);
168 response.Status.Log();
169 response.XmlString.Log();
170 if(response.Status == ResponseStatus.OK) {
171 var xml = response.Xml;
172 var nodes = xml.SelectNodes("//row");
173 foreach (XmlNode node in nodes) {
174 var description = node.SelectSingleNode("description")
176 var fields = description.Split('|');
177 var presenter = fields.FirstOrDefault(p => p.Contains("Presenter"));
178 presenter = presenter?.Substring(presenter.IndexOf('=') + 1);
179 var fos = fields.FirstOrDefault(f => f.Contains("FOS") || f.Contains("Field of Study"));
180 fos = fos?.Substring(fos.IndexOf('=') + 1);
181 var transaction = new AdobeCertificateTransaction {
182 Created = DateTime.UtcNow,
183 MeetingSessionKey = meetingSession.MeetingSessionKey,
185 Presenter = presenter
187 context.AdobeCertificateTransactions.InsertOnSubmit(transaction);