Skip to content

Commit

Permalink
error management with metadata less db being upgraded.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuotvez committed Apr 9, 2024
1 parent e04e42c commit ce48718
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,6 @@ public async void ProjectRestore_Tapped(object sender, Windows.UI.Xaml.Input.Tap
isRestoreFromZip = true;
}

//if (inFile.FileType.Contains("SQLite"))
//{
// ConvertSQLiteToGeoPackage(inFile.Name, fieldProjectPath + "/" + inFile.Name + ".gpkg");
//}

//Connect to the new database
IReadOnlyList<StorageFile> storageFiles = await newFieldBookFolder.GetFilesAsync();
StorageFile wantedDB = null;
Expand Down Expand Up @@ -861,32 +856,49 @@ public async void ProjectRestore_Tapped(object sender, Windows.UI.Xaml.Input.Tap
//Fill in current setting and change field book.
IEnumerable<object> metadata_raw = accessData.ReadTableFromDBConnection(metadataModel.GetType(), string.Empty, loadedDBConnection);
IEnumerable<Metadata> metadataTable = metadata_raw.Cast<Metadata>();
Metadata metItem = metadataTable.First() as Metadata;

//Display a warning for version validation
if (metItem.VersionSchema != DatabaseLiterals.DBVersion.ToString())
if (metadataTable != null && metadataTable.Count() > 0)
{
// Language localization using Resource.resw
var local = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
Metadata metItem = metadataTable.First() as Metadata;

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
//Display a warning for version validation
if (metItem.VersionSchema != DatabaseLiterals.DBVersion.ToString())
{
ContentDialog outDatedVersionDialog = new ContentDialog()
// Language localization using Resource.resw
var local = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
Title = local.GetString("WarningBadVersionTitle"),
Content = local.GetString("WarningBadVersionContent"),
PrimaryButtonText = local.GetString("GenericDialog_ButtonOK")
};
outDatedVersionDialog.Style = (Style)Application.Current.Resources["WarningDialog"];
await Services.ContentDialogMaker.CreateContentDialogAsync(outDatedVersionDialog, false);
ContentDialog outDatedVersionDialog = new ContentDialog()
{
Title = local.GetString("WarningBadVersionTitle"),
Content = local.GetString("WarningBadVersionContent"),
PrimaryButtonText = local.GetString("GenericDialog_ButtonOK")
};
outDatedVersionDialog.Style = (Style)Application.Current.Resources["WarningDialog"];
await Services.ContentDialogMaker.CreateContentDialogAsync(outDatedVersionDialog, false);
}).AsTask();

}).AsTask();
}

OpenFieldBook(fieldProjectPath, metItem.FieldworkType, metItem.UserCode,
metItem.MetaID, wantedDB.Path, metItem.VersionSchema, metItem.ProjectName, metItem.MetadataActivity, false);
FillProjectCollectionAsync();
}
else
{
ContentDialog missingMetadataDialog = new ContentDialog()
{
Title = loadLocalization.GetString("Generic_MessageErrorTitle"),
Content = loadLocalization.GetString("UpgradeErrorMetadataContent"),
CloseButtonText = loadLocalization.GetString("GenericCloseLabel/Label"),
};
missingMetadataDialog.Style = (Style)Application.Current.Resources["DeleteDialog"];
ContentDialogResult cdr = await missingMetadataDialog.ShowAsync();

}

OpenFieldBook(fieldProjectPath, metItem.FieldworkType, metItem.UserCode,
metItem.MetaID, wantedDB.Path, metItem.VersionSchema, metItem.ProjectName, metItem.MetadataActivity, false);
FillProjectCollectionAsync();
}


Expand Down

0 comments on commit ce48718

Please sign in to comment.