private void OKClicked(object sender, RoutedEventArgs e) { List <string> errors = new List <string>(); Location location; using (new WaitCursor()) { location = this.TryGetLocation(errors); if (location == null && errors.Count == 0) { errors.Add("Unable to create new location instance."); } } if (this.IsValid(errors)) { bool pingOk = true; const int WaitMilliseconds = 200; using (Pinger pinger = new Pinger(TimeSpan.FromMilliseconds(WaitMilliseconds))) { if (!(pinger.TryPing(location.Address) ?? false)) { // Occasionally, a ping will be lost, and it's ok. The user might also want to configure // a site to watch that is known to be intermittently available. pingOk = WindowsUtility.ShowQuestion(this, "The specified address did not respond to a ping. Continue?", null, false); } } if (pingOk) { this.DialogResult = true; } } }
private void WindowClosing(object sender, CancelEventArgs e) { if (!this.IsSessionEnding && (this.appOptions?.ConfirmClose ?? false) && !e.Cancel) { e.Cancel = !WindowsUtility.ShowQuestion(this, "Are you sure you want to exit?"); } if (!e.Cancel) { this.closing = true; this.backgroundTimer.Dispose(); this.CloseLogger(); } }
private void DeleteItemExecuted(object sender, ExecutedRoutedEventArgs e) { StatusRow statusRow = this.SelectedStatusRow; if (statusRow != null) { Location location = this.profile.Locations.FirstOrDefault(l => l.Id == statusRow.LocationId); if (location != null) { bool deletePeerGroup = this.profile.Locations.Count(l => l.PeerGroup == location.PeerGroup) == 1; StringBuilder sb = new StringBuilder("Are you sure you want to delete location \""); sb.Append(statusRow.LocationName).Append('"'); if (deletePeerGroup) { sb.Append(" (and peer group \"").Append(location.PeerGroup.Name).Append("\")"); } sb.Append('?'); string message = sb.ToString(); string caption = ApplicationInfo.ApplicationName; if (WindowsUtility.ShowQuestion(this, message, caption)) { using (new WaitCursor()) { this.profile.Locations.Remove(location); // Note: Don't remove from this.statusRowMap here. Let the next Update cycle clean it up. this.statusRows.Remove(statusRow); if (deletePeerGroup) { this.profile.PeerGroups.Remove(location.PeerGroup); // Note: Don't remove from this.failedPeerGroupToLogRowMap. Let the next Update cycle clean it up. LogRow[] removeLogRows = this.logRows.Where(row => row.PeerGroupId == location.PeerGroup.Id).ToArray(); foreach (LogRow row in removeLogRows) { this.logRows.Remove(row); } } } } } } this.TryFocus(this.statusGrid); }