Example #1
0
        private static string GetParameter(string name)
        {
            ConfigurationParameter parameter = parameters.SingleOrDefault(x => x.Name == name);

            if (parameter == null)
            {
                throw new ArgumentException($"Parameter {name} is not set");
            }
            return(parameter.Value);
        }
        /// <summary>
        /// Extracts the Parameter from the command line
        /// </summary>
        /// <param name="args">Command Line Parameters</param>
        private static void GetParameter(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Missing Parameters");
                    Console.ResetColor();
                }

                int counter = 0;
                ConfigurationParameter parameter;
                foreach (string arg in args)
                {
                    if (counter == 0 || (counter % 2) == 0)
                    {
                        parameter = new ConfigurationParameter();

                        switch (arg.ToLowerInvariant())
                        {
                        case "--connection-string":
                            parameter.Name = arg.Remove(0, 2).ToLowerInvariant();
                            if (args[counter + 1].ToString().StartsWith("--") || args[counter + 1] == null)
                            {
                                LogError("Missing Parameter Value : " + arg);
                            }
                            else
                            {
                                parameter.Value = args[counter + 1];
                            }

                            break;

                        case "--solution-name":
                            parameter.Name = arg.Remove(0, 2).ToLowerInvariant();
                            if (args[counter + 1].ToString().StartsWith("--") || args[counter + 1] == null)
                            {
                                LogError("Missing Parameter Value : " + arg);
                            }
                            else
                            {
                                parameter.Value = args[counter + 1];
                            }

                            break;

                        case "--local-path":
                            parameter.Name = arg.Remove(0, 2).ToLowerInvariant();
                            if (args[counter + 1].ToString().StartsWith("--") || args[counter + 1] == null)
                            {
                                LogError("Missing Parameter Value : " + arg);
                            }
                            else
                            {
                                parameter.Value = args[counter + 1];
                            }

                            break;

                        case "--action":
                            parameter.Name = arg.Remove(0, 2).ToLowerInvariant();
                            if (args[counter + 1].ToString().StartsWith("--") || args[counter + 1] == null)
                            {
                                parameter.Value = "false";
                            }
                            else
                            {
                                parameter.Value = args[counter + 1];
                            }

                            break;

                        default:
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Ignoring :" + arg);
                            break;
                        }

                        if (parameter.Value != null && parameter.Value != string.Empty)
                        {
                            parameters.Add(parameter);
                        }
                    }

                    counter++;
                }
            }
            catch (System.Exception ex)
            {
                LogError(ex.Message);
                LogError(ex.StackTrace);
            }
        }