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 |
/* Developer: Tyler Allen Date Created: 08/24/2016 --------------------------------------------------- */ using System; using System.Configuration; using System.Linq; using System.Xml; using CPE.App.NotifyConsole.Extensions; using CPE.App.NotifyConsole.Models; using CPE.App.NotifyConsole.Models.Enums; using IBS.Connect.API; using IBS.Connect.API.Enums; using Action = IBS.Connect.API.Action; namespace CPE.App.NotifyConsole.Helpers { /// <summary> /// </summary> public class AdobeHelper { private Session _adobeConnectSession; /// <summary> /// </summary> /// <returns></returns> private Session getAdobeConnectSession() { if(_adobeConnectSession == null) { string login = null; string password = null; string url = null; long? accountId = null; try { login = ConfigurationManager.AppSettings["Adobe_Login"]; password = ConfigurationManager.AppSettings["Adobe_Password"]; url = ConfigurationManager.AppSettings["Adobe_Url"]; accountId = int.Parse(ConfigurationManager.AppSettings["Adobe_AccountId"]); } catch (Exception exception) { exception.Log(LoggingLevels.Fatal); return null; } var connectSession = new Session(new Uri(url)) { AccountId = accountId, LoginId = login, Password = password }; if(connectSession.Login()) { _adobeConnectSession = connectSession; } } return _adobeConnectSession; } /// <summary> /// </summary> /// <param name="meetingSession"></param> /// <param name="context"></param> /// <returns></returns> public bool GetAdobeTransactions(MeetingSession meetingSession, CPEWebDataContext context) { var boolResult = false; // Test if the session has ended. if(!meetingSession.EndDate.HasValue) { return false; } // Get an Adobe Connect session and test for valid session. var connectSession = getAdobeConnectSession(); if(connectSession == null) { return false; } // Get the transaction for the meeting session from Adobe Connect var dateCreatedFilter = meetingSession.StartDate.AddHours(-6) .ToString("yyyy-MM-dd"); var request = new Request { Actions = { new Action("report-bulk-consolidated-transactions") { Filters = { new Filter { Field = "sco-id", Value = meetingSession.SCO_ID }, new Filter { Field = "date-created", FilterModifier = FilterModifiers.GreaterThan, Value = dateCreatedFilter } } } } }; request.ActionsXml.Log(); request.ExecuteUrl.Log(); var response = request.Execute(connectSession); response.Status.Log(); response.XmlString.Log(); if(response.Status == ResponseStatus.OK) { // Delete the old records that are no longer valid var oldRecords = context.AdobeTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey); context.AdobeTransactions.DeleteAllOnSubmit(oldRecords); var xml = response.Xml; var nodes = xml.SelectNodes("//row"); foreach (XmlNode node in nodes) { node.OuterXml.Log(); 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 ?? DateTime.UtcNow) : DateTime.Parse(node.SelectSingleNode("date-closed") .InnerText.Replace(offSetString, "")) .AddHours(offSet) }; context.AdobeTransactions.InsertOnSubmit(transaction); } context.SubmitChanges(); boolResult = true; } return boolResult; } /// <summary> /// </summary> /// <param name="meetingSession"></param> /// <param name="context"></param> /// <returns></returns> public bool GetAdobeCertificateTransactions(MeetingSession meetingSession, CPEWebDataContext context) { var boolResult = false; if(!meetingSession.EndDate.HasValue) { return false; } var connectSession = getAdobeConnectSession(); if(connectSession == null) { return false; } var oldRecords = context.AdobeCertificateTransactions.Where(x => x.MeetingSessionKey == meetingSession.MeetingSessionKey); context.AdobeCertificateTransactions.DeleteAllOnSubmit(oldRecords); var request = new Request { Actions = { new Action("report-bulk-objects") { Filters = { new Filter { Field = "sco-id", Value = meetingSession.SCO_ID } } } } }; request.ActionsXml.Log(); request.ExecuteUrl.Log(); var response = request.Execute(connectSession); response.Status.Log(); response.XmlString.Log(); if(response.Status == ResponseStatus.OK) { var xml = response.Xml; var nodes = xml.SelectNodes("//row"); foreach (XmlNode node in nodes) { var description = node.SelectSingleNode("description") .InnerText; var fields = description.Split('|'); var presenter = fields.FirstOrDefault(p => p.Contains("Presenter")); presenter = presenter?.Substring(presenter.IndexOf('=') + 1); var 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); } boolResult = true; } return boolResult; } } } |
Commits for CPE_learningsiteCPE/CPE.App/CPE.App.NotifyConsole/Helpers/AdobeHelper.cs
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |