public static void SetPalette(KryptonForm kryptonForm, KryptonManager kryptonManager, IPalette newKryptonPalette, bool isSystemPalette, bool enableDropShadow) { KryptonPalette kryptonPalette = new KryptonPalette(); kryptonPalette.Import(((KryptonPalette)newKryptonPalette).Export(false, true)); //Make a copy kryptonManager.GlobalPalette = kryptonPalette; kryptonForm.UseDropShadow = enableDropShadow; if (isSystemPalette) { switch (((KryptonPalette)newKryptonPalette).BasePaletteMode) { case PaletteMode.Office2007Black: case PaletteMode.Office2010Black: case PaletteMode.Office365Black: //ColumnHeader - Normal - 0 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackHeaderNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextHeaderNormal(null); //ColumnHeader - Warning - 1 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom1.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackHeaderWarning(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom1.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextHeaderWarning(null); //ColumnHeader - Error - 2 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackCellError(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextCellError(null); //ColumnHeader - Image - 3 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackCellImage(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextCellImage(null); //Cell - Editable - (Normal / Favorite) - 0 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Back.Color2 = DataGridViewHandler.ColorBackCellFavorite(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Content.Color2 = DataGridViewHandler.ColorTextCellFavorite(null); //Cell - ReadOnly - 0 (Normal / Favorite) ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Back.Color2 = DataGridViewHandler.ColorBackCellFavoriteReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Content.Color2 = DataGridViewHandler.ColorTextCellFavoriteReadOnly(null); //Cell - Warning - 1 //Cell - Error - 2 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellError(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellError(null); //Cell - RegionFace - 3 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellImage(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellImage(null); break; case PaletteMode.Office2007Blue: case PaletteMode.Office2007Silver: case PaletteMode.Office2007White: case PaletteMode.Office2010Blue: case PaletteMode.Office2010Silver: case PaletteMode.Office2010White: case PaletteMode.Office2013White: case PaletteMode.Office365Blue: case PaletteMode.Office365Silver: case PaletteMode.Office365White: case PaletteMode.ProfessionalOffice2003: case PaletteMode.ProfessionalSystem: case PaletteMode.SparkleBlue: case PaletteMode.SparkleOrange: case PaletteMode.SparklePurple: //ColumnHeader - Normal - 0 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackHeaderNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextHeaderNormal(null); //ColumnHeader - Warning - 1 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom1.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackHeaderWarning(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom1.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextHeaderWarning(null); //ColumnHeader - Error - 2 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackCellError(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextCellError(null); //ColumnHeader - Image - 3 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateCommon.HeaderColumn.Back.Color1 = DataGridViewHandler.ColorBackCellImage(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateCommon.HeaderColumn.Content.Color1 = DataGridViewHandler.ColorTextCellImage(null); //Cell - Editable - (Normal / Favorite) - 0 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellNormal(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Back.Color2 = DataGridViewHandler.ColorBackCellFavorite(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateNormal.DataCell.Content.Color2 = DataGridViewHandler.ColorTextCellFavorite(null); //Cell - ReadOnly - 0 (Normal / Favorite) ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Back.Color2 = DataGridViewHandler.ColorBackCellFavoriteReadOnly(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCommon.StateDisabled.DataCell.Content.Color2 = DataGridViewHandler.ColorTextCellFavoriteReadOnly(null); //Cell - Warning - 1 //Cell - Error - 2 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellError(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom2.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellError(null); //Cell - RegionFace - 3 ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateNormal.DataCell.Back.Color1 = DataGridViewHandler.ColorBackCellImage(null); ((KryptonPalette)kryptonManager.GlobalPalette).GridStyles.GridCustom3.StateNormal.DataCell.Content.Color1 = DataGridViewHandler.ColorTextCellImage(null); break; default: throw new NotImplementedException(); } } }
private static void PopulateKeywords(DataGridView dataGridView, Metadata metadata, int columnIndex, MetadataBrokerType metadataBrokerType, FileEntryAttribute fileEntryAttribute) { foreach (KeywordTag tag in metadata.PersonalKeywordTags) { if (tag.Confidence >= MediaAiTagConfidence) { int rowIndex = AddRowKeywords(dataGridView, columnIndex, new DataGridViewGenericRow(headerKeywords, tag.Keyword, ReadWriteAccess.ForceCellToReadOnly), tag.Keyword, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Undefine, true), true); List <KeywordTag> keywordTags = new List <KeywordTag>(); keywordTags.Add(new KeywordTag(tag.Keyword)); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, null, null, keywordTags); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); //Updated default cell status with new staus DataGridViewGenericCellStatus dataGridViewGenericCellStatus = new DataGridViewGenericCellStatus(DataGridViewHandler.GetCellStatus(dataGridView, columnIndex, rowIndex)); dataGridViewGenericCellStatus.MetadataBrokerType |= metadataBrokerType; if (fileEntryAttribute.FileEntryVersion != FileEntryVersion.CompatibilityFixedAndAutoUpdated && fileEntryAttribute.FileEntryVersion != FileEntryVersion.MetadataToSave) { if (dataGridViewGenericCellStatus.SwitchState == SwitchStates.Undefine) { dataGridViewGenericCellStatus.SwitchState = (dataGridViewGenericCellStatus.MetadataBrokerType & MetadataBrokerType.ExifTool) == MetadataBrokerType.ExifTool ? SwitchStates.On : SwitchStates.Off; } } else { dataGridViewGenericCellStatus.SwitchState = (dataGridViewGenericCellStatus.MetadataBrokerType & MetadataBrokerType.ExifTool) == MetadataBrokerType.ExifTool ? SwitchStates.On : SwitchStates.Off; DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (dataGridViewGenericRow != null && dataGridViewGenericRow.ReadWriteAccess == ReadWriteAccess.AllowCellReadAndWrite) { dataGridViewGenericRow.ReadWriteAccess = ReadWriteAccess.ForceCellToReadOnly; for (int columnIndexUpdate = 0; columnIndexUpdate < DataGridViewHandler.GetColumnCount(dataGridView); columnIndexUpdate++) { DataGridViewHandler.SetCellReadOnlyDependingOfStatus(dataGridView, columnIndexUpdate, rowIndex, dataGridViewGenericCellStatus); } } } DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndex, dataGridViewGenericCellStatus, false); } } //If updated, check if any keyword are removed from the list int keywordsStarts = DataGridViewHandler.GetRowHeaderItemStarts(dataGridView, headerKeywords); int keywordsEnds = DataGridViewHandler.GetRowHeaderItemsEnds(dataGridView, headerKeywords); for (int rowIndex = keywordsStarts; rowIndex <= keywordsEnds; rowIndex++) { DataGridViewGenericCellStatus dataGridViewGenericCellStatus = DataGridViewHandler.GetCellStatus(dataGridView, columnIndex, rowIndex); if ((dataGridViewGenericCellStatus.MetadataBrokerType & metadataBrokerType) == metadataBrokerType) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (!metadata.PersonalKeywordTags.Contains(new KeywordTag(dataGridViewGenericRow.RowName))) { if ((dataGridViewGenericCellStatus.MetadataBrokerType & metadataBrokerType) == MetadataBrokerType.ExifTool && dataGridViewGenericCellStatus.SwitchState == SwitchStates.On) { dataGridViewGenericCellStatus.SwitchState = SwitchStates.Undefine; } dataGridViewGenericCellStatus.MetadataBrokerType &= ~metadataBrokerType; //Remove flag if line deleted DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndex, dataGridViewGenericCellStatus, false); } } } }
//Check what data has been updated by users public static void GetUserInputChanges(DataGridView dataGridView, ref Metadata metadata, FileEntryAttribute fileEntryColumn) { int columnIndex = DataGridViewHandler.GetColumnIndexUserInput(dataGridView, fileEntryColumn); if (columnIndex == -1) { return; //Column has not yet become aggregated or has already been removed } if (!DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { return; } int keywordsStarts = DataGridViewHandler.GetRowHeaderItemStarts(dataGridView, headerKeywords); int keywordsEnds = DataGridViewHandler.GetRowHeaderItemsEnds(dataGridView, headerKeywords); metadata.PersonalAlbum = (string)DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagAlbum); if (metadata.PersonalAlbum != null) { metadata.PersonalAlbum = metadata.PersonalAlbum.Trim(); } metadata.PersonalTitle = (string)DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagTitle); if (metadata.PersonalTitle != null) { metadata.PersonalTitle = metadata.PersonalTitle.Trim(); } metadata.PersonalDescription = (string)DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagDescription); if (metadata.PersonalDescription != null) { metadata.PersonalDescription = metadata.PersonalDescription.Trim(); } metadata.PersonalComments = (string)DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagComments); if (metadata.PersonalComments != null) { metadata.PersonalComments = metadata.PersonalComments.Trim(); } metadata.PersonalAuthor = (string)DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagAuthor); if (metadata.PersonalAuthor != null) { metadata.PersonalAuthor = metadata.PersonalAuthor.Trim(); } byte rating = 255; //empty var ratingValue = DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagRating); if (ratingValue == null) { } else if (ratingValue.GetType() == typeof(byte)) { rating = (byte)ratingValue; } else if (ratingValue.GetType() == typeof(int)) { rating = (byte)(int)ratingValue; } else if (ratingValue.GetType() == typeof(string)) { byte.TryParse((string)ratingValue, out rating); } if (rating >= 0 && rating <= 5) { metadata.PersonalRating = rating; } else { metadata.PersonalRating = null; } for (int rowIndex = keywordsStarts; rowIndex <= keywordsEnds; rowIndex++) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); SwitchStates switchStates = DataGridViewHandler.GetCellStatusSwichStatus(dataGridView, columnIndex, rowIndex); if (switchStates == SwitchStates.On) { //Add tag if (!metadata.PersonalKeywordTags.Contains(new KeywordTag(dataGridViewGenericRow.RowName))) { metadata.PersonalKeywordTags.Add(new KeywordTag(dataGridViewGenericRow.RowName)); } } else { //Remove tag if (metadata.PersonalKeywordTags.Contains(new KeywordTag(dataGridViewGenericRow.RowName))) { metadata.PersonalKeywordTags.Remove(new KeywordTag(dataGridViewGenericRow.RowName)); } } } }
private void dataGridViewDate_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (isDataGridViewDate_CellValueChanging) { return; //To avoid loop and stack overflow } if (GlobalData.IsApplicationClosing) { return; } //if (ClipboardUtility.IsClipboardActive) return; //if (GlobalData.IsDataGridViewCutPasteDeleteFindReplaceInProgress) return; if (e.ColumnIndex < 0) { return; } if (e.RowIndex < 0) { return; } DataGridView dataGridView = ((DataGridView)sender); //if (!dataGridView.Enabled) return; if (DataGridViewHandler.GetIsPopulatingFile(dataGridView)) { return; } if (DataGridViewHandler.GetIsPopulating(dataGridView)) { return; } //if (IsPopulatingAnything("Date Cell value changed")) return; DataGridViewGenericRow gridViewGenericDataRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, e.RowIndex); if (gridViewGenericDataRow == null) { return; } if (!gridViewGenericDataRow.HeaderName.Equals(DataGridViewHandlerDate.headerMedia)) { return; } isDataGridViewDate_CellValueChanging = true; if (gridViewGenericDataRow.RowName.Equals(DataGridViewHandlerDate.tagMediaDateTaken)) //headerMedia, tagMediaDateTaken { string dataTimeString = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, e.ColumnIndex, e.RowIndex); DateTimeOffset?dateTimeZoneResult = TimeZoneLibrary.ParseExcatDateTimeOffsetAsUTC(dataTimeString); if (dateTimeZoneResult != null) //If date and time has +00:00 offset { DateTime?dateTimeLocal = TimeZoneLibrary.ParseDateTimeAsLocal(dataTimeString.Substring(0, TimeZoneLibrary.AllowedDateTimeFormatsWithoutTimeZone[0].Length)); DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagMediaDateTaken), TimeZoneLibrary.ToStringSortable(dateTimeLocal), false, false); DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagGPSLocationDateTime), TimeZoneLibrary.ToStringW3CDTF_UTC(((DateTimeOffset)dateTimeZoneResult).UtcDateTime), false, false); } else { DateTime?dateTime = TimeZoneLibrary.ParseDateTimeAsLocal(dataTimeString); if (dateTime != null) { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagMediaDateTaken), TimeZoneLibrary.ToStringSortable((DateTime)dateTime), false, false); } else if (string.IsNullOrEmpty(dataTimeString)) { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagMediaDateTaken), "", false, false); } else { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagMediaDateTaken), "Error", false, false); } } } if (gridViewGenericDataRow.RowName.Equals(DataGridViewHandlerDate.tagGPSLocationDateTime)) //headerMedia, tagGPSLocationDateTime { string dataTimeString = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, e.ColumnIndex, e.RowIndex); DateTime?dateTime = TimeZoneLibrary.ParseDateTimeAsUTC(dataTimeString); if (dateTime != null) { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagGPSLocationDateTime), TimeZoneLibrary.ToStringW3CDTF_UTC((DateTime)dateTime), false, false); } else if (string.IsNullOrEmpty(dataTimeString)) { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagGPSLocationDateTime), "", false, false); } else { DataGridViewHandler.AddRow(dataGridView, e.ColumnIndex, new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagGPSLocationDateTime), "Error", false, false); } } DataGridViewHandlerDate.PopulateTimeZone(dataGridView, e.ColumnIndex, null); UpdateGoodleHistoryCoordinateAndNearBy(e.ColumnIndex); isDataGridViewDate_CellValueChanging = false; }
private static int AddRow(DataGridView dataGridView, int columnIndex, DataGridViewGenericRow dataGridViewGenericDataRow, object value, bool cellReadOnly) { int rowIndex = DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericDataRow, value, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, cellReadOnly), false); return(rowIndex); }
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 pasteToolStripMenuItem_Click(object sender, EventArgs e) { int instructionIndex = dgBody.SelectedRows.TopmostRow().Index + 1; foreach (Instruction instruction in _copiedInstructions.OrderByDescending(i => i.Offset)) { var newInstruction = new Instruction(instruction.OpCode); if (instruction.Operand != null) { switch (instruction.OpCode.OperandType) { case OperandType.InlineField: var field = instruction.Operand as IField; if (field.DeclaringType.DefinitionAssembly != CurrentAssembly.ManifestModule.Assembly || field.Module != CurrentAssembly.ManifestModule) { var fieldRef = new MemberRefUser(field.Module, field.Name, field.FieldSig, field.DeclaringType); newInstruction.Operand = CurrentAssembly.ManifestModule.Import(fieldRef); } else { newInstruction.Operand = CurrentAssembly.ManifestModule.ResolveField(field.Rid); } break; case OperandType.InlineMethod: var method = instruction.Operand as IMethod; if (method.DeclaringType.DefinitionAssembly != CurrentAssembly.ManifestModule.Assembly || method.Module != CurrentAssembly.ManifestModule) { var methodRef = new MemberRefUser(method.Module, method.Name, method.MethodSig, method.DeclaringType); newInstruction.Operand = CurrentAssembly.ManifestModule.Import(methodRef); } else { newInstruction.Operand = CurrentAssembly.ManifestModule.ResolveMethod(method.Rid); } break; case OperandType.InlineType: var type = instruction.Operand as ITypeDefOrRef; if (type.DefinitionAssembly != CurrentAssembly.ManifestModule.Assembly || type.Module != CurrentAssembly.ManifestModule) { var typeRef = new TypeRefUser(type.Module, type.Namespace, type.Name, CurrentAssembly.ManifestModule.CorLibTypes.AssemblyRef); newInstruction.Operand = CurrentAssembly.ManifestModule.Import(typeRef); } else { newInstruction.Operand = CurrentAssembly.ManifestModule.ResolveTypeDefOrRef(type.Rid); } break; default: newInstruction.Operand = instruction.Operand; break; } } CurrentAssembly.Method.Body.Instructions.Insert(instructionIndex, newInstruction); } FixBranches(); CurrentAssembly.Method.Body.Instructions.UpdateInstructionOffsets(); DataGridViewHandler.ReadMethod(CurrentAssembly.Method); }
private void SaveRename() { if (GlobalData.IsApplicationClosing) { return; } try { if (IsFileInAnyQueueLock(imageListView1.SelectedItems)) { DataGridViewHandlerRename.RenameVaribale = Properties.Settings.Default.RenameVariable; using (new WaitCursor()) { DataGridView dataGridView = dataGridViewRename; int columnIndex = DataGridViewHandler.GetColumnIndexFirstFullFilePath(dataGridView, DataGridViewHandlerRename.headerNewFilename, false); if (columnIndex == -1) { return; } for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewGenericCell cellGridViewGenericCell = DataGridViewHandler.GetCellDataGridViewGenericCellCopy(dataGridView, columnIndex, rowIndex); if (!cellGridViewGenericCell.CellStatus.CellReadOnly) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); #region Get Old filename from grid string oldFilename = dataGridViewGenericRow.RowName; string oldDirectory = dataGridViewGenericRow.HeaderName; string oldFullFilename = FileHandler.CombinePathAndName(oldDirectory, oldFilename); #endregion AddQueueRenameMediaFilesLock(oldFullFilename, DataGridViewHandlerRename.RenameVaribale); } } } } else { Dictionary <string, string> renameSuccess; Dictionary <string, RenameToNameAndResult> renameFailed; HashSet <string> directoriesCreated; DataGridViewHandlerRename.Write(dataGridViewRename, out renameSuccess, out renameFailed, out directoriesCreated, checkBoxRenameShowFullPath.Checked); UpdateImageViewListeAfterRename(imageListView1, renameSuccess, renameFailed, true); foreach (string newDirector in directoriesCreated) { GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = true; TreeViewFolderBrowserHandler.RefreshFolderWithName(treeViewFolderBrowser1, newDirector, true); GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = false; } ImageListView_SelectionChanged_Action_ImageListView_DataGridView(false); } } catch (Exception ex) { Logger.Error(ex, "Was not able to rename files"); KryptonMessageBox.Show("Was not able to rename files.\r\n" + ex.Message, "Rename files failed.", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } }
private void KryptonContextMenuItemLocationNamesShowFavoriteRows_Click(object sender, EventArgs e) { DataGridView dataGridView = kryptonDataGridViewLocationHistory; if (!dataGridView.Enabled) { return; } DataGridViewHandler.SetShowFavouriteColumns(dataGridView, !DataGridViewHandler.ShowFavouriteColumns(dataGridView)); //DataGridViewHandler.UpdatedStripMenuItem(dataGridView, (ToolStripMenuItem)sender, DataGridViewHandler.ShowFavouriteColumns(dataGridView)); DataGridViewHandler.SetRowsVisbleStatus(dataGridView, DataGridViewHandler.HideEqualColumns(dataGridView), DataGridViewHandler.ShowFavouriteColumns(dataGridView)); }
public static void GetUserInputChanges(DataGridView dataGridView, ref Metadata metadata, FileEntryAttribute fileEntryAttribute, int columnIndex = -1) { if (fileEntryAttribute == null && columnIndex == -1) { //DEBUG return; } if (columnIndex == -1) { columnIndex = DataGridViewHandler.GetColumnIndexUserInput(dataGridView, fileEntryAttribute); } if (columnIndex == -1) { return; //Column has not yet become aggregated or has already been removed } if (!DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex)) { return; } LocationCoordinate.TryParse(DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagMediaCoordinates), out LocationCoordinate locationCoordinate); metadata.LocationCoordinate = locationCoordinate; metadata.LocationName = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagLocationName); if (metadata.LocationName != null) { metadata.LocationName = metadata.LocationName.Trim(); } if (string.IsNullOrWhiteSpace(metadata.LocationName)) { metadata.LocationName = null; } metadata.LocationCity = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagCity); if (metadata.LocationCity != null) { metadata.LocationCity = metadata.LocationCity.Trim(); } if (string.IsNullOrWhiteSpace(metadata.LocationCity)) { metadata.LocationCity = null; } metadata.LocationState = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagProvince); if (metadata.LocationState != null) { metadata.LocationState = metadata.LocationState.Trim(); } if (string.IsNullOrWhiteSpace(metadata.LocationState)) { metadata.LocationState = null; } metadata.LocationCountry = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagCountry); if (metadata.LocationCountry != null) { metadata.LocationCountry = metadata.LocationCountry.Trim(); } if (string.IsNullOrWhiteSpace(metadata.LocationCountry)) { metadata.LocationCountry = null; } }
public DataGridViewGenericCell(object value, DataGridViewGenericCellStatus dataGridViewGenericCellStatus) { Value = DataGridViewHandler.DeepCopy(value); CellStatus = dataGridViewGenericCellStatus == null ? null : new DataGridViewGenericCellStatus(dataGridViewGenericCellStatus); }
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); }
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; } }
public static void SetCameraOwner(DataGridView dataGridView, int columnIndex, string value) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, headerGoogleLocations, tagCameraOwner, value); }
public static void CopyDataGridViewSelectedCellsToClipboard(DataGridView dataGridView, bool doCut, out bool textBoxSelectionCanRestore, out int textBoxSelectionStart, out int textBoxSelectionLength) { textBoxSelectionStart = 0; textBoxSelectionLength = 0; textBoxSelectionCanRestore = false; try { if (IsCurrentCellTextBoxAndInEditMode(dataGridView)) { TextBox textBox = dataGridView.EditingControl as TextBox; if (textBox != null) { if (doCut) { textBox.Cut(); } else { textBox.Copy(); } TextBoxGetSelction(textBox, out textBoxSelectionCanRestore, out textBoxSelectionStart, out textBoxSelectionLength); textBoxSelectionCanRestore = true; } } else { dataGridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; DataGridView dataGridViewCopy = new DataGridView(); DataGridViewHandler.DataGridViewInit(dataGridViewCopy, allowUserToAddRows: false); dataGridViewCopy.TopLeftHeaderCell.Value = dataGridView.TopLeftHeaderCell.Value; #region Add Columns List <int> selectedColumns = DataGridViewHandler.GetColumnSelected(dataGridView); selectedColumns.Sort(); foreach (int columnIndex in selectedColumns) { string columnName = DataGridViewHandler.GetColumnDataGridViewName(dataGridView, columnIndex); dataGridViewCopy.Columns.Add(columnName, columnName); } #endregion List <int> selectedRows = DataGridViewHandler.GetRowSelected(dataGridView); selectedRows.Sort(); foreach (int rowIndex in selectedRows) { string rowName = DataGridViewHandler.GetRowValue(dataGridView, rowIndex); int destinationRow = dataGridViewCopy.Rows.Add(); dataGridViewCopy.Rows[destinationRow].HeaderCell.Value = rowName; int destinationColumn = 0; foreach (int columnIndex in selectedColumns) { var cellValue = DataGridViewHandler.GetCellValue(dataGridView, columnIndex, rowIndex); if (cellValue is RegionStructure) { DataGridViewHandler.SetCellValue(dataGridViewCopy, destinationColumn, destinationRow, ((RegionStructure)cellValue).Name, true); } else { DataGridViewHandler.SetCellValue(dataGridViewCopy, destinationColumn, destinationRow, cellValue, true); } destinationColumn++; } } dataGridViewCopy.SelectAll(); dataGridViewCopy.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; DataObject dataObj = dataGridViewCopy.GetClipboardContent(); if (dataObj != null) { Clipboard.SetDataObject(dataObj, true); } } } catch (Exception ex) { KryptonMessageBox.Show("Can't copy cells to clipboard. Reason:\r\n\r\n" + ex.Message, "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } }
private void PopulateMetadataLocationNames(DataGridView dataGridView, HashSet <LocationsHistory> locationsHistories, int minimumIntervalSeconds, float minimumIntervalCoordinate) { DateTime? lastDateTime = null; LocationCoordinate lastLocationCoordinate = null; DataGridViewHandler.SuspendLayoutSetDelay(dataGridView, true); foreach (LocationsHistory locationsHistory in locationsHistories) { bool isNewFund = false; if (lastDateTime == null || lastLocationCoordinate == null) { isNewFund = true; } else { bool isMinimumTimeOk = false; bool isMinimumDistanceOk = false; if (Math.Abs(((DateTime)lastDateTime - locationsHistory.Timestamp).TotalSeconds) > minimumIntervalSeconds) { isMinimumTimeOk = true; } if (Math.Abs(locationsHistory.LocationCoordinate.Latitude - lastLocationCoordinate.Latitude) > minimumIntervalCoordinate) { isMinimumDistanceOk = true; } if (Math.Abs(locationsHistory.LocationCoordinate.Longitude - lastLocationCoordinate.Longitude) > minimumIntervalCoordinate) { isMinimumDistanceOk = true; } if (isMinimumTimeOk && isMinimumDistanceOk) { isNewFund = true; } } if (isNewFund) { lastDateTime = locationsHistory.Timestamp; lastLocationCoordinate = locationsHistory.LocationCoordinate; string group = locationsHistory.Timestamp.ToShortDateString(); string rowId = locationsHistory.Timestamp.ToShortTimeString(); LocationCoordinate value = locationsHistory.LocationCoordinate; DataGridViewHandler.AddRow(dataGridView, 0, new DataGridViewGenericRow(group), null, false, false); DataGridViewHandler.AddRow(dataGridView, columnIndexTimestamp, new DataGridViewGenericRow(group, rowId, value), TimeZone.TimeZoneLibrary.ToStringSortableUTC(locationsHistory.Timestamp), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndexUserAccount, new DataGridViewGenericRow(group, rowId, value), locationsHistory.UserAccount, true, false); DataGridViewHandler.AddRow(dataGridView, columnIndexCoordinate, new DataGridViewGenericRow(group, rowId, value), locationsHistory.LocationCoordinate.ToString(), true, false); DataGridViewHandler.AddRow(dataGridView, columnIndexAltitude, new DataGridViewGenericRow(group, rowId, value), locationsHistory.Altitude, true, false); DataGridViewHandler.AddRow(dataGridView, columnIndexAccuracy, new DataGridViewGenericRow(group, rowId, value), locationsHistory.Accuracy, true, false); } } DataGridViewHandler.ResumeLayoutDelayed(dataGridView); //isCellValueUpdating = false; }
public static void PasteDataGridViewSelectedCellsFromClipboard( DataGridView dataGridView, int leftColumnOverwrite, int rightColumnOverwrite, int topRowOverwrite, int buttomRowOverwrite, bool removeTag, out bool textBoxSelectionCanRestore, out int textBoxSelectionStart, out int textBoxSelectionLength) { textBoxSelectionStart = 0; textBoxSelectionLength = 0; textBoxSelectionCanRestore = false; #region Html Format // Try to process as html format (data from excel) since it keeps the row information intact, instead of assuming // a new row for every new line if we just process it as text String HtmlFormat = Clipboard.GetData("HTML Format") as String; List <List <string> > rowContents = new List <List <string> >(); if (HtmlFormat != null) { try { // Remove html tags to just extract row information and store it in rowContents System.Text.RegularExpressions.Regex TRregex = new System.Text.RegularExpressions.Regex(@"<( )*tr([^>])*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex TDregex = new System.Text.RegularExpressions.Regex(@"<( )*td([^>])*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match trMatch = TRregex.Match(HtmlFormat); while (!string.IsNullOrWhiteSpace(trMatch.Value)) { int rowStart = trMatch.Index + trMatch.Length; int rowEnd = HtmlFormat.IndexOf("</tr>", rowStart, StringComparison.InvariantCultureIgnoreCase); System.Text.RegularExpressions.Match tdMatch = TDregex.Match(HtmlFormat, rowStart, rowEnd - rowStart); List <string> rowContent = new List <string>(); while (!string.IsNullOrWhiteSpace(tdMatch.Value)) { int cellStart = tdMatch.Index + tdMatch.Length; int cellEnd = HtmlFormat.IndexOf("</td>", cellStart, StringComparison.InvariantCultureIgnoreCase); string cellContent = HtmlFormat.Substring(cellStart, cellEnd - cellStart); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*br( )*>", "\r\n", System.Text.RegularExpressions.RegexOptions.IgnoreCase); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*li( )*>", "\r\n - ", System.Text.RegularExpressions.RegexOptions.IgnoreCase); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*div([^>])*>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*code([^>])*>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*/code([^>])*>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); cellContent = System.Text.RegularExpressions.Regex.Replace(cellContent, @"<( )*p([^>])*>", "\r\n\r\n", System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (!cellContent.StartsWith("<B>")) //Don't paste Row Header { //cellContent = cellContent.Replace(" ", " "); cellContent = System.Net.WebUtility.HtmlDecode(cellContent); rowContent.Add(cellContent); } tdMatch = tdMatch.NextMatch(); } if (rowContent.Count > 0) { rowContents.Add(rowContent); } trMatch = trMatch.NextMatch(); } } catch { rowContents.Clear(); } } #endregion #region Text format if (rowContents.Count == 0) { // Clipboard is not in html format, read as text String CopiedText = Clipboard.GetText(); String[] lines = CopiedText.Split('\n'); foreach (string line in lines) { List <string> rowContent = new List <string>(line.Split('\t')); if (rowContent.Count > 0) { rowContents.Add(rowContent); } } } #endregion #region Paste into Edit cell if (IsCurrentCellTextBoxAndInEditMode(dataGridView)) { if (rowContents.Count >= 1) { string clipboardText = ""; foreach (List <string> textsInLine in rowContents) { string clipboardLine = ""; foreach (string text in textsInLine) { clipboardLine = clipboardLine + (string.IsNullOrWhiteSpace(clipboardLine) ? "" : " ") + text; } clipboardText = clipboardText + (string.IsNullOrWhiteSpace(clipboardText) ? "" : "\r\n") + clipboardLine; } Clipboard.SetText(clipboardText); } TextBox textBox = dataGridView.EditingControl as TextBox; if (textBox != null) { textBox.Paste(); TextBoxGetSelction(textBox, out textBoxSelectionCanRestore, out textBoxSelectionStart, out textBoxSelectionLength); textBoxSelectionCanRestore = true; } return; //Can return - don't need push to stach, Edit cell did push to stacj } #endregion // ----------------------------------------------------------------------------- // Put the feach data to cells // ----------------------------------------------------------------------------- Stack <CellLocation> selectedCells = new Stack <CellLocation>(); #region Find all - SelectedCells - and - topRow and leftColumn - int topRow = int.MaxValue; int leftColumn = int.MaxValue; foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells) { topRow = Math.Min(topRow, dataGridViewCell.RowIndex); leftColumn = Math.Min(leftColumn, dataGridViewCell.ColumnIndex); selectedCells.Push(new CellLocation(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex)); } int iRow = topRow; #endregion #region Add Rows if needed if (dataGridView.AllowUserToAddRows) { // DataGridView's rowCount has one extra row (the temporary new row) if (iRow + rowContents.Count > dataGridView.Rows.Count - 1) { int iNumNewRows = iRow + rowContents.Count - dataGridView.Rows.Count + 1; // Simply add to a new row to the datagridview if it is not binded to a datasource if (dataGridView.DataSource == null) { //dataGridView.Rows.Add(iNumNewRows); //This will change the selected cell for (int i = 0; i < iNumNewRows; i++) { dataGridView.Rows.Add(); } dataGridView.ClearSelection(); //Remove the selection and select it back after } // Otherwise, add rows to binded data source else { try { BindingSource bindingSource = dataGridView.DataSource as BindingSource; if (bindingSource != null) { // This is important!! // Cancel Edit before adding new entries into bindingsource // If the UI is currently adding a new line (you have your cursor on the last time) // You will System.InvalidOperationException bindingSource.CancelEdit(); for (int i = 0; i < iNumNewRows; i++) { Object obj = bindingSource.AddNew(); dataGridView.ClearSelection(); } } } catch { // failed adding row to binding data source // It was okay for my application to ignore the error } } } } #endregion #region New rows added, and selection forgoten. Need to reselect if (dataGridView.SelectedCells.Count == 0) { while (selectedCells.Count > 0) { CellLocation cell = selectedCells.Pop(); dataGridView[cell.ColumnIndex, cell.RowIndex].Selected = true; } } #endregion //Paste one clipboard "cell/text" to all selected (Only one text to more than one selected cell) //Paste many clipbaord "cell/text" to selected fields (Paste to more than one selected cell) //Paste many clipbaord "cell/text" bases on current location (Paste to one selected cell) Dictionary <CellLocation, DataGridViewGenericCell> undoCells = new Dictionary <CellLocation, DataGridViewGenericCell>(); #region Count rows and columns in selctions List <int> columnsSelected = new List <int>(); List <int> rowsSelected = new List <int>(); foreach (CellLocation cellLocationCount in selectedCells) { if (!columnsSelected.Contains(cellLocationCount.ColumnIndex)) { columnsSelected.Add(cellLocationCount.ColumnIndex); } if (!rowsSelected.Contains(cellLocationCount.RowIndex)) { rowsSelected.Add(cellLocationCount.RowIndex); } } #endregion int columnConentsCount = 0; if (rowContents.Count > 0) { columnConentsCount = rowContents[0].Count; } #region Paste one clipboard "cell/text" to all selected (Only one text to more than one selected cell) #region Paste - Source: Nothing selected - nothing to do if (rowContents.Count == 0 && columnConentsCount == 0) { //Nothing found } #endregion #region Paste - Sourec: One Cell Selected (rowContents.Count == 1 && columnConentsCount == 1) else if (rowContents.Count == 1 && columnConentsCount == 1) { NuberOfItemsToEdit = dataGridView.SelectedCells.Count; IsClipboardActive = true; foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells) { String cellContent = rowContents[0][0]; try { if (!dataGridViewCell.ReadOnly || (dataGridViewCell.ColumnIndex >= leftColumnOverwrite && dataGridViewCell.ColumnIndex <= rightColumnOverwrite && dataGridViewCell.RowIndex >= topRowOverwrite && dataGridViewCell.RowIndex <= buttomRowOverwrite) ) { //Rememebr in the current value in cell before changed so we can "ReDo" in current DataGridView CellLocation cellPosition = new CellLocation(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); undoCells.Add(cellPosition, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridView[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex])); DataGridViewHandler.SetCellValue(dataGridView, dataGridViewCell, Convert.ChangeType(cellContent, dataGridViewCell.ValueType)); if (removeTag) { DataGridViewHandler.SetCellStatusSwichStatus(dataGridView, dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex, SwitchStates.Undefine); } dataGridView.InvalidateCell(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); } } catch { } } NuberOfItemsToEdit = 0; IsClipboardActive = false; } #endregion #region Paste - One row, and multimple columns, Only cell selected / one row from clipboard to multiple rows else if ( rowContents.Count == 1 && columnConentsCount > 1 && //One row, and multimple columns columnsSelected.Count > 1 && rowsSelected.Count >= 1) //Only cell selected { if (columnConentsCount != columnsSelected.Count) { KryptonMessageBox.Show("Can't paste selection. Can only paste selection when have selected equal numbers of columns.\r\n" + "Columns selected for copy: " + columnConentsCount + "\r\n" + "Columns selected for paste: " + columnsSelected.Count, "Can't paste selected text", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); return; } NuberOfItemsToEdit = columnsSelected.Count * rowsSelected.Count; IsClipboardActive = true; columnsSelected.Sort(); for (int columnIndex = 0; columnIndex < rowContents[0].Count; columnIndex++) { String cellContent = rowContents[0][columnIndex]; //Row content will always be 1 int columnIndexPaste = columnsSelected[columnIndex]; foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells) { if (dataGridViewCell.ColumnIndex == columnIndexPaste) { try { if (!dataGridViewCell.ReadOnly || (dataGridViewCell.ColumnIndex >= leftColumnOverwrite && dataGridViewCell.ColumnIndex <= rightColumnOverwrite && dataGridViewCell.RowIndex >= topRowOverwrite && dataGridViewCell.RowIndex <= buttomRowOverwrite) ) { //Rememebr in the current value in cell before changed so we can "ReDo" in current DataGridView CellLocation cellPosition = new CellLocation(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); undoCells.Add(cellPosition, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridViewCell)); DataGridViewHandler.SetCellValue(dataGridView, dataGridViewCell, Convert.ChangeType(cellContent, dataGridViewCell.ValueType)); if (removeTag) { DataGridViewHandler.SetCellStatusSwichStatus(dataGridView, dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex, SwitchStates.Undefine); } dataGridView.InvalidateCell(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); } } catch { } } } } NuberOfItemsToEdit = 0; IsClipboardActive = false; } #endregion #region Paste - one column from clipboard to multiple columns / Only cell selected else if (rowContents.Count > 1 && columnConentsCount == 1 && //One column, and multimple rows !(columnsSelected.Count == 1 && rowsSelected.Count == 1)) //Only cell selected { if (rowContents.Count != rowsSelected.Count) { KryptonMessageBox.Show("Can't paste selection. Can only paste selection when have selected equal numbers of rows.\r\n" + "Rows selected for copy: " + rowContents.Count + "\r\n" + "Rows selected for paste: " + rowsSelected.Count, "Can't paste selected text", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); return; } NuberOfItemsToEdit = columnsSelected.Count * rowsSelected.Count; IsClipboardActive = true; rowsSelected.Sort(); for (int rowIndex = 0; rowIndex < rowContents.Count; rowIndex++) { String cellContent = rowContents[rowIndex][0]; foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells) { int columnIndexPaste = rowsSelected[rowIndex]; if (dataGridViewCell.RowIndex == columnIndexPaste) { try { if (!dataGridViewCell.ReadOnly || (dataGridViewCell.ColumnIndex >= leftColumnOverwrite && dataGridViewCell.ColumnIndex <= rightColumnOverwrite && dataGridViewCell.RowIndex >= topRowOverwrite && dataGridViewCell.RowIndex <= buttomRowOverwrite) ) { //Rememebr in the current value in cell before changed so we can "ReDo" in current DataGridView CellLocation cellPosition = new CellLocation(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); undoCells.Add(cellPosition, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridViewCell)); DataGridViewHandler.SetCellValue(dataGridView, dataGridViewCell, Convert.ChangeType(cellContent, dataGridViewCell.ValueType)); if (removeTag) { DataGridViewHandler.SetCellStatusSwichStatus(dataGridView, dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex, SwitchStates.Undefine); } dataGridView.InvalidateCell(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); } } catch { } } } } NuberOfItemsToEdit = 0; IsClipboardActive = false; } #endregion #region Paste - rest else { NuberOfItemsToEdit = columnsSelected.Count * rowsSelected.Count; IsClipboardActive = true; foreach (List <string> rowContent in rowContents) { int iCol = leftColumn; foreach (string cellContent in rowContent) { try { bool cellOk = false; if (dataGridView.SelectedCells.Count == 1) { cellOk = true; } else { foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells) { if (dataGridViewCell.ColumnIndex == iCol && dataGridViewCell.RowIndex == iRow) { cellOk = true; } } } if (cellOk) { if (iCol < dataGridView.Columns.Count) { DataGridViewCell cell = dataGridView[iCol, iRow]; //if (!cell.ReadOnly) if (!cell.ReadOnly || (cell.ColumnIndex >= leftColumnOverwrite && cell.ColumnIndex <= rightColumnOverwrite && cell.RowIndex >= topRowOverwrite && cell.RowIndex <= buttomRowOverwrite) ) { //Rememebr in the current value in cell before changed so we can "ReDo" in current DataGridView CellLocation cellPosition = new CellLocation(iCol, iRow); undoCells.Add(cellPosition, DataGridViewHandler.CopyCellDataGridViewGenericCell(dataGridView, iCol, iRow)); DataGridViewHandler.SetCellValue(dataGridView, cell, Convert.ChangeType(cellContent, cell.ValueType)); if (removeTag) { DataGridViewHandler.SetCellStatusSwichStatus(dataGridView, cell.ColumnIndex, cell.RowIndex, SwitchStates.Undefine); } dataGridView.InvalidateCell(iCol, iRow); } } } } catch { } iCol++; } iRow++; if (iRow >= dataGridView.Rows.Count) { break; } } NuberOfItemsToEdit = 0; IsClipboardActive = false; dataGridView.ResumeLayout(); } #endregion #endregion //CAN BE REMOVED foreach (CellLocation cellLocation in undoCells.Keys) dataGridView[cellLocation.ColumnIndex, cellLocation.RowIndex].Selected = true; //Already done, can be removed after check PushToUndoStack(dataGridView, undoCells); }
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); } } }
public static void PopulateFile(DataGridView dataGridView, FileEntryAttribute fileEntryAttribute, ShowWhatColumns showWhatColumns) { //----------------------------------------------------------------- //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, fileEntryAttribute.FileFullPath)) { return; } //When file found, Tell it's populating file, avoid two process updates DataGridViewHandler.SetIsPopulatingFile(dataGridView, true); //----------------------------------------------------------------- exiftoolReader.MetadataReadPrioity.ReadOnlyOnce(); Image thumbnail = DatabaseAndCacheThumbnail.ReadThumbnailFromCacheOnly(fileEntryAttribute); int columnIndex = DataGridViewHandler.AddColumnOrUpdateNew( dataGridView, fileEntryAttribute, thumbnail, null, ReadWriteAccess.ForceCellToReadOnly, showWhatColumns, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, true), out FileEntryVersionCompare fileEntryVersionCompareReason); if (FileEntryVersionHandler.NeedUpdate(fileEntryVersionCompareReason)) { //Clear old content, in case of new values are updated or deleted for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndex, null, false); } List <ExiftoolData> exifToolDataList = DatabaseExiftoolData.Read(fileEntryAttribute); string lastRegion = ""; foreach (ExiftoolData exiftoolData in exifToolDataList) { if (lastRegion != exiftoolData.Region) { DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(exiftoolData.Region), null, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, true), false); lastRegion = exiftoolData.Region; } MetadataPriorityKey metadataPriorityKey = new MetadataPriorityKey(exiftoolData.Region, exiftoolData.Command); MetadataPriorityGroup metadataPriorityGroup = null; bool priorityKeyExisit = exiftoolReader.MetadataReadPrioity.MetadataPrioityDictionary.ContainsKey(metadataPriorityKey); if (priorityKeyExisit) { metadataPriorityGroup = new MetadataPriorityGroup(metadataPriorityKey, exiftoolReader.MetadataReadPrioity.MetadataPrioityDictionary[metadataPriorityKey]); if (metadataPriorityGroup.MetadataPriorityValues.Composite == CompositeTags.NotDefined) { priorityKeyExisit = false; } } int rowIndex = DataGridViewHandler.AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(exiftoolData.Region, exiftoolData.Command, true, metadataPriorityKey), exiftoolData.Parameter, new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Disabled, true), true); if (priorityKeyExisit) { DataGridViewHandler.SetRowToolTipText(dataGridView, rowIndex, metadataPriorityGroup.ToString()); } else { DataGridViewHandler.SetRowToolTipText(dataGridView, rowIndex, ""); } } DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- }
public static void Write(DataGridView dataGridView, out Dictionary <string, string> renameSuccess, out Dictionary <string, RenameToNameAndResult> renameFailed, out HashSet <string> directoryCreated, bool showFullPathIsUsed) { using (new WaitCursor()) { renameSuccess = new Dictionary <string, string>(); renameFailed = new Dictionary <string, RenameToNameAndResult>(); directoryCreated = new HashSet <string>(); int columnIndex = DataGridViewHandler.GetColumnIndexFirstFullFilePath(dataGridView, headerNewFilename, false); if (columnIndex == -1) { return; } for (int rowIndex = 0; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewGenericCell cellGridViewGenericCell = DataGridViewHandler.GetCellDataGridViewGenericCellCopy(dataGridView, columnIndex, rowIndex); if (!cellGridViewGenericCell.CellStatus.CellReadOnly) { DataGridViewGenericRow dataGridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); #region Get Old filename from grid string oldFilename = dataGridViewGenericRow.RowName; string oldDirectory = dataGridViewGenericRow.HeaderName; string oldFullFilename = FileHandler.CombinePathAndName(oldDirectory, oldFilename); #endregion #region Get New filename from grid and rename if (dataGridViewGenericRow.Metadata != null) { string newFullFilename = FileHandler.CombinePathAndName(oldDirectory, DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, rowIndex)); string newDirectory = Path.GetDirectoryName(newFullFilename); if (!Directory.Exists(newDirectory) && !directoryCreated.Contains(newDirectory)) { directoryCreated.Add(newDirectory); } FilesCutCopyPasteDrag.RenameFile(oldFullFilename, newFullFilename, ref renameSuccess, ref renameFailed); } #endregion } } } }
private void InitializeBody() { DataGridViewHandler.InitializeBody(); }
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); //----------------------------------------------------------------- }
private static int AddRow(DataGridView dataGridView, int columnIndex, DataGridViewGenericRow dataGridViewGenericDataRow, bool sort) { return(DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericDataRow, sort)); }
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); }
private static int AddRowKeywords(DataGridView dataGridView, int columnIndex, DataGridViewGenericRow dataGridViewGenericDataRow, object value, DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefaults, bool sort) { int rowIndex = DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericDataRow, value, dataGridViewGenericCellStatusDefaults, sort); return(rowIndex); }
public static void SetCellDefault(DataGridView dataGridView, MetadataBrokerType metadataBrokerType, int columnIndex, int rowIndexUsed) { DataGridViewHandler.SetCellDefaultAfterUpdated(dataGridView, metadataBrokerType, columnIndex, rowIndexUsed); }
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 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)) { DataGridViewHandler.SetDataGridViewAllowUserToAddRows(dataGridView, true); //Media int rowIndex; AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia), false); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagAlbum), metadataExiftool?.PersonalAlbum, false); List <string> newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, metadataExiftool?.PersonalAlbum, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagTitle), metadataExiftool?.PersonalTitle, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, metadataExiftool?.PersonalTitle, null, null, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagDescription), metadataExiftool?.PersonalDescription, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, metadataExiftool?.PersonalDescription, null, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); rowIndex = AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagComments), metadataExiftool?.PersonalComments, false); newKeywords = AutoKeywordHandler.NewKeywords(AutoKeywordConvertions, null, null, null, null, metadataExiftool?.PersonalComments, null); DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Running AutoCorrect will add these keywords", newKeywords); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagRating), metadataExiftool?.PersonalRating, false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagAuthor), metadataExiftool?.PersonalAuthor, false); // Microsoft Phontos AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos), false); Metadata metadataMicrosoftPhotos = null; if (metadataExiftool != null) { metadataMicrosoftPhotos = DatabaseAndCacheMetadataMicrosoftPhotos.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.MicrosoftPhotos)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagAlbum), metadataMicrosoftPhotos?.PersonalAlbum, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMicrosoftPhotos, tagTitle), metadataMicrosoftPhotos?.PersonalTitle, true); // Folder path as Album AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerFolder), false); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerFolder, tagAlbum), new DirectoryInfo(fileEntryBrokerReadVersion.Directory).Name, true); //Windows Live Photo Gallery AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery), false); Metadata metadataWindowsLivePhotoGallery = null; if (metadataExiftool != null) { metadataWindowsLivePhotoGallery = DatabaseAndCacheMetadataWindowsLivePhotoGallery.ReadMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WindowsLivePhotoGallery)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagTitle), metadataWindowsLivePhotoGallery?.PersonalTitle, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWindowsLivePhotoGallery, tagRating), metadataWindowsLivePhotoGallery?.PersonalRating, true); // WebScarping AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping), false); Metadata metadataWebScraping = null; if (metadataExiftool != null) { metadataWebScraping = DatabaseAndCacheMetadataExiftool.ReadWebScraperMetadataFromCacheOrDatabase(new FileEntryBroker(fileEntryBrokerReadVersion, MetadataBrokerType.WebScraping)); } AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagAlbum), metadataWebScraping?.PersonalAlbum, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerWebScraping, tagTitle), metadataWebScraping?.PersonalTitle, true); AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerKeywords), false); if (fileEntryAttribute.FileEntryVersion == FileEntryVersion.CompatibilityFixedAndAutoUpdated || fileEntryAttribute.FileEntryVersion == FileEntryVersion.MetadataToSave) { int keywordsStarts = DataGridViewHandler.GetRowHeaderItemStarts(dataGridView, headerKeywords); int keywordsEnds = DataGridViewHandler.GetRowHeaderItemsEnds(dataGridView, headerKeywords); for (int rowIndexToClean = keywordsStarts; rowIndexToClean <= keywordsEnds; rowIndexToClean++) { DataGridViewGenericCellStatus dataGridViewGenericCellStatus = new DataGridViewGenericCellStatus(MetadataBrokerType.Empty, SwitchStates.Undefine, true); DataGridViewHandler.SetCellReadOnlyDependingOfStatus(dataGridView, columnIndex, rowIndexToClean, dataGridViewGenericCellStatus); DataGridViewHandler.SetCellStatus(dataGridView, columnIndex, rowIndexToClean, dataGridViewGenericCellStatus, false); } } if (metadataExiftool != null) { PopulateKeywords(dataGridView, metadataExiftool, columnIndex, metadataExiftool.Broker, fileEntryAttribute); } if (metadataMicrosoftPhotos != null) { PopulateKeywords(dataGridView, metadataMicrosoftPhotos, columnIndex, metadataMicrosoftPhotos.Broker, fileEntryAttribute); } if (metadataWindowsLivePhotoGallery != null) { PopulateKeywords(dataGridView, metadataWindowsLivePhotoGallery, columnIndex, metadataWindowsLivePhotoGallery.Broker, fileEntryAttribute); } if (metadataWebScraping != null) { PopulateKeywords(dataGridView, metadataWebScraping, columnIndex, metadataWebScraping.Broker, fileEntryAttribute); } DataGridViewHandler.SetColumnPopulatedFlag(dataGridView, columnIndex, true); } //----------------------------------------------------------------- DataGridViewHandler.SetIsPopulatingFile(dataGridView, false); //----------------------------------------------------------------- return(columnIndex); }
private static int AddRowRegion(DataGridView dataGridView, MetadataBrokerType metadataBrokerType, Metadata metadata, int columnIndex, DataGridViewGenericRow dataGridViewGenericRow, RegionStructure regionStructureToAdd, DataGridViewGenericCellStatus dataGridViewGenericCellStatusDefaults) { #region Find Row to Edit or Where to add bool rowFound = false; int lastHeaderRowFound = -1; bool rowBlankFound = false; int firstBlankFound = -1; int rowIndexRowFound = -1; int startSearchRow = 0; for (int rowIndex = startSearchRow; rowIndex < DataGridViewHandler.GetRowCountWithoutEditRow(dataGridView); rowIndex++) { DataGridViewGenericRow dataGridViewGenericRowCheck = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, rowIndex); if (!dataGridViewGenericRowCheck.IsHeader && !dataGridViewGenericRow.IsHeader && //Is row dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName && dataGridViewGenericRowCheck.RowName == dataGridViewGenericRow.RowName) { //Check if region match RegionStructure regionStructureInCell = DataGridViewHandler.GetCellValue(dataGridView, columnIndex, rowIndex) as RegionStructure; if (regionStructureToAdd != null && regionStructureInCell != null) { if (metadata != null && metadata.MediaHeight != null && metadata.MediaWidth != null) { Size imageSize = new Size((int)metadata.MediaWidth, (int)metadata.MediaHeight); Rectangle mediaRectangleToAdd = regionStructureToAdd.GetImageRegionPixelRectangle(imageSize); Rectangle mediaRectangleCell = regionStructureInCell.GetImageRegionPixelRectangle(imageSize); if (RegionStructure.RectangleEqual(mediaRectangleToAdd, mediaRectangleCell)) { rowFound = true; rowIndexRowFound = rowIndex; break; // return rowIndex; } } } if (regionStructureInCell == null) { rowBlankFound = true; if (firstBlankFound == -1) { firstBlankFound = rowIndex; } } } #region Sorting if (dataGridViewGenericRow.IsHeader && //A normal row is add (not header) //dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRow.HeaderName.CompareTo(dataGridViewGenericRowCheck.HeaderName) >= 0) { lastHeaderRowFound = rowIndex; //Remember head row found } //Add sorted if (!dataGridViewGenericRow.IsHeader && //A normal row is add (not header) dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName) { lastHeaderRowFound = rowIndex; //Remember head row found } if (!dataGridViewGenericRow.IsHeader && //A normal row is add (not header) !dataGridViewGenericRowCheck.IsHeader && //If header, then check if same header name dataGridViewGenericRowCheck.HeaderName == dataGridViewGenericRow.HeaderName && dataGridViewGenericRow.RowName.CompareTo(dataGridViewGenericRowCheck.RowName) >= 0) { lastHeaderRowFound = rowIndex; //If lower or eaual, remeber last } #endregion } #endregion #region Update row or Add int rowIndexUsed; if (rowFound) //Found row and cell with correct region { rowIndexUsed = rowIndexRowFound; RegionStructure regionStructureInCell = DataGridViewHandler.GetCellRegionStructure(dataGridView, columnIndex, rowIndexUsed); if (regionStructureInCell == null || regionStructureInCell?.Thumbnail == null || (metadata.Broker == MetadataBrokerType.ExifTool && regionStructureToAdd.Thumbnail != null)) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndexUsed, regionStructureToAdd, false); //Prioritize ExifTool } } else if (rowBlankFound) //Found row and but no cell with correct region { rowIndexUsed = firstBlankFound; RegionStructure regionStructureInCell = DataGridViewHandler.GetCellRegionStructure(dataGridView, columnIndex, rowIndexUsed); if (regionStructureInCell == null || regionStructureInCell?.Thumbnail == null || (metadata.Broker == MetadataBrokerType.ExifTool && regionStructureToAdd.Thumbnail != null)) { DataGridViewHandler.SetCellValue(dataGridView, columnIndex, rowIndexUsed, regionStructureToAdd, false); //Prioritize ExifTool } } else //No postion found, add on sorted location { //lastHeaderRowFound rowIndexUsed = DataGridViewHandler.AddRow(dataGridView, columnIndex, dataGridViewGenericRow, DataGridViewHandler.GetFavoriteList(dataGridView), regionStructureToAdd, dataGridViewGenericCellStatusDefaults, lastHeaderRowFound, true, true, true); } #endregion SetCellDefault(dataGridView, metadataBrokerType, columnIndex, rowIndexUsed); //No DirtyFlagSet DataGridViewHandler.SetCellRowHeight(dataGridView, rowIndexUsed, DataGridViewHandler.GetCellRowHeight(dataGridView)); #region Delete from suggestion DataGridViewHandler.DeleteRow(dataGridView, headerPeopleSuggestion, regionStructureToAdd.Name); DataGridViewHandler.DeleteRow(dataGridView, headerPeopleMostUsed, regionStructureToAdd.Name); #endregion return(rowIndexUsed); }
bool FindAndReplaceString(bool bReplace, DataGridViewCell SearchCell, String FindString, String ReplaceString, bool bMatchCase, bool bMatchCell, int iSearchMethod) { String SearchString = SearchCell.FormattedValue.ToString(); // Regular string search if (iSearchMethod == 0) { // Match Cell if (bMatchCell) { if (!bMatchCase) { if (SearchString.ToLowerInvariant() == FindString.ToLowerInvariant()) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(ReplaceString, SearchCell.ValueType); } return(true); } } else { if (SearchString == FindString) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(ReplaceString, SearchCell.ValueType); } return(true); } } } // No Match Cell else { bool bFound = false; StringComparison strCompare = StringComparison.InvariantCulture; if (!bMatchCase) { strCompare = StringComparison.InvariantCultureIgnoreCase; } if (bReplace && !SearchCell.ReadOnly) { String NewString = null; int strIndex = 0; while (strIndex != -1) { int nextStrIndex = SearchString.IndexOf(FindString, strIndex, strCompare); if (nextStrIndex != -1) { bFound = true; NewString += SearchString.Substring(strIndex, nextStrIndex - strIndex); NewString += ReplaceString; nextStrIndex = nextStrIndex + FindString.Length; } else { NewString += SearchString.Substring(strIndex); } strIndex = nextStrIndex; } if (bFound) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(NewString, SearchCell.ValueType); } } else { bFound = SearchString.IndexOf(FindString, 0, strCompare) != -1; } return(bFound); } } else { // Regular Expression String RegexPattern = FindString; // Wildcards if (iSearchMethod == 2) { // Convert wildcard to regex: RegexPattern = "^" + System.Text.RegularExpressions.Regex.Escape(FindString).Replace("\\*", ".*").Replace("\\?", ".") + "$"; } System.Text.RegularExpressions.RegexOptions strCompare = System.Text.RegularExpressions.RegexOptions.None; if (!bMatchCase) { strCompare = System.Text.RegularExpressions.RegexOptions.IgnoreCase; } System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(RegexPattern, strCompare); if (regex.IsMatch(SearchString)) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } String NewString = regex.Replace(SearchString, ReplaceString); SearchCell.Value = Convert.ChangeType(NewString, SearchCell.ValueType); } return(true); } return(false); } return(false); }
private async void FolderShare_Click(object sender, EventArgs e) { label4.Text = "Processing, please wait"; progressBar1.Value = 0; progressBar1.Visible = true; dgv.Rows.Clear(); dgv.Refresh(); SaleForceConnect con = SaleForceConnect.getInstance(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], ConfigurationManager.AppSettings["ServerURLsoap"]); SforceService connection = con.getCon();// private connection. //clear columns //dgv.Columns.Clear(); //clear rows //dgv.Rows.Clear(); DataGridViewHandler dgvFS = new DataGridViewHandler(); FolderSecurity fs = new FolderSecurity(); ////////////////////////////method that retrieve a list with FolderSecurity information for the dgv\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /************loading private and public reports and dashboard******************/ int param; if (Int32.TryParse(publicParams.Text, out param)) { param = Convert.ToInt32(publicParams.Text); } else { param = 0; } PrivateReportFactory prf = new PrivateReportFactory(connection); await Task.Factory.StartNew(() => prf.loadPrivateReport()).ContinueWith(t => progressBar1.Value += 25, TaskScheduler.FromCurrentSynchronizationContext()); PublicReportFactory pr = new PublicReportFactory(connection); await Task.Factory.StartNew(() => pr.loadPublicReport(param)).ContinueWith(t => progressBar1.Value += 25, TaskScheduler.FromCurrentSynchronizationContext()); PublicDashboardFactory pdf = new PublicDashboardFactory(connection); await Task.Factory.StartNew(() => pdf.loadPublicDashboard()).ContinueWith(t => progressBar1.Value += 25, TaskScheduler.FromCurrentSynchronizationContext()); PrivateDashboardFactory prdf = new PrivateDashboardFactory(connection); await Task.Factory.StartNew(() => prdf.loadPrivateDashboard()); /************loading Folders and FolderShare********************************/ Rootobject rObjFolders = new Rootobject(); Rootobject rObjFolders2 = new Rootobject(); RootobjectShares rObjectShares = new RootobjectShares(); List <string> folderIdList = new List <string>(); IDictionary <String, List <FolderShare> > mappingFolderIdAndShares = new Dictionary <String, List <FolderShare> >(); //List<FolderShare> fsList = new List<FolderShare>(); folderIdList = await rObjFolders.GetFolderIdAsync(); mappingFolderIdAndShares = await rObjectShares.GetFolderShareListAsync(folderIdList); rObjFolders2 = await Rootobject.GetFoldersAsync(); /******************Query for the final report*******************************/ List <FolderSecurity> qFolderSecurity = new List <FolderSecurity>(); ListasSfCollectionObjects fsq = new ListasSfCollectionObjects(); qFolderSecurity = fsq.QueryFolderSecurity(pr.getPublicReport(), prf.getPrivateReport(), pdf.GetPublicDashboards(), prdf.GetPrivateDashboards(), mappingFolderIdAndShares, rObjFolders2); //await Task.Factory.StartNew(() => dgvFS.dgvFolderSecurity(qFolderSecurity, dgv, label4).ContinueWith(t => progressBar1.Value += 25, TaskScheduler.FromCurrentSynchronizationContext())); dgvFS.dgvFolderSecurity(qFolderSecurity, dgv, label4); progressBar1.Value += 25; buttonFolderShareWasClicked = true; }