protected BaseUserController(ULearnDb db) { this.db = db; userManager = new ULearnUserManager(db); usersRepo = new UsersRepo(db); metricSender = new MetricSender(ApplicationConfiguration.Read <UlearnConfiguration>().GraphiteServiceName); secretForHashes = WebConfigurationManager.AppSettings["ulearn.secretForHashes"] ?? ""; var spamEndpoint = WebConfigurationManager.AppSettings["ulearn.spam.endpoint"] ?? ""; var spamLogin = WebConfigurationManager.AppSettings["ulearn.spam.login"] ?? "ulearn"; var spamPassword = WebConfigurationManager.AppSettings["ulearn.spam.password"] ?? ""; spamChannelId = WebConfigurationManager.AppSettings["ulearn.spam.channels.emailConfirmations"] ?? ""; spamTemplateId = WebConfigurationManager.AppSettings["ulearn.spam.templates.withButton"] ?? ""; try { spamClient = new SpamClient(new Uri(spamEndpoint), spamLogin, spamPassword); } catch (Exception e) { log.Error($"Can\'t initialize Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}", e); throw; } }
public KonturSpamEmailSender(MetricSender metricSender, IOptions <NotificationsConfiguration> options) { this.metricSender = metricSender; var config = options.Value; var spamEndpoint = config.Spam.Endpoint ?? ""; var spamLogin = config.Spam.Login ?? "ulearn"; var spamPassword = config.Spam.Password ?? ""; channelId = config.Spam.Channels.Notifications ?? ""; templateId = config.Spam.Templates.WithButton; try { client = new SpamClient(new Uri(spamEndpoint), spamLogin, spamPassword); } catch (Exception e) { log.Error(e, $"Can\'t initialize Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}"); throw; } log.Info($"Initialized Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}"); log.Info($"Using channel '{channelId}'"); }
public StyleErrorsResultObserver(IWebCourseManager courseManager, MetricSender metricSender, IUsersRepo usersRepo, ISlideCheckingsRepo slideCheckingsRepo) { this.courseManager = courseManager; this.metricSender = metricSender; this.slideCheckingsRepo = slideCheckingsRepo; this.usersRepo = usersRepo; }
public NotificationSender(CourseManager courseManager, IEmailSender emailSender, ITelegramSender telegramSender, MetricSender metricSender) { this.emailSender = emailSender; this.telegramSender = telegramSender; this.courseManager = courseManager; this.metricSender = metricSender; baseUrl = ConfigurationManager.AppSettings["ulearn.baseUrl"] ?? ""; secretForHashes = ConfigurationManager.AppSettings["ulearn.secretForHashes"] ?? ""; }
public NotificationSender(IWebCourseManager courseManager, IEmailSender emailSender, ITelegramSender telegramSender, MetricSender metricSender, IOptions <NotificationsConfiguration> options) { this.emailSender = emailSender; this.telegramSender = telegramSender; this.courseManager = courseManager; this.metricSender = metricSender; baseUrl = options.Value.BaseUrl ?? ""; secretForHashes = options.Value.SecretForHashes ?? ""; }
public RunnerController(ULearnDb db, CourseManager courseManager) { this.db = db; this.courseManager = courseManager; userSolutionsRepo = new UserSolutionsRepo(db, courseManager); slideCheckingsRepo = new SlideCheckingsRepo(db); visitsRepo = new VisitsRepo(db); groupsRepo = new GroupsRepo(db, courseManager); usersRepo = new UsersRepo(db); metricSender = new MetricSender(ApplicationConfiguration.Read <UlearnConfiguration>().GraphiteServiceName); }
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 BaseExerciseController(ULearnDb db, CourseManager courseManager, MetricSender 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); unitsRepo = new UnitsRepo(db); }
public ExerciseController(IWebCourseManager courseManager, UlearnDb db, MetricSender metricSender, IUsersRepo usersRepo, IUserSolutionsRepo userSolutionsRepo, ICourseRolesRepo courseRolesRepo, IVisitsRepo visitsRepo, ILtiConsumersRepo ltiConsumersRepo, ILtiRequestsRepo ltiRequestsRepo, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, IStyleErrorsRepo styleErrorsRepo) : base(courseManager, db, usersRepo) { this.metricSender = metricSender; this.userSolutionsRepo = userSolutionsRepo; this.courseRolesRepo = courseRolesRepo; this.visitsRepo = visitsRepo; this.ltiConsumersRepo = ltiConsumersRepo; this.ltiRequestsRepo = ltiRequestsRepo; this.slideCheckingsRepo = slideCheckingsRepo; this.groupsRepo = groupsRepo; this.styleErrorsRepo = styleErrorsRepo; }
public ExerciseController(IWebCourseManager courseManager, UlearnDb db, MetricSender metricSender, IUsersRepo usersRepo, IUserSolutionsRepo userSolutionsRepo, ICourseRolesRepo courseRolesRepo, IVisitsRepo visitsRepo, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, StyleErrorsResultObserver styleErrorsResultObserver, IStyleErrorsRepo styleErrorsRepo, IServiceScopeFactory serviceScopeFactory) : base(courseManager, db, usersRepo) { this.metricSender = metricSender; this.userSolutionsRepo = userSolutionsRepo; this.courseRolesRepo = courseRolesRepo; this.visitsRepo = visitsRepo; this.slideCheckingsRepo = slideCheckingsRepo; this.groupsRepo = groupsRepo; this.styleErrorsRepo = styleErrorsRepo; this.styleErrorsResultObserver = styleErrorsResultObserver; this.serviceScopeFactory = serviceScopeFactory; }
public static void PreStart() { var connectionString = ApplicationConfiguration.Read <UlearnConfiguration>().StatsdConnectionString; var isGraphiteSendingEnabled = !string.IsNullOrEmpty(connectionString); if (!isGraphiteSendingEnabled) { return; } // Make sure MetricsPipe handles BeginRequest and EndRequest DynamicModuleUtility.RegisterModule(typeof(MetricsPipeStartupModule)); MetricsPipeStartupModule.Settings.ReportRequestTime = true; // The prefix is added in GraphiteConfiguration with ConfigurationManager.GetSection("graphite"). If you specify here, there will be duplication MetricsPipeStartupModule.Settings.RequestTimePrefix = MetricSender.BuildKey(null, "web", "request.time"); }
public TelegramSender(MetricSender metricSender, IOptions <NotificationsConfiguration> options) { this.metricSender = metricSender; var botToken = options.Value.Telegram.BotToken; try { bot = new TelegramBotClient(botToken); } catch (Exception e) { log.Error(e, $"Can\'t initialize telegram bot with token \"{botToken.MaskAsSecret()}\""); throw; } log.Info($"Initialized telegram bot with token \"{botToken.MaskAsSecret()}\""); }
public TelegramSender() { var configuration = ApplicationConfiguration.Read <UlearnConfiguration>(); var botToken = configuration.Telegram.BotToken; try { bot = new TelegramBotClient(botToken); } catch (Exception e) { log.Error($"Can\'t initialize telegram bot with token \"{botToken.MaskAsSecret()}\"", e); throw; } log.Info($"Initialized telegram bot with token \"{botToken.MaskAsSecret()}\""); metricSender = new MetricSender(configuration.GraphiteServiceName); }
public RunnerController(IWebCourseManager courseManager, UlearnDb db, IOptions <WebApiConfiguration> options, IUsersRepo usersRepo, IUserSolutionsRepo userSolutionsRepo, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, IVisitsRepo visitsRepo, MetricSender metricSender, XQueueResultObserver xQueueResultObserver, SandboxErrorsResultObserver sandboxErrorsResultObserver, AntiPlagiarismResultObserver antiPlagiarismResultObserver, StyleErrorsResultObserver styleErrorsResultObserver) : base(courseManager, db, usersRepo) { configuration = options.Value; resultObservers = new List <IResultObserver> { xQueueResultObserver, sandboxErrorsResultObserver, antiPlagiarismResultObserver, styleErrorsResultObserver, }; this.userSolutionsRepo = userSolutionsRepo; this.slideCheckingsRepo = slideCheckingsRepo; this.groupsRepo = groupsRepo; this.visitsRepo = visitsRepo; this.metricSender = metricSender; }
public RestorePasswordController(ULearnDb db) { this.db = db; userManager = new ULearnUserManager(db); requestRepo = new RestoreRequestRepo(db); metricSender = new MetricSender(ApplicationConfiguration.Read <UlearnConfiguration>().GraphiteServiceName); var spamEndpoint = WebConfigurationManager.AppSettings["ulearn.spam.endpoint"] ?? ""; var spamLogin = WebConfigurationManager.AppSettings["ulearn.spam.login"] ?? "ulearn"; var spamPassword = WebConfigurationManager.AppSettings["ulearn.spam.password"] ?? ""; spamChannelId = WebConfigurationManager.AppSettings["ulearn.spam.channels.passwords"] ?? ""; try { spamClient = new SpamClient(new Uri(spamEndpoint), spamLogin, spamPassword); } catch (Exception e) { log.Error(e, $"Can\'t initialize Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}"); throw; } }
public KonturSpamEmailSender() { var spamEndpoint = ConfigurationManager.AppSettings["ulearn.spam.endpoint"] ?? ""; var spamLogin = ConfigurationManager.AppSettings["ulearn.spam.login"] ?? "ulearn"; var spamPassword = ConfigurationManager.AppSettings["ulearn.spam.password"] ?? ""; channelId = ConfigurationManager.AppSettings["ulearn.spam.channels.notifications"] ?? ""; templateId = ConfigurationManager.AppSettings["ulearn.spam.templates.withButton"]; metricSender = new MetricSender(ApplicationConfiguration.Read <UlearnConfiguration>().GraphiteServiceName); try { client = new SpamClient(new Uri(spamEndpoint), spamLogin, spamPassword); } catch (Exception e) { log.Error($"Can\'t initialize Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}", e); throw; } log.Info($"Initialized Spam.API client to {spamEndpoint}, login {spamLogin}, password {spamPassword.MaskAsSecret()}"); log.Info($"Using channel '{channelId}'"); }
public static async Task <bool> SendToReviewAndUpdateScore(UserExerciseSubmission submission, CourseManager courseManager, SlideCheckingsRepo slideCheckingsRepo, GroupsRepo groupsRepo, VisitsRepo visitsRepo, MetricSender metricSender, bool startTransaction) { var userId = submission.User.Id; var courseId = submission.CourseId; var course = courseManager.GetCourse(courseId); var exerciseSlide = course.FindSlideById(submission.SlideId) as ExerciseSlide; if (exerciseSlide == null) { return(false); } var exerciseMetricId = GetExerciseMetricId(courseId, exerciseSlide); var automaticChecking = submission.AutomaticChecking; var isProhibitedUserToSendForReview = slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseSlide.Scoring.RequireReview && submission.AutomaticCheckingIsRightAnswer && !isProhibitedUserToSendForReview && groupsRepo.IsManualCheckingEnabledForUser(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualCheckings <ManualExerciseChecking>(courseId, exerciseSlide.Id, userId, false); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submission); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, exerciseSlide.Id, userId); metricSender.SendCount($"exercise.{exerciseMetricId}.sent_to_review"); metricSender.SendCount("exercise.sent_to_review"); } await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide.Id, exerciseSlide.MaxScore, userId); if (automaticChecking != null) { var verdictForMetric = automaticChecking.GetVerdict().Replace(" ", ""); metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}"); } return(sendToReview); }
public static async Task <bool> SendToReviewAndUpdateScore(UserExerciseSubmission submissionNoTracking, IWebCourseManager courseManager, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, IVisitsRepo visitsRepo, MetricSender metricSender) { var userId = submissionNoTracking.UserId; var courseId = submissionNoTracking.CourseId; var course = await courseManager.GetCourseAsync(courseId); var exerciseSlide = course.FindSlideById(submissionNoTracking.SlideId, true) as ExerciseSlide; // SlideId проверен в вызывающем методе if (exerciseSlide == null) { return(false); } var exerciseMetricId = GetExerciseMetricId(courseId, exerciseSlide); var automaticCheckingNoTracking = submissionNoTracking.AutomaticChecking; var isProhibitedUserToSendForReview = await slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseSlide.Scoring.RequireReview && submissionNoTracking.AutomaticCheckingIsRightAnswer && !isProhibitedUserToSendForReview && await groupsRepo.IsManualCheckingEnabledForUserAsync(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualCheckings <ManualExerciseChecking>(courseId, exerciseSlide.Id, userId, false); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submissionNoTracking.Id); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, exerciseSlide.Id, userId); metricSender.SendCount($"exercise.{exerciseMetricId}.sent_to_review"); metricSender.SendCount("exercise.sent_to_review"); } await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide, userId); if (automaticCheckingNoTracking != null) { var verdictForMetric = automaticCheckingNoTracking.GetVerdict().Replace(" ", ""); metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}"); } return(sendToReview); }