コード例 #1
0
        public override CodeFile FileChanged(string fullPath, FileSystemEventArgs e)
        {
            var find = Files.FirstOrDefault(c => c.FullPath == fullPath);

            if (find == null)
            {
                find = new CodeFile(fullPath);
                Files.Add(find);
            }

            //WARNING?
            //if ((e.ChangeType & WatcherChangeTypes.Changed) == 0) return find;

            var history = new CodeHistory(find);

            if (find.Changes.Count > 0)
            {
                if (find.Changes.Last().Content == history.Content)
                {
                    return(null);
                }
            }

            find.Exists = true;
            find.Changes.Add(history);

            return(find);
        }
コード例 #2
0
        public IMeasure Measure(CodeHistory history)
        {
            int index = history.Parent.Changes.IndexOf(history);

            if (index == 0) // This is the First version of file
            {
                return(countAsBase(history));
            }
            else
            {
                CodeHistory previous = history.Parent.Changes[index - 1];
                return(countAsModification(history, previous));
            }
        }
コード例 #3
0
        }//index()

        public ActionResult viewCodeFromHistory(int id)
        {
            CodeHistory     codeHistory = _context.CodeHistories.FirstOrDefault(c => c.id == id);
            ApplicationUser user        = getUser();

            if (codeHistory == null || codeHistory.UserId != user.Id)
            {
                return(View("Error"));
            }
            else
            {
                return(View(codeHistory));
            }
        }//viewCodeFromHistory()
コード例 #4
0
        public static SizeFormModel[] ToPSPForm(this List <ComponentBase.FilePoint.CodeFile> files)
        {
            List <SizeFormModel> forms = new List <SizeFormModel>();

            foreach (var codeFile in files)
            {
                CodeHistory[]    newChanges = new CodeHistory[0];
                PSPSizeMeasure[] measures   = new PSPSizeMeasure[0];

                try
                {
                    newChanges = codeFile.Changes.SkipWhile(h => _visitedHistories.Contains(h.Id)).ToArray();
                    measures   = newChanges.Select(h => h.GetMeasurement(typeof(PSPSizeMeasure).FullName)).Cast <PSPSizeMeasure>().ToArray();

                    var measure = consolidateMeasures(measures);

                    if (measure == null || measure.NewAndChanged + measure.Deleted == 0)
                    {
                        continue;
                    }

                    forms.Add(new SizeFormModel(Guid.NewGuid())
                    {
                        Program   = codeFile.Name,
                        CreatedAt = DateTime.Now,
                        Base      = measure.Base,
                        Added     = measure.Added,
                        Modified  = measure.Modified,
                        Deleted   = measure.Deleted,
                        Reused    = measure.Reused,
                        Total     = measure.Total,
                        Solution  = GetProjectName()
                    });
                }
                catch (Exception e)
                {
                    Logger.Instance.Log(e.ToString());
                }

                for (var i = 0; i < newChanges.Length - 1; i++)
                {
                    _visitedHistories.Add(newChanges[i].Id);
                }
            }

            return(forms.ToArray());
        }
コード例 #5
0
        private PSPSizeMeasure countAsBase(CodeHistory current)
        {
            var c = (LOCMeasure)loc.Measure(current);

            PSPSizeMeasure m = new PSPSizeMeasure()
            {
                Base     = c.PhysicalLOC,
                Added    = 0,
                Deleted  = 0,
                Modified = 0,
                NewReuse = 0,
                Reused   = 0,
                Total    = c.PhysicalLOC
            };

            return(m);
        }
コード例 #6
0
        private PSPSizeMeasure countAsModification(CodeHistory current, CodeHistory previous)
        {
            var c1 = (LOCMeasure)loc.Measure(previous);
            var c2 = (LOCMeasure)loc.Measure(current);

            var changes = DiffHelper.SimpleDiff(current.Content, previous.Content);

            PSPSizeMeasure m = new PSPSizeMeasure()
            {
                Base     = c1.PhysicalLOC,
                Added    = changes.Count(t => t == ChangeType.Inserted),
                Deleted  = changes.Count(t => t == ChangeType.Deleted),
                Modified = changes.Count(t => t == ChangeType.Modified),
                Total    = c2.PhysicalLOC
            };

            return(m);
        }
コード例 #7
0
        }//viewCodeFromHistory()

        public ActionResult deleteOneCodeFromHistory(int id)
        {
            CodeHistory     codeHistory = _context.CodeHistories.FirstOrDefault(c => c.id == id);
            ApplicationUser user        = getUser();

            if (codeHistory.UserId != user.Id)
            {
                return(View("Error"));
            }
            else
            {
                _context.CodeHistories.Remove(codeHistory);
                _context.SaveChanges();

                TempData["success"] = "Successfully deleted code from history";

                return(RedirectToAction("Index"));
            }
        }//deleteOneCodeFromHistory()
コード例 #8
0
 public IMeasure Measure(CodeHistory history)
 {
     return(GetLocMeasure(history.Content));
 }
コード例 #9
0
        public ActionResult customFormPost()
        {
            NameValueCollection nvc = Request.Form;

            StringBuilder code = new StringBuilder();

            if (!string.IsNullOrEmpty(nvc["numberOfSelects"]))
            {
                bool bootstrap = false;
                if (Validation.validate(nvc))
                {
                    if (nvc["cb"] != null)
                    {
                        code.Append(generateWithBootstrap(nvc));
                        bootstrap = true;
                    }
                    else
                    {
                        //generate code without bootstrap
                        code.Append(generateNoBootstrap(nvc));
                    }
                }
                else
                {
                    //validation error
                    return(View("Error"));
                }

                code.Append("</form>");


                string selectedStyle = nvc["styleSelect"].ToString();
                Style  style;
                if (selectedStyle == "/")
                {
                    style = _context.Styles.FirstOrDefault(s => s.Name == "None");
                }
                else
                {
                    style = _context.Styles.FirstOrDefault(s => s.Code == selectedStyle);
                }

                ApplicationUser user = getUser();
                if (user.Email == "*****@*****.**")
                {
                    PreMadeForm form = new PreMadeForm()
                    {
                        Name          = nvc["formName"],
                        Category      = nvc["formCategory"],
                        withBootstrap = bootstrap,
                        Code          = code.ToString(),
                        StyleId       = style.id
                    };

                    if (nvc["free"] != null)
                    {
                        form.Free = true;
                    }
                    else
                    {
                        form.Free = false;
                    }

                    _context.PreMadeForms.Add(form);
                    _context.SaveChanges();
                }


                if (selectedStyle != "/")
                {
                    code.Append("\n\n<style>");
                    code.Append("\n" + style.Code);
                    code.Append("\n</style>");
                }

                if (user.Email != "*****@*****.**")
                {
                    CodeHistory codeHistory = new CodeHistory()
                    {
                        UserId = user.Id,
                        Code   = code.ToString(),
                        Date   = DateTime.Now
                    };

                    _context.CodeHistories.Add(codeHistory);
                    _context.SaveChanges();
                }

                ViewBag.Code = code;

                //success page
                return(View());
            }
            else
            {
                //error
                return(View("Error"));
            }
        }//customFormPost()