示例#1
0
        public void Z_BindParent()
        {
            AutoMapperHelpers ourHelper = new AutoMapperHelpers();

            IPropBagMapperService autoMapperService = ourHelper.GetAutoMapperSetup_V1();

            IPropFactory        propFactory_V1     = ourHelper.GetNewPropFactory_V1();
            ICreateWrapperTypes wrapperTypeCreator = ourHelper.GetWrapperTypeCreator_V1();

            ViewModelFactoryInterface viewModelFactory = ourHelper.ViewModelFactory;

            //viewModelFactory.PropModelCache.Add(propModel5);
            _propModelCache = viewModelFactory.PropModelCache;


            Assert.That(ourHelper.StoreAccessCreator.AccessCounter == 0, "The Provider of PropStoreAccessServices has not had its Access Counter reset.");

            List <DestinationModel1> destinationList = new List <DestinationModel1>();



            PropModelHelpers pmHelpers = new PropModelHelpers();

            // Set up Child VM (Using Model 5)
            PropModelType propModel5 = pmHelpers.GetPropModelForModel5Dest(propFactory_V1, _propModelCache);


            DestinationModel5 testChildVM = new DestinationModel5(pm: propModel5, viewModelFactory: viewModelFactory, autoMapperService: autoMapperService, propFactory: propFactory_V1, fullClassName: "PropBagLib.Tests.PerformanceDb.DestinationModel5");

            Business b = new Business();

            testChildVM.SetIt(b, "Business");
            testChildVM.RegisterBinding <Business>("Business", "../Business");

            //List<Person> personList = b.Get().ToList();
            //ObservableCollection<Person> personList2 = new ObservableCollection<Person>(personList);
            //testChildVM.SetIt(personList2, "PersonCollection");


            // Set up MainVM (Using Model 6)
            PropModelType     propModel6 = pmHelpers.GetPropModelForModel6Dest(propFactory_V1, _propModelCache);
            DestinationModel6 testMainVM = new DestinationModel6(propModel6, viewModelFactory, autoMapperService, propFactory_V1, null);

            Business b2 = new Business();

            testMainVM.SetIt(b2, "Business");


            testMainVM.SetIt <DestinationModel5>(testChildVM, "ChildVM");
            testMainVM.RegisterBinding <Business>("Business", "./ChildVM/Business");

            b2 = new Business();
            testMainVM.SetIt(b2, "Business");
        }
示例#2
0
        public void SetupAutoMapperSupport_V1()
        {
            AutoMapperHelpers ourHelper = new AutoMapperHelpers();

            _propFactory_V1        = ourHelper.PropFactory_V1;
            _amp                   = ourHelper.GetAutoMapperSetup_V1();
            _wrapperTypeCreator_V1 = ourHelper.GetWrapperTypeCreator_V1();
            PropModelCacheInterface _propModelCache = ourHelper.GetPropModelCache_V1();

            _viewModelFactory = ourHelper.ViewModelFactory;
        }
示例#3
0
 /// <summary>
 /// Full service, all arguments must have a non-null value.
 /// </summary>
 /// <param name="propModelCache"></param>
 /// <param name="viewModelActivator"></param>
 /// <param name="storeAccessCreator"></param>
 /// <param name="autoMapperService"></param>
 /// <param name="wrapperTypeCreator"></param>
 public SimpleViewModelFactory
 (
     PropModelCacheInterface propModelCache,
     ViewModelActivatorInterface viewModelActivator,
     PSAccessServiceCreatorInterface storeAccessCreator,
     object autoMapperService,
     ICreateWrapperTypes wrapperTypeCreator
 )
     : this(propModelCache, viewModelActivator, storeAccessCreator)
 {
     AutoMapperService   = autoMapperService; // ?? throw new ArgumentNullException(nameof(autoMapperService));
     _wrapperTypeCreator = wrapperTypeCreator ?? throw new ArgumentNullException(nameof(wrapperTypeCreator));
 }
示例#4
0
        /// <summary>
        /// This is provided for use by clients that require no loading of PropModels by FullClassName,
        /// or will otherwise retrieve PropModels using some other mechanisim.
        /// </summary>
        /// <param name="viewModelActivator"></param>
        /// <param name="storeAccessCreator"></param>
        public SimpleViewModelFactory
        (
            ViewModelActivatorInterface viewModelActivator,
            PSAccessServiceCreatorInterface storeAccessCreator
        )
        {
            _propModelCache     = null;
            _viewModelActivator = viewModelActivator ?? throw new ArgumentNullException(nameof(viewModelActivator));
            _storeAccessCreator = storeAccessCreator ?? throw new ArgumentNullException(nameof(storeAccessCreator));

            AutoMapperService   = null;
            _wrapperTypeCreator = null;
        }
