Beispiel #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());
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public int DeleteById(int id)
        {
            SubModuleItem moduleItem;
            var           model = this.SubModuleItemModel;

            if ((moduleItem = model.GetOneById(id).Value) == null)
            {
                var error = new Error(
                    Errors.CODE_ERRORTYPE_OBJECT_NOT_FOUND,
                    ErrorsTexts.GetResultError_Subject,
                    ErrorsTexts.GetResultError_NotFound);
                this.LogError("SubModuleItem.DeleteById", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            foreach (var quiz in moduleItem.Quizes)
            {
                var  mappings           = CompanyEventQuizMappingModel.GetAllMappedByQuizId(quiz.Id);
                bool informAboutMapping = false;
                foreach (var mapping in mappings)
                {
                    var acUri         = new Uri(mapping.CompanyAcDomain.AcServer);
                    var acProvider    = new AdobeConnectProvider(new ConnectionDetails(acUri));
                    var acProxy       = new AdobeConnectProxy(acProvider, Logger, acUri);
                    var scoInfoResult = acProxy.GetScoInfo(mapping.AcEventScoId);
                    if (scoInfoResult.Status.Code == StatusCodes.no_data)
                    {
                        CompanyEventQuizMappingModel.RegisterDelete(mapping);
                    }
                    else
                    {
                        informAboutMapping = true;
                    }
                }

                if (informAboutMapping)
                {
                    var msg   = "This item cannot be removed as it's mapped with an Event. Please delete the Mapping first.";
                    var error = new Error(
                        Errors.CODE_ERRORTYPE_USER_MESSAGE,
                        msg,
                        msg);
                    throw new FaultException <Error>(error, error.errorMessage);
                }
            }

            model.RegisterDelete(moduleItem, true);
            return(id);
        }
Beispiel #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());
        }