Esempio n. 1
0
        private static CodeBlockMappingExpression DoWithRemainingCode(
            this IModificationMappingExpression expression,
            IQueryable <Commit> commits,
            int fileId,
            Func <IModificationMappingExpression, string, double, CodeBlockMappingExpression> codeToExp)
        {
            var remainigCodeByRevision = (
                from m in expression.Get <Modification>().Where(x => x.FileId == fileId)
                join c in commits on m.CommitNumber equals c.Number
                join cb in expression.Get <CodeBlock>() on m.Id equals cb.ModificationId
                join tcb in expression.Get <CodeBlock>() on cb.TargetCodeBlockId ?? cb.Id equals tcb.Id
                join tcbc in expression.Get <Commit>() on tcb.AddedInitiallyInCommitNumber equals tcbc.Number
                group cb.Size by tcbc.Revision into g
                select new
            {
                Revision = g.Key,
                Size = g.Sum()
            }).ToArray();

            CodeBlockMappingExpression codeExp = null;

            foreach (var codeForRevision in remainigCodeByRevision)
            {
                codeExp = codeToExp(
                    codeExp ?? expression,
                    codeForRevision.Revision,
                    codeForRevision.Size) ?? codeExp;
            }

            return(codeExp);
        }
Esempio n. 2
0
        public static CodeBlockMappingExpression DeleteCode(this IModificationMappingExpression exp)
        {
            CodeBlockMappingExpression lastCodeBlockExp = null;

            foreach (var codeByAddedCode in (
                         from cb in exp.Queryable <CodeBlock>()
                         join m in exp.Queryable <Modification>() on cb.ModificationID equals m.ID
                         join f in exp.Queryable <ProjectFile>() on m.FileID equals f.ID
                         let addedCodeID = cb.Size < 0 ? cb.TargetCodeBlockID : cb.ID
                                           where
                                           f.ID == exp.CurrentEntity <ProjectFile>().ID
                                           group cb.Size by addedCodeID
                         )
                     )
            {
                double currentCodeSize = codeByAddedCode.Sum();

                if (currentCodeSize != 0)
                {
                    if (lastCodeBlockExp == null)
                    {
                        lastCodeBlockExp = exp.Code(-currentCodeSize);
                    }
                    else
                    {
                        lastCodeBlockExp = lastCodeBlockExp.Code(-currentCodeSize);
                    }
                    lastCodeBlockExp.ForCodeAddedInitiallyInRevision(
                        RevisionCodeBlockWasInitiallyAddedIn(exp, codeByAddedCode.Key ?? 0)
                        );
                }
            }

            return(lastCodeBlockExp);
        }
Esempio n. 3
0
        public static CodeBlockMappingExpression RemoveCode(this IModificationMappingExpression exp)
        {
            var file = exp.CurrentEntity <CodeFile>();
            var currentCommitBranch = exp.CurrentEntity <Branch>();
            var commitsOnBranch     = exp.SelectionDSL().Commits()
                                      .OnBranchBack(currentCommitBranch.Mask);

            return(DoWithRemainingCode(
                       exp, commitsOnBranch, file.Id, RemoveCodeBlock));
        }
Esempio n. 4
0
        public static CodeBlockMappingExpression UpdateCode(
            this IModificationMappingExpression exp,
            Func <IModificationMappingExpression, string, double, CodeBlockMappingExpression> codeToExp)
        {
            var file = exp.CurrentEntity <CodeFile>();
            var currentCommitBranch = exp.CurrentEntity <Branch>();
            var commitsOnBranch     = exp.SelectionDSL().Commits()
                                      .OnBranchBack(currentCommitBranch.Mask);

            return(DoWithRemainingCode(
                       exp, commitsOnBranch, file.Id, codeToExp));
        }
Esempio n. 5
0
        private static CodeBlockMappingExpression RemoveCodeBlock(
            IModificationMappingExpression expression,
            string revision,
            double codeSize)
        {
            if (codeSize != 0)
            {
                var newExp = expression.Code(-codeSize);
                newExp.ForCodeAddedInitiallyInRevision(revision);
                return(newExp);
            }

            return(null);
        }
Esempio n. 6
0
        private static CodeBlockMappingExpression CopyCodeBlock(
            IModificationMappingExpression expression,
            string revision,
            double codeSize)
        {
            if (codeSize != 0)
            {
                var newExp = expression.Code(codeSize);
                newExp.CopiedFrom(revision);
                return(newExp);
            }

            return(null);
        }
Esempio n. 7
0
        public static CodeBlockMappingExpression CopyCode(this IModificationMappingExpression exp)
        {
            var modification = exp.CurrentEntity <Modification>();
            var sourceCommit = (
                from c in exp.GetReadOnly <Commit>().Where(x => x.Number == modification.SourceCommit.Number)
                join b in exp.GetReadOnly <Branch>() on c.BranchId equals b.Id
                select new { c.Number, b.Mask }).Single();
            var commitsOnBranch = exp.SelectionDSL().Commits()
                                  .OnBranchBack(sourceCommit.Mask)
                                  .Where(x => x.Number <= sourceCommit.Number);

            return(DoWithRemainingCode(
                       exp, commitsOnBranch, modification.SourceFile.Id, CopyCodeBlock));
        }
Esempio n. 8
0
 public static CodeBlockMappingExpression Code(this IModificationMappingExpression exp, double size)
 {
     return(new CodeBlockMappingExpression(exp, size));
 }