public ActionResult Show()
        {
            var model = new FiddleExecuteModel()
            {
                CodeBlock = ViewBag.text
            };

            return(View(model));
        }
        public ActionResult ShowEditorArea(string Code)
        {
            var model = new FiddleExecuteModel()
            {
                CodeBlock = Code
                            //ProjectType= ProjectType.Console
            };

            return(View(model));
        }
        private static string ExecuteFiddle(FiddleExecuteModel model)
        {
            var client = new RestClient(ApiUrl);

            // execute request through API
            var request = new RestRequest("execute", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(model);

            IRestResponse <FiddleExecuteResult> response = client.Execute <FiddleExecuteResult>(request);

            StringBuilder result = new StringBuilder();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                result.AppendLine("Failed to execute API request. Here is an answer from API");
                result.AppendLine("Response Code: " + response.StatusCode);
                result.AppendLine("Response Body: " + response.Content);
            }
            else
            {
                // write usage statistics
                foreach (var header in response.Headers)
                {
                    if (header.Name == "X-RateLimit-Limit")
                    {
                        result.AppendLine("Your total per hour limit is " + header.Value);
                    }

                    if (header.Name == "X-RateLimit-Remaining")
                    {
                        result.AppendLine("Your remaining executions count per hour is " + header.Value);
                    }

                    if (header.Name == "X-RateLimit-Reset")
                    {
                        var epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                        epochTime = epochTime.AddSeconds(int.Parse(header.Value.ToString()));
                        result.AppendLine("UTC Time when limit will be refreshed " + epochTime);
                    }
                }

                result.AppendLine();
                result.AppendLine("Code output:");
                result.AppendLine(response.Data.ConsoleOutput);
            }

            return(result.Replace(Environment.NewLine, "<br/>").ToString());
        }