示例#5
0
        public PropModelType GetPropModelForModel5Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache)
        {
            PropModelType result = new PropModel
                                   (
                className: "DestinationModel5",
                namespaceName: "PropBagLib.Tests.PerformanceDb",
                deriveFrom: DeriveFromClassModeEnum.Custom,
                targetType: typeof(DestinationModel5),
                propFactory: propFactory,
                propFactoryType: null,
                propModelCache: null,
                typeSafetyMode: PropBagTypeSafetyMode.Tight,
                deferMethodRefResolution: true,
                requireExplicitInitialValue: true
                                   );

            result.Namespaces.Add("System");
            result.Namespaces.Add("DRM.PropBag");
            result.Namespaces.Add("DRM.TypeSafePropertyBag");

            // ProductId (Guid - default)
            IPropInitialValueField pivf = PropInitialValueField.UseDefault;

            PropItemModel propItem = new PropItemModel(type: typeof(Guid), name: "ProductId",
                                                       storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                                       initialValueField: pivf);

            result.Add(propItem.PropertyName, propItem);


            // Business (Business - null)
            pivf = PropInitialValueField.UseNull;

            propItem = new PropItemModel(type: typeof(Business), name: "Business",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);


            // PersonCollection (ObservableCollection<Person> - null)
            propItem = new PropItemModel(type: typeof(ObservableCollection <Person>), name: "PersonCollection",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.ObservableCollection,
                                         initialValueField: pivf, itemType: typeof(Person));
            result.Add(propItem.PropertyName, propItem);

            result.Open();

            propModelCache.Add(result);

            return(result);
        }
示例#6
0
        public void CanMapObservableCollection_AProxy()
        {
            _ourHelper      = new AutoMapperHelpers();
            _propFactory_V1 = _ourHelper.GetNewPropFactory_V1();
            _amp            = _ourHelper.GetAutoMapperSetup_V1();
            _propModelCache = _ourHelper.GetPropModelCache_V1();

            _pmHelpers = new PropModelHelpers();

            string configPackageName = "Emit_Proxy";

            ObservableCollTestObject oTester = new ObservableCollTestObject();

            oTester.CanMapObservableCollection(configPackageName, _ourHelper, _propFactory_V1, _propModelCache, _amp, _pmHelpers, NUMBER_OF_PEOPLE);
            //oTester.DoCleanup();
        }
示例#7
0
        public PropModelCacheInterface GetPropModelCache_V1()
        {
            if (_propModelCache_V1 == null)
            {
                IPropFactoryFactory propFactoryFactory = GetThePropFactoryFactory();

                // PropModel Provider
                RemotePropModelBuilder remotePropModelProvider = GetPropModelProvider(propFactoryFactory);

                // Load the PropBag and Mapper Templates
                LoadPropModelsAndMappers(remotePropModelProvider, _resourceFolderPath, _pbTemplateFilenames, _mapperRequestFilenames);

                _propModelCache_V1 = new SimplePropModelCache(remotePropModelProvider);
            }
            return(_propModelCache_V1);
        }
