private void ActionMarkRows()
        {
            DataGridView dataGridView = DataGridViewLocationHistory;

            dataGridView.ClearSelection();

            HashSet <FileEntry> files = DataGridViewHandler.GetSelectFileEntries(ActiveDataGridView, ActiveDataGridViewSelectedFilesMode);

            for (int columnIndex = 0; columnIndex < DataGridViewHandler.GetColumnCount(DataGridViewDateTime); columnIndex++)
            {
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(DataGridViewDateTime, columnIndex);
                if (dataGridViewGenericColumn != null)
                {
                    if (files.Contains(dataGridViewGenericColumn.FileEntryAttribute.FileEntry))
                    {
                        DateTime?dataTimeTaken       = DataGridViewHandlerDate.GetUserInputDateTaken(DataGridViewDateTime, columnIndex, null);
                        DateTime?dataTimeLocationUtc = DataGridViewHandlerDate.GetUserInputLocationDate(DataGridViewDateTime, columnIndex, null);
                        DateTime?dateTimeSuggestionFromGPSDateTime = DataGridViewHandlerDate.GetSuggestionFromGPSDate(DataGridViewDateTime, columnIndex, null);
                        FindAndSelect(dataTimeTaken, dataTimeLocationUtc, dateTimeSuggestionFromGPSDateTime);
                    }
                }
            }


            if (dataGridView.SelectedRows.Count > 0)
            {
                selectedRowsSorted.Clear();
                foreach (DataGridViewRow dataGridViewRow in dataGridView.SelectedRows)
                {
                    selectedRowsSorted.Add(dataGridViewRow.Index);
                }
                selectedRowsSorted.Sort();

                SetRowVisbible(visibleRowIndex);
                SetButtonStatus(enabledPreviousNext: selectedRowsSorted.Count > 0);
            }
            else
            {
                selectedRowsSorted.Clear();
                SetButtonStatus(enabledPreviousNext: selectedRowsSorted.Count > 0);
            }
            Properties.Settings.Default.LocationAnalyticsZoomLevel = (byte)comboBoxMapZoomLevel.SelectedIndex;
            GetLocationAndShow(MapProvider.OpenStreetMap);
            selectionChanged = false;
        }
Пример #2
0
        private void KryptonContextMenuItemMapReloadUsingNominatim_Click(object sender, EventArgs e)
        {
            DataGridView dataGridView    = dataGridViewMap;
            List <int>   selectedColumns = DataGridViewHandler.GetColumnSelected(dataGridView);

            if (selectedColumns.Count == 0)
            {
                return;
            }

            isDataGridViewMaps_CellValueChanging = true;
            int rowIndex = DataGridViewHandler.GetRowIndex(dataGridView, DataGridViewHandlerMap.headerMedia, DataGridViewHandlerMap.tagMediaCoordinates);

            //Reload data from Nomnatatim or if from database in case equal
            foreach (int columnIndex in selectedColumns)
            {
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);
                if (dataGridViewGenericColumn != null && dataGridViewGenericColumn?.FileEntryAttribute != null)
                {
                    AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumn?.FileEntryAttribute, forceReloadUsingReverseGeocoder: true);
                }
            }
            isDataGridViewMaps_CellValueChanging = false;
        }
