public static Site GetSite( AddressBookEntry abEntry ) { if ( ! sites.ContainsKey(abEntry) ) { Site site = new Site( abEntry ); sites.Add( abEntry, site ); } return sites[abEntry]; }
public Site( AddressBookEntry abEntry ) { this.addressBookEntry = abEntry; UriBuilder uriBuilder = new UriBuilder( "ftp", addressBookEntry.host ); this.uri = uriBuilder.Uri; this.cred = new NetworkCredential( addressBookEntry.userName, addressBookEntry.userPass ); this.map = new Dictionary<string, SiteEntry>(); this.ftp = new FtpClient( uri, cred ); }
private void PopulateFields( AddressBookEntry entry ) { if ( entry == null ) entry = new AddressBookEntry(); textTitle.Text = entry.title; textHost.Text = entry.host; textPort.Text = entry.port.ToString(); textUsername.Text = entry.userName; textPassword.Text = entry.userPass; textIniDir.Text = entry.iniDir; textComment.Text = entry.comment; }
private void ABE_Connect( AddressBookEntry abEntry ) { try { formMain.SetConnection( abEntry ); this.Close(); } catch ( Exception ex ) { MessageBox.Show( this, "There was an error:" + Environment.NewLine + Environment.NewLine + ex.Message, "Error connecting to FTP site" ); } }
public FormAddressBookEntry( AddressBookEntry abEntry, AddressBookEntryAction action ) { InitializeComponent(); this.abEntry = abEntry; // set header if ( action == AddressBookEntryAction.Create ) labelHeader.Text = "Creating new entry"; else if ( action == AddressBookEntryAction.Edit ) labelHeader.Text = "Editing entry"; else labelHeader.Text = "Unknown operation"; // populate fields PopulateFields( abEntry ); }
public void SetConnection( AddressBookEntry abEntry ) { site = DataWarehouse.GetSite( abEntry ); site.SiteUpdatedEvent += HandleSiteUpdatedEvent; mapTree = new Dictionary<TreeNode, SiteEntry>(); labelHostName.Text = site.addressBookEntry.host; SetAppState( AppState.Busy ); SiteEntry rootEntry; rootEntry = ChangeDir( null, true ); SetAppState( AppState.Available ); TreeBuild(); }
private void ABE_Edit( AddressBookEntry abEntry ) { // we make a copy of the current entry, and send that for edit. // if user approves of his/her edit, then we replace current with data from edited copy. AddressBookEntry copyOfCurrent = new AddressBookEntry( abEntry ); FormAddressBookEntry formABE = new FormAddressBookEntry( copyOfCurrent, AddressBookEntryAction.Edit ); DialogResult result = formABE.ShowDialog( this ); if ( result == DialogResult.Cancel ) { MessageBox.Show( this, "Edit cancelled" ); return; } // add update current entry with edited data abEntry.UpdateFrom( copyOfCurrent ); }
// TODO: Need error checking for info: Make sure host has valid format, user name is not blank. private bool UnpopulateFields( AddressBookEntry entry ) { entry.title = textTitle.Text; entry.host = textHost.Text; entry.userName = textUsername.Text; entry.userPass = textPassword.Text; entry.iniDir = textIniDir.Text; entry.comment = textComment.Text; try { entry.port = Int32.Parse( textPort.Text ); if ( entry.port < 0 || entry.port > 70000 ) throw new Exception(); } catch(Exception ex) { MessageBox.Show( this, "Please make sure the port is an integer number between 1 and 70000" ); return false; } return true; }
private void ABE_New() { AddressBookEntry newAbEntry = new AddressBookEntry(); FormAddressBookEntry formABE = new FormAddressBookEntry( newAbEntry, AddressBookEntryAction.Create ); DialogResult result = formABE.ShowDialog( this ); if ( result == DialogResult.Cancel ) { MessageBox.Show( this, "Create cancelled" ); return; } // add new entry to address book addressBook.AddEntry( newAbEntry ); }
private void toolStripMenuItem_Clear_Click( object sender, EventArgs e ) { AB_Clear(); currentEntry = null; RefreshGrid(); }
//TODO: Right now after refresh, selection is lost. Perhaps we should re-select after refresh what was selected before refresh. Problems: What if multiple items were selected? What if item(s) were deleted? What if item was edited? private void RefreshGrid() { gridAddressBookSkipEvents = true; map = new Dictionary<DataGridViewRow, AddressBookEntry>(); gridAddressBook.Rows.Clear(); foreach ( AddressBookEntry entry in addressBook.Book ) { int id = gridAddressBook.Rows.Add(); DataGridViewRow row = gridAddressBook.Rows[id]; row.Cells["Title"].Value = entry.title; row.Cells["Host"].Value = entry.host; row.Cells["Comment"].Value = entry.comment; map.Add( row, entry ); } gridAddressBook.ClearSelection(); currentEntry = null; gridAddressBookSkipEvents = false; }
private void linkBookLoad_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) { AB_LoadFromFile(); // refresh grid currentEntry = null; RefreshGrid(); }
private void gridAddressBook_SelectionChanged( object sender, EventArgs e ) { if ( gridAddressBookSkipEvents ) return; // if nothing or >1 is selected, we don't like it if ( gridAddressBook.SelectedRows.Count != 1 ) { currentEntry = null; return; } DataGridViewRow row = gridAddressBook.SelectedRows[0]; currentEntry = map[row]; }
public AddressBookEntry( AddressBookEntry getDataFromHere ) { this.UpdateFrom( getDataFromHere ); }
public void DeleteEntry( AddressBookEntry entry ) { book.Remove( entry ); }
public void AddEntry( AddressBookEntry newEntry ) { book.Add( newEntry ); }
public void AddEntry( string title, string host, int port, string user, string pass, string iniDir, string comment ) { AddressBookEntry entry = new AddressBookEntry( title, host, port, user, pass, iniDir, comment ); book.Add( entry ); }
public void UpdateFrom( AddressBookEntry getDataFromHere ) { this.title = getDataFromHere.title; this.host = getDataFromHere.host; this.userName = getDataFromHere.userName; this.userPass = getDataFromHere.userPass; this.iniDir = getDataFromHere.iniDir; this.comment = getDataFromHere.comment; }