From 4ca6b40c19cc81cff235a906993e99284daddfc0 Mon Sep 17 00:00:00 2001 From: markoz Date: Sun, 7 Oct 2018 01:54:31 +0200 Subject: [PATCH] Azure task generator --- FlubuCore.Azure/AzureTaskGenerator.cs | 45 +++++++++++++++++++++++++++ FlubuCore.Azure/StringExtensions.cs | 20 ++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 FlubuCore.Azure/AzureTaskGenerator.cs create mode 100644 FlubuCore.Azure/StringExtensions.cs diff --git a/FlubuCore.Azure/AzureTaskGenerator.cs b/FlubuCore.Azure/AzureTaskGenerator.cs new file mode 100644 index 0000000..510dfda --- /dev/null +++ b/FlubuCore.Azure/AzureTaskGenerator.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using FlubuCore.TaskGenerator.Models; +using Scripty.Core; + +namespace FlubuCore.Azure +{ + public class AzureTaskGenerator : TaskGenerator.TaskGenerator + { + public AzureTaskGenerator(ScriptContext context) : base(context) + { + } + + protected override string WriteParameter(Parameter parameter) + { + if (parameter == null) + { + return string.Empty; + } + + return $"{parameter.ParameterType} {parameter.ParameterName} = null"; + } + + protected override string WriteArgument(Argument argument) + { + if (argument == null) + { + return string.Empty; + } + + if (argument.Parameter == null) + { + return $@"WithArguments(""{argument.ArgumentKey}"");"; + } + + return $@"WithArguments(""{argument.ArgumentKey}""); + if (!string.IsNullOrEmpty({argument.Parameter.ParameterName})) + {{ + WithArguments({argument.Parameter.ParameterName}); + }} +"; + } + } +} diff --git a/FlubuCore.Azure/StringExtensions.cs b/FlubuCore.Azure/StringExtensions.cs new file mode 100644 index 0000000..8535303 --- /dev/null +++ b/FlubuCore.Azure/StringExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FlubuCore.Azure +{ + public static class StringExtensions + { + public static string FirstCharToUpper(this string value) + { + switch (value) + { + case null: throw new ArgumentNullException(nameof(value)); + case "": throw new ArgumentException($"{nameof(value)} cannot be empty", nameof(value)); + default: return value.First().ToString().ToUpper() + value.Substring(1); + } + } + } +}