Exemple #1
0
 /// <summary>
 /// Allows the user to select all the text files within a single folder
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private void miOpenFolder_Click(object sender, RoutedEventArgs e)
 {
     if (!String.IsNullOrWhiteSpace(fileBrowser.SelectFolder()))
     {
         ReadSelectedFiles();
         gpxHandler = new GpxHandler(fileBrowser.WorkingFolder);
     }
 }
Exemple #2
0
 /// <summary>
 /// Processes the file.
 /// </summary>
 /// <param name="batSummary">The bat summary.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="gpxHandler">The GPX handler.</param>
 /// <returns></returns>
 public String ProcessFile(BatSummary batSummary, string fileName, GpxHandler gpxHandler)
 {
     mBatSummary  = batSummary;
     OutputString = "";
     if (fileName.ToUpper().EndsWith(".TXT"))
     {
         OutputString = ProcessLabelOrManualFile(fileName, gpxHandler);
     }
     return(OutputString);
 }
Exemple #3
0
        /// <summary>
        /// Processes a text file with a simple .txt extension that has been
        /// generated as an Audacity LabelTrack.  The fileName will be added to the
        /// output at the start of the OutputString.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="gpxHandler">The GPX handler.</param>
        /// <returns></returns>
        private string ProcessLabelOrManualFile(string fileName, GpxHandler gpxHandler)
        {
            TimeSpan duration = new TimeSpan();
            Match    match    = null;

            mode = MODE.PROCESS;



            BatsFound = new Dictionary <string, BatStats>();
            string[] allLines = new string[1];
            DateTime fileStart;
            DateTime fileEnd;

            if (File.Exists(fileName))
            {
                string wavfile = "";
                duration     = GetFileDuration(fileName, out wavfile, out fileStart, out fileEnd);
                OutputString = fileName;
                if (!string.IsNullOrWhiteSpace(wavfile))
                {
                    OutputString = fileName;
                }
                if (duration.Ticks > 0L)
                {
                    OutputString = OutputString + " \t" + duration.Minutes + "m" + duration.Seconds + "s";
                }
                OutputString = OutputString + "\n";
                List <decimal> gpsLocation = gpxHandler.GetLocation(fileStart);
                if (gpsLocation != null && gpsLocation.Count() == 2)
                {
                    OutputString = OutputString + gpsLocation[0] + ", " + gpsLocation[1];
                }
                gpsLocation = gpxHandler.GetLocation(fileEnd);
                if (gpsLocation != null && gpsLocation.Count() == 2)
                {
                    OutputString = OutputString + " => " + gpsLocation[0] + ", " + gpsLocation[1] + "\n";
                }

                try
                {
                    allLines = File.ReadAllLines(fileName);
                }
                catch (Exception ex) { Debug.WriteLine(ex); }

                if (allLines.Count() > 1 && allLines[0].StartsWith("["))
                {
                    if (allLines[0].ToUpper().StartsWith("[SKIP]") || allLines[0].ToUpper().StartsWith("[LOG]"))
                    {
                        mode = MODE.COPY;
                        return("");
                    }
                    if (allLines[0].ToUpper().StartsWith("[COPY]"))
                    {
                        mode         = MODE.COPY;
                        OutputString = "";
                        foreach (var line in allLines)
                        {
                            if (line.Contains("[MERGE]"))
                            {
                                mode = MODE.MERGE;

                                linesToMerge = new List <string>();
                            }
                            if (!line.Contains("[COPY]") && !line.Contains("[MERGE]"))
                            {
                                if (mode == MODE.MERGE)
                                {
                                    linesToMerge.Add(line);
                                }
                                else
                                {
                                    OutputString = OutputString + line + "\n";
                                }
                            }
                        }
                        return(OutputString);
                    }
                }
                if (allLines != null && allLines.Count() > 0)
                {
                    if (linesToMerge != null && linesToMerge.Count > 0)
                    {
                        OutputString = OutputString + linesToMerge[0] + "\n";
                        linesToMerge.Remove(linesToMerge[0]);
                    }
                    foreach (var line in allLines)
                    {
                        if (!String.IsNullOrWhiteSpace(line))
                        {
                            string modline = Regex.Replace(line, @"[Ss][Tt][Aa][Rr][Tt]", "0.0");
                            modline = Regex.Replace(modline, @"[Ee][Nn][Dd]", FormattedTimeSpan(duration));

                            if (IsLabelFileLine(modline))
                            {
                                OutputString = OutputString + ProcessLabelFileLine(modline);
                            }
                            else if ((match = IsManualFileLine(modline)) != null)
                            {
                                OutputString = OutputString + ProcessManualFileLine(match);
                            }
                            else
                            {
                                OutputString = OutputString + line + "\n";
                            }
                        }
                    }
                }
            }

            if (!String.IsNullOrWhiteSpace(OutputString) && BatsFound != null && BatsFound.Count() > 0)
            {
                foreach (var bat in BatsFound)
                {
                    OutputString = OutputString + "\n" + FormattedBatStats(bat);
                }
            }

            return(OutputString);
        }