Пример #3
0
        public static void PopulateGoogleHistoryCoordinateAndNearby(DataGridView dataGridViewMap, DataGridView dataGridViewDate, int columnIndexMap, int timeZoneShift, int accepedIntervalSecound)
        {
            #region Check if Aggegated
            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, columnIndexMap);
            if (dataGridViewGenericColumn == null)
            {
                return;
            }
            #endregion

            #region Get Metadata
            Metadata metadata = dataGridViewGenericColumn.Metadata;
            if (metadata == null)
            {
                DataGridViewHandler.SetCellValue(dataGridViewMap, columnIndexMap, headerGoogleLocations, tagGoogleCoordinateUTC, "No metadata loaded");
                return;
            }
            #endregion

            DateTime?dateTaken    = DataGridViewHandlerDate.GetUserInputDateTaken(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
            DateTime?locationDate = DataGridViewHandlerDate.GetUserInputLocationDate(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
            if (dateTaken == null)
            {
                dateTaken = metadata.MediaDateTaken;
            }
            if (locationDate == null)
            {
                locationDate = metadata.LocationDateTime;
            }

            PopulateGoogleHistoryCoordinate(
                dataGridViewMap, columnIndexMap, timeZoneShift, accepedIntervalSecound, dateTaken, locationDate, metadata);

            PopulateNearbyCoordinate(
                dataGridViewMap, columnIndexMap, timeZoneShift, accepedIntervalSecound, (DateTime)metadata.FileDate, dateTaken, locationDate);
        }
        public void Write(DataGridView dataGridView, int columnIndex)
        {
            List <PropertyKey> notSet = new List <PropertyKey>();

            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);

            if (dataGridViewGenericColumn == null)
            {
                return;                                    //continue;
            }
            string fullFileName = dataGridViewGenericColumn.FileEntryAttribute.FileFullPath;

            using (PropertyStore propertyStore = new PropertyStore(fullFileName, PropertyStore.GetFlags.ReadWrite | PropertyStore.GetFlags.SlowItem))
            {
                for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++)
                {
                    bool isReadOnly = DataGridViewHandler.GetCellReadOnly(dataGridView, columnIndex, rowIndex);
                    DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex);
                    object value = DataGridViewHandler.GetCellValue(dataGridView, columnIndex, rowIndex);

                    if (value is string)
                    {
                        PropertyKey propertyKey = dataGridViewGenericRow.PropertyKey;
                        string      valueString = (string)value;

                        if (!isReadOnly && propertyStore.IsEditable(propertyKey))
                        {
                            try
                            {
                                using (PropertyDescription propertyDescription = new PropertyDescription(propertyKey))
                                {
                                    if (!string.IsNullOrEmpty(valueString))
                                    {
                                        if (propertyDescription.TypeFlags.IsMultiValued)
                                        {
                                            valueString = valueString.Replace("\r\n", ";");
                                            PropVariant val = PropVariant.FromStringAsVector(valueString);
                                            propertyStore.SetValue(propertyKey, val);
                                        }
                                        else
                                        {
                                            switch (propertyDescription.PropertyType)
                                            {
                                            case VarEnum.VT_UI4:
                                                string cleanedString = new string(valueString.Where(char.IsDigit).ToArray());
                                                UInt32 valueUint32;
                                                if (UInt32.TryParse(cleanedString, out valueUint32))
                                                {
                                                    if (propertyKey.CanonicalName == "System.Rating")
                                                    {
                                                        valueUint32 = (UInt32)Metadata.ConvertRatingStarsToRatingPercent((byte)valueUint32);
                                                    }

                                                    propertyStore.SetValue(propertyKey, new PropVariant(valueUint32, propertyDescription.PropertyType));
                                                }
                                                else
                                                {
                                                    propertyStore.SetValue(propertyKey, new PropVariant());
                                                }
                                                break;

                                            case VarEnum.VT_DATE:
                                            case VarEnum.VT_FILETIME:
                                                string cleanedString2 = new string(valueString.Where(c => !char.IsControl(c)).ToArray());
                                                // https://social.msdn.microsoft.com/Forums/windows/en-US/61687b42-9882-4025-8b3a-b3251f121f94/how-to-prevent-a-textbox-to-accept-unicode-control-characters?forum=winforms
                                                cleanedString2 = Regex.Replace(cleanedString2, @"[\u200e-\u200f]", string.Empty);
                                                cleanedString2 = Regex.Replace(cleanedString2, @"[\u202a-\u202e]", string.Empty);
                                                cleanedString2 = Regex.Replace(cleanedString2, @"[\u206a-\u206f]", string.Empty);
                                                cleanedString2 = Regex.Replace(cleanedString2, @"[\u001e-\u001f]", string.Empty);

                                                DateTime valueDateTime;
                                                if (DateTime.TryParse(cleanedString2, out valueDateTime))
                                                {
                                                    propertyStore.SetValue(propertyKey, new PropVariant(valueDateTime.ToUniversalTime(), propertyDescription.PropertyType));
                                                }
                                                break;

                                            default:
                                                propertyStore.SetValue(propertyKey, new PropVariant(valueString, propertyDescription.PropertyType));
                                                break;
                                            }
                                        }
                                        //store.SetValue(key, new PropVariant(_displayProps[key], desc.PropertyType));
                                    }
                                    else
                                    {
                                        propertyStore.SetValue(propertyKey, new PropVariant());
                                    }
                                }
                                continue;
                            }
                            catch (Exception ex)
                            {
                                Logger.Error(ex);
                            }
                            notSet.Add(propertyKey);
                        }
                    }
                }
                propertyStore.Commit();
            }

            if (notSet.Count > 0)
            {
                throw new Exception("The following keys were not set:\n\t" + string.Join("\n\t", notSet.Select(k => k.CanonicalName)));
            }
        }
