private ActionResult CreateJsonResult(DiagramResult result, string id) { return(new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { source = result.Arguments.Source, errors = result.Errors.Select(error => new { message = error.Message, token = new { line = error.TokenLine, start = error.TokenStart, end = error.TokenStart + error.TokenLength, value = error.TokenValue, } }), diagram = Url.Action("get", "api", new { Id = id }, "http"), diagramWidth = result.Image.Width, diagramHeight = result.Image.Height, } }); }
public DiagramResult Compare(Difficulty difficulty) { var result = new DiagramResult(_received.Pattern); foreach (var property in _received.GetType().GetProperties()) { if (property.Name == "Pattern") { continue; } if (difficulty == Difficulty.Medium) { if (property.Name == "SubjectMethods" || property.Name == "SubjectProperties" || property.Name == "MethodParameters") { continue; } } var type = property.PropertyType.GetGenericArguments()[0]; var methodInfo = typeof(DiagramWorker).GetRuntimeMethods() .Where(x => x.Name == "CompareList").Single(); var genericMethod = methodInfo.MakeGenericMethod(type); genericMethod.Invoke(this, new object[] { property.GetValue(_correct), property.GetValue(_received), result }); } result.Finish(difficulty); return(result); }
private ActionResult CreateResult(DiagramResult result, string id) { if (Request.AcceptTypes != null && Request.AcceptTypes.Any(acceptType => acceptType.Contains("json"))) { return(CreateJsonResult(result, id)); } return(CreateImageResult(id)); }
protected override async Task <DiagramResult> GenerateDiagrams() { foreach (Project project in solution.Projects) { await ProcessCompilation(await project.GetCompilationAsync(), project.AssemblyName); } DiagramResult result = new DiagramResult(); foreach (MethodDeclarationSyntax root in methodDeclarations.Keys.Where(key => key != null && !methodDeclarations.Values.Any(value => value.Contains(key)))) { result[root] = GenerateMethod(root); } return(result); }
private void SaveImage(DiagramResult result, string imageId) { using (var imageStream = new MemoryStream()) { result.Image.Save(imageStream, ImageFormat.Png); HttpContext.Cache.Add( imageId, imageStream.GetBuffer(), null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5), CacheItemPriority.Default, null); } }
// POST api/Diagram public DiagramResult Post([FromBody] DiagramView diagramView) { if (!ModelState.IsValid) { return(new DiagramResult("Model state isn't valid")); } DiagramResult result = null; var diagram = diagramView.Diagram; try { var worker = new DiagramWorker(diagram); result = worker.Compare(diagramView.Difficulty); var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(_cx)); var user = userManager.Users.Where(x => x.UserName == User.Identity.Name).Single(); var mark = new Mark() { difficulty = diagramView.Difficulty, mark = result.Mark, percent = result.Percentage, pattern = _cx.Patterns.Find(result.Pattern.Id), User = user }; _cx.Marks.Add(mark); _cx.SaveChanges(); } catch (Exception e) { return(new DiagramResult("Bad Request. Exception: " + e.Message)); } return(result); }
private void ProcessName(DiagramResult diagramResult) { m_LastTitle = diagramResult.Name; }
private void ProcessResult(DiagramResult diagramResult) { ProcessName(diagramResult); ProcessResultImage(diagramResult.Image); ProcessResultErrors(diagramResult.Errors); }
private void CompareList <T>(IEnumerable <T> correct, IEnumerable <T> received, DiagramResult result) where T : IViewBase, IDiagramElement { double percentage = 100.0 / correct.Count(); var listComparationSuccess = new List <T>(); foreach (var item in correct) { if (CompareElement <T>(received, item, out T founded)) { result.AddComparationSuccess <T>(percentage); listComparationSuccess.Add(founded); } else { result.AddError <T>(item.ToString() + " - Not found in diagram"); } } var listFails = received.ToList(); foreach (var item in listComparationSuccess) { listFails.Remove(item); } var ids = correct.Select(x => (int)x.GetId()).ToList(); foreach (var item in listFails) { if (!ids.Contains((int)item.GetId())) { result.AddExtraErrorPercentage <T>(percentage); result.AddError <T>(item.ToString() + " - extra in diagram"); } } //---------doublicates------------- if (typeof(T) == typeof(SubjectReferenceView)) { return; } ids = received.Select(x => (int)x.GetId()).ToList(); foreach (var item in received) { int count = ids.Where(x => x == (int)item.GetId()).Count(); if (count > 1) { result.AddExtraErrorPercentage <T>(percentage * (count - 1)); result.AddError <T>("There is dublicates of element - " + item.ToString()); ids.RemoveAll(x => x == (int)item.GetId()); } } }