示例#8
0
        public void MapOcAndCleanUp()
        {
            GC.WaitForPendingFinalizers();
            GC.WaitForFullGCComplete();

            _ourHelper = new AutoMapperHelpers();
            ICreateWrapperTypes wrapperTypeCreator = _ourHelper.GetWrapperTypeCreator_V1();

            _propFactory_V1 = _ourHelper.GetNewPropFactory_V1();
            _propModelCache = _ourHelper.GetPropModelCache_V1();

            _amp = _ourHelper.GetAutoMapperSetup_V1();

            _pmHelpers = new PropModelHelpers();

            string configPackageName = "Extra_Members";

            ObservableCollTestObject oTester = new ObservableCollTestObject();

            oTester.CanMapObservableCollection(configPackageName, _ourHelper, _propFactory_V1, _propModelCache, _amp, _pmHelpers, NUMBER_OF_PEOPLE);

            oTester.DoCleanup();
            oTester = null;

            //Thread.Sleep(new TimeSpan(0, 0, 1));

            //for (int tp = 0; tp < 5; tp++)
            //{
            //    // Yield for 1 seconds.
            //    Thread.Sleep(new TimeSpan(0, 0, 1));
            //    GC.WaitForPendingFinalizers();
            //    GC.WaitForFullGCComplete();
            //}

            GC.WaitForPendingFinalizers();
            GC.WaitForFullGCComplete();
        }
        public void CanMapObservableCollection(
            string configPackageName,
            AutoMapperHelpers ourHelper,
            IPropFactory propFactory_V1,
            PropModelCacheInterface propModelCache,
            IPropBagMapperService amp,
            PropModelHelpers pmHelpers,
            int numberOfItemsToLoad
            )
        {
            ourHelper.StoreAccessCreator.ResetAccessCounter();

            Assert.That(ourHelper.StoreAccessCreator.AccessCounter == 0, "The Provider of PropStoreAccessServices did not have its Access Counter reset.");

            // Setup Mapping between Model1 and Person
            PropModelType propModel1 = pmHelpers.GetPropModelForModel1Dest(propFactory_V1, propModelCache);

            ViewModelActivatorInterface viewModelActivator = new SimpleViewModelActivator();
            IPropBagMapperService       autoMapperService  = ourHelper.GetAutoMapperSetup_V1();
            ICreateWrapperTypes         wrapperTypeCreator = ourHelper.GetWrapperTypeCreator_V1();

            ViewModelFactoryInterface viewModelFactory = new SimpleViewModelFactory(propModelCache, viewModelActivator, ourHelper.StoreAccessCreator, amp, wrapperTypeCreator);

            // TODO: Move this to a separate test.
            #region Clone Tests

            // Make sure we can activate (or clone as appropriate) the destination type.
            DestinationModel1 test = new DestinationModel1(PropBagTypeSafetyMode.AllPropsMustBeRegistered, ourHelper.StoreAccessCreator, ourHelper.PropFactory_V1, "Test");
            if (configPackageName == "Emit_Proxy")
            {
                DestinationModel1 testCopy = new DestinationModel1(test);
            }
            else
            {
                DestinationModel1 testCopy = (DestinationModel1)test.Clone();
            }

            DestinationModel1 test2 = new DestinationModel1(propModel1, viewModelFactory, amp, ourHelper.PropFactory_V1, null);

            if (configPackageName == "Emit_Proxy")
            {
                DestinationModel1 test2Copy = new DestinationModel1(test2);
            }
            else
            {
                DestinationModel1 test2Copy = (DestinationModel1)test2.Clone();
            }

            #endregion

            Type typeToWrap = typeof(PropBag);

            IMapperRequest localMr = new MapperRequest(typeof(Person), propModel1, configPackageName);

            IPropBagMapper <Person, DestinationModel1>           propBagMapper           = null;
            IPropBagMapperRequestKey <Person, DestinationModel1> propBagMapperRequestKey = null;

            IPropBagMapperGen           propBagMapperGen           = null;
            IPropBagMapperRequestKeyGen propBagMapperRequestKeyGen = null;

            if (configPackageName == "Emit_Proxy")
            {
                wrapperTypeCreator = ourHelper.GetWrapperTypeCreator_V1();
                Type et = wrapperTypeCreator.GetWrapperType(propModel1, typeToWrap);
                propModel1.NewEmittedType = et;

                propBagMapperGen = AutoMapperHelpers.GetAutoMapper
                                   (
                    localMr,
                    amp,
                    out propBagMapperRequestKeyGen
                                   );
                Assert.That(propBagMapperRequestKeyGen, Is.Not.Null, "mapperRequest should be non-null.");
                Assert.That(propBagMapperGen, Is.Not.Null, "mapper should be non-null");
            }
            else
            {
                propBagMapper = AutoMapperHelpers.GetAutoMapper <Person, DestinationModel1>
                                (
                    localMr,
                    autoMapperService,
                    out propBagMapperRequestKey
                                );
                Assert.That(propBagMapperRequestKey, Is.Not.Null, "mapperRequest should be non-null.");
                Assert.That(propBagMapper, Is.Not.Null, "mapper should be non-null");
            }

            PropModelType propModel5 = pmHelpers.GetPropModelForModel5Dest(propFactory_V1, propModelCache);

            string fullClassName = null; // Don't override the value from the PropModel.
            _testMainVM = new DestinationModel5(propModel5, viewModelFactory, amp, ourHelper.PropFactory_V1, fullClassName);

            Business b = new Business();
            _testMainVM.SetIt(b, "Business"); // THIS IS A SET ACESSS OPERATION.

            b = _testMainVM.GetIt <Business>("Business");

            // TODO: try using IEnumerable<Person> instead.
            List <Person> unMappedPeople = b.Get(1000);

            //IEnumerable<DestinationModel1> mappedPeople;
            IEnumerable <object> mappedPeople;

            if (configPackageName == "Emit_Proxy")
            {
                mappedPeople = propBagMapperGen.MapToDestination(unMappedPeople);
            }
            else
            {
                mappedPeople = propBagMapper.MapToDestination(unMappedPeople);
            }

            _readyForTheView = new ObservableCollection <object>(mappedPeople);

            // Each time a item is mapped, it is first created. (5 sets during consruction, and another 5 for the actual mapping.)
            int totalNumberOfGets = ourHelper.StoreAccessCreator.AccessCounter;

            if (configPackageName == "Extra_Members")
            {
                Assert.That(totalNumberOfGets == 1, $"Total # of SetIt access operations is wrong: it should be {1}, but instead it is {totalNumberOfGets}.");
            }
            else
            {
                Assert.That(totalNumberOfGets == 1 + (numberOfItemsToLoad * 5), $"Total # of SetIt access operations is wrong: it should be {1 + numberOfItemsToLoad * 5}, but instead it is {totalNumberOfGets}.");
            }

            int currentNumRootPropBags   = ourHelper.StoreAccessCreator.NumberOfRootPropBagsInPlay;
            int totalRootPropBagsCreated = ourHelper.StoreAccessCreator.TotalNumberOfAccessServicesCreated;

            PropBag sampleItem = (PropBag)_readyForTheView[0];

            int howManyDoSetDelegatesGotCreated = sampleItem.NumOfDoSetDelegatesInCache;
            int howManyCreateFromString         = sampleItem.CreatePropFromStringCacheCount;
            //int howManyCreateWithNoVal = sampleItem.CreatePropWithNoValCacheCount;

            //Thread.Sleep(new TimeSpan(0, 0, 1));
        }
