コード例 #1
0
        public static int PopulateFile(DataGridView dataGridView, 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);
            //-----------------------------------------------------------------

            List <string> regionNamesAddedPeople       = new List <string>();
            List <string> regionNamesAddedTopMost      = new List <string>();
            List <string> regionNamesAddedDateInterval = new List <string>();


            for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++)
            {
                DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex);
                if (dataGridViewGenericRow != null && !dataGridViewGenericRow.IsHeader)
                {
                    if (dataGridViewGenericRow.HeaderName == headerPeople && !regionNamesAddedPeople.Contains(dataGridViewGenericRow.RowName))
                    {
                        regionNamesAddedPeople.Add(dataGridViewGenericRow.RowName);
                    }
                    else if (dataGridViewGenericRow.HeaderName == headerPeopleSuggestion && !regionNamesAddedDateInterval.Contains(dataGridViewGenericRow.RowName))
                    {
                        regionNamesAddedDateInterval.Add(dataGridViewGenericRow.RowName);
                    }
                    else if (dataGridViewGenericRow.HeaderName == headerPeopleMostUsed && !regionNamesAddedTopMost.Contains(dataGridViewGenericRow.RowName))
                    {
                        regionNamesAddedTopMost.Add(dataGridViewGenericRow.RowName);
                    }
                }
            }

            //-----------------------------------------------------------------

            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))
            {
                DataGridViewHandler.SetDataGridViewAllowUserToAddRows(dataGridView, true);

                AddRowHeader(dataGridView, columnIndex, new DataGridViewGenericRow(headerPeople), false);

                //Remove column data, due to Populate People append data -
                for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++)
                {
                    DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndex, null, false);
                    DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefault = new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, true);
                    DataGridViewHandler.SetCellDefaultAfterUpdated(dataGridView, dataGridViewGenericCellStatusDefault, columnIndex, rowIndex);
                }

                if (metadataExiftool != null)
                {
                    Metadata metadataCopy = new Metadata(metadataExiftool);
                    Metadata metadataWindowsLivePhotoGallery     = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery));
                    Metadata metadataWindowsLivePhotoGalleryCopy = metadataWindowsLivePhotoGallery == null ? null : new Metadata(metadataWindowsLivePhotoGallery);
                    Metadata metadataMicrosoftPhotos             = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos));
                    Metadata metadataMicrosoftPhotosCopy         = metadataMicrosoftPhotos == null ? null : new Metadata(metadataMicrosoftPhotos);
                    Metadata metadataWebScraping     = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping));
                    Metadata metadataWebScrapingCopy = metadataWebScraping == null ? null : new Metadata(metadataWebScraping);

                    //Remove doubles and add names where missing, only work with copy, don't change metadata in buffer.
                    //Don't remove region in ExifTool metadata when found other places

                    if (metadataWindowsLivePhotoGalleryCopy != null)
                    {
                        metadataCopy.PersonalRegionSetNamelessRegions(metadataWindowsLivePhotoGalleryCopy.PersonalRegionList);
                    }
                    if (metadataMicrosoftPhotosCopy != null)
                    {
                        metadataCopy.PersonalRegionSetNamelessRegions(metadataMicrosoftPhotosCopy.PersonalRegionList);
                    }

                    if (metadataWebScrapingCopy != null)
                    {
                        metadataWebScrapingCopy.MediaHeight      = metadataCopy.MediaHeight;
                        metadataWebScrapingCopy.MediaWidth       = metadataCopy.MediaWidth;
                        metadataWebScrapingCopy.MediaOrientation = metadataCopy.MediaOrientation;
                        metadataWebScrapingCopy.MediaVideoLength = metadataCopy.MediaVideoLength;

                        if (metadataCopy != null)
                        {
                            metadataCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList);
                        }
                        if (metadataWindowsLivePhotoGalleryCopy != null)
                        {
                            metadataWindowsLivePhotoGalleryCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList);
                        }
                        if (metadataMicrosoftPhotosCopy != null)
                        {
                            metadataMicrosoftPhotosCopy.PersonalRegionSetRegionlessRegions(metadataWebScrapingCopy.PersonalRegionList);
                        }
                    }


                    //Populate
                    PopulatePeople(dataGridView, metadataCopy, columnIndex, metadataCopy.Broker);
                    if (metadataWindowsLivePhotoGalleryCopy != null)
                    {
                        PopulatePeople(dataGridView, metadataWindowsLivePhotoGalleryCopy, columnIndex, metadataWindowsLivePhotoGalleryCopy.Broker);
                    }
                    if (metadataMicrosoftPhotosCopy != null)
                    {
                        PopulatePeople(dataGridView, metadataMicrosoftPhotosCopy, columnIndex, metadataMicrosoftPhotosCopy.Broker);
                    }
                    if (metadataWebScrapingCopy != null)
                    {
                        PopulatePeople(dataGridView, metadataWebScrapingCopy, columnIndex, metadataWebScrapingCopy.Broker);
                    }

                    //Remember names added
                    foreach (RegionStructure regionStructure in metadataExiftool.PersonalRegionList)
                    {
                        if (!regionNamesAddedPeople.Contains(regionStructure.Name))
                        {
                            regionNamesAddedPeople.Add(regionStructure.Name);
                        }
                    }
                }

                DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true);
            }

            if (FileEntryVersionHandler.IsCurrenOrUpdatedVersion(fileEntryAttribute.FileEntryVersion) && metadataExiftool != null)
            {
                #region Suggestion of Names - Near date
                int           columnIndexDummy     = -1;
                List <string> regioNameSuggestions = null;
                DateTime?     dateTimeSmartDate    = metadataExiftool.FileSmartDate(RenameDateFormats);

                if (dateTimeSmartDate != null)
                {
                    DateTime date         = new DateTime(((DateTime)dateTimeSmartDate).Year, ((DateTime)dateTimeSmartDate).Month, ((DateTime)dateTimeSmartDate).Day);
                    DateTime dateTimeFrom = date.AddDays(-SuggestRegionNameNearByDays);
                    DateTime dateTimeTo   = date.AddDays(SuggestRegionNameNearByDays);

                    bool isHeaderPeopleSuggestionAdded = false;
                    regioNameSuggestions = DatabaseAndCacheMetadataExiftool.ListAllRegionNamesNearByCache(MetadataBrokerType.ExifTool,
                                                                                                          (DateTime)dateTimeFrom, (DateTime)dateTimeTo, SuggestRegionNameNearByTopMostCount);

                    if (regioNameSuggestions != null && regioNameSuggestions.Count > 0)
                    {
                        foreach (string regionName in regioNameSuggestions)
                        {
                            if (!string.IsNullOrWhiteSpace(regionName))
                            {
                                if (regionNamesAddedTopMost.Contains(regionName))
                                {
                                    DataGridViewHandler.DeleteRow(dataGridView, headerPeopleMostUsed, regionName);
                                    regionNamesAddedTopMost.Remove(regionName);
                                }

                                if (!regionNamesAddedPeople.Contains(regionName))
                                {
                                    if (!isHeaderPeopleSuggestionAdded)
                                    {
                                        AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleSuggestion), false);
                                        isHeaderPeopleSuggestionAdded = true;
                                    }
                                    AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleSuggestion, regionName), true);
                                }
                            }
                        }
                    }
                }
                #endregion

                #region Suggestion of names - Top Most
                List <string> regioNamesTopMost = DatabaseAndCacheMetadataExiftool.ListAllPersonalRegionName(SuggestRegionNameNearByTopMostCount - regionNamesAddedTopMost.Count, regionNamesAddedPeople, regioNameSuggestions);
                if (regioNamesTopMost != null && regioNamesTopMost.Count > 0)
                {
                    AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleMostUsed), false);
                    foreach (string regionName in regioNamesTopMost)
                    {
                        AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleMostUsed, regionName), true);
                    }
                }
                #endregion

                AddRowHeader(dataGridView, columnIndexDummy, new DataGridViewGenericRow(headerPeopleAdded), false);
            }


            //DataGridViewHandler.Refresh(dataGridView);

            //-----------------------------------------------------------------
            DataGridViewHandler.SetIsPopulatingFile(dataGridView, false);
            //-----------------------------------------------------------------

            return(columnIndex);
        }
