Пример #1
0
        public async Task MainLoop()
        {
            StaticMetricsPipeProvider.Instance.Start();

            Stopped = false;
            while (!Stopped)
            {
                db = new ULearnDb();
                notificationsRepo = new NotificationsRepo(db);

                try
                {
                    await CreateDeliveries().ConfigureAwait(false);
                    await SendDeliveries().ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    log.Error("Can\'t create deliveries or send them", e);
                    log.Info("Waiting one second and repeat");
                }

                keepAliver.Ping(keepAliveInterval);
                await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
            }

            StaticMetricsPipeProvider.Instance.Stop();
        }
Пример #2
0
 public CommentsController(ULearnDb db)
 {
     commentsRepo       = new CommentsRepo(db);
     userManager        = new ULearnUserManager(db);
     notificationsRepo  = new NotificationsRepo(db);
     coursesRepo        = new CoursesRepo(db);
     systemAccessesRepo = new SystemAccessesRepo(db);
 }
Пример #3
0
 public StepikController(CourseManager courseManager, StepikRepo stepikRepo, NotificationsRepo notificationsRepo, UsersRepo usersRepo)
 {
     this.stepikRepo        = stepikRepo;
     this.notificationsRepo = notificationsRepo;
     this.usersRepo         = usersRepo;
     this.courseManager     = courseManager;
     stepikClientId         = WebConfigurationManager.AppSettings["stepik.clientId"];
     stepikClientSecret     = WebConfigurationManager.AppSettings["stepik.clientSecret"];
     defaultXQueueName      = WebConfigurationManager.AppSettings["stepik.defaultXQueueName"];
 }
Пример #4
0
        public QuizController()
        {
            metricSender = new GraphiteMetricSender("web");

            userQuizzesRepo    = new UserQuizzesRepo(db);
            visitsRepo         = new VisitsRepo(db);
            groupsRepo         = new GroupsRepo(db, courseManager);
            slideCheckingsRepo = new SlideCheckingsRepo(db);
            notificationsRepo  = new NotificationsRepo(db);
        }
Пример #5
0
        private string GetEmailHtmlSignature(int transportId, NotificationType notificationType, string courseId, string courseTitle)
        {
            var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            var signature = NotificationsRepo.GetNotificationTransportEnablingSignature(transportId, timestamp, secretForHashes);
            var transportUnsubscribeUrl = $"{baseUrl}/Notifications/SaveSettings?courseId={courseId}&transportId={transportId}&notificationType={(int)notificationType}&isEnabled=False&timestamp={timestamp}&signature={signature}";

            return("<p style=\"color: #999; font-size: 12px;\">" +
                   $"<a href=\"{transportUnsubscribeUrl}\">Нажмите здесь</a>, если вы не хотите получать такие уведомления от курса «{courseTitle}» на почту.<br/>" +
                   $"Если вы вовсе не хотите получать от нас уведомления на почту, выключите их <a href=\"{baseUrl}/Account/Manage\">в профиле</a>." +
                   "</p>");
        }
Пример #6
0
        public NotificationsController(ULearnDb db, CourseManager courseManager)
        {
            notificationsRepo = new NotificationsRepo(db);
            usersRepo         = new UsersRepo(db);
            visitsRepo        = new VisitsRepo(db);
            userManager       = new ULearnUserManager(db);

            this.courseManager = courseManager;
            telegramBotName    = WebConfigurationManager.AppSettings["ulearn.telegram.botName"];
            secretForHashes    = WebConfigurationManager.AppSettings["ulearn.secretForHashes"] ?? "";
        }
Пример #7
0
        public QuizController()
        {
            metricSender = new MetricSender(ApplicationConfiguration.Read <UlearnConfiguration>().GraphiteServiceName);

            userQuizzesRepo    = new UserQuizzesRepo(db);
            visitsRepo         = new VisitsRepo(db);
            groupsRepo         = new GroupsRepo(db, courseManager);
            slideCheckingsRepo = new SlideCheckingsRepo(db);
            notificationsRepo  = new NotificationsRepo(db);
            unitsRepo          = new UnitsRepo(db);
        }
Пример #8
0
        public AccountController()
        {
            userRolesRepo      = new UserRolesRepo(db);
            groupsRepo         = new GroupsRepo(db, courseManager);
            certificatesRepo   = new CertificatesRepo(db);
            visitsRepo         = new VisitsRepo(db);
            notificationsRepo  = new NotificationsRepo(db);
            coursesRepo        = new CoursesRepo(db);
            systemAccessesRepo = new SystemAccessesRepo(db);

            telegramSecret = WebConfigurationManager.AppSettings["ulearn.telegram.webhook.secret"] ?? "";
        }