示例#10
0
        public PropModelType GetPropModelForModel1Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache)
        {
            PropModelType result = new PropModel
                                   (
                className: "DestinationModel1",
                namespaceName: "PropBagLib.Tests.PerformanceDb",
                deriveFrom: DeriveFromClassModeEnum.Custom,
                targetType: typeof(DestinationModel1),
                propFactory: propFactory,
                propFactoryType: null,
                propModelCache: null, //propModelCache,
                typeSafetyMode: PropBagTypeSafetyMode.Tight,
                deferMethodRefResolution: true,
                requireExplicitInitialValue: true
                                   );

            result.Namespaces.Add("System");
            result.Namespaces.Add("DRM.PropBag");
            result.Namespaces.Add("DRM.TypeSafePropertyBag");

            // Id (Int - 0)
            IPropInitialValueField pivf = new PropInitialValueField(initialValue: "0");

            PropItemModel propItem = new PropItemModel(type: typeof(int), name: "Id",
                                                       storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                                       initialValueField: pivf);

            result.Add(propItem.PropertyName, propItem);

            pivf = PropInitialValueField.UseNull;

            // First Name (string - null)
            propItem = new PropItemModel(type: typeof(string), name: "FirstName",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            // Last Name (string - null)
            propItem = new PropItemModel(type: typeof(string), name: "LastName",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            // City Of Residence (string - null)
            propItem = new PropItemModel(type: typeof(string), name: "CityOfResidence",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            pivf = PropInitialValueField.UseDefault;

            // Profession
            propItem = new PropItemModel(type: typeof(Profession), name: "Profession",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            result.Open();

            propModelCache.Add(result);

            return(result);
        }
示例#11
0
        public PropModelType GetPropModelForModel6Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache)
        {
            PropModelType result = new PropModel
                                   (
                className: "DestinationModel6",
                namespaceName: "PropBagLib.Tests.PerformanceDb",
                deriveFrom: DeriveFromClassModeEnum.Custom,
                targetType: typeof(DestinationModel6),
                propFactory: propFactory,
                propFactoryType: null,
                propModelCache: null,
                typeSafetyMode: PropBagTypeSafetyMode.Tight,
                deferMethodRefResolution: true,
                requireExplicitInitialValue: true
                                   );

            result.Namespaces.Add("System");
            result.Namespaces.Add("DRM.PropBag");
            result.Namespaces.Add("DRM.TypeSafePropertyBag");

            // Business (Business - null)
            IPropInitialValueField pivf = PropInitialValueField.UseNull;

            PropItemModel propItem = new PropItemModel(type: typeof(Business), name: "Business",
                                                       storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                                       initialValueField: pivf);

            result.Add(propItem.PropertyName, propItem);

            //// PersonCollection (ObservableCollection<Person> - null)
            //pivf = new PropInitialValueField(initialValue: null,
            //    setToDefault: false, setToUndefined: false, setToNull: true, setToEmptyString: false);

            //propItem = new PropItem(type: typeof(ObservableCollection<Person>), name: "PersonCollection",
            //    hasStore: true, propKind: PropKindEnum.Collection,
            //    propTypeInfoField: null,
            //    initialValueField: pivf,
            //    doWhenChanged: null, extraInfo: null, comparer: null, itemType: typeof(Person));
            //result.Props.Add(propItem);

            // ChildVM (DestinationModel5 - null)
            propItem = new PropItemModel(type: typeof(DestinationModel5), name: "ChildVM",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            // SelectedPerson (Business - null)
            propItem = new PropItemModel(type: typeof(Person), name: "SelectedPerson",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            // WMessage (String - null)
            propItem = new PropItemModel(type: typeof(string), name: "WMessage",
                                         storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop,
                                         initialValueField: pivf);
            result.Add(propItem.PropertyName, propItem);

            result.Open();

            propModelCache.Add(result);

            return(result);
        }