public void UpdateVenue(VenueState vs) { this.UpdateFromFile(); Venue v = vs.Venue; venues[v.Identifier] = v; SetPasswordStatus(vs); WriteCacheToFile(); }
public void AddVenue(VenueState vs) { this.UpdateFromFile(); Venue v = vs.Venue; venues.Add(v.Identifier, v); SetPasswordStatus(vs); WriteCacheToFile(); }
private ListViewItem CreateLvi(VenueState venueState, int imageIndex) { Venue venue = venueState.Venue; string[] columns = new string[] { venue.Name, venue.Identifier, venue.IPAddress.ToString(), venue.Port.ToString(CultureInfo.InvariantCulture) }; ListViewItem item = new ListViewItem(columns); item.ImageIndex = imageIndex; item.Tag = venueState; return(item); }
/// <summary> /// Return all state (client-visible and server-private) associated with /// the complete list of venues. This is used by only by the admin /// program, so the results are not obfucated (IP addresses /// are preserved). /// </summary> /// <returns></returns> public VenueState[] GetVenuesComplete() { this.UpdateFromFile(); ICollection vals = venues.Values; VenueState[] venueArray = new VenueState[vals.Count]; int i = 0; foreach (Venue venue in vals) { PrivateVenueState pvs = this.GetPrivateVenueState(venue.Identifier); VenueState vs = new VenueState(venue, pvs); venueArray[i++] = vs; } return(venueArray); }
private void deleteBtn_Click(object sender, EventArgs e) { VenueState selectedVenueState = ((VenueState)list.SelectedItems[0].Tag); Venue selectedVenue = selectedVenueState.Venue; string removeStr = string.Format(CultureInfo.CurrentCulture, Strings.ConfirmVenueDeleteText, selectedVenue.Name); DialogResult dr = RtlAwareMessageBox.Show(this, removeStr, Strings.ConfirmVenueDeleteTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); if (dr == DialogResult.Yes) { StorageFile.DeleteVenue(selectedVenue.Identifier); // don't remove the image; it will screw up the images for all of the other venues list.Items.RemoveAt(list.SelectedIndices[0]); } }
/// <summary> /// At present, the venue has "weak password" status iff the password field /// is non-null and no empty. There is no support for strong (encryption-based) /// passwords. /// /// </summary> /// <param name="v"></param> /// <param name="pvs"></param> //private void SetPasswordStatus(VenueState vs) //{ // PrivateVenueState pvs = vs.PrivateVenueState; // Venue v = vs.Venue; // if (pvs.PasswordHash != null && pvs.PasswordHash.Length > 0) // { // passwords.Add(v.Identifier, pvs.PasswordHash); // v.PWStatus = PasswordStatus.WEAK_PASSWORD; // } // else // { // passwords.Remove(v.Identifier); // v.PWStatus = PasswordStatus.NO_PASSWORD; // } //} private void SetPasswordStatus(VenueState vs) { Venue vnu = vs.Venue; if (vnu.PWStatus == PasswordStatus.NO_PASSWORD) { passwords.Remove(vnu.Identifier); } else { if (passwords.ContainsKey(vnu.Identifier)) { passwords.Remove(vnu.Identifier); } passwords.Add(vnu.Identifier, vs.PrivateVenueState.PasswordHash); } }
/// <summary> /// When the edit form is closing, check to make sure the IP is unique. /// </summary> private void CheckForDupID(object sender, CancelEventArgs e) { VenueEditor editor = (VenueEditor)sender; if (editor.DialogResult != DialogResult.OK) { return; } Venue ven = editor.GetVenue(); string id = ven.Identifier.ToLower(CultureInfo.InvariantCulture).Trim(); // First check to see if the ID changed from the selected venue // If it changed, we have to check against all of the venue IDs Venue original = editor.OriginalVenue; if (original.Identifier == null || original.Identifier.ToLower(CultureInfo.InvariantCulture).Trim() != id) { Venue dupIDVenue = null; // The IP has changed, so check to make sure it's not a dup foreach (ListViewItem item in list.Items) { VenueState currentVenueState = (VenueState)item.Tag; Venue currentVen = currentVenueState.Venue; if (currentVen.Identifier.ToLower(CultureInfo.InvariantCulture).Trim() == id) { dupIDVenue = currentVen; break; } } // If the ID is a duplicate, show an error and prevent the dialog from closing if (dupIDVenue != null) { RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.DuplicateOwnerText, dupIDVenue.Name), Strings.DuplicateOwnerTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); e.Cancel = true; } } }
private void editBtn_Click(object sender, EventArgs e) { VenueState selectedVenueState = (VenueState)list.SelectedItems[0].Tag; VenueEditor editor = new VenueEditor(selectedVenueState); editor.Text = Strings.EditVenue; editor.Closing += new CancelEventHandler(CheckForDupIP); editor.Closing += new CancelEventHandler(CheckForDupID); DialogResult dr = editor.ShowDialog(); if (dr == DialogResult.OK) { VenueState newVenueState = editor.GetVenueState(); if (newVenueState.Identifier != selectedVenueState.Identifier) { // The venue identifier was edited, so we need to completely delete & re-add this venue StorageFile.DeleteVenue(selectedVenueState.Identifier); StorageFile.AddVenue(newVenueState); } else { StorageFile.UpdateVenue(newVenueState); } // Don't remove the image; it will screw up the images for all of the other venues // But we will check to see if the image has changed (if not, just use the old imageIndex) int imageIndex; if (newVenueState.Venue.Icon == selectedVenueState.Venue.Icon) { imageIndex = list.SelectedItems[0].ImageIndex; } else { imageIndex = AddVenueIcon(newVenueState.Venue.Icon); } // Remove the old item list.Items.RemoveAt(list.SelectedIndices[0]); // Create and add the new item list.Items.Add(CreateLvi(newVenueState, imageIndex)); } }
/// <summary> /// When the edit form is closing, check to make sure the IP is unique. /// </summary> private void CheckForDupIP(object sender, CancelEventArgs e) { VenueEditor editor = (VenueEditor)sender; if (editor.DialogResult != DialogResult.OK) { return; } Venue ven = editor.GetVenue(); IPAddress ip = IPAddress.Parse(ven.IPAddress.Trim()); // First check to see if the IP changed from the selected venue // If it changed, we have to check against all of the venue IPs Venue original = editor.OriginalVenue; if (original.IPAddress == null || !IPAddress.Parse(original.IPAddress.Trim()).Equals(ip)) { Venue dupIPVenue = null; // The IP has changed, so check to make sure it's not a dup foreach (ListViewItem item in list.Items) { VenueState currentVenueState = (VenueState)item.Tag; Venue currentVen = currentVenueState.Venue; if (IPAddress.Parse(currentVen.IPAddress.Trim()).Equals(ip)) { dupIPVenue = currentVen; break; } } // If the IP is a duplicate, show an error and prevent the dialog from closing if (dupIPVenue != null) { RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.DuplicateIPAddressText, dupIPVenue.Name), Strings.DuplicateIpAddressTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); e.Cancel = true; } } }
public VenueEditor(VenueState venueState) { // // Required for Windows Form Designer support // InitializeComponent(); iconInput.DefaultIcon = defaultVenueIcon; // Show the venue information in the UI Venue venueToEdit = venueState.Venue; this.nameInput.Text = venueToEdit.Name; this.ownerInput.Text = venueToEdit.Identifier; this.ipInput.Text = venueToEdit.IPAddress; this.portInput.Text = venueToEdit.Port.ToString(CultureInfo.InvariantCulture); this.iconInput.IconAsBytes = venueToEdit.Icon; this.newAccessList = venueToEdit.AccessList; this.original = venueToEdit; this.privateVenueState = venueState.PrivateVenueState; this.passwordStatus = venueToEdit.PWStatus; }
private void newBtn_Click(object sender, EventArgs e) { VenueEditor editor = new VenueEditor(new VenueState()); editor.Text = Strings.NewVenue; editor.Closing += new CancelEventHandler(CheckForDupIP); editor.Closing += new CancelEventHandler(CheckForDupID); DialogResult dr = editor.ShowDialog(); if (dr == DialogResult.OK) { // Get the new venue VenueState venueState = editor.GetVenueState(); // Store it StorageFile.AddVenue(venueState); // Create the new LVI int imageIndex = AddVenueIcon(venueState.Venue.Icon); // Add it to the list list.Items.Add(CreateLvi(venueState, imageIndex)); } }
/// <summary> /// Return all state (client-visible and server-private) associated with /// the complete list of venues. This is used by only by the admin /// program, so the results are not obfucated (IP addresses /// are preserved). /// </summary> /// <returns></returns> public VenueState[] GetVenuesComplete() { this.UpdateFromFile(); ICollection vals = venues.Values; VenueState[] venueArray = new VenueState[vals.Count]; int i=0; foreach (Venue venue in vals) { PrivateVenueState pvs = this.GetPrivateVenueState(venue.Identifier); VenueState vs = new VenueState(venue,pvs); venueArray[i++] = vs; } return venueArray; }
public void AddVenue(VenueState vs) { this.UpdateFromFile(); Venue v = vs.Venue; venues.Add( v.Identifier, v); SetPasswordStatus(vs); WriteCacheToFile(); }
private ListViewItem CreateLvi(VenueState venueState, int imageIndex) { Venue venue = venueState.Venue; string[] columns = new string[]{venue.Name, venue.Identifier, venue.IPAddress.ToString(), venue.Port.ToString(CultureInfo.InvariantCulture)}; ListViewItem item = new ListViewItem(columns); item.ImageIndex = imageIndex; item.Tag = venueState; return item; }