コード例 #2
0
        public static void PopulateFile(DataGridView dataGridView, FileEntryAttribute fileEntryAttribute, bool showFullPath, Metadata metadataAutoCorrected, bool onlyRefresh)
        {
            //-----------------------------------------------------------------
            //Chech if need to stop
            if (GlobalData.IsApplicationClosing)
            {
                return;
            }
            if (!DataGridViewHandler.GetIsAgregated(dataGridView))
            {
                return;                                                         //Not default columns or rows added
            }
            if (DataGridViewHandler.GetIsPopulatingFile(dataGridView))
            {
                return;                                                         //In progress doing so
            }
            //Check if file is in DataGridView, and needs updated
            if (!DataGridViewHandler.DoesColumnFilenameExist(dataGridView, headerNewFilename))
            {
                return;
            }
            if (!FileEntryVersionHandler.IsCurrenOrUpdatedVersion(fileEntryAttribute.FileEntryVersion))
            {
                return;
            }

            //When file found, Tell it's populating file, avoid two process updates
            DataGridViewHandler.SetIsPopulatingFile(dataGridView, true);
            //-----------------------------------------------------------------


            int columnIndex = DataGridViewHandler.GetColumnIndexFirstFullFilePath(dataGridView, headerNewFilename, false);

            if (columnIndex != -1)
            {
                Metadata metadata;
                if (metadataAutoCorrected != null)
                {
                    metadata = metadataAutoCorrected;
                }
                else
                {
                    metadata = DatabaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(fileEntryAttribute.GetFileEntryBroker(MetadataBrokerType.ExifTool));
                }

                #region Folder header
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(fileEntryAttribute.Directory), true);
                #endregion

                #region Filename
                string newShortOrFullFilename;
                if (metadata == null)
                {
                    newShortOrFullFilename = "Waiting metadata to be loaded";
                }
                else
                {
                    newShortOrFullFilename = GetShortOrFullFilename(RenameVaribale, metadata, showFullPath, fileEntryAttribute.Directory, fileEntryAttribute.FileName);
                }

                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(
                           fileEntryAttribute.Directory, fileEntryAttribute.FileName, metadata, fileEntryAttribute), newShortOrFullFilename, metadata == null);
                #endregion
            }

            //-----------------------------------------------------------------
            DataGridViewHandler.SetIsPopulatingFile(dataGridView, false);
            //-----------------------------------------------------------------
        }