示例#1
0
        //public virtual IProp CreateGenFromString(Type typeOfThisProperty,
        //    string value, bool useDefault,
        //    PropNameType propertyName, object extraInfo,
        //    PropStorageStrategyEnum storageStrategy, bool isTypeSolid, PropKindEnum propKind,
        //    Delegate comparer, bool useRefEquality = false, Type itemType = null)
        //{
        //    MemConsumptionTracker mct = new MemConsumptionTracker(enabled: false);

        //    if (propKind == PropKindEnum.Prop)
        //    {
        //        CreateScalarProp propCreator = GetPropCreator(typeOfThisProperty);
        //        mct.MeasureAndReport("GetPropCreator", $"for {propertyName}");

        //        // TODO: This is where strings are parsed to create objects of type T.
        //        // TODO: This needs more work, to say the least.


        //        IProp prop = propCreator(this, haveValue: true, value: value, useDefault: useDefault, propertyName: propertyName,
        //            extraInfo: extraInfo, storageStrategy: storageStrategy, isTypeSolid: isTypeSolid,
        //            comparer: comparer, useRefEquality: useRefEquality, getDefaultValFunc: null);

        //        mct.MeasureAndReport("Ran propCreator to get IProp", $"for {propertyName}");

        //        return prop;
        //    }
        //    else if (propKind.IsCollection())
        //    {
        //        CreateCPropFromStringDelegate propCreator = GetCPropFromStringCreator(typeOfThisProperty, itemType);
        //        mct.MeasureAndReport("GetCPropFromStringCreator", $"for {propertyName}");

        //        IProp prop = propCreator(this, value: value, useDefault: useDefault, propertyName: propertyName,
        //            extraInfo: extraInfo, storageStrategy: storageStrategy, isTypeSolid: isTypeSolid,
        //            comparer: comparer, useRefEquality: useRefEquality);

        //        mct.MeasureAndReport("Ran GetCPropFromStringCreator to get IProp", $"for {propertyName}");

        //        return prop;
        //    }
        //    else
        //    {
        //        throw new InvalidOperationException($"PropKind = {propKind} is not recognized or is not supported.");
        //    }
        //}

        public virtual IProp CreateGenWithNoValue(Type typeOfThisProperty,
                                                  PropNameType propertyName, object extraInfo,
                                                  PropStorageStrategyEnum storageStrategy, bool isTypeSolid, PropKindEnum propKind,
                                                  Delegate comparer, bool useRefEquality = false, Type itemType = null)
        {
            MemConsumptionTracker mct = new MemConsumptionTracker(enabled: false);

            if (propKind == PropKindEnum.Prop)
            {
                CreateScalarProp propCreator = GetPropCreator(typeOfThisProperty);
                mct.MeasureAndReport("GetPropCreator", $"for {propertyName}");

                IProp prop = propCreator(this, haveValue: false, value: null, useDefault: false, propertyName: propertyName,
                                         extraInfo: extraInfo, storageStrategy: storageStrategy, isTypeSolid: isTypeSolid,
                                         comparer: comparer, useRefEquality: useRefEquality, getDefaultValFunc: null);

                mct.MeasureAndReport("Ran propCreator to get IProp", $"for {propertyName}");

                return(prop);
            }
            else if (propKind.IsCollection())
            {
                CreateCPropWithNoValueDelegate propCreator = GetCPropWithNoValueCreator(typeOfThisProperty, itemType);
                IProp prop = propCreator(this, propertyName: propertyName,
                                         extraInfo: extraInfo, storageStrategy: storageStrategy, isTypeSolid: isTypeSolid,
                                         comparer: comparer, useRefEquality: useRefEquality);

                return(prop);
            }
            else
            {
                throw new InvalidOperationException($"PropKind = {propKind} is not recognized or is not supported.");
            }
        }
        static PropStoreServicesForThisApp()
        {
            _mct.Measure("Begin PropStoreServicesForThisApp");

            //Person p = new Person();
            //    _mct.MeasureAndReport("New Person");

            // 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;

            _propFactoryFactory = BuildThePropFactoryFactory(valueConverter, delegateCacheProvider, typeResolver);

            // Build the AppDomain-Wide Property Store and the EventHandler (Delegate) Dispatch cache on which it depends.
            HandlerDispatchDelegateCacheProvider = new SimpleHandlerDispatchDelegateCacheProvider();
            _mct.MeasureAndReport("After new SimpleHandlerDispatchDelegateCacheProvider");

            // This creates the global, shared, Property Store.
            _theStore = new SimplePropStoreProxy(MAX_NUMBER_OF_PROPERTIES, HandlerDispatchDelegateCacheProvider);

            // Get a reference to the PropStoreAccessService Factory that the PropertyStore provides.
            PSAccessServiceCreatorInterface psAccessServiceFactory = _theStore.PropStoreAccessServiceFactory;

            _vmActivator = new SimpleViewModelActivator();
            _mct.MeasureAndReport("After new SimpleViewModelActivator");


            IPropModelBuilder propModelBuilder = GetPropModelProvider(_propFactoryFactory);

            PropModelCache = new SimplePropModelCache(propModelBuilder);

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


            ViewModelFactory = new SimpleViewModelFactory(PropModelCache, _vmActivator, psAccessServiceFactory, null, WrapperTypeCreator);
            _mct.MeasureAndReport("After new ViewModelHelper");

            AutoMapperService = GetAutoMapperProvider(ViewModelFactory);
            _mct.MeasureAndReport("After GetAutoMapperProvider");

            ViewModelFactory.AutoMapperService = AutoMapperService;


            //_defaultPropFactory = BuildDefaultPropFactory(valueConverter, delegateCacheProvider, typeResolver);
            //_mct.MeasureAndReport("After new BuildDefaultPropFactory");
        }
