Example #1
0
        private static bool ConvertFiles(ConvertSubOptions opts)
        {
            logger.Info("Starting...");
            DataConvert dc   = new DataConvert();
            bool        bRes = dc.init(opts);

            return(bRes? dc.Step(): false);
        }
Example #2
0
        public bool init(ConvertSubOptions opts)
        {
            try
            {
                _dataDirectory = Path.IsPathRooted(opts.inDirectoryName) ? opts.inDirectoryName : _CurrentDirectory + @"\" + opts.inDirectoryName;

                if (Directory.Exists(_dataDirectory) == false)
                {
                    throw new Exception("Error: input directory is not exist!");
                }

                if (!String.IsNullOrEmpty(opts.lpFileName))
                {
                    _lpFile = Path.IsPathRooted(opts.lpFileName) ? opts.lpFileName : _CurrentDirectory + @"\" + opts.lpFileName;
                }

                if (!String.IsNullOrEmpty(opts.outDirectoryName))
                {
                    _outDirectory = Path.IsPathRooted(opts.outDirectoryName) ? opts.outDirectoryName : _CurrentDirectory + @"\" + opts.outDirectoryName;
                }
                else
                {
                    _outDirectory = _CurrentDirectory + @"\gps_result\";
                }

                _bFilter   = opts.filter;
                _maxThread = opts.maxThread;

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(false);
            }
        }
Example #3
0
 public VerbCommand()
 {
     // Since we create this instance the parser will not overwrite it
     ConvertVerb   = new ConvertSubOptions();
     MarkpointVerb = new mpSubOptions();
 }
Example #4
0
        //[STAThread()]
        static void Main(string[] args)
        {
            //args = ("convert -i TRK20160307 -l lpFile.csv -f -n 6").Split();
            //args = ("convert -i test -f -n 1 -o test_sgps").Split();
            //args = ("convert -i TRK20160307 -l lpFile.csv -f -n 8 -o stay_gps").Split();
            //args = ("extract -i stay_gps -n 6 -n 3").Split();
            //args = ("help").Split();

            if (args.Length > 0)
            {
                if (args[0].ToLowerInvariant() == "help")
                {
                    args = args.Skip(1).ToArray();
                }
            }

            Stopwatch watch = new Stopwatch();

            Action <bool> printIfNotEmpty = flag =>
            {
                if (flag == false)
                {
                    return;
                }
                watch.Stop();
                logger.Info("All done! Total cost " + watch.Elapsed.TotalSeconds.ToString() + "s");
            };

            watch.Start();

            Func <ConvertSubOptions, bool> convertor = opts => { return(ConvertFiles(opts)); };
            Func <ExtractSubOptions, bool> extractor = opts => { return(ExtractFiles(opts)); };

            string invokedVerb         = null;
            object invokedVerbInstance = null;

            var  options  = new VerbCommand();
            bool exitCode = CommandLine.Parser.Default.ParseArguments(args, options,
                                                                      (verb, subOptions) =>
            {
                // if parsing succeeds the verb name and correct instance
                // will be passed to onVerbCommand delegate (string,object)
                invokedVerb         = verb;
                invokedVerbInstance = subOptions;
            });

            if (exitCode)
            {
                switch (invokedVerb)
                {
                case "convert":
                    ConvertSubOptions convertSubOptions = (ConvertSubOptions)invokedVerbInstance;
                    convertor(convertSubOptions);
                    break;

                case "extract":
                    ExtractSubOptions extractSubOptions = (ExtractSubOptions)invokedVerbInstance;
                    extractor(extractSubOptions);
                    break;
                }
            }

            printIfNotEmpty(exitCode);
            Array.Clear(args, 0, args.Length);
            //Console.ReadKey(true);
        }