Esempio n. 1
0
        private void file_MultiChoiceTest_click(object sender, EventArgs e)
        {
            List <string> fileNames = new List <string>
            {
                "FileName 1", "FileName 2", "FileName 3", "FileName 4"
            };
            MultiChoiceCheckDialog dlg = new MultiChoiceCheckDialog(fileNames);

            dlg.Label = "Select which files to use:";
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                List <Result> results = dlg.Results;
                string        info    = "";
                foreach (Result result in results)
                {
                    if (result.Checked)
                    {
                        info += "X  " + result.FileName + NL;
                    }
                    else
                    {
                        info += "O  " + result.FileName + NL;
                    }
                }
                Utils.infoMsg("Check State: " + NL + info);
            }
        }
Esempio n. 2
0
        private void consolidateData()
        {
            writeInfo(NL + "Consolidating the data");
            sortData();
            GpsData        gpxData;
            List <GpsData> gpxDataList = new List <GpsData>();

            // Find GPX files with the same name as a TCX file
            foreach (GpsData data in exerciseDataList)
            {
                if (data.IsTcx)
                {
                    gpxData = exerciseDataList.Find(item =>
                                                    item.Extension.ToLower() == ".gpx" &&
                                                    item.FileNameWithoutExtension == data.FileNameWithoutExtension
                                                    );
#if consolidateVerbose
                    if (gpxData != null)
                    {
                        writeInfo(NL + "Comparing " + data.SimpleFileName);
                        writeInfo(compareData(data, gpxData));
                    }
#endif
                    if (gpxData != null)
                    {
                        gpxDataList.Add(gpxData);
                    }
                }
            }
            writeInfo("  Found " + gpxDataList.Count +
                      " GPX file names matching TCX file names");
            // Remove the matching GPX files
            bool           res;
            int            nErrors    = 0;
            List <GpsData> failedList = new List <GpsData>();
            foreach (GpsData data in gpxDataList)
            {
                res = exerciseDataList.Remove(data);
                if (!res)
                {
                    nErrors++;
                    failedList.Add(data);
                }
            }
            if (nErrors > 0)
            {
                writeInfo("Failed to remove " + nErrors + " Gpx files");
                foreach (GpsData data in failedList)
                {
                    writeInfo("    " + data.FileName);
                }
            }

            // Find files with similar start time
            IEnumerable <IGrouping <DateTime, GpsData> > groupList = exerciseDataList
                                                                     .GroupBy(data => data.StartTimeRounded)
                                                                     .Where(grp => grp.Count() > 1);
            int nDuplicates = groupList.Count();
            List <IGrouping <DateTime, GpsData> > groups = groupList.ToList();
            writeInfo("  Found " + nDuplicates + " Groups with simlilar StartTime");
            foreach (IGrouping <DateTime, GpsData> group in groups)
            {
                DateTime startTimeRounded = group.Key;
                writeInfo("  StartTimeRounded=" + startTimeRounded);
                foreach (GpsData data in group)
                {
                    string fileName = data.FileName;
                    writeInfo("    " + data.FileName + " " + data.StartTime);
                }
            }

            // Prompt for which ones to keep
            List <GpsData> removeList    = new List <GpsData>();
            List <string>  fileNamesList = new List <string>();
            foreach (IGrouping <DateTime, GpsData> group in groups)
            {
                DateTime      startTimeRounded = group.Key;
                List <string> filesList        = new List <string>(group.Count());
                foreach (GpsData data in group)
                {
                    filesList.Add(data.FileName);
                }
                MultiChoiceCheckDialog dlg = new MultiChoiceCheckDialog(filesList);
                dlg.Label = "There are duplicate files for StartTime near "
                            + startTimeRounded + NL + "Select which files to use:";
                DialogResult dialogRes = dlg.ShowDialog();
                if (dialogRes == System.Windows.Forms.DialogResult.Abort)
                {
                    break;
                }
                if (dialogRes == System.Windows.Forms.DialogResult.Cancel)
                {
                    continue;
                }
                List <Result> results = dlg.Results;
                foreach (Result result in results)
                {
                    if (!result.Checked)
                    {
                        GpsData data =
                            exerciseDataList.Find(d => d.FileName.Equals(result.FileName));
                        if (data != null)
                        {
                            removeList.Add(data);
                        }
                        else
                        {
                            // Should not happen
                            writeInfo("  " + startTimeRounded + ": Did not find "
                                      + result.FileName + " in the data list");
                        }
                    }
                }
            }
            // Remove the duplicates
            writeInfo("  Removing " + removeList.Count + " duplicates");
            nErrors    = 0;
            failedList = new List <GpsData>();
            foreach (GpsData data in removeList)
            {
                res = exerciseDataList.Remove(data);
                if (!res)
                {
                    nErrors++;
                    failedList.Add(data);
                }
            }
            if (nErrors > 0)
            {
                writeInfo("  Failed to remove " + nErrors + " duplicate files");
            }
        }