Esempio n. 1
0
        public bool init(ExtractSubOptions 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.outFileName))
                {
                    _outFile = Path.IsPathRooted(opts.outFileName) ? opts.outFileName + ".csv" : _CurrentDirectory + @"\" + opts.outFileName + ".csv";
                }
                else
                {
                    _outFile = _CurrentDirectory + @"\extracted_result.csv";
                }

                _outTempDirectory = _CurrentDirectory + @"\temp";
                _pointType        = opts.pointType;
                _maxThread        = opts.maxThread;
                _onlyExportPos    = opts.onlyExportPos;

                _sw = new StreamWriter(_outFile, false, Encoding.GetEncoding("UTF-8"));

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(false);
            }
        }
Esempio n. 2
0
        private static bool ExtractFiles(ExtractSubOptions opts)
        {
            logger.Info("Starting...");
            ExtractData ed   = new ExtractData();
            bool        bRes = ed.init(opts);

            return(bRes ? ed.Step() : false);
        }
Esempio n. 3
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);
        }