示例#1
0
        private void UpdateGoodleHistoryCoordinateAndNearBy(int columnIndex)
        {
            DataGridView dataGridView = dataGridViewMap;

            if (!DataGridViewHandler.GetIsAgregated(dataGridView))
            {
                return;
            }


            DataGridViewHandlerMap.TimeZoneShift          = GetTimeZoneShift();
            DataGridViewHandlerMap.AccepedIntervalSecound = GetAccepedIntervalSecound();

            DataGridViewHandlerMap.PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, DataGridViewHandlerMap.TimeZoneShift, DataGridViewHandlerMap.AccepedIntervalSecound);
        }
示例#2
0
        public static void PopulateTimeZone(DataGridView dataGridViewDateTime, int?columnIndexDateTime, FileEntryAttribute fileEntryAttribute)
        {
            #region Check if all data IsAgregated, //need this check, due to Maps tab also updated this, when coordinates has been updated
            if (!DataGridViewHandler.GetIsAgregated(dataGridViewDateTime))
            {
                return;
            }
            if (columnIndexDateTime == null)
            {
                columnIndexDateTime = DataGridViewHandler.GetColumnIndexUserInput(dataGridViewDateTime, fileEntryAttribute);
            }
            if (columnIndexDateTime == -1)
            {
                return;
            }
            int columnIndex = (int)columnIndexDateTime;
            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewDateTime, columnIndex);
            if (dataGridViewGenericColumn == null)
            {
                return;
            }
            #endregion

            #region Get Media Date&Time and GPS Location Date&time from DataGridView or use Metadata
            //Get Date and Time for DataGridView
            DateTime?metadataMediaDateTaken   = GetUserInputDateTaken(dataGridViewDateTime, columnIndex, null);
            DateTime?metadataLocationDateTime = GetUserInputLocationDate(dataGridViewDateTime, columnIndex, null);
            if (metadataMediaDateTaken == null)
            {
                metadataMediaDateTaken = dataGridViewGenericColumn?.Metadata?.MediaDateTaken;
            }
            if (metadataLocationDateTime == null)
            {
                metadataLocationDateTime = dataGridViewGenericColumn?.Metadata?.LocationDateTime;
            }
            #endregion

            #region Get GPS Coorindates - 1. DataGridViewMap user input, 2. Metadata record 3. null
            //Get Media GPS Coordinates from DataGridViewMap is exist or use Metadata coordinates
            double?metadataLocationLatitude;
            double?metadataLocationLongitude;

            //If DataGridViewMap is agregated then pick up coordinates from what user have entered
            LocationCoordinate locationCoordinate = DataGridViewHandlerMap.GetUserInputLocationCoordinate(DataGridViewMap, null, dataGridViewGenericColumn.FileEntryAttribute);
            if (locationCoordinate != null)
            {
                metadataLocationLatitude  = locationCoordinate.Latitude;
                metadataLocationLongitude = locationCoordinate.Longitude;
            }
            else
            {
                metadataLocationLatitude  = dataGridViewGenericColumn?.Metadata?.LocationLatitude;
                metadataLocationLongitude = dataGridViewGenericColumn?.Metadata?.LocationLongitude;
            }
            #endregion


            //------------------------------------
            DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion), false);


            if (metadataLocationLatitude != null && metadataLocationLongitude != null)
            {
                TimeZoneInfo timeZoneInfoGPSLocation = TimeZoneLibrary.GetTimeZoneInfoOnGeoLocation((double)metadataLocationLatitude, (double)metadataLocationLongitude);

                if (timeZoneInfoGPSLocation != null)
                {
                    DateTime findOffsettDateTime;
                    if (metadataLocationDateTime != null)
                    {
                        findOffsettDateTime = (DateTime)metadataLocationDateTime;
                    }
                    else if (metadataLocationDateTime != null)
                    {
                        findOffsettDateTime = (DateTime)metadataMediaDateTaken;
                    }
                    else
                    {
                        findOffsettDateTime = DateTime.Now;
                    }

                    //Media header
                    DateTime       findOffsettDateTimeUTC = findOffsettDateTime.ToUniversalTime();
                    DateTimeOffset locationOffset         = new DateTimeOffset(findOffsettDateTimeUTC.Ticks, timeZoneInfoGPSLocation.GetUtcOffset(findOffsettDateTimeUTC));

                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationOffsetTimeZone),
                                               TimeZoneLibrary.ToStringOffset(locationOffset.Offset) + " " + TimeZoneLibrary.TimeZoneNameStandarOrDaylight(timeZoneInfoGPSLocation, findOffsettDateTimeUTC), true, false);

                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagCalulatedOffsetZimeZone), "", true, false);

                    //
                    if (metadataLocationDateTime != null)
                    {
                        DateTime locationDateTimeUTC = ((DateTime)metadataLocationDateTime).ToUniversalTime();
                        DateTime dateTimeFromGPS     = new DateTime(locationDateTimeUTC.Ticks).Add(locationOffset.Offset);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeFromGPS) + TimeZoneLibrary.ToStringOffset(locationOffset.Offset, false), true, false);
                    }
                    else
                    {
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime), "No GPS time found", true, false);
                    }

                    if (metadataMediaDateTaken != null)
                    {
                        DateTime       mediaTakenDateTimeUTC       = ((DateTime)metadataMediaDateTaken).ToUniversalTime();
                        DateTimeOffset mediaTakenDateTimeOffsetUTC = new DateTimeOffset(mediaTakenDateTimeUTC.Ticks, timeZoneInfoGPSLocation.GetUtcOffset(mediaTakenDateTimeUTC));

                        TimeSpan timeZoneDifferenceLocalAndLocation = timeZoneInfoGPSLocation.BaseUtcOffset - TimeZoneInfo.Local.BaseUtcOffset;
                        DateTime dateTimeUsedHomeClockOnTravel      = new DateTime(((DateTime)metadataMediaDateTaken).Ticks).Add(timeZoneDifferenceLocalAndLocation);

                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeUsedHomeClockOnTravel) + TimeZoneLibrary.ToStringOffset(mediaTakenDateTimeOffsetUTC.Offset, false), true, false);

                        timeZoneDifferenceLocalAndLocation = TimeZoneInfo.Local.BaseUtcOffset - timeZoneInfoGPSLocation.BaseUtcOffset;
                        dateTimeUsedHomeClockOnTravel      = new DateTime(((DateTime)metadataMediaDateTaken).Ticks).Add(timeZoneDifferenceLocalAndLocation);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeUsedHomeClockOnTravel) + TimeZoneLibrary.ToStringOffset(mediaTakenDateTimeOffsetUTC.Offset, false), true, false);
                    }
                    else
                    {
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "Can't find local time, location error", true, false);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "Can't find local time, location error", true, false);
                    }
                }
                else
                {
                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "Can't find local time", true, false);
                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "Can't find local time", true, false);
                }
            }
            else
            {
                //Media header
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationOffsetTimeZone), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagCalulatedOffsetZimeZone), "No GPS location found", true, false);
                //Suggestion header
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "No GPS location found", true, false);
            }

            // -------------------------------------------------------
            string   timeSpanString      = "(±??:??)";
            TimeSpan?timeSpan            = TimeZoneLibrary.CalulateTimeDiffrentWithoutTimeZone(metadataMediaDateTaken, metadataLocationDateTime);
            string   prefredTimeZoneName = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewDateTime, columnIndex, headerMedia, tagLocationOffsetTimeZone);
            DateTime?dateTimeLocation    = null;
            if (metadataMediaDateTaken != null)
            {
                dateTimeLocation = new DateTime(((DateTime)metadataMediaDateTaken).Ticks, DateTimeKind.Utc);
            }

            string timeZoneName = TimeZoneLibrary.GetTimeZoneName(timeSpan, dateTimeLocation, prefredTimeZoneName, out string timeZoneAlternatives);

            if (timeSpan != null)
            {
                timeSpanString = TimeZoneLibrary.ToStringOffset((TimeSpan)timeSpan);
            }


            int rowIndex = DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex,
                                                      new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagCalulatedOffsetZimeZone),
                                                      timeSpanString + " " + timeZoneName, true, false);

            DataGridViewHandler.SetCellToolTipText(dataGridViewDateTime, columnIndex, rowIndex, timeZoneAlternatives);
        }
示例#3
0
        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;
        }