Пример #1
0
        public static ExecuteConfigurationTemplateOptions GetOptionsFromCommandLine(string[] args)
        {
            var option = new ExecuteConfigurationTemplateOptions();

            Parser.Default.ParseArguments <ExecuteConfigurationTemplateOptions>(args)
            .WithParsed(opts => { option = opts; })
            .WithNotParsed((errs) =>
            {
                option = GetScuOptionsFromReadLineLoop();
            });
            return(option);
        }
Пример #2
0
 static void Main(string[] args)
 {
     try
     {
         var options = ExecuteConfigurationTemplateOptions.GetOptionsFromCommandLine(args);
         var cashbox = ExecuteTemplate(options).Result;
         Console.WriteLine($"Successfully created cashbox with id {cashbox.CashBoxId}");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Пример #3
0
        public static ExecuteConfigurationTemplateOptions GetScuOptionsFromReadLineLoop()
        {
            var option     = new ExecuteConfigurationTemplateOptions();
            var properties = typeof(ExecuteConfigurationTemplateOptions).GetProperties();

            foreach (var property in properties)
            {
                OptionAttribute attr = property.GetCustomAttributes(typeof(OptionAttribute), true).FirstOrDefault() as OptionAttribute;
                if (attr != null)
                {
                    string value = "";
                    while (value == string.Empty)
                    {
                        if (attr.Default != null)
                        {
                            Console.Write($"{attr.LongName} ({attr.Default}):");
                        }
                        else
                        {
                            Console.Write($"{attr.LongName}:");
                        }

                        value = ReadLine();
                        if (string.IsNullOrWhiteSpace(value) && attr.Default != null)
                        {
                            Console.Error.WriteLine($"No value given for {attr.LongName}. Using Default Value: {attr.Default}");
                            value = attr.Default.ToString();
                        }

                        if (string.IsNullOrEmpty(value))
                        {
                            Console.Error.WriteLine($"Error. Please provide a value for {attr.LongName}.");
                        }
                    }

                    property.SetValue(option, TypeDescriptor.GetConverter(property.PropertyType).ConvertFromInvariantString(value));
                }
            }
            return(option);
        }
Пример #4
0
        private static async Task <NewCashBoxModel> ExecuteTemplate(ExecuteConfigurationTemplateOptions options)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("accountid", options.AccountId.ToString());
                client.DefaultRequestHeaders.Add("accesstoken", options.AccessToken);
                client.DefaultRequestHeaders.Add("version", "v0");

                var content    = new StringContent(JsonConvert.SerializeObject(options.Template), Encoding.UTF8, "application/json");
                var uriBuilder = new UriBuilder($"{options.HelipadUrl}api/configuration");
                var response   = await client.PostAsync(uriBuilder.Uri, content);

                var responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <NewCashBoxModel>(responseContent));
                }
                else
                {
                    throw new Exception($"Request failed with Statuscode: {response.StatusCode}. {response.ReasonPhrase} - {responseContent}");
                }
            }
        }