Пример #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Submissions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSubmissions(Submission submission)
 {
     base.AddObject("Submissions", submission);
 }
Пример #2
0
 /// <summary>
 /// Create a new Submission object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="problemId">Initial value of the ProblemId property.</param>
 /// <param name="isReady">Initial value of the IsReady property.</param>
 public static Submission CreateSubmission(global::System.Int32 id, global::System.Int32 userId, global::System.Int32 problemId, global::System.Boolean isReady)
 {
     Submission submission = new Submission();
     submission.ID = id;
     submission.UserId = userId;
     submission.ProblemId = problemId;
     submission.IsReady = isReady;
     return submission;
 }
Пример #3
0
        internal static bool SubmitSimpleQuestion(string username, int problemId, int answer)
        {
            using (TopCoderPrototypeEntities entityModel = new TopCoderPrototypeEntities())
            {
                CompetitionsUser cuser = entityModel.CompetitionsUsers.
                    Where(x => x.User.Username == username && x.Competition.CompetetionsProblems.Any(y => y.ProblemId == problemId)).FirstOrDefault();
                if(cuser == null || !cuser.Start.HasValue || cuser.Start.Value.AddMinutes(cuser.Competition.Duration) < DateTime.Now)
                {
                    return false;
                }

                SimpleProblemAnswer ans = new SimpleProblemAnswer();
                ans.Answer = answer;

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, ans);

                Submission submission = new Submission();
                submission.UserId = cuser.UserId;
                submission.ProblemId = problemId;
                submission.Submitted = DateTime.Now;
                submission.Answer = ms.ToArray();

                entityModel.Submissions.Where(x => x.UserId == cuser.UserId && x.ProblemId == problemId).ToList()
                    .ForEach(entityModel.Submissions.DeleteObject);
                entityModel.AddToSubmissions(submission);
                entityModel.SaveChanges();
            }

            return true;
        }
Пример #4
0
 private static IProblemAnswer GetAnswer(Submission submission)
 {
     MemoryStream stream = new MemoryStream(submission.Answer);
     BinaryFormatter formatter = new BinaryFormatter();
     IProblemAnswer answer = (IProblemAnswer)formatter.Deserialize(stream);
     return answer;
 }
Пример #5
0
        internal static bool SubmitComplexQuestion(string username, int problemId, string answer)
        {
            using (TopCoderPrototypeEntities entityModel = new TopCoderPrototypeEntities())
            {
                CompetitionsUser cuser = entityModel.CompetitionsUsers.
                    Where(x => x.User.Username == username && x.Competition.CompetetionsProblems.Any(y => y.ProblemId == problemId)).FirstOrDefault();
                if (cuser == null || !cuser.Start.HasValue || cuser.Start.Value.AddMinutes(cuser.Competition.Duration) < DateTime.Now)
                {
                    return false;
                }

                string[] tokens = answer.Split(',');
                List<int> ints = new List<int>();

                foreach (string token in tokens)
                {
                    int res = -1;
                    if (int.TryParse(token, out res))
                    {
                        ints.Add(res);
                    }
                }

                ComplexProblemAnswer ans = new ComplexProblemAnswer();
                ans.Answers = ints.ToArray();

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, ans);

                Submission submission = new Submission();
                submission.UserId = cuser.UserId;
                submission.ProblemId = problemId;
                submission.Submitted = DateTime.Now;
                submission.Answer = ms.ToArray();

                entityModel.Submissions.Where(x => x.UserId == cuser.UserId && x.ProblemId == problemId).ToList()
                    .ForEach(entityModel.Submissions.DeleteObject);
                entityModel.AddToSubmissions(submission);
                entityModel.SaveChanges();
            }

            return true;
        }