public override int GetHashCode() { unchecked { return((TaskTopic.GetHashCode() * 397) ^ (int)TaskState); } }
public ExamTopicViewModel(TaskTopic sourseTopic, int solvedCount) { id = sourseTopic.Id; title = sourseTopic.Name; code = sourseTopic.Code; type = sourseTopic.IsShort ? 0 : 1; max_points = sourseTopic.PointsPerTask; solved = solvedCount; all = sourseTopic.ExamTasks.Count; }
public static string GetSQLInstance(TaskTopic topic) { try { return(SQLCmds[(int)topic]); } catch (Exception) { return(string.Empty); } }
public static string GetSQLInstance(TaskTopic topic) { try { return SQLCmds[(int)topic]; } catch (Exception) { return string.Empty; } }
public async Task AddNewTasks(ExamAppDbContext examAppDbContext) { var exam = examAppDbContext.Exams.OfType <EgeExam>().FirstOrDefault(); var existingTopics = examAppDbContext.TaskTopics.ToList(); var existingTasks = examAppDbContext.Tasks.ToList(); var createdTasksTopics = new List <TaskTopic>(); var createdTasks = new List <ExamTask>(); var config = Configuration.Default.WithDefaultLoader(); const int numberOfVariants = 20; for (int i = 1; i <= numberOfVariants; i++) { var address = "http://kpolyakov.spb.ru/school/ege/gen.php?B=on&C=on&action=viewVar&varId=" + i; var document = await BrowsingContext.New(config).OpenAsync(address).ConfigureAwait(false); var cellSelector = "td.topicview script"; var cells = document.QuerySelectorAll(cellSelector); const string numberPrefix = "№ "; const string textPrexfix = "changeImageFilePath('"; foreach (var cell in cells) { var result = cell.TextContent; var firstOrDefault = cell.ParentElement.ParentElement.QuerySelectorAll("td.egeno span").FirstOrDefault(); if (firstOrDefault != null) { int orderNum = int.Parse(firstOrDefault.TextContent); int numStartPoint = result.IndexOf(numberPrefix) + numberPrefix.Length; int textStartPoint = result.IndexOf(textPrexfix) + textPrexfix.Length; if (existingTopics.All(x => x.Number != orderNum)) { var newTopic = new TaskTopic() { Exam = exam, Name = "DefaultName" + orderNum, Number = orderNum, PointsPerTask = 0 }; createdTasksTopics.Add(newTopic); existingTopics.Add(newTopic); } var topic = existingTopics.FirstOrDefault(x => x.Number == orderNum); var number = int.Parse(result.Substring(numStartPoint, result.IndexOf(")") - numStartPoint)); if (!existingTasks.Any(x => x.Number == number)) { var newTask = new ExamTask() { TaskTopic = topic, Number = number, Text = result.Substring(textStartPoint, result.LastIndexOf("\') );") - textStartPoint), Answer = document .QuerySelectorAll("table.varanswer tr td.egeno") .Where( x => int.Parse(x.TextContent.Substring(0, x.TextContent.Length - 1)) == orderNum) .Next("td.answer") .FirstOrDefault()?.TextContent }; createdTasks.Add(newTask); existingTasks.Add(newTask); } } } } examAppDbContext.TaskTopics.AddRange(createdTasksTopics); examAppDbContext.Tasks.AddRange(createdTasks); CreateEgeTasksTopics(examAppDbContext, existingTopics); examAppDbContext.SaveChanges(); }