GoogleCloudExtension.CloudExplorerSources.Gce.GceSourceRootViewModel.PresentViewModels C# (CSharp) Method

PresentViewModels() private method

private PresentViewModels ( ) : void
return void
        private void PresentViewModels()
        {
            // If there's no data then there's nothing to do.
            if (_instancesPerZone == null)
            {
                return;
            }

            IEnumerable<TreeNode> viewModels;
            if (_showZones)
            {
                // This query creates the zone view model with the following steps:
                //   * Create an object that represents the zone and the instances that must be shown (after filtering)
                //     for that zone. The instances in the zone are sorted by their name.
                //   * Filter out the zones that (after filtering instances) are empty.
                //   * Sort the resulting zones by the zone name.
                //   * Create the view model for each zone, containing the instances for that zone.
                viewModels = _instancesPerZone
                    .Select(x => new
                    {
                        Zone = x.Zone,
                        Instances = x.Instances
                            .Where(i => _showOnlyWindowsInstances ? i.IsWindowsInstance() : true)
                            .OrderBy(i => i.Name)
                    })
                    .Where(x => x.Instances.Count() > 0)
                    .OrderBy(x => x.Zone.Name)
                    .Select(x => new ZoneViewModel(this, x.Zone, x.Instances.Select(i => new GceInstanceViewModel(this, i))));
            }
            else
            {
                // This query gets the list of view models for the instnaces with the following steps:
                //   * Select all of the instances in all of the zones in a source list.
                //   * Filters the instances according to the _showOnlyWindowsInstances setting.
                //   * Sorts the resulting instances by name.
                //   * Creates the view model for each instance.
                viewModels = _instancesPerZone
                    .SelectMany(x => x.Instances)
                    .Where(x => _showOnlyWindowsInstances ? x.IsWindowsInstance() : true)
                    .OrderBy(x => x.Name)
                    .Select(x => new GceInstanceViewModel(this, x));
            }
            UpdateViewModels(viewModels);
        }