コード例 #1
0
        TemplateElement Macro_Push_FirstCommit_MessageSummary(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (String.Compare("FirstCommit.MessageSummary", macroName, StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException("Macro name must be 'FirstCommit.MessageSummary'", "fragment");
            }

            var propref = new TemplateElementPropertyReference <Commit> ("Message");

            return(new TemplateElementSynthetic <Push> (GetElementArgumentList(fragment), (Push data, List <TemplateElementArgument> args) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return null;
                }

                Commit first = commits[0];
                string ret = propref.Generate(first);
                if (String.IsNullOrEmpty(ret))
                {
                    return null;
                }

                return ShortenString(ret, args, 72);
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #2
0
        public TemplateElement GetElement(TemplateFragment fragment)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException("fragment");
            }

            TemplateFragmentPlainText text = fragment as TemplateFragmentPlainText;

            if (text != null)
            {
                return(new TemplateElementText(text.Data));
            }

            TemplateElement       ret   = null;
            TemplateFragmentMacro macro = fragment as TemplateFragmentMacro;

            if (macro != null)
            {
                ret = ProcessMacro(macro);
            }

            if (ret == null)
            {
                throw new InvalidOperationException(
                          String.Format("Failed to generate a template element from fragment {0} at {1}:{2},{3}",
                                        fragment, fragment.InFile, fragment.LineStart, fragment.ColumnStart)
                          );
            }

            return(ret);
        }
コード例 #3
0
        TemplateElement Macro_Commit_RemovedPaths(TemplateFragmentMacro fragment)
        {
            return(new TemplateElementSynthetic <Commit> (GetElementArgumentList(fragment), (Commit data, List <TemplateElementArgument> args) =>
            {
                List <string> removed = data.Removed;
                if (removed == null || removed.Count == 0)
                {
                    return null;
                }

                var sb = new StringBuilder();
                if (args == null)
                {
                    sb.AppendLine("Removed paths:");
                }
                else
                {
                    sb.AppendLine(args[0].Generate(data));
                }

                foreach (string file in removed)
                {
                    sb.Append(" D " + file + newline);
                }

                return sb.ToString();
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #4
0
        TemplateElement Macro_Push_AffectedDirectories(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (String.Compare("AffectedDirectories", macroName, StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException("Macro name must be 'AffectedDirectories'", "fragment");
            }

            return(new TemplateElementListMailHeader <Push> (GetElementArgumentList(fragment), (Push data, List <string> values) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return;
                }

                var paths = new SortedDictionary <string, bool> (StringComparer.Ordinal);
                foreach (Commit c in commits)
                {
                    AddUniqueDirectoriesToCache(c.Added, paths);
                    AddUniqueDirectoriesToCache(c.Modified, paths);
                    AddUniqueDirectoriesToCache(c.Removed, paths);
                }

                foreach (string dir in paths.Keys)
                {
                    values.Add(dir);
                }
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #5
0
        TemplateElement Macro_Push_FirstCommit(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (!macroName.StartsWith("FirstCommit", StringComparison.Ordinal))
            {
                throw new ArgumentException("Macro name must start with FirstCommit", "fragment");
            }

            string propName = macroName.Substring(12);

            if (String.IsNullOrEmpty(propName))
            {
                throw new InvalidOperationException("A non-empty property name is required.");
            }

            var propref = new TemplateElementPropertyReference <Commit> (propName);

            return(new TemplateElementSynthetic <Push> (GetElementArgumentList(fragment), (Push data, List <TemplateElementArgument> args) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return null;
                }

                Commit first = commits[0];
                return ShortenString(propref.Generate(first), args, -1);
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #6
0
        TemplateElement Macro_Global_Header(TemplateFragmentMacro fragment)
        {
            List <TemplateElementArgument> arguments = GetElementArgumentList(fragment);

            return(new TemplateElementMailHeader(arguments)
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #7
0
        TemplateElement Macro_Push_Subject(TemplateFragmentMacro fragment)
        {
            List <TemplateElementArgument> arguments = GetElementArgumentList(fragment);

            return(new TemplateElementMailHeader("Subject", arguments)
            {
                SkipNewlineIfLineEmpty = true,
                IgnoreEqualsSign = true
            });
        }
コード例 #8
0
		public TemplateFragmentArgument (string inputFile, TemplateFragmentMacro parent)
		{
			if (String.IsNullOrEmpty (inputFile))
				throw new ArgumentNullException ("inputFile");

			if (parent == null)
				throw new ArgumentNullException ("parent");
			
			this.InFile = inputFile;
		}
コード例 #9
0
        TemplateElement Macro_Push_NumberOfCommits(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (String.Compare("NumberOfCommits", macroName, StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException("Macro name must be 'NumberOfCommits'", "fragment");
            }

            return(new TemplateElementSynthetic <Push> (GetElementArgumentList(fragment), (Push data, List <TemplateElementArgument> args) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return null;
                }

                if (args == null || args.Count == 0)
                {
                    return null;
                }

                var sb = new StringBuilder();
                foreach (TemplateElementArgument a in args)
                {
                    sb.Append(a.Generate(data));
                }

                string arg = sb.ToString();
                int comma = arg.IndexOf(',');
                int min = 2;

                if (comma != -1)
                {
                    int v;

                    if (Int32.TryParse(arg.Substring(0, comma), out v))
                    {
                        min = v;
                        arg = arg.Substring(comma + 1);
                    }
                }

                if (commits.Count < min)
                {
                    return null;
                }

                return arg;
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #10
0
        public TemplateFragmentArgument(string inputFile, TemplateFragmentMacro parent)
        {
            if (String.IsNullOrEmpty(inputFile))
            {
                throw new ArgumentNullException("inputFile");
            }

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            this.InFile = inputFile;
        }
コード例 #11
0
        TemplateElement Macro_Commit_FullDiff(TemplateFragmentMacro fragment)
        {
            return(new TemplateElementSynthetic <Commit> (GetElementArgumentList(fragment), (Commit data, List <TemplateElementArgument> args) =>
            {
                CommitWithDiff diff = data.Diff;
                if (diff != null)
                {
                    return diff.GetFullDiff();
                }

                return null;
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #12
0
        TemplateElement ProcessMacro(TemplateFragmentMacro macro)
        {
            string name = macro.MacroName;

            if (name.StartsWith("this.", StringComparison.Ordinal))
            {
                name = name.Substring(5);
            }

            Func <TemplateFragmentMacro, TemplateElement> processor = GetProcessor(name);

            if (processor != null)
            {
                return(processor(macro));
            }

            int dot = name.IndexOf('.');

            if (dot != -1)
            {
                string nameLead = name.Substring(0, dot);
                processor = GetProcessor(nameLead);
                if (processor != null)
                {
                    return(processor(macro));
                }
            }
            var ret = new TemplateElementPropertyReference <TData> (name);

            if (ret.IsCollection)
            {
                Type tt = typeof(Template <>);
                tt = tt.MakeGenericType(new Type[] { GetCollectionElementType(ret.PropertyType) });
                ITemplate template = Activator.CreateInstance(tt, new object[] { basePath, commitSourceID }) as ITemplate;
                if (!template.Compile())
                {
                    return(null);
                }

                ret.Template = template;
            }

            return(ret);
        }
コード例 #13
0
        TemplateElement Macro_Global_IfDifferent(TemplateFragmentMacro fragment)
        {
            return(new TemplateElementSynthetic <TData> (GetElementArgumentList(fragment), (TData data, List <TemplateElementArgument> args) =>
            {
                if (args == null || args.Count == 0)
                {
                    return null;
                }

                var sb = new StringBuilder();
                foreach (TemplateElementArgument a in args)
                {
                    sb.Append(a.Generate(data));
                }

                string argstr = sb.ToString();
                if (argstr.Length == 0)
                {
                    return null;
                }

                string[] arglist = argstr.Split(argumentSplitChars);
                if (arglist.Length < 3)
                {
                    Log(LogSeverity.Error, "Not enough arguments for the IfDifferent macro (expected 3, got {0}", arglist.Length);
                    return null;
                }

                string heading = arglist[0];
                string left = arglist[1];
                string right = String.Join(",", arglist, 2, arglist.Length - 2);

                if (String.Compare(left, right, StringComparison.Ordinal) == 0)
                {
                    return null;
                }

                return heading + left;
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
コード例 #14
0
        List <TemplateElementArgument> GetElementArgumentList(TemplateFragmentMacro fragment)
        {
            List <TemplateElementArgument> arguments = null;

            if (fragment.HasArguments)
            {
                arguments = new List <TemplateElementArgument> ();
                foreach (TemplateFragmentArgument arg in fragment.Arguments)
                {
                    arguments.Add(GetElementArgument(arg));
                }
            }

            if (arguments != null && arguments.Count > 0)
            {
                return(arguments);
            }

            return(null);
        }
コード例 #15
0
 TemplateElement Macro_Global_Version(TemplateFragmentMacro fragment)
 {
     return(new TemplateElementText(Config.Instance.Version));
 }