Пример #9
0
        public NotificationsController(ILogger logger, WebCourseManager courseManager, UlearnDb db, NotificationsRepo notificationsRepo, FeedRepo feedRepo, NotificationDataPreloader notificationDataPreloader)
            : base(logger, courseManager, db)
        {
            this.notificationsRepo         = notificationsRepo ?? throw new ArgumentNullException(nameof(notificationsRepo));
            this.feedRepo                  = feedRepo ?? throw new ArgumentNullException(nameof(feedRepo));
            this.notificationDataPreloader = notificationDataPreloader;

            if (commentsFeedNotificationTransport == null)
            {
                commentsFeedNotificationTransport = feedRepo.GetCommentsFeedNotificationTransport();
            }
        }
Пример #10
0
        public BaseExerciseController(ULearnDb db, CourseManager courseManager, GraphiteMetricSender metricSender)
        {
            this.db            = db;
            this.courseManager = courseManager;
            this.metricSender  = metricSender;

            userSolutionsRepo  = new UserSolutionsRepo(db, courseManager);
            slideCheckingsRepo = new SlideCheckingsRepo(db);
            groupsRepo         = new GroupsRepo(db, courseManager);
            visitsRepo         = new VisitsRepo(db);
            notificationsRepo  = new NotificationsRepo(db);
            usersRepo          = new UsersRepo(db);
            styleErrorsRepo    = new StyleErrorsRepo(db);
        }
Пример #11
0
        public TelegramController()
        {
            var db = new ULearnDb();

            notificationsRepo = new NotificationsRepo(db);

            webhookSecret = WebConfigurationManager.AppSettings["ulearn.telegram.webhook.secret"] ?? "";
            var botToken = WebConfigurationManager.AppSettings["ulearn.telegram.botToken"];

            if (botToken != null)
            {
                telegramBot = new TelegramBotClient(botToken);
            }

            protocol = Convert.ToBoolean(WebConfigurationManager.AppSettings["ulearn.requireHttps"] ?? "true") ? "https" : "http";
        }
Пример #12
0
        public ActionResult Settings()
        {
            var user = userManager.FindByName(User.Identity.Name);

            var mailTransport     = notificationsRepo.FindUsersNotificationTransport <MailNotificationTransport>(user.Id, includeDisabled: true);
            var telegramTransport = notificationsRepo.FindUsersNotificationTransport <TelegramNotificationTransport>(user.Id, includeDisabled: true);

            var courseIds    = visitsRepo.GetUserCourses(user.Id).Where(c => courseManager.FindCourse(c) != null).ToList();
            var courseTitles = courseIds.ToDictionary(c => c, c => courseManager.GetCourse(c).Title);
            var notificationTypesByCourse = courseIds.ToDictionary(c => c, c => notificationsRepo.GetNotificationTypes(User, c));
            var allNotificationTypes      = NotificationsRepo.GetAllNotificationTypes();

            var notificationTransportsSettings = courseIds.SelectMany(
                c => notificationsRepo.GetNotificationTransportsSettings(c, user.Id).Select(
                    kvp => Tuple.Create(Tuple.Create(c, kvp.Key.Item1, kvp.Key.Item2), kvp.Value.IsEnabled)
                    )
                ).ToDictionary(kvp => kvp.Item1, kvp => kvp.Item2);

            var selectedTransportIdStr = Request.QueryString["transportId"] ?? "";

            int.TryParse(selectedTransportIdStr, out int selectedTransportId);

            var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            var getEnableLinkSignature = new Func <int, string>(transportId => GetNotificationTransportEnablingSignature(transportId, timestamp));

            return(PartialView(new NotificationSettingsViewModel
            {
                User = user,
                TelegramBotName = telegramBotName,

                MailTransport = mailTransport,
                TelegramTransport = telegramTransport,
                SelectedTransportId = selectedTransportId,

                CourseTitles = courseTitles,
                AllNotificationTypes = allNotificationTypes,
                NotificationTypesByCourse = notificationTypesByCourse,
                NotificationTransportsSettings = notificationTransportsSettings,

                EnableLinkTimestamp = timestamp,
                GetEnableLinkSignature = getEnableLinkSignature,
            }));
        }
Пример #13
0
 public string GetNotificationTransportEnablingSignature(int transportId, long timestamp)
 {
     return(NotificationsRepo.GetNotificationTransportEnablingSignature(transportId, timestamp, secretForHashes));
 }
Пример #14
0
 public OneTimeEmailSender()
 {
     emailSender       = new KonturSpamEmailSender();
     usersRepo         = new UsersRepo(new ULearnDb());
     notificationsRepo = new NotificationsRepo(new ULearnDb());
 }