Exemplo n.º 1
0
        private CompanyEventDTO[] GetAllEventsFromAcServer(CompanyAcServer defaultAcDomain, bool isShowPastEvents = false, bool publishedOnly = false)
        {
            var acUri       = new Uri(defaultAcDomain.AcServer);
            var acProvider  = new AdobeConnectProvider(new ConnectionDetails(acUri));
            var acProxy     = new AdobeConnectProxy(acProvider, Logger, acUri);
            var loginResult = acProxy.Login(new UserCredentials(defaultAcDomain.Username, defaultAcDomain.Password));

            if (!loginResult.Success)
            {
                return(null);
            }

            var eventType    = acProxy.GetShortcutByType("events");
            var eventContent = acProxy.GetScoExpandedContent(eventType.ScoId);

            if (!eventContent.Success)
            {
                return(null);
            }

            var result     = new List <CompanyEventDTO>();
            var eventsOnly = eventContent.Values.Where(x => x.Type == "event");

            if (!isShowPastEvents)
            {
                eventsOnly = eventsOnly.Where(x => x.EndDateLocal >= DateTime.Now);
            }

            if (publishedOnly)
            {
                var publishedEvents = acProxy.GetEventList();
                if (!publishedEvents.Success)
                {
                    return(null); // TODO: may be write error message to log at least?
                }
                eventsOnly = eventsOnly.Where(x => publishedEvents.Values.Any(e => e.ScoId == x.ScoId));
            }

            foreach (var content in eventsOnly)
            {
                result.Add(new CompanyEventDTO
                {
                    companyId         = defaultAcDomain.Company.Id,
                    dateBegin         = DateTime.SpecifyKind(content.BeginDate, DateTimeKind.Utc),
                    dateEnd           = DateTime.SpecifyKind(content.EndDate, DateTimeKind.Utc),
                    name              = content.Name,
                    desc              = content.Description,
                    scoId             = content.ScoId,
                    urlPath           = content.UrlPath,
                    dateCreated       = DateTime.SpecifyKind(content.DateCreated, DateTimeKind.Utc),
                    dateModified      = DateTime.SpecifyKind(content.DateModified, DateTimeKind.Utc),
                    isSeminar         = content.IsSeminar,
                    isMappedToQuizzes = CompanyEventQuizMappingModel.GetAllByCompanyId(defaultAcDomain.Company.Id).Any(x => x.AcEventScoId == content.ScoId),
                    meetingUrl        = acProxy.GetScoInfo(content.ScoId).ScoInfo?.SourceSco?.UrlPath,
                });
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
        public OperationResultDto IsEventValid(CompanyQuizEventMappingSaveDTO eventQuizMapping)
        {
            var defaultAcDomain = CompanyAcServerModel.GetOneById(eventQuizMapping.companyAcDomainId).Value;

            if (defaultAcDomain == null)
            {
                return(OperationResultDto.Error("Company was not found"));
            }

            var acUri       = new Uri(defaultAcDomain.AcServer);
            var acProvider  = new AdobeConnectProvider(new ConnectionDetails(acUri));
            var acProxy     = new AdobeConnectProxy(acProvider, Logger, acUri);
            var loginResult = acProxy.Login(new UserCredentials(defaultAcDomain.Username, defaultAcDomain.Password));

            if (!loginResult.Success)
            {
                return(null);
            }

            var eventRegistrationDetails = acProxy.GetEventRegistrationDetails(eventQuizMapping.acEventScoId);

            string[] requiredFieldNames = new string[3] {
                "School", "State", "Trainee number or ID"
            };
            StringBuilder errorMessage = new StringBuilder();

            foreach (var fieldName in requiredFieldNames)
            {
                if (!eventRegistrationDetails.EventFields.Any(ef =>
                                                              string.Equals(ef.Description, fieldName, StringComparison.OrdinalIgnoreCase)))
                {
                    errorMessage.Append($"{fieldName} field is missed.{Environment.NewLine}");
                }
            }

            var eventInfo = acProxy.GetEventInfo(eventQuizMapping.acEventScoId);

            if (string.IsNullOrEmpty(eventInfo.EventInfo.Info))
            {
                errorMessage.Append(
                    $"Event info should be set for the event with sco-id {eventQuizMapping.acEventScoId}.{Environment.NewLine}");
            }

            if (string.IsNullOrEmpty(eventInfo.EventInfo.SpeakerName))
            {
                errorMessage.Append(
                    $"Speaker name should be set for the event with sco-id {eventQuizMapping.acEventScoId}.{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(errorMessage.ToString()))
            {
                errorMessage.Append(
                    $"Please fix the event details in Adobe Connect and try again.{Environment.NewLine}");
            }

            return(string.IsNullOrEmpty(errorMessage.ToString())
                ? OperationResultDto.Success()
                : OperationResultDto.Error(errorMessage.ToString()));
        }
Exemplo n.º 3
0
        public void TestNewEventFieldsInScoInfo()
        {
            var acApiUrl   = new Uri("https://connect.esynctraining.com");
            var con        = new ConnectionDetails(acApiUrl);
            var acProvider = new AdobeConnectProvider(con);
            var proxy      = new AdobeConnectProxy(acProvider, new FakeLogger(), acApiUrl);

            proxy.Login(new UserCredentials("*****@*****.**", "Nastya123"));
            var eventInfo = proxy.GetScoInfo("2957329");

            Assert.Equals(eventInfo.ScoInfo.EventTemplateScoId, 56489);
        }
Exemplo n.º 4
0
        public OperationResultDto SendRegistrationEmail(EventRegistrationDTO registrationInfo)
        {
            var mapping = CompanyEventQuizMappingModel.GetOneById(registrationInfo.eventQuizMappingId).Value;

            if (mapping == null)
            {
                return(OperationResultDto.Error("There is no event for this info."));
            }

            var acDomain = CompanyAcServerModel.GetOneById(mapping.CompanyAcDomain.Id).Value;
            var apiUrl   = new Uri(acDomain.AcServer);
            var proxy    = new AdobeConnectProxy(new AdobeConnectProvider(new ConnectionDetails(apiUrl)), Logger, apiUrl);

            var loginResult = proxy.Login(new UserCredentials(acDomain.Username, acDomain.Password));

            if (!loginResult.Success)
            {
                throw new InvalidOperationException($"Can't login to AC url {acDomain.AcServer} user {acDomain.Username}");
            }

            var eventInfo = proxy.GetScoInfo(mapping.AcEventScoId);

            if (!eventInfo.Success)
            {
                throw new InvalidOperationException(eventInfo.Status.GetErrorInfo());
            }

            List <string> emailsNotSend = new List <string>();

            try
            {
                //todo: create model based on success/fail
                var model = new EventQuizRegistrationModel(Settings)
                {
                    FirstName      = registrationInfo.FirstName,
                    LastName       = registrationInfo.LastName,
                    EventName      = eventInfo.ScoInfo.Name,
                    EventDesc      = eventInfo.ScoInfo.Description,
                    EventScoId     = eventInfo.ScoInfo.ScoId,
                    EventStartDate = DateTimeHelper.ConvertToEST(eventInfo.ScoInfo.BeginDate).Value,
                    EventEndDate   = DateTimeHelper.ConvertToEST(eventInfo.ScoInfo.EndDate).Value,
                    MailSubject    = Emails.RegistrationSubject,
                    MeetingUrl     = acDomain.AcServer.TrimEnd('/') + "/" + eventInfo.ScoInfo.SourceSco.UrlPath.TrimStart('/'),
                    Email          = registrationInfo.Email
                };

                var attachments = new List <System.Net.Mail.Attachment>();

                var e = new Event
                {
                    //DtStart = new CalDateTime(DateTimeHelper.ConvertToEST(model.EventStartDate).Value),
                    //DtEnd = new CalDateTime(DateTimeHelper.ConvertToEST(model.EventEndDate).Value),
                    DtStart     = new CalDateTime(eventInfo.ScoInfo.BeginDate),
                    DtEnd       = new CalDateTime(eventInfo.ScoInfo.EndDate),
                    Summary     = $"{model.EventName}",
                    Description = model.MeetingUrl,
                    Url         = new Uri(model.MeetingUrl)
                };

                var calendar = new Calendar();
                calendar.Events.Add(e);

                var serializer         = new CalendarSerializer(new SerializationContext());
                var serializedCalendar = serializer.SerializeToString(calendar);
                Logger.Debug(serializedCalendar);

                //var ms = new MemoryStream();
                //using (var writer = new StreamWriter(ms))
                //{
                //    writer.Write(serializedCalendar);
                //    writer.Flush();
                //}
                //ms.Position = 0;
                byte[] bytes = new byte[serializedCalendar.Length * sizeof(char)];
                Buffer.BlockCopy(serializedCalendar.ToCharArray(), 0, bytes, 0, bytes.Length);

                var contype = new System.Net.Mime.ContentType("text/calendar");
                contype.Parameters.Add("method", "REQUEST");
                contype.Parameters.Add("name", "EventInformation.ics");
                var calendarItem = new System.Net.Mail.Attachment(new MemoryStream(bytes), contype);
                calendarItem.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                attachments.Add(calendarItem);

                var sentSuccessfully = MailModel.SendEmailSync($"{model.FirstName} {model.LastName}", model.Email,
                                                               Emails.RegistrationSubject,
                                                               model, Common.AppEmailName, Common.AppEmail, attachments: attachments);
                if (!sentSuccessfully)
                {
                    emailsNotSend.Add(model.Email);
                }
            }
            catch (Exception e)
            {
                Logger.Error($"[SendRegistrationEmail] error.", e);
                emailsNotSend.Add(registrationInfo.Email);
            }


            return(emailsNotSend.Any() ? OperationResultDto.Error("Not all emails were sent correctly") : OperationResultDto.Success());
        }