internal LaunchProfile CreateProfile(string name, string commandName)
        {
            var profile = new LaunchProfile()
            {
                Name = name, CommandName = commandName
            };

            DebugProfiles.Add(profile);

            // Fire a property changed so we can get the page to be dirty when we add a new profile
            OnPropertyChanged("_NewProfile");
            SelectedDebugProfile = profile;
            return(profile);
        }
 internal bool IsNewProfileNameValid(string name)
 {
     return(DebugProfiles.Where(
                profile => LaunchProfile.IsSameProfileName(profile.Name, name)).Count() == 0);
 }
        /// <summary>
        /// Called whenever the debug targets change. Note that after a save this function will be
        /// called. It looks for changes and applies them to the UI as needed. Switching profiles
        /// will also cause this to change as the active profile is stored in profiles snaphost.
        /// </summary>
        internal virtual void InitializeDebugTargetsCore(ILaunchSettings profiles)
        {
            bool profilesChanged    = true;
            bool IISSettingsChanged = true;

            // Since this get's reentered if the user saves or the user switches active profiles.
            if (DebugProfiles != null)
            {
                profilesChanged = profiles.ProfilesAreDifferent(DebugProfiles.Select(p => (ILaunchProfile)p).ToList());
                if (!profilesChanged && !IISSettingsChanged)
                {
                    return;
                }
            }

            try
            {
                // This should never change the dirty state
                PushIgnoreEvents();

                if (profilesChanged)
                {
                    // Remember the current selection
                    string curProfileName = SelectedDebugProfile == null ? null : SelectedDebugProfile.Name;

                    // Load debug profiles
                    var debugProfiles = new ObservableCollection <LaunchProfile>();

                    foreach (var profile in profiles.Profiles)
                    {
                        // Don't show the dummy NoAction profile
                        if (profile.CommandName != ProfileCommandNames.NoAction)
                        {
                            var newProfile = new LaunchProfile(profile);
                            debugProfiles.Add(newProfile);
                        }
                    }

                    DebugProfiles = debugProfiles;

                    // If we have a selection, we want to leave it as is
                    if (curProfileName == null || profiles.Profiles.FirstOrDefault(p => { return(LaunchProfile.IsSameProfileName(p.Name, curProfileName)); }) == null)
                    {
                        // Note that we have to be careful since the collection can be empty.
                        if (!string.IsNullOrEmpty(profiles.ActiveProfile.Name))
                        {
                            SelectedDebugProfile = DebugProfiles.Where((p) => LaunchProfile.IsSameProfileName(p.Name, profiles.ActiveProfile.Name)).Single();
                        }
                        else
                        {
                            if (debugProfiles.Count > 0)
                            {
                                SelectedDebugProfile = debugProfiles[0];
                            }
                            else
                            {
                                SetEnvironmentGrid(null);
                            }
                        }
                    }
                    else
                    {
                        SelectedDebugProfile = DebugProfiles.Where((p) => LaunchProfile.IsSameProfileName(p.Name, curProfileName)).Single();
                    }
                }
            }
            finally
            {
                PopIgnoreEvents();
            }
        }