private void dataGridViewMap_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex < 0) { return; } if (e.RowIndex < 0) { return; } if (isDataGridViewMaps_CellValueChanging) { return; //Avoid requirng isues } if (GlobalData.IsApplicationClosing) { return; } DataGridView dataGridView = ((DataGridView)sender); if (!dataGridView.Enabled) { return; } if (GlobalData.IsPopulatingMapLocation) { return; } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return; } if (DataGridViewHandler.GetIsPopulating(dataGridView)) { return; } DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, e.ColumnIndex); if (dataGridViewGenericColumn?.Metadata == null) { return; } DataGridViewGenericRow gridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, e.RowIndex); isDataGridViewMaps_CellValueChanging = true; /////////////////////////////////////////////////////////////////////////// /// Coordinate changes, updated Nomnatatim address /////////////////////////////////////////////////////////////////////////// if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerMedia) && gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagMediaCoordinates)) { string coordinate = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewMap, e.ColumnIndex, e.RowIndex); UpdateBrowserMap(coordinate, GetMapProvider()); DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, e.ColumnIndex); AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false); DataGridViewHandlerDate.PopulateTimeZone(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute); } /////////////////////////////////////////////////////////////////////////// /// Camera make and model owner changed, upated all fields /////////////////////////////////////////////////////////////////////////// else if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerGoogleLocations) && gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagCameraOwner)) { string selectedCameraOwner = DataGridViewHandlerMap.GetUserInputCameraOwner(dataGridView, e.ColumnIndex); DataGridViewHandlerMap.SetCameraOwner(dataGridView, e.ColumnIndex, selectedCameraOwner); if (!string.IsNullOrWhiteSpace(selectedCameraOwner)) { if (dataGridViewGenericColumn.Metadata != null) { CameraOwner cameraOwner = new CameraOwner( dataGridViewGenericColumn.Metadata.CameraMake, dataGridViewGenericColumn.Metadata.CameraModel, selectedCameraOwner); databaseAndCahceCameraOwner.SaveCameraMakeModelAndOwner(cameraOwner); databaseAndCahceCameraOwner.CameraMakeModelAndOwnerMakeDirty(); for (int columnIndex = 0; columnIndex < DataGridViewHandler.GetColumnCount(dataGridViewMap); columnIndex++) { DataGridViewGenericColumn gridViewGenericColumnCheck = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex); if (gridViewGenericColumnCheck?.Metadata == null) { //DEBUG } if (dataGridViewGenericColumn.Metadata == null) { //DEBUG } if (gridViewGenericColumnCheck?.Metadata?.CameraMake == dataGridViewGenericColumn.Metadata.CameraMake && gridViewGenericColumnCheck?.Metadata?.CameraModel == dataGridViewGenericColumn.Metadata.CameraModel) { DataGridViewHandlerMap.PopulateCameraOwner(dataGridView, columnIndex, gridViewGenericColumnCheck.ReadWriteAccess, gridViewGenericColumnCheck?.Metadata?.CameraMake, gridViewGenericColumnCheck?.Metadata?.CameraModel); DataGridViewHandlerMap.PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, GetTimeZoneShift(), GetAccepedIntervalSecound()); } } } } } /////////////////////////////////////////////////////////////////////////// /// Nomnatatim /////////////////////////////////////////////////////////////////////////// float locationAccuracyLatitude = Properties.Settings.Default.LocationAccuracyLatitude; float locationAccuracyLongitude = Properties.Settings.Default.LocationAccuracyLongitude; if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerNominatim)) { LocationCoordinate locationCoordinateNomnatatim = DataGridViewHandlerMap.GetUserInputLocationCoordinate(dataGridViewMap, e.ColumnIndex, null); bool createNewAccurateLocation = DataGridViewHandlerMap.GetUserInputIsCreateNewAccurateLocationUsingSearchLocation(dataGridViewMap, e.ColumnIndex, null); if (locationCoordinateNomnatatim != null) { #region Get Coordinateds enter by user LocationCoordinate locationCoordinateSearch = new LocationCoordinate( (float)locationCoordinateNomnatatim.Latitude, (float)locationCoordinateNomnatatim.Longitude); #endregion #region Get Coordinates use to store in database LocationCoordinateAndDescription locationCoordinateAndDescriptionFromDatabase = databaseLocationNameAndLookUp.ReadLocationNameFromDatabaseOrCache( locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude); #endregion #region Find nearby location in Datbase LocationCoordinate locationCoordinateFromDatabase; if (locationCoordinateAndDescriptionFromDatabase != null && !createNewAccurateLocation) { locationCoordinateFromDatabase = locationCoordinateAndDescriptionFromDatabase.Coordinate; //If exist, updated } else { locationCoordinateFromDatabase = locationCoordinateSearch; //If not, create new } LocationCoordinateAndDescription locationCoordinateAndDescriptionUpdated = new LocationCoordinateAndDescription ( locationCoordinateSearch, new LocationDescription( (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagLocationName), //Name (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCity), //City (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagProvince), //State (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCountry)) //Country ); #endregion #region Updated the database databaseLocationNameAndLookUp.AddressUpdate(locationCoordinateFromDatabase, locationCoordinateAndDescriptionUpdated, locationAccuracyLatitude, locationAccuracyLongitude); #endregion #region Updated DataGridView with new data for (int columnIndex = 0; columnIndex < dataGridViewMap.ColumnCount; columnIndex++) { DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, columnIndex); AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false); } #endregion } } isDataGridViewMaps_CellValueChanging = false; }
public static int PopulateFile(DataGridView dataGridView, DataGridView dataGridViewDate, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns, Metadata metadataAutoCorrected, bool onlyRefresh) { //----------------------------------------------------------------- //Chech if need to stop if (GlobalData.IsApplicationClosing) { return(-1); } if (!DataGridViewHandler.GetIsAgregated(dataGridView)) { return(-1); //Not default columns or rows added } if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return(-1); //In progress doing so } //Check if file is in DataGridView, and needs updated if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, fileEntryAttribute.FileFullPath)) { return(-1); } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- FileEntryBroker fileEntryBrokerReadVersion = fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryBrokerReadVersion); if (thumbnail == null && metadataAutoCorrected != null) { thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(metadataAutoCorrected.FileEntry); } Metadata metadataExiftool = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryBrokerReadVersion); if (metadataExiftool != null) { metadataExiftool = new Metadata(metadataExiftool); } if (metadataAutoCorrected != null) { metadataExiftool = metadataAutoCorrected; //If AutoCorrect is run, use AutoCorrect values. Needs to be after DataGridViewHandler.AddColumnOrUpdateNew, so orignal metadata stored will not be overwritten } ReadWriteAccess readWriteAccessColumn = (FileEntryVersionHandler.IsReadOnlyType(fileEntryAttribute.FileEntryVersion) || metadataExiftool == null) ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.AllowCellReadAndWrite; int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, metadataExiftool, readWriteAccessColumn, showWhatColumns, DataGridViewGenericCellStatus.DefaultEmpty(), out FileEntryVersionCompare fileEntryVersionCompareReason); //Chech if populated and new refresh data if (onlyRefresh && FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason) && !DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { fileEntryVersionCompareReason = FileEntryVersionCompare.LostNoneEqualFound_ContinueSearch; //No need to populate } //----------------------------------------------------------------- if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { //Media int rowIndex; AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates), metadataExiftool?.LocationCoordinate, false); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationName), metadataExiftool?.LocationName, false); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, metadataExiftool?.LocationName, null, null, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCity), metadataExiftool?.LocationCity, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagProvince), metadataExiftool?.LocationState, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCountry), metadataExiftool?.LocationCountry, false); //List<string> newKeywords = AutoKeywordHandler.NewKeywords(autoKeywordConvertions, metadataCopy.LocationName, metadataCopy.PersonalTitle, // metadataCopy.PersonalAlbum, metadataCopy.PersonalDescription, metadataCopy.PersonalComments, metadataCopy.PersonalKeywordTags); //Google location history AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations)); if (metadataExiftool != null) { CameraOwner cameraOwnerPrint = new CameraOwner(metadataExiftool.CameraMake, metadataExiftool.CameraModel, ""); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraMakeModel), cameraOwnerPrint, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraOwner), "Owner???", false); DataGridViewGenericColumn gridViewGenericColumnCheck = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex); PopulateCameraOwner(dataGridView, columnIndex, readWriteAccessColumn, metadataExiftool.CameraMake, metadataExiftool.CameraModel); } else { if (!DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagCameraMakeModel), "", false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagCameraOwner), "Select Camera owner/locations", true); } } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerGoogleLocations, tagGoogleCoordinateUTC), metadataExiftool?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNearByLocations)); PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, TimeZoneShift, AccepedIntervalSecound); //Nominatim.API AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim)); PopulateGrivViewMapNomnatatim(dataGridView, columnIndex, metadataExiftool?.LocationCoordinate, onlyFromCache: true, canReverseGeocoder: false, forceReloadUsingReverseGeocoder: false, createNewAccurateLocationUsingSearchLocation: false); //WebScraper //headerWebScraping = "WebScraper"; // WebScarping AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping)); Metadata metadataWebScraping = null; if (metadataExiftool != null) { metadataWebScraping = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagLocationName), metadataWebScraping?.LocationName, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagCountry), metadataWebScraping?.LocationCountry, true); //Microsoft Photos Locations Metadata metadataMicrosoftPhotos = null; if (metadataExiftool != null) { metadataMicrosoftPhotos = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase( new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagExternalCoordinates), metadataMicrosoftPhotos?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagLocationName), metadataMicrosoftPhotos?.LocationName, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagCity), metadataMicrosoftPhotos?.LocationCity, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagProvince), metadataMicrosoftPhotos?.LocationState, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagCountry), metadataMicrosoftPhotos?.LocationCountry, true); //Windows Live Photo Gallary Locations Metadata metadataWindowsLivePhotoGallery = null; if (metadataExiftool != null) { metadataWindowsLivePhotoGallery = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase( new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagExternalCoordinates), metadataWindowsLivePhotoGallery?.LocationCoordinate, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagLocationName), metadataWindowsLivePhotoGallery?.LocationName, true); //Browser AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerBrowser)); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerBrowser, tagExternalCoordinates), "", true); DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }