Beispiel #1
0
        /// <summary>
        /// Responds to the save command from the current (sub) view model.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _currentViewModel_OnSaved(object sender, System.EventArgs e)
        {
            if (CurrentViewModel is VirtualHostVM)
            {
                var vHost = ((VirtualHostVM)CurrentViewModel).SelectedVirtualHost;
                if (vHost == null)
                {
                    return;
                }

                var old = VirtualHosts.FirstOrDefault(p => p.Id == vHost.Id);

                if (old == null)
                {
                    VirtualHosts.Add(vHost);
                }
                else
                {
                    var idx = VirtualHosts.IndexOf(old);
                    VirtualHosts.Remove(old);
                    VirtualHosts.Insert(idx, vHost);
                }

                // This bypasses the INotify event.
                // Currently there doesn't seem much point firing the event, but this may change later.
                _selectedVirtualHost = vHost;
            }
            else if (CurrentViewModel is HostFileEntryVM)
            {
                var host = ((HostFileEntryVM)CurrentViewModel).CurrentHostFileEntry;
                if (host == null)
                {
                    return;
                }

                var old = HostFileEntries.FirstOrDefault(p => p.Id == host.Id);

                if (old == null)
                {
                    HostFileEntries.Add(host);
                }
                else
                {
                    var idx = HostFileEntries.IndexOf(old);
                    HostFileEntries.Remove(old);
                    HostFileEntries.Insert(idx, host);
                }

                // This bypasses the INotify event.
                // Currently there doesn't seem much point firing the event, but this may change later.
                _selectedHostFileEntry = host;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets associated objects when required.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _objectViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            object obj = null;

            switch (e.PropertyName)
            {
            case "CurrentHostFileEntry":
                // Set the backing value so we skip the actions that occur when assigning to the public property.
                _selectedVirtualHost = VirtualHosts.FirstOrDefault(
                    p => p.ServerName == SelectedHostFileEntry.Url ||
                    p.ServerAlias == SelectedHostFileEntry.Url);

                // Assign found value to obj, even if null as this will tell the viewmodel to clear the property.
                obj = _selectedVirtualHost;

                // Now we need to raise the property changed event on the changed property to allow UI to react.
                OnPropertyChanged("SelectedVirtualHost");
                break;

            case "SelectedVirtualHost":
                _selectedHostFileEntry = HostFileEntries.FirstOrDefault(
                    p => p.Url == SelectedVirtualHost.ServerName ||
                    p.Url == SelectedVirtualHost.ServerAlias);

                obj = _selectedHostFileEntry;

                OnPropertyChanged("SelectedHostFileEntry");
                break;

            default:
                // If not a property we want to act on we should return to prevent setting unwanted values.
                return;
            }
            CurrentViewModel.SetAssociatedObject(obj);
        }