public void Init() { m_Class = new GeoDataWorker(); }
public int ChangeGeoDataForFiles(IEnumerable<string> pathToImageFiles, string pathToTrack, int timezone, Action actionDuringIteration, out string errors) { errors = ""; if (pathToImageFiles.Count() == 0) return 0; IEnumerable<GeoData> track; try { using (var gpxeReader = new GpxFileReader(pathToTrack)) { track = gpxeReader.GetData(); } } catch (Exception e) { errors = String.Format(Resources.ErrorREadTrackFileUI, pathToTrack); m_Log.Error(String.Format(Resources.ErrorReadTrackFileLog, pathToTrack), e); return 0; } int countChangedFiles = 0; BlockingCollection<string> errosInProcces = new BlockingCollection<string>(); SynchronizationContext ctx = SynchronizationContext.Current; Parallel.ForEach(pathToImageFiles, file => { string error; var res = changeExifInformationInFile(file, createDirectoryForOutput(file), out error, (EXIFFileWorker photoExifInfo, out string er) => { er = ""; GeoData? geoData = new GeoDataWorker().GetGeoForPointByTime(photoExifInfo.GetDateTimeTaken().AddHours(-timezone), track); if (geoData == null) { er = String.Format(EXIFPhotoEditor.Properties.Resources.CantFindCoordsForPhotoUI, file); m_Log.ErrorFormat(EXIFPhotoEditor.Properties.Resources.CanTFindCoordsForPhotoLog, file); return false; } photoExifInfo.ChangeGeoData(geoData.Value.Latitude,geoData.Value.Longitude, geoData.Value.Altitude); return true; }); if (res) countChangedFiles++; else errosInProcces.Add(error); actionDuringIteration(); }); errors = errosInProcces.Aggregate("", (acum, str) => acum + str + "\r\n"); return countChangedFiles; }