Esempio n. 1
0
        static void Extract(ExtractOptions options)
        {
            OnMov200 onMov200 = new OnMov200(options.RootDir, options.OutputDir);

            var activities = onMov200.GetHeaders();
            int i          = 0;

            foreach (var activity in activities)
            {
                i++;
                Console.WriteLine($"{i} - {activity}");
            }
            ;
            string which = Console.ReadLine();
            int    index = -1;

            if (int.TryParse(which, out index))
            {
                if (index >= 1 && index <= activities.Count)
                {
                    var result = onMov200.ExtractActivity(activities[index - 1]);
                    if (result.IsRight)
                    {
                        var error = result.IfLeft(() => new OMError(null, "no error"));
                        Console.WriteLine(error.ErrorMessage);
                    }
                    else
                    {
                        Console.WriteLine($"OK. File extracted in {onMov200.OutputDirectory}");
                    }
                }
            }
            else
            {
                if (which == "all")
                {
                    var result = onMov200.ExtractAll(activities);

                    var errors = result.Where(x => x.IsRight).Select(x => x.IfLeft(new OMError(null, "no error"))).ToList();
                    if (errors.Count == 0)
                    {
                        Console.WriteLine($"OK. files extracted in {onMov200.OutputDirectory}");
                    }
                    else
                    {
                        var errorsMessage = string.Join('\n', errors.Select(x => x.ErrorMessage));
                        Console.WriteLine(errorsMessage);
                    }
                }
            }
        }
Esempio n. 2
0
 public Database(string root = null)
 {
     OnMov200 = new OnMov200(null, root, false);
 }
Esempio n. 3
0
        private List <ExtractionSummary> ProcessActivities(List <IFormFile> files)
        {
            List <ExtractionSummary> summary = new List <ExtractionSummary>();

            var onmov      = new OnMov200();
            var validFiles = files.Where(f =>
                                         f.FileName.EndsWith(OnMov200.HeaderExtension) || f.FileName.EndsWith(OnMov200.DataExtension));

            if (validFiles.Count() % 2 != 0)
            {
                throw new Exception("even file number expected");
            }

            var groupedActivitiesFiles = validFiles.GroupBy(f => f.NameWithoutExtension()).ToList();

            int countOk   = 0;
            var extracted = new Dictionary <ActivityHeader, string>();
            int countKo   = 0;
            var errors    = new Dictionary <string, string>();

            foreach (var activityFiles in groupedActivitiesFiles)
            {
                var headerFile = activityFiles.FirstOrDefault(f => f.Extension() == $".{OnMov200.HeaderExtension}");
                if (headerFile != null)
                {
                    string         name   = headerFile.NameWithoutExtension();
                    ActivityHeader header = null;
                    using (var stream = headerFile.OpenReadStream())
                    {
                        header = onmov.GetHeader(name, stream);
                    }

                    if (header != null)
                    {
                        var dataFile = activityFiles.FirstOrDefault(f => f.Extension() == $".{OnMov200.DataExtension}");
                        if (dataFile != null)
                        {
                            using (var stream = dataFile.OpenReadStream())
                            {
                                var result = onmov.ToGpx(header, stream);
                                if (result.IsLeft)
                                {
                                    var res = result.IfRight(() => (header, null));
                                    extracted[res.activity] = res.gpx;
                                    var sum = new ExtractionSummary(res.activity, res.gpx);
                                    summary.Add(sum);
                                    countOk++;
                                }
                                else
                                {
                                    countKo++;
                                    var error = result.IfLeft(() => new OMError(header, "no error"));

                                    var sum = new ExtractionSummary(header.Name, error.ErrorMessage);
                                    summary.Add(sum);
                                }
                            }
                        }
                        else
                        {
                            countKo++;

                            var sum = new ExtractionSummary(header.Name, "unable to find data file.");
                            summary.Add(sum);
                        }
                    }
                    else
                    {
                        countKo++;

                        var sum = new ExtractionSummary(header.Name, " bad header file.");
                        summary.Add(sum);
                    }
                }
                else
                {
                    countKo++;
                    var sum = new ExtractionSummary(activityFiles.Key, " unable to find header file.");
                }
            }



            return(summary);
        }
Esempio n. 4
0
        static void FastFix(FastFixOptions options)
        {
            OnMov200 onMov200 = new OnMov200(options.RootDir, options.RootDir);

            onMov200.UpDateFastFixIfNeeded(options.Force).GetAwaiter().GetResult();
        }
Esempio n. 5
0
        static void List(ListOptions options)
        {
            OnMov200 onMov200 = new OnMov200(options.RootDir, options.OutputDir);

            onMov200.PrintSummary();
        }