public Settings() { InitializeComponent(); Certainty.Text = Properties.Settings.Default.UncertaintyLevel.ToString(); Annotator.Text = Properties.Settings.Default.Annotator; DefaultZoom.Text = Properties.Settings.Default.DefaultZoomInSeconds.ToString(); Segmentmindur.Text = Properties.Settings.Default.DefaultMinSegmentSize.ToString(); Samplerate.Text = Properties.Settings.Default.DefaultDiscreteSampleRate.ToString(); DrawwaveformCheckbox.IsChecked = Properties.Settings.Default.DrawVideoWavform; ContinuousHotkeysnum.Text = Properties.Settings.Default.ContinuousHotkeysNumber.ToString(); string[] tokens = Properties.Settings.Default.DatabaseAddress.Split(':'); if (tokens.Length == 2) { DBHost.Text = tokens[0]; DBPort.Text = tokens[1]; } string[] history = Properties.Settings.Default.serverhistory.Split(';'); DBHost.DropItems = history; DBHost.DropdownClosed += split; DBUser.Text = Properties.Settings.Default.MongoDBUser; DBPassword.Password = MainHandler.Decode(Properties.Settings.Default.MongoDBPass); DBConnnect.IsChecked = Properties.Settings.Default.DatabaseAutoLogin; UpdatesCheckbox.IsChecked = Properties.Settings.Default.CheckUpdateOnStart; OverwriteAnnotation.IsChecked = Properties.Settings.Default.DatabaseAskBeforeOverwrite; DownloadDirectory.Text = Properties.Settings.Default.DatabaseDirectory; CMLDirectory.Text = Properties.Settings.Default.CMLDirectory; }
public DatabaseAnnoMainWindow() { InitializeComponent(); serverLogin.Text = Properties.Settings.Default.DataServerLogin; serverPassword.Password = MainHandler.Decode(Properties.Settings.Default.DataServerPass); GetDatabases(DatabaseHandler.DatabaseName); showonlymine.IsChecked = Properties.Settings.Default.DatabaseShowOnlyMine; showOnlyUnfinished.IsChecked = Properties.Settings.Default.DatabaseShowOnlyFinished; hideMissing.IsChecked = Properties.Settings.Default.DBHideMissingStreams; }
private void Apply_Click(object sender, RoutedEventArgs e) { bool force = ForceCheckBox.IsChecked.Value; string database = DatabaseHandler.DatabaseName; string[] sessions = new string[SessionsBox.SelectedItems.Count]; int i = 0; foreach (DatabaseSession item in SessionsBox.SelectedItems) { sessions[i] = item.Name; i++; } string[] schemes = new string[SchemeandAnnotatorBox.Items.Count]; int s = 0; foreach (SchemeAnnotatorPair item in SchemeandAnnotatorBox.Items) { schemes[s] = item.Name + ":" + item.Annotator; s++; } string rolesList = ""; var roles = RolesBox.SelectedItems; foreach (string role in roles) { if (rolesList == "") { rolesList += role; } else { rolesList += ";" + role; } } Properties.Settings.Default.SettingCMLDefaultBN = NetworkBox.SelectedItem.ToString(); if (RolesBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultRole = RolesBox.SelectedItem.ToString(); } if (AnnotatorInputBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultAnnotator = AnnotatorInputBox.SelectedItem.ToString(); } if (SchemeOutputBox.SelectedItem != null) { Properties.Settings.Default.CMLDefaultScheme = SchemeOutputBox.SelectedItem.ToString(); } Properties.Settings.Default.CMLDefaultAnnotatorPrediction = AnnotatorsBox.SelectedItem.ToString(); Properties.Settings.Default.Save(); logTextBox.Text = ""; string outputscheme = SchemeOutputBox.SelectedItem.ToString(); string annotator = DatabaseHandler.Annotators.Find(n => n.FullName == Properties.Settings.Default.CMLDefaultAnnotatorPrediction).Name; string roleout = Outrole.SelectedItem.ToString(); bool tocontinuous = false; DatabaseScheme outscheme = DatabaseHandler.Schemes.Find(n => n.Name == outputscheme); if (outscheme.Type == AnnoScheme.TYPE.CONTINUOUS) { tocontinuous = true; } string cmlfolderpath = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\"; string netpath = cmlfolderpath + NetworkBox.SelectedItem.ToString(); string schemespath = cmlfolderpath + "schemes.set"; string sessionsspath = cmlfolderpath + "sessions.set"; System.IO.File.WriteAllLines(schemespath, schemes); System.IO.File.WriteAllLines(sessionsspath, sessions); float filter = -1.0f; if (smoothcheckbox.IsChecked == true) { float.TryParse(WindowSmoothBox.Text, out filter); } logTextBox.Text += handler.CMLPredictBayesFusion(roleout, sessionsspath, schemespath, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), Properties.Settings.Default.DatabaseDirectory, database, outputscheme, rolesList, annotator, tocontinuous, netpath, filter); }
private async Task httpPost(string URL, string localpath) { string login = Properties.Settings.Default.DataServerLogin; string password = MainHandler.Decode(Properties.Settings.Default.DataServerPass); string fileName = Path.GetFileName(localpath); if (fileName.EndsWith(".stream%7E")) { fileName = fileName.Remove(fileName.Length - 3); fileName = fileName + "~"; } numberOfActiveParallelDownloads++; filesToDownload.Add(localpath); if (!File.Exists(localpath)) { DownloadStatus dl = new DownloadStatus(); dl.File = localpath; dl.percent = 0.0; dl.active = true; statusOfDownloads.Add(dl); try { Action EmptyDelegate = delegate() { }; control.ShadowBoxText.Text = "Downloading '" + fileName + "'"; control.ShadowBox.Visibility = Visibility.Visible; control.shadowBoxCancelButton.Visibility = Visibility.Visible; control.UpdateLayout(); control.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); // Create a new WebClient instance. WebClient client = new WebClient(); client.UploadProgressChanged += (s, e) => { double percent = ((double)e.BytesReceived / (double)e.TotalBytesToReceive) * 100.0; string param = localpath + "#" + percent.ToString("F2"); control.Dispatcher.BeginInvoke(new Action <DownloadStatus>(UpdateOnDownload), DispatcherPriority.Normal, dl); }; client.UploadValuesCompleted += (s, e) => { try { byte[] response = e.Result; File.WriteAllBytes(localpath, response); control.Dispatcher.BeginInvoke(new Action <string>(FinishedDownload), DispatcherPriority.Normal, localpath); } catch { //Could happen when we cancel the download. } }; Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, URL); CancellationToken token = tokenSource.Token; await Task.Run(() => { token.Register(() => { client.CancelAsync(); CanceledDownload(); return; }); //Here we assume that the session is stored as simple ID. (as it is done in the Noxi Database). If the SessionID really is a string, this step is not needed. string resultString = Regex.Match(DatabaseHandler.SessionName, @"\d+").Value; int sid = Int32.Parse(resultString); var values = new NameValueCollection(); values.Add("username", login); values.Add("password", password); values.Add("session_id", sid.ToString()); values.Add("filename", fileName); Uri url = new Uri(URL); client.UploadValuesAsync(url, values); }, token); } catch (Exception ex) { MessageTools.Error(ex.ToString()); } } else { await control.Dispatcher.BeginInvoke(new Action <string>(FinishedDownload), DispatcherPriority.Normal, ""); } }
private async Task SFTP(string url, string localpath) { bool iscanceled = false; string[] split = url.Split(':'); string[] split2 = split[1].Split(new char[] { '/' }, 4); string ftphost = split2[2]; string fileName = split2[3].Substring(split2[3].LastIndexOf("/") + 1, (split2[3].Length - split2[3].LastIndexOf("/") - 1)); string folder = split2[3].Remove(split2[3].Length - fileName.Length); string login = Properties.Settings.Default.DataServerLogin; string password = MainHandler.Decode(Properties.Settings.Default.DataServerPass); lastDownloadFileName = fileName; string ftpfilepath = "/" + folder + fileName; filesToDownload.Add(localpath); numberOfActiveParallelDownloads++; if (!File.Exists(localpath)) { DownloadStatus dl = new DownloadStatus(); dl.File = localpath; dl.percent = 0.0; dl.active = true; statusOfDownloads.Add(dl); Sftp sftp = new Sftp(ftphost, login, password); try { sftp.OnTransferProgress += (src, dst, transferredBytes, totalBytes, message) => { dl.percent = ((double)transferredBytes / (double)totalBytes) * 100.0; control.Dispatcher.BeginInvoke(new Action <DownloadStatus>(UpdateOnDownload), DispatcherPriority.Normal, dl); }; Action EmptyDelegate = delegate() { }; control.ShadowBoxText.Text = "Connecting to Server..."; control.ShadowBox.Visibility = Visibility.Visible; control.shadowBoxCancelButton.Visibility = Visibility.Visible; control.UpdateLayout(); control.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); sftp.Connect(); CancellationToken token = tokenSource.Token; await Task.Run(() => { if (sftp.Connected) { token.Register(() => { sftp.Cancel(); iscanceled = true; while (sftp.Connected) { Thread.Sleep(100); } CanceledDownload(); return; }); if (!iscanceled) { try { sftp.Get(ftpfilepath, localpath); sftp.Close(); } catch { sftp.Cancel(); sftp.Close(); } } } }, token); } catch { if (null != sftp && sftp.Connected) { sftp.Cancel(); } MessageBox.Show("Can't login to data server, not authorized!"); } } if (!iscanceled) { await control.Dispatcher.BeginInvoke(new Action <string>(FinishedDownload), DispatcherPriority.Normal, localpath); } }
private void Apply_Click(object sender, RoutedEventArgs e) { Trainer trainer = (Trainer)TrainerPathComboBox.SelectedItem; bool force = mode == Mode.COMPLETE || ForceCheckBox.IsChecked.Value; if (!File.Exists(trainer.Path)) { MessageTools.Warning("file does not exist '" + trainer.Path + "'"); return; } string database = DatabaseHandler.DatabaseName; DatabaseStream stream = (DatabaseStream)StreamsBox.SelectedItem; string sessionList = ""; var sessions = SessionsBox.SelectedItems; foreach (DatabaseSession session in sessions) { if (sessionList == "") { sessionList += session.Name; } else { sessionList += ";" + session.Name; } } DatabaseScheme scheme = (DatabaseScheme)SchemesBox.SelectedItem; string rolesList = ""; var roles = RolesBox.SelectedItems; foreach (DatabaseRole role in roles) { if (rolesList == "") { rolesList += role.Name; } else { rolesList += ";" + role.Name; } } DatabaseAnnotator annotator = (DatabaseAnnotator)AnnotatorsBox.SelectedItem; string trainerLeftContext = LeftContextTextBox.Text; string trainerRightContext = RightContextTextBox.Text; string trainerBalance = ((ComboBoxItem)BalanceComboBox.SelectedItem).Content.ToString(); logTextBox.Text = ""; if (mode == Mode.TRAIN || mode == Mode.COMPLETE) { string streamName = ""; string[] streamParts = stream.Name.Split('.'); if (streamParts.Length <= 1) { streamName = stream.Name; } else { streamName = streamParts[1]; for (int i = 2; i < streamParts.Length; i++) { streamName += "." + streamParts[i]; } } string trainerDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.ModelsFolderName + "\\" + Defaults.CML.ModelsTrainerFolderName + "\\" + scheme.Type.ToString().ToLower() + "\\" + scheme.Name + "\\" + stream.Type + "{" + streamName + "}\\" + trainer.Name + "\\"; Directory.CreateDirectory(trainerDir); string trainerName = TrainerNameTextBox.Text == "" ? trainer.Name : TrainerNameTextBox.Text; string trainerOutPath = mode == Mode.COMPLETE ? tempTrainerPath : trainerDir + trainerName; if (force || !File.Exists(trainerOutPath + ".trainer")) { try { logTextBox.Text += handler.CMLTrainModel(trainer.Path, trainerOutPath, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, trainerLeftContext, trainerRightContext, trainerBalance, mode == Mode.COMPLETE); } catch (Exception ex) { logTextBox.Text += ex; } } else { logTextBox.Text += "skip " + trainerOutPath + "\n"; } } if (mode == Mode.PREDICT || mode == Mode.COMPLETE) { if (true || force) { double confidence = -1.0; if (ConfidenceCheckBox.IsChecked == true && ConfidenceTextBox.IsEnabled) { double.TryParse(ConfidenceTextBox.Text, out confidence); Properties.Settings.Default.CMLDefaultConf = confidence; } double minGap = 0.0; if (FillGapCheckBox.IsChecked == true && FillGapTextBox.IsEnabled) { double.TryParse(FillGapTextBox.Text, out minGap); Properties.Settings.Default.CMLDefaultGap = minGap; } double minDur = 0.0; if (RemoveLabelCheckBox.IsChecked == true && RemoveLabelTextBox.IsEnabled) { double.TryParse(RemoveLabelTextBox.Text, out minDur); Properties.Settings.Default.CMLDefaultMinDur = minDur; } Properties.Settings.Default.Save(); try { logTextBox.Text += handler.CMLPredictAnnos(mode == Mode.COMPLETE ? tempTrainerPath : trainer.Path, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, trainerLeftContext, trainerRightContext, confidence, minGap, minDur, mode == Mode.COMPLETE); } catch (Exception ex) { logTextBox.Text += ex; } } } if (mode == Mode.EVALUATE) { string evalOutPath = Properties.Settings.Default.CMLDirectory + "\\" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); try { logTextBox.Text += handler.CMLEvaluateModel(evalOutPath, trainer.Path, Properties.Settings.Default.DatabaseDirectory, Properties.Settings.Default.DatabaseAddress, Properties.Settings.Default.MongoDBUser, MainHandler.Decode(Properties.Settings.Default.MongoDBPass), database, sessionList, scheme.Name, rolesList, annotator.Name, stream.Name, LosoCheckBox.IsChecked.Value); if (File.Exists(evalOutPath)) { ConfmatWindow confmat = new ConfmatWindow(evalOutPath); confmat.ShowDialog(); File.Delete(evalOutPath); } } catch (Exception ex) { logTextBox.Text += ex; } } if (mode == Mode.COMPLETE) { handler.ReloadAnnoTierFromDatabase(AnnoTierStatic.Selected, false); var dir = new DirectoryInfo(Path.GetDirectoryName(tempTrainerPath)); foreach (var file in dir.EnumerateFiles(Path.GetFileName(tempTrainerPath) + "*")) { file.Delete(); } Close(); } }