Exemplo n.º 1
0
        private void EditLocation(StatusRow statusRow)
        {
            ObservableCollection <PeerGroup> peerGroups = this.profile.PeerGroups;

            if (peerGroups.Count > 0 || (this.EditPeerGroups() && peerGroups.Count > 0))
            {
                ObservableCollection <Location> locations = this.profile.Locations;

                bool     insert        = statusRow == null;
                Location location      = insert ? null : locations.FirstOrDefault(l => l.Id == statusRow.LocationId);
                int      locationIndex = location == null ? -1 : locations.IndexOf(location);

                LocationDialog dialog = new LocationDialog();
                if (dialog.Execute(this, peerGroups, ref location))
                {
                    if (location != null && peerGroups.Contains(location.PeerGroup))
                    {
                        if (locationIndex >= 0 && locationIndex < locations.Count)
                        {
                            locations[locationIndex] = location;
                        }
                        else
                        {
                            locations.Add(location);
                        }
                    }
                }

                this.TryFocus(this.statusGrid);
            }
        }
Exemplo n.º 2
0
        private void UpdateStatusRows(StateSnapshot states)
        {
            HashSet <Guid> currentLocations = new HashSet <Guid>(this.statusRowMap.Comparer);

            foreach (var pair in states.AllPeerGroupLocations)
            {
                PeerGroupState peerGroupState = pair.Key;
                foreach (LocationState locationState in pair.Value)
                {
                    Guid locationId = locationState.Location.Id;
                    currentLocations.Add(locationId);

                    if (this.statusRowMap.TryGetValue(locationId, out StatusRow row))
                    {
                        row.Update(peerGroupState, locationState);
                    }
                    else
                    {
                        row = new StatusRow();
                        row.Update(peerGroupState, locationState);
                        this.statusRows.Add(row);
                        this.statusRowMap.Add(locationId, row);
                    }
                }
            }

            foreach (var pair in this.statusRowMap.Where(pair => !currentLocations.Contains(pair.Key)).ToArray())
            {
                this.statusRows.Remove(pair.Value);
                this.statusRowMap.Remove(pair.Key);
            }
        }
Exemplo n.º 3
0
        private void StatusGridMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            StatusRow statusRow = this.SelectedStatusRow;

            if (statusRow != null)
            {
                this.EditLocation(statusRow);
            }
        }
Exemplo n.º 4
0
        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);
        }