示例#3
0
        private void PropBagProxyEmit_Click(object sender, RoutedEventArgs e)
        {
            _mct.Enabled = true;
            _mct.CompactAndMeasure("Before Starting MainWindow (EmitProxy)");

            ShowMain("Emit");

            _mct.MeasureAndReport("The Main Window has been closed. Before Compaction.", "FrontWindow");
            _mct.CompactAndMeasure();
            _mct.MeasureAndReport("The Main Window has been closed. After Compaction.", "FrontWindow");
        }
示例#4
0
        protected virtual RemotePropModelBuilder GetPropModelProvider
        (
            IPropFactoryFactory propFactoryFactory
            //, string configPackageNameSuffix
        )
        {
            ResourceDictionaryProvider rdProvider = new ResourceDictionaryProvider();

            PropBagTemplateParser pbtParser = new PropBagTemplateParser();

            RemotePropModelBuilder propModelBuilder = new RemotePropModelBuilder(rdProvider, pbtParser, propFactoryFactory /*, configPackageNameSuffix*/);

            _mct.MeasureAndReport("After new PropModelBuilder");

            return(propModelBuilder);
        }
示例#5
0
        public Type TargetRunTimeType => DestinationType;  //=> RunTimeType;

        #endregion

        #region Constructor

        public AbstractPropBagMapper
        (
            PropModelType propModel,
            IMapper mapper,
            ViewModelFactoryInterface viewModelFactory,
            IPropBagMapperService propBagMapperService,
            IConfigureAMapper <TSource, TDestination> mappingConfiguration
        )
        {
            SourceType      = typeof(TSource);
            DestinationType = typeof(TDestination);

            PropModel = propModel;               //(PropModelType) mapRequest.DestinationTypeDef.UniqueRef;

            PropFactory = PropModel.PropFactory; // (IPropFactory)mapRequest.DestinationTypeDef.PropFactory;

            Mapper = mapper;

            _viewModelFactory     = viewModelFactory;
            _propBagMapperService = propBagMapperService;
            _mappingConfiguration = mappingConfiguration;

            SupportsMapFrom = true;

            _requiresWrappperTypeEmitServices = _mappingConfiguration.RequiresWrappperTypeEmitServices;

            CheckRequiresEmitted(_requiresWrappperTypeEmitServices, DestinationType);

            _mct.Measure();

            _destPropBagTemplate = GetDestinationTemplate(DestinationType);

            _mct.MeasureAndReport("GetNewDestination(PropModel, ... [In Constructor]", "AbstractPropBagMapper");

            // Working on see if we can get the SupportsMapFrom from the Mapper itself.
            //TypePair tp = new TypePair(SourceType, DestinationType);
            //IObjectMapper mpr = mapper.ConfigurationProvider.FindMapper(tp);

            return;
        }
示例#6
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");
            }
        }