Пример #5
0
        public static void CopySelectedCellFromToDateCell(DataGridView dataGridView, bool overwrite, bool copyDate, bool copyTime)
        {
            Dictionary <CellLocation, DataGridViewGenericCell> updatedCells = new Dictionary <CellLocation, DataGridViewGenericCell>();

            string targetHeader     = headerMedia;
            string targetRowName    = tagMediaDateTaken;
            string targetRowNameUtc = tagGPSLocationDateTime;

            foreach (DataGridViewCell dataGridViewSelectedCell in dataGridView.SelectedCells)
            {
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, dataGridViewSelectedCell.ColumnIndex);
                if (dataGridViewGenericColumn.ReadWriteAccess == ReadWriteAccess.AllowCellReadAndWrite)
                {
                    int columnIndex       = dataGridViewSelectedCell.ColumnIndex;
                    int rowIndex          = dataGridViewSelectedCell.RowIndex;
                    int targetRowIndex    = DataGridViewHandler.GetRowIndex(dataGridView, targetHeader, targetRowName);
                    int targetRowIndexUtc = DataGridViewHandler.GetRowIndex(dataGridView, targetHeader, targetRowNameUtc);

                    DateTime?targetDateTime    = GetUserInputDateTaken(dataGridView, columnIndex, null);
                    DateTime?targetDateTimeUtc = GetUserInputLocationDate(dataGridView, columnIndex, null);

                    if (targetRowIndex != -1)
                    {
                        if (overwrite || (!overwrite && targetDateTime == null))
                        {
                            CellLocation            cellLocation = new CellLocation(columnIndex, targetRowIndex);
                            DataGridViewGenericCell dataGridViewGenericCellCopyFrom = DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridView, columnIndex, rowIndex);

                            if (dataGridViewGenericCellCopyFrom.Value != null)
                            {
                                bool     sourceHasDate     = false;
                                bool     sourceHasTime     = false;
                                bool     sourceHasUTC      = false;
                                DateTime?sourceDateTime    = null;
                                DateTime?sourceDateTimeUtc = null;

                                DateTimeOffset?sourceDateTimeOffset = TimeZoneLibrary.ParseExcatDateTimeOffset(dataGridViewGenericCellCopyFrom.Value.ToString());
                                if (sourceDateTimeOffset != null)
                                {
                                    sourceHasUTC   = true;
                                    sourceHasDate  = true;
                                    sourceHasTime  = true;
                                    sourceDateTime = new DateTime(
                                        ((DateTimeOffset)sourceDateTimeOffset).Year, ((DateTimeOffset)sourceDateTimeOffset).Month, ((DateTimeOffset)sourceDateTimeOffset).Day,
                                        ((DateTimeOffset)sourceDateTimeOffset).Hour, ((DateTimeOffset)sourceDateTimeOffset).Minute, ((DateTimeOffset)sourceDateTimeOffset).Second, ((DateTimeOffset)sourceDateTimeOffset).Millisecond);
                                    sourceDateTimeUtc = ((DateTimeOffset)sourceDateTimeOffset).UtcDateTime;
                                }
                                else
                                {
                                    sourceDateTimeOffset = TimeZoneLibrary.ParseExcatTimeOffset(dataGridViewGenericCellCopyFrom.Value.ToString());
                                    if (sourceDateTimeOffset != null)
                                    {
                                        sourceHasUTC   = true;
                                        sourceHasDate  = false;
                                        sourceHasTime  = true;
                                        sourceDateTime = new DateTime(1601, 1, 1,
                                                                      ((DateTimeOffset)sourceDateTimeOffset).Hour, ((DateTimeOffset)sourceDateTimeOffset).Minute, ((DateTimeOffset)sourceDateTimeOffset).Second, ((DateTimeOffset)sourceDateTimeOffset).Millisecond);
                                        sourceDateTimeUtc = ((DateTimeOffset)sourceDateTimeOffset).UtcDateTime;
                                    }
                                }

                                if (!sourceHasUTC)
                                {
                                    sourceDateTime = TimeZoneLibrary.ParseExactDateTimeAsLocal(dataGridViewGenericCellCopyFrom.Value.ToString());
                                    if (sourceDateTime != null)
                                    {
                                        sourceHasDate = true;
                                        sourceHasTime = true;
                                    }
                                    else
                                    {
                                        sourceDateTime = TimeZoneLibrary.ParseExactDateAsLocal(dataGridViewGenericCellCopyFrom.Value.ToString());
                                        if (sourceDateTime != null)
                                        {
                                            sourceHasDate = true;
                                            sourceHasTime = false;
                                        }
                                        else
                                        {
                                            sourceDateTime = TimeZoneLibrary.ParseExactTimeAsLocal(dataGridViewGenericCellCopyFrom.Value.ToString());
                                            if (sourceDateTime != null)
                                            {
                                                sourceHasDate = false;
                                                sourceHasTime = true;
                                            }
                                        }
                                    }
                                }

                                DateTime newTargetDateTime    = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Local);
                                DateTime newTargetDateTimeUtc = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                                if (targetDateTime == null)
                                {
                                    targetDateTime = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Local);
                                }
                                if (targetDateTimeUtc == null)
                                {
                                    targetDateTimeUtc = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                                }

                                if (copyDate && copyTime && sourceHasDate && sourceHasTime)
                                {
                                    newTargetDateTime = (DateTime)sourceDateTime;
                                    if (sourceHasUTC)
                                    {
                                        newTargetDateTimeUtc = (DateTime)sourceDateTimeUtc;
                                    }
                                }
                                else if (copyDate && sourceHasDate)
                                {
                                    newTargetDateTime = new DateTime(((DateTime)sourceDateTime).Year, ((DateTime)sourceDateTime).Month, ((DateTime)sourceDateTime).Day,
                                                                     ((DateTime)targetDateTime).Hour, ((DateTime)targetDateTime).Minute, ((DateTime)targetDateTime).Second, ((DateTime)targetDateTime).Millisecond, DateTimeKind.Local);

                                    if (sourceHasUTC)
                                    {
                                        newTargetDateTimeUtc = new DateTime(((DateTime)sourceDateTimeUtc).Year, ((DateTime)sourceDateTimeUtc).Month, ((DateTime)sourceDateTimeUtc).Day,
                                                                            ((DateTime)targetDateTimeUtc).Hour, ((DateTime)targetDateTimeUtc).Minute, ((DateTime)targetDateTimeUtc).Second, ((DateTime)targetDateTimeUtc).Millisecond, DateTimeKind.Utc);
                                    }
                                }
                                else if (copyTime && sourceHasTime)
                                {
                                    newTargetDateTime = new DateTime(((DateTime)targetDateTime).Year, ((DateTime)targetDateTime).Month, ((DateTime)targetDateTime).Day,
                                                                     ((DateTime)sourceDateTime).Hour, ((DateTime)sourceDateTime).Minute, ((DateTime)sourceDateTime).Second, ((DateTime)sourceDateTime).Millisecond, DateTimeKind.Local);

                                    if (sourceHasUTC)
                                    {
                                        newTargetDateTimeUtc = new DateTime(((DateTime)targetDateTimeUtc).Year, ((DateTime)targetDateTimeUtc).Month, ((DateTime)targetDateTimeUtc).Day,
                                                                            ((DateTime)sourceDateTimeUtc).Hour, ((DateTime)sourceDateTimeUtc).Minute, ((DateTime)sourceDateTimeUtc).Second, ((DateTime)sourceDateTimeUtc).Millisecond, DateTimeKind.Utc);
                                    }
                                }

                                if ((sourceHasDate || sourceHasTime) && targetDateTime != null && newTargetDateTime != (DateTime)targetDateTime)
                                {
                                    if (!updatedCells.ContainsKey(cellLocation))
                                    {
                                        updatedCells.Add(cellLocation, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridView, columnIndex, targetRowIndex));
                                    }
                                    DataGridViewHandler.SetCellValue(dataGridView, columnIndex, targetRowIndex, TimeZoneLibrary.ToStringSortable(newTargetDateTime), true);
                                }

                                if (sourceHasUTC && newTargetDateTimeUtc != targetDateTimeUtc)
                                {
                                    if (!updatedCells.ContainsKey(cellLocation))
                                    {
                                        updatedCells.Add(cellLocation, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridView, columnIndex, targetRowIndexUtc));
                                    }
                                    DataGridViewHandler.SetCellValue(dataGridView, columnIndex, targetRowIndexUtc, TimeZoneLibrary.ToStringSortable(newTargetDateTimeUtc), true);
                                }
                            }
                        }
                    }
                }
            }

            if (updatedCells != null && updatedCells.Count > 0)
            {
                ClipboardUtility.PushToUndoStack(dataGridView, updatedCells);
            }
        }
