private void databaseLoad() { clearSession(); if (loadedDBmedia != null) { loadedDBmedia.Clear(); } if (filesToDownload != null) { filesToDownload.Clear(); } System.Collections.IList annotations = null; List <DatabaseMediaInfo> ci = null; DatabaseAnnoMainWindow dbhw = new DatabaseAnnoMainWindow(); try { dbhw.WindowStartupLocation = WindowStartupLocation.CenterScreen; dbhw.ShowDialog(); if (dbhw.DialogResult == true) { annotations = dbhw.Annotations(); loadedDBmedia = dbhw.Media(); ci = dbhw.MediaConnectionInfo(); control.databaseSaveSessionMenu.IsEnabled = true; control.databaseSaveSessionAndMarkAsFinishedMenu.IsEnabled = true; control.databaseCMLCompleteStepMenu.IsEnabled = true; control.databaseCMLTransferStepMenu.IsEnabled = true; control.databaseCMLExtractFeaturesMenu.IsEnabled = true; //This is just a UI thing. If a user does not have according rights in the mongodb he will not have acess anyway. We just dont want to show the ui here. if (dbhw.Authlevel() > 2) { control.databaseManageMenu.Visibility = Visibility.Visible; control.databaseCMLTransferStepMenu.Visibility = Visibility.Visible; } else { control.databaseManageMenu.Visibility = Visibility.Collapsed; control.databaseCMLTransferStepMenu.Visibility = Visibility.Collapsed; } } control.databaseSaveSessionMenu.IsEnabled = true; if (annotations != null) { Action EmptyDelegate = delegate() { }; control.ShadowBox.Visibility = Visibility.Visible; control.UpdateLayout(); control.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); List <AnnoList> annoLists = DatabaseHandler.LoadFromDatabase(annotations, Properties.Settings.Default.DatabaseName, Properties.Settings.Default.LastSessionId, Properties.Settings.Default.MongoDBUser); control.navigator.Statusbar.Content = "Database Session: " + (Properties.Settings.Default.LastSessionId).Replace('_', '-'); try { if (annoLists != null) { foreach (AnnoList annoList in annoLists) { //annoList.FilePath = annoList.Role + "." + annoList.Scheme.Name + "." + annoList.AnnotatorFullName; handleAnnotation(annoList); } control.ShadowBox.Visibility = Visibility.Collapsed; //handle media if (loadedDBmedia.Count > 0) { for (int i = 0; i < loadedDBmedia.Count; i++) { foreach (DatabaseMediaInfo c in ci) { Properties.Settings.Default.DataServerConnectionType = c.connection; if (c.filename == loadedDBmedia[i].filename.ToString()) { if (c.connection == "sftp") { Properties.Settings.Default.DataServerConnectionType = "sftp"; SFTPDownloadFiles(c.ip, c.folder, Properties.Settings.Default.DatabaseName, Properties.Settings.Default.LastSessionId, c.filename, Properties.Settings.Default.DataServerLogin, Properties.Settings.Default.DataServerPass); } else if (ci[i].connection == "http" || ci[i].connection == "https" && ci[i].requiresauth == "false") { Properties.Settings.Default.DataServerConnectionType = "http"; httpGet(c.filepath, Properties.Settings.Default.DatabaseName, Properties.Settings.Default.LastSessionId, c.filename); } else if (ci[i].connection == "http" || ci[i].connection == "https" && ci[i].requiresauth == "true") { Properties.Settings.Default.DataServerConnectionType = "http"; //This has not been tested and probably needs rework. httpPost(c.filepath, c.filename, Properties.Settings.Default.DatabaseName, Properties.Settings.Default.DataServerLogin, Properties.Settings.Default.DataServerPass, Properties.Settings.Default.LastSessionId); } } } } } } DatabaseLoaded = true; } catch (TimeoutException e1) { MessageBox.Show("Make sure ip, login and password are correct", "Connection to database not possible"); } } } catch (Exception ex) { dbhw.Close(); MessageTools.Error(ex.ToString()); } }
private void databaseLoadSession() { DatabaseAnnoMainWindow dialog = new DatabaseAnnoMainWindow(); if (showDialogClearWorkspace(dialog) && (dialog.DialogResult == true)) { Action EmptyDelegate = delegate() { }; control.ShadowBox.Visibility = Visibility.Visible; control.UpdateLayout(); control.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); System.Collections.IList annotations = dialog.Annotations(); if (annotations != null && annotations.Count > 0) { List <AnnoList> annoLists = DatabaseHandler.LoadSession(annotations); if (annoLists != null) { foreach (AnnoList annoList in annoLists) { addAnnoTierFromList(annoList); } } } control.ShadowBox.Visibility = Visibility.Collapsed; List <StreamItem> streams = dialog.SelectedStreams(); databaseSessionStreams = new List <string>(); foreach (StreamItem stream in streams) { databaseSessionStreams.Add(stream.Name); } if (streams != null && streams.Count > 0) { List <string> streamsAll = new List <string>(); foreach (StreamItem stream in streams) { if (stream.Extension == "stream") { streamsAll.Add(stream.Name + "~"); } streamsAll.Add(stream.Name); } try { if (filesToDownload != null) { filesToDownload.Clear(); } MainHandler.NumberOfAllCurrentDownloads = streamsAll.Count; tokenSource = new CancellationTokenSource(); string url = ""; bool requiresAuth = false; DatabaseDBMeta meta = new DatabaseDBMeta() { Name = DatabaseHandler.DatabaseName }; if (!DatabaseHandler.GetDBMeta(ref meta)) { return; } string localPath = Properties.Settings.Default.DatabaseDirectory + "\\" + DatabaseHandler.DatabaseName + "\\" + DatabaseHandler.SessionName + "\\"; if (meta.UrlFormat == UrlFormat.NEXTCLOUD) { url = meta.Server + "/download?path=%2F" + DatabaseHandler.DatabaseName + "%2F" + DatabaseHandler.SessionName + "&files="; } else { url = meta.Server + '/' + DatabaseHandler.SessionName + '/'; requiresAuth = meta.ServerAuth; } string connection = ""; if (meta.Server == "") { connection = ""; } else { string[] split = url.Split(':'); connection = split[0]; } Directory.CreateDirectory(Path.GetDirectoryName(localPath)); List <string> streamstoDownload = new List <string>(); foreach (string stream in streamsAll) { string llocal = localPath + stream; string lurl = url + stream; if (File.Exists(llocal)) { loadFile(llocal); continue; } streamstoDownload.Add(stream); Thread.Sleep(100); //TODO add more servers... if (connection == "sftp") { SFTP(lurl, llocal); } else if (connection == "http" || connection == "https" && requiresAuth == false) { int result = httpGetSync(lurl, llocal); if (result == -1) { streamstoDownload.RemoveAt(streamstoDownload.Count - 1); } } else if (connection == "http" || connection == "https" && requiresAuth == true) { httpPost(lurl, llocal); } else { loadFile(localPath); } } control.ShadowBoxText.UpdateLayout(); control.ShadowBoxText.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); control.ShadowBoxText.Text = "Loading Data"; control.ShadowBox.Visibility = Visibility.Collapsed; control.shadowBoxCancelButton.Visibility = Visibility.Collapsed; control.ShadowBox.UpdateLayout(); foreach (string stream in streamstoDownload) { string llocal = localPath + stream; try { long length = new System.IO.FileInfo(llocal).Length; if (length == 0) { Thread.Sleep(100); if (File.Exists(llocal)) { File.Delete(llocal); } continue; } } catch { } loadFile(llocal); } } catch (Exception e) { MessageBox.Show("Error: " + e, "Connection to database not possible"); } } } }