using Microsoft.Practices.Composite.Presentation.Regions;
using ModuleB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RadDockingAndPRISM
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Shell : Window
    {
        public Shell()
        {
            InitializeComponent();
        }

        private void SelectCache(object sender, RoutedEventArgs e)
        {
            Application.Current.Resources.MergedDictionaries.Clear();
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("CacheTemplate.xaml",UriKind.RelativeOrAbsolute) });
            ClearPreviousValues();
        }

        private void SelectNonCache(object sender, RoutedEventArgs e)
        {
            Application.Current.Resources.MergedDictionaries.Clear();
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("NonCacheTemplate.xaml", UriKind.RelativeOrAbsolute) });
            ClearPreviousValues();
        }

        private void ClearPreviousValues()
        {
            var manager = RegionManager.GetRegionManager(Application.Current.MainWindow);
            if (manager != null)
            {
                foreach (var region in manager.Regions)
                {
                    foreach (var vms in region.Views)
                    {
                        if (vms is ViewTesterVm)
                        {
                            ((ViewTesterVm)vms).Reset();
                        }
                    }

                }
            }

        }

        private void RunGC(object sender, RoutedEventArgs e)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect(1);
            GC.WaitForPendingFinalizers();
            GC.Collect(2);
            GC.WaitForPendingFinalizers();
            GC.Collect(3);
            GC.WaitForPendingFinalizers();
            GC.Collect(4);
            GC.WaitForPendingFinalizers();

        }
    }
}
