/// <summary> /// Add additional bcf info into the existing database /// </summary> /// <param name="bcfPath"></param> /// <returns></returns> public bool AddBCF(string bcfPath) { bool added = false; try { TaskDialogOption selectedOption = TaskDialogOption.NONE; var bcfExisting = from bcf in bcfFiles where bcf.ZipFilePath == bcfPath select bcf; if (bcfExisting.Count() > 0) { TaskDialogWindow dialogWindow = new TaskDialogWindow("\"" + bcfPath + "\" already exists in the database.\nDo you want to replace it?"); if ((bool)dialogWindow.ShowDialog()) { selectedOption = dialogWindow.SelectedOption; switch (selectedOption) { case TaskDialogOption.REPLACE: BCFZIP existingBCF = bcfExisting.First(); bool deleted = BCFDBWriter.BCFDBWriter.DeleteBCF(existingBCF); if (deleted) { this.BCFFiles.Remove(existingBCF); } break; case TaskDialogOption.MERGE: break; case TaskDialogOption.IGNORE: return(false); case TaskDialogOption.NONE: return(false); } } } BCFZIP bcfzip = BCFReader.BCFReader.Read(bcfPath); if (bcfzip.Markups.Count > 0) { ConflictMode mode = ConflictMode.IGNORE; if (selectedOption == TaskDialogOption.MERGE) { int index = bcfFiles.IndexOf(bcfExisting.First()); if (index > -1) { BCFZIP mergedBCF = BCFDBWriter.BCFDBWriter.MergeDatabase(bcfzip, bcfFiles[index]); if (null != mergedBCF) { this.BCFFiles[index] = mergedBCF; } } } else { bool written = BCFDBWriter.BCFDBWriter.WriteDatabase(bcfzip, mode); if (written) { bcfzip.IsPrimary = false; this.BCFFiles.Add(bcfzip); } } } } catch (Exception ex) { MessageBox.Show("Failed to add BCF into the connected database.\n" + ex.Message, "Add BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } return(added); }
private void buttonMerge_Click(object sender, RoutedEventArgs e) { selectedOption = TaskDialogOption.MERGE; this.DialogResult = true; }
private void buttonCancel_Click(object sender, RoutedEventArgs e) { selectedOption = TaskDialogOption.IGNORE; this.DialogResult = true; }
private void buttonReplace_Click(object sender, RoutedEventArgs e) { selectedOption = TaskDialogOption.REPLACE; this.DialogResult = true; }