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(); }
public CommentsController(ULearnDb db) { commentsRepo = new CommentsRepo(db); userManager = new ULearnUserManager(db); notificationsRepo = new NotificationsRepo(db); coursesRepo = new CoursesRepo(db); systemAccessesRepo = new SystemAccessesRepo(db); }
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"]; }
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); }
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}¬ificationType={(int)notificationType}&isEnabled=False×tamp={timestamp}&signature={signature}"; return("<p style=\"color: #999; font-size: 12px;\">" + $"<a href=\"{transportUnsubscribeUrl}\">Нажмите здесь</a>, если вы не хотите получать такие уведомления от курса «{courseTitle}» на почту.<br/>" + $"Если вы вовсе не хотите получать от нас уведомления на почту, выключите их <a href=\"{baseUrl}/Account/Manage\">в профиле</a>." + "</p>"); }
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"] ?? ""; }
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); }
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"] ?? ""; }
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(); } }
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); }
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"; }
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, })); }
public string GetNotificationTransportEnablingSignature(int transportId, long timestamp) { return(NotificationsRepo.GetNotificationTransportEnablingSignature(transportId, timestamp, secretForHashes)); }
public OneTimeEmailSender() { emailSender = new KonturSpamEmailSender(); usersRepo = new UsersRepo(new ULearnDb()); notificationsRepo = new NotificationsRepo(new ULearnDb()); }