Ejemplo n.º 1
0
        protected void CallContextEstablisher()
        {
            BaseMemTracker = new MemConsumptionTracker(MemTrackerMsgPrefix, MemTrackerStartMessage, GetMemTrackerEnabledState());
            BaseMemTracker.CompactMeasureAndReport("Before Context Established.", "Abstract Spec.");
            Action cleanupAction = EstablishContext();

            Destroyer = new ContextCleaner(cleanupAction);
            BaseMemTracker.CompactMeasureAndReport("After Context Established.", "Abstract Spec.");
        }
Ejemplo n.º 2
0
        protected override Action EstablishContext()
        {
            _mct = new MemConsumptionTracker
                   (
                "PSMT",
                "Starting MemTracker for PropStoreServices, AutoMapperSupport and related.",
                TrackMemConsumptionUsedToEstablishContext
                   );

            // Build the PropFactory Provider and the two Delegate Caches on which it depends.
            ITypeDescBasedTConverterCache typeDescBasedTConverterCache = new TypeDescBasedTConverterCache();

            _mct.MeasureAndReport("After new TypeDescBasedTConverterCache");

            IProvideDelegateCaches delegateCacheProvider = new SimpleDelegateCacheProvider(typeof(PropBag), typeof(APFGenericMethodTemplates));

            _mct.MeasureAndReport("After new SimpleDelegateCacheProvider");

            IConvertValues      valueConverter = new PropFactoryValueConverter(typeDescBasedTConverterCache);
            ResolveTypeDelegate typeResolver   = null;

            // The Factory used to build PropFactories.
            IPropFactoryFactory propFactoryFactory = BuildThePropFactoryFactory
                                                     (
                valueConverter,
                delegateCacheProvider,
                typeResolver
                                                     );

            // Build the Property Store and the EventHandler (Delegate) Dispatch cache on which it depends.
            // This Property Store is a regular property of this class and not a (static) AppDomain-wide singleton.

            IProvideHandlerDispatchDelegateCaches handlerDispatchDelegateCacheProvider = new SimpleHandlerDispatchDelegateCacheProvider();

            _mct.MeasureAndReport("After new SimpleHandlerDispatchDelegateCacheProvider");

            // Property Store
            _theStore = new SimplePropStoreProxy(MaxPropsPerObject, handlerDispatchDelegateCacheProvider);
            propModelBuilder
            // PropStoreAccessService Factory.
                PropStoreAccessService_Factory = _theStore.PropStoreAccessServiceFactory;

            // ViewModelActivator.
            ViewModelActivatorInterface vmActivator = new SimpleViewModelActivator();

            _mct.MeasureAndReport("After new SimpleViewModelActivator");

            WrapperTypeCreator = BuildSimpleWrapperTypeCreator();
            _mct.MeasureAndReport("After GetSimpleWrapperTypeCreator");


            // PropModel Provider
            RemotePropModelBuilder remotePropModelProvider = GetPropModelProvider(propFactoryFactory /*, ConfigPackageNameSuffix*/);

            //PropModelBuilder = remotePropModelProvider;
            _mct.MeasureAndReport("After GetPropModelProvider");

            // Load the PropBag and Mapper Templates
            LoadPropModelsAndMappers(remotePropModelProvider, ResourceFolderPath, PBTemplateFilenames, MapperRequestFilenames);
            _mct.MeasureAndReport("After LoadPropModelsAndMappers");

            PropModelCache = new SimplePropModelCache(remotePropModelProvider);

            // Create the ViewModelFactory
            ViewModelFactory = new SimpleViewModelFactory(PropModelCache, vmActivator, PropStoreAccessService_Factory, null, WrapperTypeCreator);
            _mct.MeasureAndReport("After new ViewModelFactory");

            // AutoMapper Services
            PropBagMapperService = GetAutoMapperProvider(ViewModelFactory);
            _mct.MeasureAndReport("After GetAutoMapperProvider");

            ViewModelFactory.AutoMapperService = PropBagMapperService;

            //// Default PropFactory
            //DefaultPropFactory = BuildDefaultPropFactory
            //    (
            //    valueConverter,
            //    delegateCacheProvider,
            //    typeResolver
            //    );

            //_mct.MeasureAndReport("After BuildDefaultPropFactory");

            return(OurCleanupRoutine);

            void OurCleanupRoutine()
            {
                _mct.CompactMeasureAndReport("Before Context Cleanup");

                // Wrapper Type Creator
                if (WrapperTypeCreator is IDisposable disable1)
                {
                    disable1.Dispose();
                }

                // AutoMapper Provider
                if (PropBagMapperService is IDisposable disable2)
                {
                    disable2.Dispose();
                }
                PropBagMapperService = null;

                // PropModel Provider
                if (PropModelCache is IDisposable disable3)
                {
                    disable3.Dispose();
                }
                PropModelCache = null;

                // ViewModel Helper
                //if (ViewModelHelper is IDisposable disable4)
                //{
                //    disable4.Dispose();
                //}
                //ViewModelHelper = null;

                // The Property Store
                _theStore.Dispose();

                // Type Converter Cache
                if (typeDescBasedTConverterCache is IDisposable disable5)
                {
                    disable5.Dispose();
                }

                // Delegate Cache Provider
                if (delegateCacheProvider is IDisposable disable6)
                {
                    disable6.Dispose();
                }

                // Event Handler Dispatcher Delegate Cache Provider
                if (handlerDispatchDelegateCacheProvider is IDisposable disable7)
                {
                    disable7.Dispose();
                }

                // PropModel Provider
                if (remotePropModelProvider is IDisposable disable8)
                {
                    disable8.Dispose();
                }

                propFactoryFactory = null;
                //DefaultPropFactory = null;

                _mct.CompactMeasureAndReport("After Context Cleanup");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a set of MergedDictionaries from the list of filenames at the basePath
        /// using a new thread using a Single Threaded Apartment.
        /// </summary>
        /// <param name="basePath"></param>
        /// <param name="filenames"></param>
        /// <returns>A ResourceDictionary whose MergedDictionaries property contains the set of merged resource dictionaries.</returns>
        public ResourceDictionary LoadUsingSTA(string basePath, string[] filenames)
        {
            _mct.CompactMeasureAndReport("Just Started LoadUsingSTA from a basePath and a list of filenames.");

            ResourceDictionary result = EmptySet;

            Thread thread = new Thread(() =>
            {
                result = Load(basePath, filenames);
            });

            thread.SetApartmentState(ApartmentState.STA);

            thread.Start();
            thread.Join();

            _mct.CompactMeasureAndReport("About to return from LoadUsingSTA.");

            return(result);
        }