Exemplo n.º 4
0
        public ActionResult Index(int?id)
        {
            Session["curstate"] = 5;
            var user     = User.Identity.GetUserId();
            var upcoming = db.PracticeAndUserMarks

                           .Include(c => c.Artist)
                           .Include(c => c.Practice)
                           .Where(c => c.ArtistId == user)
                           .Where(c => c.PracticePracticeId == id);


            if (upcoming.Count() == 0)
            {
                var model1 = new PracticeAndUserMark
                {
                    ArtistId           = User.Identity.GetUserId(),
                    Mark               = 0,
                    PracticePracticeId = id.Value
                };
                if (ModelState.IsValid)
                {
                    db.PracticeAndUserMarks.Add(model1);
                    db.SaveChanges();
                }
            }
            var Iddd = upcoming.Single(c => c.PracticePracticeId == id.Value);

            Session["Id"] = Iddd.Id;
            var up = upcoming.Single();

            Session["mark"]          = up.Mark.ToString();
            Session["res"]           = false;
            Session["CurrentUserId"] = User.Identity.GetUserId();
            // db.PracticeAndUserMarks.Find(Session["CurrentUserId"], Session["CurrentPractId"]);

            string text  = (string)Session["UI"];
            var    model = new FiddleExecuteModel()
            {
                CodeBlock = text
            };

            return(View(model));
        }
        public ActionResult Index()
        {
            if ((int)Session["totalFails"] == 5)
            {
                return(View("ShowResults"));
            }
            var l = new List <int>();

            Session["CurrentUserId"] = User.Identity.GetUserId();
            if ((bool)Session["correct"])
            {
                Session["totalFails"]   = (int)Session["totalFails"] - 1;
                Session["countFails"]   = (int)-1;
                Session["countSuccess"] = (int)Session["countSuccess"] + 1;
                if ((int)Session["countSuccess"] == 1)
                {
                    Session["countSuccess"] = 0;
                    //тут будет выполняться переход на след ур-нь
                    Session["startmark"] = ((int)Session["startmark"]) + 1;
                }
                if ((int)Session["countFails"] == 2)
                {
                    Session["countFails"] = 0;
                    //тут будет выполняться переход на след ур-нь
                    Session["startmark"] = ((int)Session["startmark"]) - 1;
                }


                Session["correct"] = false;
                var strtmark = (int)Session["startmark"];
                var curPr    = db.Practices
                               .Where(c => c.Mark == strtmark);

                if (curPr.Count() == 0)
                {
                    return(View("ShowResults"));
                }
                int count = curPr.Count();
Link:
                int random = new Random().Next(0, count);
                foreach (var item in l)
                {
                    if (random == item)
                    {
                        random = new Random().Next(0, count);
                    }
                }

                l.Add(random);
                var PR = curPr.AsEnumerable().ElementAt(random);   //получаем случайную практику из базы для текущей сложности
                if (PR == (Practice)Session["lastPr"])
                {
                    goto Link;
                }
                Session["lastPr"] = PR;
                if (PR.PracticeUserInput != null)
                {
                    Session["UI"] = PR.PracticeUserInput.ToString();
                }
                if (PR.FirstPart != null)
                {
                    Session["FP"] = PR.FirstPart.ToString();
                }
                if (PR.TestsPart != null)
                {
                    Session["TEST"] = PR.TestsPart.ToString();
                }
                if (PR.SecondPart != null)
                {
                    Session["LP"] = PR.SecondPart.ToString();
                }
                if (PR.PracticeDescription != null)
                {
                    Session["TEXT"] = PR.PracticeDescription.ToString();
                }                                                                                             //записываем все в переменные сессии
                Session["ans1"] = "Ответ: ";
                foreach (var item in db.CorrectAnswers)
                {
                    if (item.PracticePracticeId == PR.PracticeId)
                    {
                        Session["ans1"] += "\n \t" + item.Answer + "\n \t" + "//" + new string('_', 30);
                    }
                }

                return(RedirectToAction("Index", "ExecuteChallenge"));
            }
            if (!(bool)Session["correct"])
            {
                Session["totalFails"] = (int)Session["totalFails"] + 1;
                Session["countFails"] = (int)Session["countFails"] + 1;
                if ((int)Session["countFails"] == 2)
                {
                    Session["countFails"] = -1;
                    //тут будет выполняться переход на след ур-нь

                    Session["startmark"] = ((int)Session["startmark"]) - 1;
                    var strtmark = (int)Session["startmark"];
                    var curPr    = db.Practices
                                   .Where(c => c.Mark == strtmark);

                    if (curPr.Count() == 0)
                    {
                        if ((int)Session["startmark"] < 0)
                        {
                            Session["startmark"] = 0;
                        }
                        return(View("ShowResults"));
                    }
                    int count = curPr.Count();
Link:
                    int random = new Random().Next(0, count);
                    foreach (var item in l)
                    {
                        if (random == item)
                        {
                            random = new Random().Next(0, count);
                        }
                    }

                    l.Add(random);
                    var PR = curPr.AsEnumerable().ElementAt(random);   //получаем случайную практику из базы для текущей сложности
                    if (PR == (Practice)Session["lastPr"])
                    {
                        goto Link;
                    }
                    Session["lastPr"] = PR;
                    if (PR.PracticeUserInput != null)
                    {
                        Session["UI"] = PR.PracticeUserInput.ToString();
                    }
                    if (PR.FirstPart != null)
                    {
                        Session["FP"] = PR.FirstPart.ToString();
                    }
                    if (PR.TestsPart != null)
                    {
                        Session["TEST"] = PR.TestsPart.ToString();
                    }
                    if (PR.SecondPart != null)
                    {
                        Session["LP"] = PR.SecondPart.ToString();
                    }
                    if (PR.PracticeDescription != null)
                    {
                        Session["TEXT"] = PR.PracticeDescription.ToString();
                    }                                                                                             //записываем все в переменные сессии
                    Session["ans1"] = "Ответ: ";
                    foreach (var item in db.CorrectAnswers)
                    {
                        if (item.PracticePracticeId == PR.PracticeId)
                        {
                            Session["ans1"] += "\n \t" + item.Answer + "\n \t" + "//" + new string('_', 30);
                        }
                    }

                    return(RedirectToAction("Index", "ExecuteChallenge"));
                }
                string text = (string)Session["UI"];

                var model = new FiddleExecuteModel()
                {
                    CodeBlock = text
                };

                return(View(model));
            }
            else
            {
                string text = (string)Session["UI"];

                var model = new FiddleExecuteModel()
                {
                    CodeBlock = text
                };
                Session["startmark"] = 0;
                return(View(model));
            }
        }