/// <summary> /// Displays the address book directory using the tree view /// </summary> /// <param name="directory"></param> protected virtual void DisplayAddressBookDirectory(AddressBookDirectory directory) { try { _treeView.SuspendLayout(); _treeView.Nodes.Clear(); AddressBookDirectoryTreeNode directoryNode = new AddressBookDirectoryTreeNode(directory); _treeView.Nodes.Add(directoryNode); foreach (AddressBook addressBook in directory.Books) { AddressBookTreeNode bookNode = new AddressBookTreeNode(addressBook); directoryNode.Nodes.Add(bookNode); foreach (AddressBookItem addressBookItem in addressBook.Items) { AddressBookItemTreeNode itemNode = new AddressBookItemTreeNode(addressBookItem); bookNode.Nodes.Add(itemNode); } } directoryNode.Expand(); directoryNode.Checked = _checkRootItems; } catch (Exception ex) { Trace.WriteLine(ex); } finally { _treeView.ResumeLayout(true); } }
/// <summary> /// Handles the OK button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void OnButtonOKClicked(object sender, EventArgs e) { // create the directory that represents the items that were selcted _selectedDirectory = this.CreateSelectedDirectory(); this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Initializes a new instance of the AddressBookDirectoryBrowseWindow class /// </summary> /// <param name="directory"></param> public AddressBookDirectoryBrowseWindow(AddressBookDirectory directory) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // _treeView.CheckBoxes = true; _treeView.AfterCheck += new TreeViewEventHandler(OnAfterNodeCheck); _directory = directory; this.AcceptButton = _buttonOK; this.CancelButton = _buttonCancel; _buttonOK.Click += new EventHandler(OnButtonOKClicked); _buttonCancel.Click += new EventHandler(OnButtonCancelClicked); }
/// <summary> /// Creates a new address book directory containing only the items that were selected /// </summary> /// <returns></returns> protected virtual AddressBookDirectory CreateSelectedDirectory() { // create a new directory AddressBookDirectory directory = new AddressBookDirectory(_directory.Name); // start with the root node which is the directory foreach (AddressBookDirectoryTreeNode directoryNode in _treeView.Nodes) { // check each book node foreach (AddressBookTreeNode bookNode in directoryNode.Nodes) { // if it is selected if (bookNode.Checked) { // take the book for the selected node AddressBook book = bookNode.Book; // clear it's items book.Items.Clear(); // add it to the directory directory.Books.Add(book); // check each item node foreach (AddressBookItemTreeNode itemNode in bookNode.Nodes) { // if it is selected if (itemNode.Checked) { // add it to the book book.Items.Add(itemNode.Item); } } } } } return(directory); }
public AddressBookDirectoryEventArgs(AddressBookDirectory directory, AddressingActions action) : base(directory, action) { }
/// <summary> /// Exports the specified Address Book Directory to a file, allowing the user to select the elements that will be exported /// </summary> /// <param name="owner">A window that will own any prompts</param> /// <param name="directory">An address book directory that will be the basis for the export connection</param> /// <param name="initialDirectory">The initial directory in which to open the save file dialog</param> /// <param name="filename">A buffer that will receive the path to the file that was exported</param> /// <returns></returns> public virtual bool Export(IWin32Window owner, AddressBookDirectory directory, string initialDirectory, out string filename) { // ensure we have an owner form Debug.Assert(owner != null); // wipe the path buffer filename = null; // create a new browsing window to allow the user to select the items to export AddressBookDirectoryBrowseWindow window = new AddressBookDirectoryBrowseWindow(directory); // give them some instructions window.Instructions = @"Choose the items to export..."; // initially check the root items window.CheckRootItems = true; // show the dialog if (window.ShowDialog(owner) == DialogResult.OK) { // tiny delay to allow repainting System.Threading.Thread.Sleep(10); // get the selected directory AddressBookDirectory selectedDirectory = window.SelectedDirectory; // ensure we have a directory to export Debug.Assert(directory != null); // create a new save file dialog SaveFileDialog dialog = new SaveFileDialog(); // and try to save the file, making sure to prompt it the path doesn't exist, or the file exists to overwrite it dialog.AddExtension = true; dialog.DefaultExt = ".xml"; dialog.Filter = "Address Book Directory files (*.xml)|*.xml|All files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = (_lastInitialDirectory == null || _lastInitialDirectory == string.Empty ? initialDirectory : _lastInitialDirectory); dialog.OverwritePrompt = true; dialog.ValidateNames = true; // if they select a file and hit ok if (dialog.ShowDialog(owner) == DialogResult.OK) { // the folder the file is in, should be cached for next time _lastInitialDirectory = Directory.GetParent(dialog.FileName).FullName; // save the filename filename = dialog.FileName; // now try and save it using (FileStream fs = new FileStream(filename, FileMode.Create)) { // create a new binary formatter IFormatter formatter = new SoapFormatter(); // serialize the formatter.Serialize(fs, selectedDirectory); fs.Close(); } return(true); } } return(false); }
/// <summary> /// Orphans the item, killing it's parent and wiping out any attached event handlers /// </summary> public virtual void Orphan() { this.Changed = null; this.BeforeNameChanged = null; _parent = null; }
/// <summary> /// /// </summary> /// <param name="owner"></param> /// <param name="directory"></param> /// <param name="initialDirectory"></param> /// <param name="filename"></param> /// <returns></returns> public virtual bool Import(IWin32Window owner, AddressBookDirectory directory, string initialDirectory, out string filename) { // ensure we have an owner form Debug.Assert(owner != null); // wipe the path buffer filename = null; // create a new save file dialog OpenFileDialog dialog = new OpenFileDialog(); // and try to save the file, making sure to prompt it the path doesn't exist, or the file exists to overwrite it dialog.AddExtension = true; dialog.DefaultExt = ".xml"; dialog.Filter = "Address Book Directory files (*.xml)|*.xml|All files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = (_lastInitialDirectory == null || _lastInitialDirectory == string.Empty ? initialDirectory : _lastInitialDirectory); // dialog.OverwritePrompt = true; dialog.ValidateNames = true; // if they select a file and hit ok if (dialog.ShowDialog(owner) == DialogResult.OK) { // the folder the file is in, should be cached for next time _lastInitialDirectory = Directory.GetParent(dialog.FileName).FullName; // save the filename filename = dialog.FileName; AddressBookDirectory directoryToImport = null; try { // now try and save it using (FileStream fs = new FileStream(filename, FileMode.Open)) { // create a new binary formatter IFormatter formatter = new SoapFormatter(); // serialize the directoryToImport = (AddressBookDirectory)formatter.Deserialize(fs); fs.Close(); } } catch (Exception ex) { throw new AddressBookDirectoryImporterException(filename, ex); } // assert that we we have a directory to import Debug.Assert(directoryToImport != null); // flag the start of the import directory.ImportInProgress = true; // loop through the books, adding them foreach (AddressBook book in directoryToImport.Books) { Debug.WriteLine(string.Format("Importing address book '{0}', which has '{1}' items.", book.Name, book.Items.Count.ToString())); // pre-load the items from the book AddressBookItem[] items = (AddressBookItem[])book.Items; // clear the items from the book, and orphan the book book.Items.Clear(); book.Orphan(); book.GetNewId(); // add the book, or ovewrite an existing book // the lab management will see and not add the items in the book during an import // keeping item collisions out of the equation directory.Books.Add(book, true /* overwrite */); // loop through the items in the book foreach (AddressBookItem item in items) { // orphan the item item.Orphan(); item.GetNewId(); Debug.WriteLine(string.Format("Importing address book item '{0}'", item.Name)); // get the existing book by name, and add or overwrite an existing item AddressBook existingBook = directory.Books[book.Name]; // and add the items in the book to be imported, into the existing book existingBook.Items.Add(item, true /* overwrite */); } } // flag the end of the import directory.ImportInProgress = false; return(true); } return(false); }
public AddressBookDirectoryTreeNode(AddressBookDirectory directory) : base(directory.Name, 0 /* image index */, 0 /* selected image index */) { _directory = directory; }
/// <summary> /// Creates a new address book directory containing only the items that were selected /// </summary> /// <returns></returns> protected virtual AddressBookDirectory CreateSelectedDirectory() { // create a new directory AddressBookDirectory directory = new AddressBookDirectory(_directory.Name); // start with the root node which is the directory foreach(AddressBookDirectoryTreeNode directoryNode in _treeView.Nodes) { // check each book node foreach(AddressBookTreeNode bookNode in directoryNode.Nodes) { // if it is selected if (bookNode.Checked) { // take the book for the selected node AddressBook book = bookNode.Book; // clear it's items book.Items.Clear(); // add it to the directory directory.Books.Add(book); // check each item node foreach(AddressBookItemTreeNode itemNode in bookNode.Nodes) { // if it is selected if (itemNode.Checked) { // add it to the book book.Items.Add(itemNode.Item); } } } } } return directory; }
/// <summary> /// Displays the address book directory using the tree view /// </summary> /// <param name="directory"></param> protected virtual void DisplayAddressBookDirectory(AddressBookDirectory directory) { try { _treeView.SuspendLayout(); _treeView.Nodes.Clear(); AddressBookDirectoryTreeNode directoryNode = new AddressBookDirectoryTreeNode(directory); _treeView.Nodes.Add(directoryNode); foreach(AddressBook addressBook in directory.Books) { AddressBookTreeNode bookNode = new AddressBookTreeNode(addressBook); directoryNode.Nodes.Add(bookNode); foreach(AddressBookItem addressBookItem in addressBook.Items) { AddressBookItemTreeNode itemNode = new AddressBookItemTreeNode(addressBookItem); bookNode.Nodes.Add(itemNode); } } directoryNode.Expand(); directoryNode.Checked = _checkRootItems; } catch(Exception ex) { Trace.WriteLine(ex); } finally { _treeView.ResumeLayout(true); } }
/// <summary> /// Exports the specified Address Book Directory to a file, allowing the user to select the elements that will be exported /// </summary> /// <param name="owner">A window that will own any prompts</param> /// <param name="directory">An address book directory that will be the basis for the export connection</param> /// <param name="initialDirectory">The initial directory in which to open the save file dialog</param> /// <param name="filename">A buffer that will receive the path to the file that was exported</param> /// <returns></returns> public virtual bool Export(IWin32Window owner, AddressBookDirectory directory, string initialDirectory, out string filename) { // ensure we have an owner form Debug.Assert(owner != null); // wipe the path buffer filename = null; // create a new browsing window to allow the user to select the items to export AddressBookDirectoryBrowseWindow window = new AddressBookDirectoryBrowseWindow(directory); // give them some instructions window.Instructions = @"Choose the items to export..."; // initially check the root items window.CheckRootItems = true; // show the dialog if (window.ShowDialog(owner) == DialogResult.OK) { // tiny delay to allow repainting System.Threading.Thread.Sleep(10); // get the selected directory AddressBookDirectory selectedDirectory = window.SelectedDirectory; // ensure we have a directory to export Debug.Assert(directory != null); // create a new save file dialog SaveFileDialog dialog = new SaveFileDialog(); // and try to save the file, making sure to prompt it the path doesn't exist, or the file exists to overwrite it dialog.AddExtension = true; dialog.DefaultExt = ".xml"; dialog.Filter = "Address Book Directory files (*.xml)|*.xml|All files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = (_lastInitialDirectory == null || _lastInitialDirectory == string.Empty ? initialDirectory : _lastInitialDirectory); dialog.OverwritePrompt = true; dialog.ValidateNames = true; // if they select a file and hit ok if (dialog.ShowDialog(owner) == DialogResult.OK) { // the folder the file is in, should be cached for next time _lastInitialDirectory = Directory.GetParent(dialog.FileName).FullName; // save the filename filename = dialog.FileName; // now try and save it using (FileStream fs = new FileStream(filename, FileMode.Create)) { // create a new binary formatter IFormatter formatter = new SoapFormatter(); // serialize the formatter.Serialize(fs, selectedDirectory); fs.Close(); } return true; } } return false; }
/// <summary> /// /// </summary> /// <param name="owner"></param> /// <param name="directory"></param> /// <param name="initialDirectory"></param> /// <param name="filename"></param> /// <returns></returns> public virtual bool Import(IWin32Window owner, AddressBookDirectory directory, string initialDirectory, out string filename) { // ensure we have an owner form Debug.Assert(owner != null); // wipe the path buffer filename = null; // create a new save file dialog OpenFileDialog dialog = new OpenFileDialog(); // and try to save the file, making sure to prompt it the path doesn't exist, or the file exists to overwrite it dialog.AddExtension = true; dialog.DefaultExt = ".xml"; dialog.Filter = "Address Book Directory files (*.xml)|*.xml|All files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = (_lastInitialDirectory == null || _lastInitialDirectory == string.Empty ? initialDirectory : _lastInitialDirectory); // dialog.OverwritePrompt = true; dialog.ValidateNames = true; // if they select a file and hit ok if (dialog.ShowDialog(owner) == DialogResult.OK) { // the folder the file is in, should be cached for next time _lastInitialDirectory = Directory.GetParent(dialog.FileName).FullName; // save the filename filename = dialog.FileName; AddressBookDirectory directoryToImport = null; try { // now try and save it using (FileStream fs = new FileStream(filename, FileMode.Open)) { // create a new binary formatter IFormatter formatter = new SoapFormatter(); // serialize the directoryToImport = (AddressBookDirectory)formatter.Deserialize(fs); fs.Close(); } } catch(Exception ex) { throw new AddressBookDirectoryImporterException(filename, ex); } // assert that we we have a directory to import Debug.Assert(directoryToImport != null); // flag the start of the import directory.ImportInProgress = true; // loop through the books, adding them foreach(AddressBook book in directoryToImport.Books) { Debug.WriteLine(string.Format("Importing address book '{0}', which has '{1}' items.", book.Name, book.Items.Count.ToString())); // pre-load the items from the book AddressBookItem[] items = (AddressBookItem[])book.Items; // clear the items from the book, and orphan the book book.Items.Clear(); book.Orphan(); book.GetNewId(); // add the book, or ovewrite an existing book // the lab management will see and not add the items in the book during an import // keeping item collisions out of the equation directory.Books.Add(book, true /* overwrite */); // loop through the items in the book foreach(AddressBookItem item in items) { // orphan the item item.Orphan(); item.GetNewId(); Debug.WriteLine(string.Format("Importing address book item '{0}'", item.Name)); // get the existing book by name, and add or overwrite an existing item AddressBook existingBook = directory.Books[book.Name]; // and add the items in the book to be imported, into the existing book existingBook.Items.Add(item, true /* overwrite */); } } // flag the end of the import directory.ImportInProgress = false; return true; } return false; }