Example #1
0
        public static CommandLineParams ParseCommandLine(string[] args)
        {
            int count = 3;

            if (args.Length >= 1)
            {
                var parsedArgs = ParseArguments(args);

                if (!parsedArgs.ContainsKey("help") && !parsedArgs.ContainsKey("?"))
                {
                    var cmdLineArgs = new CommandLineParams();

                    foreach (var s in parsedArgs)
                    {
                        if (s.Key.Equals("type"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("dbf+kml"))
                            {
                                cmdLineArgs.DataType = SourceDataType.DbfAndKml;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("csv"))
                            {
                                cmdLineArgs.DataType = SourceDataType.Csv;
                            }
                            else
                            {
                                goto UseMessage;
                            }

                            count--;
                        }
                        else if (s.Key.Equals("target"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("console"))
                            {
                                cmdLineArgs.LoadingTarget = DataLoadingTarget.Console;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("tables"))
                            {
                                cmdLineArgs.LoadingTarget = DataLoadingTarget.Tables;
                            }
                            else
                            {
                                goto UseMessage;
                            }

                            count--;
                        }
                        else if (s.Key.Equals("fsname"))
                        {
                            cmdLineArgs.FileSetName = s.Value;
                            count--;
                        }
                        else if (s.Key.Equals("date"))
                        {
                            cmdLineArgs.RefreshLastUpdateDate = true;
                        }
                        else if (s.Key.Equals("mode"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("create"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Create;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("add"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Add;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("update"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Update;
                            }
                            else
                            {
                                goto UseMessage;
                            }
                        }
                        else if (s.Key.Equals("sourceorder"))
                        {
                            cmdLineArgs.SourceOrder = true;
                        }
                        else
                        {
                            goto UseMessage;
                        }
                    }

                    if (count == 0)
                    {
                        if (cmdLineArgs.DataType == SourceDataType.DbfAndKml && cmdLineArgs.OverwriteMode != TableOverwriteMode.Create)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(mode_restriction);
                            Console.ResetColor();
                            goto UseMessage;
                        }
                        return(cmdLineArgs);
                    }
                }
            }

UseMessage:
            Console.WriteLine(s_use);
            return(null);
        }
        public static CommandLineParams ParseCommandLine(string[] args)
        {
            int count = 3;

            if (args.Length >= 1)
            {
                var parsedArgs = ParseArguments(args);

                if (!parsedArgs.ContainsKey("help") && !parsedArgs.ContainsKey("?"))
                {
                    var cmdLineArgs = new CommandLineParams();

                    foreach (var s in parsedArgs)
                    {
                        if (s.Key.Equals("type"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("dbf+kml"))
                            {
                                cmdLineArgs.DataType = SourceDataType.DbfAndKml;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("csv"))
                            {
                                cmdLineArgs.DataType = SourceDataType.Csv;
                            }
                            else
                            {
                                goto UseMessage;
                            }

                            count--;
                        }
                        else if (s.Key.Equals("target"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("console"))
                            {
                                cmdLineArgs.LoadingTarget = DataLoadingTarget.Console;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("tables"))
                            {
                                cmdLineArgs.LoadingTarget = DataLoadingTarget.Tables;
                            }
                            else
                            {
                                goto UseMessage;
                            }

                            count--;
                        }
                        else if (s.Key.Equals("fsname"))
                        {
                            cmdLineArgs.FileSetName = s.Value;
                            count--;
                        }
                        else if (s.Key.Equals("date"))
                        {
                            cmdLineArgs.RefreshLastUpdateDate = true;
                        }
                        else if (s.Key.Equals("mode"))
                        {
                            if (s.Value.ToLowerInvariant().Equals("create"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Create;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("add"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Add;
                            }
                            else if (s.Value.ToLowerInvariant().Equals("update"))
                            {
                                cmdLineArgs.OverwriteMode = TableOverwriteMode.Update;
                            }
                            else
                            {
                                goto UseMessage;
                            }
                        }
                        else if (s.Key.Equals("sourceorder"))
                        {
                            cmdLineArgs.SourceOrder = true;
                        }
                        else
                        {
                            goto UseMessage;
                        }
                    }

                    if (count == 0)
                    {
                        if (cmdLineArgs.DataType == SourceDataType.DbfAndKml && cmdLineArgs.OverwriteMode != TableOverwriteMode.Create)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(mode_restriction);
                            Console.ResetColor();
                            goto UseMessage;
                        }
                        return cmdLineArgs;
                    }
                }
            }

            UseMessage:
            Console.WriteLine(s_use);
            return null;
        }