Exemple #1
0
        private static void ImageFix()
        {
            var tests = new SpecialistTestDataContext().Tests.ToList();

            foreach (var test in tests)
            {
                var query = new SharpQuery("<div>" + test.Description + "</div>");
                var imgs  = query.Find("img");
                if (imgs.Length == 0)
                {
                    continue;
                }

                var scr = imgs.Attr("src");
                var url = scr;
                if (!url.Contains("http"))
                {
                    url = "http://test.specialist.ru" + url;
                }
                var ext   = Path.GetExtension(scr);
                var image = GetImage(url);
                if (image != null)
                {
                    image.Save(test.Id + ext);
                }
            }
        }
Exemple #2
0
        public void Run()
        {
            var testId = 482;

            var contest = new SpecialistTestDataContext();

            var test = contest.Tests.FirstOrDefault(x => x.Id == testId);

            Images(test);

            Directory.CreateDirectory(testId.ToString());
            var xml = X("Test", A("name", test.Name), X("Questions", test.TestQuestions.Select(Question)))
                      .ToString();

            File.WriteAllText(testId + "/test.xml", xml);
        }
Exemple #3
0
        public void Start()
        {
            var contest = new SpecialistTestDataContext();
            var qIds    = contest.TestQuestions.Where(x => x.TestId == TestId)
                          .Select(x => x.Id).ToList();
            var answers = contest.GetTable <CloneAnswer>()
                          .Where(x => qIds.Contains(x.QuestionId)).ToList();
            var dir = TestId.ToString();

            if (Directory.Exists(dir))
            {
                Directory.Delete(dir);
            }
            Directory.CreateDirectory(dir);
            answers.AsParallel().ForAll(answer => {
                var url = "http://cdn.specialist.ru/Content/File/Test/Answer/{0}.jpg"
                          .FormatWith(answer.SourceId);
                var image = Program.GetImage(url);
                if (image != null)
                {
                    image.Save(TestId + "/" + answer.Id + ".jpg");
                }
            });
        }