예제 #1
0
 private static TaskWriter WriteMainTask(this TaskWriter writer)
 {
     return(writer
            .WriteSummary(writer.Task)
            .WriteLine(GetTaskSignature(writer.Task))
            .WriteBlock(WriteMainTaskBlock));
 }
예제 #2
0
        private static TaskWriter WriteTaskOverloads(this TaskWriter writer, int index = 0)
        {
            var task       = writer.Task;
            var properties = task.SettingsClass.Properties.Where(x => x.CreateOverload).Take(index + 1).ToList();

            if (properties.Count == 0 || index >= properties.Count)
            {
                return(writer);
            }

            var additionalParameterDeclarations = properties.Select(x => $"{x.GetNullabilityAttribute()}{x.Type} {x.Name.ToInstance()}");
            var nextArguments    = properties.AsEnumerable().Reverse().Skip(count: 1).Reverse().Select(x => x.Name.ToInstance());
            var configuratorName = "configurator";
            var currentArgument  = properties.Last();
            var setter           = $"x => {configuratorName}(x).Set{currentArgument.Name}({currentArgument.Name.ToInstance()})";
            var allArguments     = nextArguments.Concat(new[] { setter });

            writer
            .WriteSummary(task)
            .WriteLine(GetTaskSignature(writer.Task, additionalParameterDeclarations))
            .WriteBlock(w => w
                        .WriteLine("configurator = configurator ?? (x => x);")
                        .WriteLine($"{task.GetTaskMethodName()}({allArguments.Join()});"));

            return(writer.WriteTaskOverloads(index + 1));
        }
예제 #3
0
        private static TaskWriter WriteConfiguratorTask(this TaskWriter writer)
        {
            var task       = writer.Task;
            var returnType = task.HasReturnValue()
                ? $"({task.ReturnType} Result, IReadOnlyCollection<Output> Output)"
                : "IReadOnlyCollection<Output>";

            return(writer
                   .WriteSummary(task)
                   .WriteRemarks(task)
                   .WriteObsoleteAttributeWhenObsolete(task)
                   .WriteLine($"public static {returnType} {task.GetTaskMethodName()}(Configure<{task.SettingsClass.Name}> configurator)")
                   .WriteBlock(w => w
                               .WriteLine($"return {task.GetTaskMethodName()}(configurator(new {task.SettingsClass.Name}()));")));
        }
예제 #4
0
        private static TaskWriter WriteToolSettingsTask(this TaskWriter writer)
        {
            var task       = writer.Task;
            var returnType = task.HasReturnValue()
                ? $"({task.ReturnType} Result, IReadOnlyCollection<Output> Output)"
                : "IReadOnlyCollection<Output>";

            return(writer
                   .WriteSummary(task)
                   .WriteObsoleteAttributeWhenObsolete(task)
                   .WriteLine($"public static {returnType} {task.GetTaskMethodName()}({task.SettingsClass.Name} toolSettings = null)")
                   .WriteBlock(w => w
                               .WriteLine($"toolSettings = toolSettings ?? new {task.SettingsClass.Name}();")
                               .WriteLineIfTrue(task.PreProcess, "PreProcess(ref toolSettings);")
                               .WriteLine($"var process = {GetProcessStart(task)};")
                               .WriteLine(GetProcessAssertion(task))
                               .WriteLineIfTrue(task.PostProcess, "PostProcess(toolSettings);")
                               .WriteLine(task.HasReturnValue()
                        ? "return (GetResult(process, toolSettings), process.Output);"
                        : "return process.Output;")));
        }
예제 #5
0
        private static TaskWriter WriteCombinatorialConfiguratorTask(this TaskWriter writer)
        {
            var task = writer.Task;

            var returnType = !task.HasReturnValue()
                ? $"IEnumerable<({task.SettingsClass.Name} Settings, IReadOnlyCollection<Output> Output)>"
                : $"IEnumerable<({task.SettingsClass.Name} Settings, {task.ReturnType} Result, IReadOnlyCollection<Output> Output)>";

            var parameters = new[]
            {
                $"CombinatorialConfigure<{task.SettingsClass.Name}> configurator",
                "int degreeOfParallelism = 1",
                "bool completeOnFailure = false"
            }.JoinComma();

            return(writer
                   .WriteSummary(task)
                   .WriteRemarks(task)
                   .WriteObsoleteAttributeWhenObsolete(task)
                   .WriteLine($"public static {returnType} {task.GetTaskMethodName()}({parameters})")
                   .WriteBlock(w => w
                               .WriteLine($"return configurator.Invoke({task.GetTaskMethodName()}, {task.Tool.Name}Logger, degreeOfParallelism, completeOnFailure);")));
        }