Esempio n. 1
0
        private static IDesignTimeManager GeMaxPriorityManager(List <ConstructorInfo> managers)
        {
            IDesignTimeManager maxManager = null;

            for (int i = 0; i < managers.Count; i++)
            {
                var m = (IDesignTimeManager)managers[i].InvokeEx(Empty.Array <object>());
                if (maxManager == null || m.Priority > maxManager.Priority)
                {
                    if (maxManager != null)
                    {
                        maxManager.Dispose();
                    }
                    maxManager = m;
                }
            }
            return(maxManager);
        }
        private static void Initialize()
        {
            IList<Assembly> assemblies = GetAssemblies(false);
            if (assemblies.Count == 0)
                return;

            var managers = new List<ConstructorInfo>();
            for (int index = 0; index < assemblies.Count; index++)
                TryAddManagers(managers, assemblies[index]);

            //Trying to load all assemblies, WinRT designer has problems with loading assemblies with same name.
            if (_designTimeManager == null && managers.Count == 0)
            {
                assemblies.Clear();
                foreach (var assembly in LoadedAssemblies)
                {
                    if (CanLoadAssembly(true, assembly))
                        assemblies.Add(assembly);
                }
                for (int index = 0; index < assemblies.Count; index++)
                    TryAddManagers(managers, assemblies[index]);
                _isWinRT = managers.Count != 0;
            }

            bool isNew = false;
            IDesignTimeManager designTimeManager = null;
            if (_designTimeManager == null)
            {
                designTimeManager = GeMaxPriorityManager(managers);
                isNew = designTimeManager != null;
            }
            else
            {
                if (managers.Count != 1 || managers[0].DeclaringType != _designTimeManager.GetType())
                {
                    designTimeManager = GeMaxPriorityManager(managers);
                    isNew = designTimeManager != null && designTimeManager.GetType() != _designTimeManager.GetType();
                }
            }
            if (isNew)
            {
                if (_lastContext != null)
                {
                    foreach (var module in LoadedModules.Values)
                    {
                        module.Unload(_lastContext);
                        module.TraceModule(false);
                    }
                    LoadedModules.Clear();
                }
                if (_designTimeManager != null)
                {
                    _designTimeManager.Dispose();
                    Tracer.Info("The design time manager was unloaded " + _designTimeManager);
                }

                _designTimeManager = designTimeManager;
                _designTimeManager.Initialize();
                Tracer.Info("The design time manager was loaded " + _designTimeManager);
                InitializeDesignTimeModules(GetAssemblies(true), true);
            }
            else
                InitializeDesignTimeModules(assemblies, false);
        }
Esempio n. 3
0
        private static void Initialize()
        {
            IList <Assembly> assemblies = GetAssemblies(false);

            if (assemblies.Count == 0)
            {
                return;
            }

            var managers = new List <ConstructorInfo>();

            for (int index = 0; index < assemblies.Count; index++)
            {
                TryAddManagers(managers, assemblies[index]);
            }

            //Trying to load all assemblies, WinRT designer has problems with loading assemblies with same name.
            if (_designTimeManager == null && managers.Count == 0)
            {
                assemblies.Clear();
                foreach (var assembly in LoadedAssemblies)
                {
                    if (CanLoadAssembly(true, assembly))
                    {
                        assemblies.Add(assembly);
                    }
                }
                for (int index = 0; index < assemblies.Count; index++)
                {
                    TryAddManagers(managers, assemblies[index]);
                }
                _isWinRT = managers.Count != 0;
            }

            bool isNew = false;
            IDesignTimeManager designTimeManager = null;

            if (_designTimeManager == null)
            {
                designTimeManager = GeMaxPriorityManager(managers);
                isNew             = designTimeManager != null;
            }
            else
            {
                if (managers.Count != 1 || managers[0].DeclaringType != _designTimeManager.GetType())
                {
                    designTimeManager = GeMaxPriorityManager(managers);
                    isNew             = designTimeManager != null && designTimeManager.GetType() != _designTimeManager.GetType();
                }
            }
            if (isNew)
            {
                if (_lastContext != null)
                {
                    foreach (var module in LoadedModules.Values)
                    {
                        module.Unload(_lastContext);
                        module.TraceModule(false);
                    }
                    LoadedModules.Clear();
                }
                if (_designTimeManager != null)
                {
                    _designTimeManager.Dispose();
                    Tracer.Info("The design time manager was unloaded " + _designTimeManager);
                }

                _designTimeManager = designTimeManager;
                _designTimeManager.Initialize();
                Tracer.Info("The design time manager was loaded " + _designTimeManager);
                InitializeDesignTimeModules(GetAssemblies(true), true);
            }
            else
            {
                InitializeDesignTimeModules(assemblies, false);
            }
        }