Пример #6
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);
        }
Пример #7
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;
        }
        private void ShowFormLocationHistoryAnalytics(DataGridView dataGridViewLocationHistory, DataGridView dataGridViewDate, DataGridView dataGridViewActive)
        {
            using (new WaitCursor())
            {
                SetButtonStatus(false);

                List <DateTime> datesFound   = new List <DateTime>();
                DateTime?       dateTimeFrom = null;
                DateTime?       dateTimeTo   = null;

                if (DataGridViewHandler.GetIsAgregated(dataGridViewActive))
                {
                    //ShowFormLocationHistoryAnalyticsInit();
                    PopulateMetadataLocationsClear(dataGridViewLocationHistory);

                    foreach (int columnIndex in DataGridViewHandler.GetColumnSelected(dataGridViewActive))
                    {
                        DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewActive, columnIndex);

                        if (dataGridViewGenericColumn != null)
                        {
                            DateTime?date = DataGridViewHandlerDate.GetUserInputDateTaken(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
                            if (date != null)
                            {
                                AddDatesFound((DateTime)date, ref datesFound);
                                if (dateTimeFrom == null || date < dateTimeFrom)
                                {
                                    dateTimeFrom = date;
                                }
                                if (dateTimeTo == null || date > dateTimeTo)
                                {
                                    dateTimeTo = date;
                                }
                            }

                            date = DataGridViewHandlerDate.GetUserInputLocationDate(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
                            if (date != null)
                            {
                                AddDatesFound((DateTime)date, ref datesFound);
                                if (dateTimeFrom == null || date < dateTimeFrom)
                                {
                                    dateTimeFrom = date;
                                }
                                if (dateTimeTo == null || date > dateTimeTo)
                                {
                                    dateTimeTo = date;
                                }
                            }

                            if (dataGridViewGenericColumn != null && dataGridViewGenericColumn.Metadata != null)
                            {
                                date = dataGridViewGenericColumn.Metadata.MediaDateTaken;
                                if (date != null)
                                {
                                    AddDatesFound((DateTime)date, ref datesFound);
                                    if (dateTimeFrom == null || date < dateTimeFrom)
                                    {
                                        dateTimeFrom = date;
                                    }
                                    if (dateTimeTo == null || date > dateTimeTo)
                                    {
                                        dateTimeTo = date;
                                    }
                                }

                                date = dataGridViewGenericColumn.Metadata.LocationDateTime;
                                if (date != null)
                                {
                                    AddDatesFound((DateTime)date, ref datesFound);
                                    if (dateTimeFrom == null || date < dateTimeFrom)
                                    {
                                        dateTimeFrom = date;
                                    }
                                    if (dateTimeTo == null || date > dateTimeTo)
                                    {
                                        dateTimeTo = date;
                                    }
                                }

                                //date = dataGridViewGenericColumn.Metadata.FileDateCreated;
                                //if (date != null)
                                //{
                                //    if (dateTimeFrom == null || date < dateTimeFrom) dateTimeFrom = date;
                                //    if (dateTimeTo == null || date > dateTimeTo) dateTimeTo = date;
                                //}

                                //date = dataGridViewGenericColumn.Metadata.FileDateModified;
                                //if (date != null)
                                //{
                                //    if (dateTimeFrom == null || date < dateTimeFrom) dateTimeFrom = date;
                                //    if (dateTimeTo == null || date > dateTimeTo) dateTimeTo = date;
                                //}

                                if (dataGridViewGenericColumn.Metadata.FileDateCreated != null && dataGridViewGenericColumn.Metadata.FileDateModified != null)
                                {
                                    date = (dataGridViewGenericColumn.Metadata.FileDateCreated < dataGridViewGenericColumn.Metadata.FileDateModified ? dataGridViewGenericColumn.Metadata.FileDateCreated : dataGridViewGenericColumn.Metadata.FileDateModified);
                                    AddDatesFound((DateTime)date, ref datesFound);
                                }
                            }
                        }
                    }

                    DateTime?dateTimeFoundFrom = null;
                    DateTime?dateTimeFoundTo   = null;
                    for (int index = 0; index < datesFound.Count - 1; index++)
                    {
                        if (index == 0)
                        {
                            dateTimeFoundFrom = datesFound[index];
                        }
                        if (datesFound[index].AddDays(1) != datesFound[index + 1])
                        {
                            dateTimeFoundTo = datesFound[index];
                        }
                        if (index == datesFound.Count - 2)
                        {
                            dateTimeFoundTo = datesFound[index + 1];
                        }
                        if (dateTimeFoundFrom != null && dateTimeFoundTo == null)
                        {
                            dateTimeFoundTo = ((DateTime)dateTimeFoundFrom).AddDays(1);
                        }
                        if (dateTimeFoundFrom == null && dateTimeFoundTo != null)
                        {
                            dateTimeFoundFrom = ((DateTime)dateTimeFoundTo).AddDays(-1);
                        }

                        if (dateTimeFoundFrom != null && dateTimeFoundTo != null)
                        {
                            PopulateMetadataLocationsAdd(dataGridViewLocationHistory, (DateTime)dateTimeFoundFrom, ((DateTime)dateTimeFoundTo).AddDays(1).AddMilliseconds(-1), Properties.Settings.Default.LocationAnalyticsMinimumTimeInterval * 60, (float)Properties.Settings.Default.LocationAnalyticsMinimumDistance);
                            dateTimeFoundFrom = datesFound[index + 1];
                            dateTimeFoundTo   = null;
                        }
                    }
                }

                if (dateTimeFrom != null)
                {
                    DefaultDateTimeFrom = new DateTime(((DateTime)dateTimeFrom).Year, ((DateTime)dateTimeFrom).Month, ((DateTime)dateTimeFrom).Day, 0, 0, 0, DateTimeKind.Utc);
                }
                if (dateTimeTo != null)
                {
                    DefaultDateTimeTo = new DateTime(((DateTime)dateTimeTo).Year, ((DateTime)dateTimeTo).Month, ((DateTime)dateTimeTo).Day, 0, 0, 0, DateTimeKind.Utc).AddDays(1);
                }
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
        public static void PopulateGrivViewMapNomnatatim(DataGridView dataGridView, int columnIndex, LocationCoordinate locationCoordinateSearch,
                                                         bool onlyFromCache, bool canReverseGeocoder, bool forceReloadUsingReverseGeocoder, bool createNewAccurateLocationUsingSearchLocation)
        {
            GlobalData.IsPopulatingMapLocation = true;
            try
            {
                LocationCoordinateAndDescription locationCoordinateAndDescriptionInDatabase = null;

                float locationAccuracyLatitude  = Properties.Settings.Default.LocationAccuracyLatitude;
                float locationAccuracyLongitude = Properties.Settings.Default.LocationAccuracyLongitude;

                //LocationDescription locationDescription = null;
                LocationDescription locationDescription = null;

                #region Get Location Info from User when allowed
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);
                if (!forceReloadUsingReverseGeocoder && dataGridViewGenericColumn?.Metadata != null)
                {
                    #region Get UserInput Location data
                    Metadata metadataUser = new Metadata(MetadataBrokerType.Empty);
                    GetUserInputChanges(dataGridView, ref metadataUser, null, columnIndex);
                    #endregion

                    if (!string.IsNullOrEmpty(metadataUser.LocationName) || !string.IsNullOrEmpty(metadataUser.LocationCity) ||
                        !string.IsNullOrEmpty(metadataUser.LocationState) || !string.IsNullOrEmpty(metadataUser.LocationCountry))
                    {
                        locationDescription = new LocationDescription(metadataUser.LocationName, metadataUser.LocationCity, metadataUser.LocationState, metadataUser.LocationCountry);

                        #region createNewAccurateLocationUsingSearchLocation
                        if (createNewAccurateLocationUsingSearchLocation)
                        {
                            try
                            {
                                LocationCoordinateAndDescription locationCoordinateAndDescriptionFromUserInput = new LocationCoordinateAndDescription(
                                    locationCoordinateSearch, locationDescription);
                                DatabaseAndCacheLocationAddress.WriteLocationName(locationCoordinateSearch, locationCoordinateAndDescriptionFromUserInput);

                                dataGridView.EndEdit();
                                //Remove + sign
                                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                             ReadWriteAccess.AllowCellReadAndWrite), locationCoordinateSearch.ToString(), false);
                            }
                            catch
                            {
                                //DEBUG
                            }
                        }
                        #endregion
                    }
                }
                #endregion

                if (locationCoordinateSearch != null)
                {
                    #region Get Nearby Location Coordinate and Info in Database
                    locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                        locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: onlyFromCache,
                        canReverseGeocoder: canReverseGeocoder, metadataLocationDescription: locationDescription, forceReloadUsingReverseGeocoder: false);
                    #endregion



                    #region If Asked to Reload, reload from UsingReverseGeocoder
                    if (forceReloadUsingReverseGeocoder && locationCoordinateAndDescriptionInDatabase != null)
                    {
                        locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                            locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: false,
                            canReverseGeocoder: true, metadataLocationDescription: null, forceReloadUsingReverseGeocoder: true);
                    }
                    #endregion
                }
                else
                {
                    #region No coordinates found
                    AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                 ReadWriteAccess.AllowCellReadAndWrite), null, false);
                    #endregion
                }
                #region Show Tooltip when Use need Nearby coordinate
                int rowIndex = DataGridViewHandler.GetRowIndex(dataGridView, headerMedia, tagMediaCoordinates);
                if (locationCoordinateAndDescriptionInDatabase != null && locationCoordinateSearch != locationCoordinateAndDescriptionInDatabase.Coordinate)
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Near by location used: " + locationCoordinateAndDescriptionInDatabase.Coordinate.ToString());
                }
                else
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "");
                }
                #endregion

                #region No data location data loaded, set as readonly
                bool isReadOnly = (locationCoordinateAndDescriptionInDatabase == null);
                #endregion

                #region Updated DataGridView with new data
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagLocationName, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Name, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCity, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.City, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagProvince, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Region, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCountry, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Country, isReadOnly);
                #endregion
            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n",
                                       "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true);
            }
            finally
            {
                GlobalData.IsPopulatingMapLocation = false;
            }
        }