Esempio n. 1
0
        public static Action<object, object, TypeMappingContext> GetComplexPropertiesMapper(
			Func<object, object> fromPropertyGetter, Action<object, object> toPropertySetter,
			MapperCollection mappers, ObjectFactory objectFactory)
        {
            return delegate(object from, object to, TypeMappingContext context)
            {
                object obj = fromPropertyGetter(from);

                if (obj != null)
                {
                    var type = obj.GetType();
                    Type targetType = null;
                    var bySourceType = mappers.GetBySourceType(type, out targetType);

                    Error.MappingException_IfMapperIsNull(bySourceType, type);

                    object toObject = objectFactory.CreateTargetObject(obj, targetType, context.MappingContext);

                    var arg = new TypeMappingContext
                    {
                        From = obj,
                        To = toObject,
                        MappingContext = context.MappingContext
                    };

                    bySourceType(obj, toObject, arg);

                    toPropertySetter(to, toObject);
                }
            };
        }
Esempio n. 2
0
        public static Action<object, object, TypeMappingContext> GetComplexEnumerablePropertiesMapper(
			Type toEnumerableType, Func<object, object> fromEnumerableGetter,
			Action<object, object> toEnumerableSetter, ObjectFactory objectFactory, MapperCollection mappers)
        {
            return delegate(object from, object to, TypeMappingContext context)
            {
                object obj = fromEnumerableGetter(from);

                if (obj != null)
                {
                    object targetObject = objectFactory.CreateTargetObject(obj, toEnumerableType, context.MappingContext);

                    var ctx = new TypeMappingContext
                    {
                        From = obj,
                        To = targetObject,
                        MappingContext = context.MappingContext
                    };

                    Mappers.MapComplexEnumerables(ctx, mappers, objectFactory);

                    toEnumerableSetter(to, targetObject);
                }
            };
        }
        public ResourceUseCase(
            // Get the ViewToRegionBinder that the baseclass needs
            IViewToRegionBinder viewtoToRegionBinder
            , IRegionManager regionManager
            , IUnityContainer container
            , IEventAggregator eventAggregator
            // Get the factories that can create the viewmodels
            , ObjectFactory<ResourceListViewModel> resourceViewModel
            , ObjectFactory<ResourceToolbarViewModel> resourceToolbarViewModel
            , IApplicationModel applicationModel
            , IModelVisualizationRegistry modelVisualizationRegistry)
           : base(viewtoToRegionBinder)
        {
            this.ApplicationModel = applicationModel;
            this.Container = container;
            // Just before the view is initialized for the first time
            this.AddInitializationMethods(
                // Create the emailViewModel and assign it to this variable
               () => this._resourceListViewModel = resourceViewModel.CreateInstance()
               , () => this._resourceToolbarViewModel = resourceToolbarViewModel.CreateInstance());

            // Register visualizations for these view models. This means: whenever a viewmodel is displayed, 
            // use this type of view to visualize it. 
            modelVisualizationRegistry.Register<ResourceListViewModel, ResourceListView>();
            modelVisualizationRegistry.Register<ResourceToolbarViewModel, ResourceToolbarView>();
            modelVisualizationRegistry.Register<ResourceEditViewModel, ResourceEditView>();

            container.RegisterType<IResourceAssignService, ResourceAssignmentService>(new ContainerControlledLifetimeManager());
            container.RegisterInstance(container.Resolve<IResourceAssignService>());

            regionManager.RegisterViewWithRegion("ResourceEditRegion", typeof(ResourceEditViewModel));
            // watch for OpenResourceEvents fired by (Link)Button command in ProjectEditViewModel...
            eventAggregator.GetEvent<OpenResourceByIdEvent>().Subscribe(OpenResourceById);
        }
		public void MyTestInitialize() 
		{
			// Store current objectFactory:
			this.defaultFactory = ObjectFactory.Instance;

			// Install virgin objectFactory:
			ObjectFactory.Instance = new ObjectFactory();
		}
 public StudentController(ObjectFactory objectFactory)
 {
     _objectFactory = objectFactory;
     _studentManager = new StudentManager(objectFactory);
     _facultyManager = new FacultyManager(objectFactory);
     _markManager = new MarkManager(objectFactory);
     _subjectManager = new SubjectManager(objectFactory);
 }
 public void CanCreateView()
 {
     var serviceLocator = new UnityServiceLocatorAdapter(new UnityContainer());
     var objectFactory = new ObjectFactory<MockView>(serviceLocator);
     
     Assert.IsInstanceOfType(objectFactory.CreateInstance(), typeof(MockView));
     Assert.IsInstanceOfType(objectFactory.Value, typeof(MockView));
 }
Esempio n. 7
0
        public void CreateTargetObject_GoodValues_Succeeds()
        {
            //Arrange
            //Act
            object value = new ObjectFactory().CreateTargetObject(null, null, null);

            //Assert
            Assert.IsNotNull(value);
        }
        public void CanImplicitlyConvertToType()
        {
            var serviceLocator = new UnityServiceLocatorAdapter(new UnityContainer());
            var objectFactory = new ObjectFactory<MockView>(serviceLocator);

            var expected = objectFactory.CreateInstance();
            MockView view = objectFactory;

            Assert.AreEqual(expected, view);
        }
Esempio n. 9
0
        public IFilter CreateInstance([NotNull] IServiceProvider serviceProvider)
        {
            if (_factory == null)
            {
                var argumentTypes = Arguments?.Select(a => a.GetType())?.ToArray();

                _factory = ActivatorUtilities.CreateFactory(ImplementationType, argumentTypes ?? Type.EmptyTypes);
            }

            return (IFilter)_factory(serviceProvider, Arguments);
        }
Esempio n. 10
0
        public void CreateTargetObject_TargetTypeIsComplexObject_ReturnsComplexObject()
        {
            //Arrange
            var objectFactory = new ObjectFactory();

            //Act
            object obj = objectFactory.CreateTargetObject(new MainEntity(), typeof(MainEntity), null);

            //Assert
            Assert.AreEqual<Type>(typeof(MainEntity), obj.GetType());
        }
        public CalendarMainUseCase(
            // Get the ViewToRegionBinder that the baseclass needs
            IViewToRegionBinder viewtoToRegionBinder, 
            // Get the factory that will create the viewmodel
            ObjectFactory<CalendarMainViewModel> calendarMainViewFactory): base(viewtoToRegionBinder)
        {
            // When the usecase get's activated for the first time
            AddInitializationMethods(
                // Create the viewmodel and assign it to this variable
                () => this.viewModel = calendarMainViewFactory.CreateInstance());

        }
        public void ShouldCreateNewObject()
        {
            ObjectFactory<Client> objectFactory = new ObjectFactory<Client>(new TemplateHolder<Client>()
                .AddTemplate (TEMPLATE_NAME, new Rule ()
                                            .Add(PROPERTY_LABEL, PROPERTY_VALUE)
                                 )
            );

            var obj = objectFactory.Gimme(TEMPLATE_NAME);
            Assert.IsNotNull(obj);
            Assert.IsInstanceOf<Client>(obj);
            Assert.AreEqual (PROPERTY_VALUE, ((Client)obj).Name);
        }
        public void SetUp()
        {
            _objectFactory = MockRepository.GenerateStub<ObjectFactory>();
            _metadata = MockRepository.GenerateStub<Metadata>();
            _parametersParser = MockRepository.GenerateStub<ParametersParser>();
            _target = new DirectHandler(_objectFactory, _metadata, _parametersParser);

            _metadata.Stub(x => x.GetActionType("Action")).Return(typeof(Action));
            _metadata.Stub(x => x.GetMethodInfo("Action", "method")).Return(typeof(Action).GetMethod("Method"));
            _metadata.Stub(x => x.GetMethodInfo("Action", "methodWithParams")).Return(typeof(Action).GetMethod("MethodWithParams"));
            _metadata.Stub(x => x.GetMethodInfo("Action", "methodThatThrowException")).Return(typeof(Action).GetMethod("MethodThatThrowException"));
            _metadata.Stub(x => x.GetMethodInfo("Action", "methodWithRawParameters")).Return(typeof(Action).GetMethod("MethodWithRawParameters"));
        }
Esempio n. 14
0
        public Universe()
        {
            this.syncRoot = new object();

            this.factory = new ObjectFactory(this);
            this.starClusters = new ObjectCollection<StarCluster>(this);
            this.corporations = new ObjectCollection<Corporation>(this);

            Location = this;
            EventPump = new EventPump();

            this.nextObjectID = 0;
            EnsureObjectID();
        }
 public NewEmailUseCase(
     IViewToRegionBinder viewtoToRegionBinder,
     ObjectFactory<NewEmailViewModel> newEmailViewFactory,
     ObjectFactory< NewEmailToolBarViewModel> newEmailToolBarFactory,
     IExchangeService exchangeService, 
     IRegionManager regionManager) : base (viewtoToRegionBinder)
 {
     this.AddInitializationMethods(
         () => this.newEmailViewModel = newEmailViewFactory.CreateInstance()
         , () => this.newEmailToolBarViewModel = newEmailToolBarFactory.CreateInstance());
     
     this.exchangeService = exchangeService;
     this.RegionManager = regionManager;
 }
Esempio n. 16
0
        /// <inheritdoc />
        public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (_factory == null)
            {
                var argumentTypes = Arguments?.Select(a => a.GetType())?.ToArray();

                _factory = ActivatorUtilities.CreateFactory(ImplementationType, argumentTypes ?? Type.EmptyTypes);
            }

            return (IFilterMetadata)_factory(serviceProvider, Arguments);
        }
        public EmailMainUseCase(
            // Get the ViewToRegionBinder that the baseclass needs
            IViewToRegionBinder viewtoToRegionBinder
            // Get the factories that can create the viewmodels
            , ObjectFactory<EmailMainViewModel> emailViewFactory
            , ObjectFactory<EmailToolBarViewModel> emailToolBarFactory
            , IApplicationModel applicationModel) : base(viewtoToRegionBinder)
        {
            ApplicationModel = applicationModel;

            // Just before the view is initialized for the first time
            this.AddInitializationMethods(
                    // Create the emailViewModel and assign it to this variable
                () => this.emailViewModel = emailViewFactory.CreateInstance()
                    // Create the toolbarViewModel and assign it to this variable
                , () => this.emailToolBarViewModel = emailToolBarFactory.CreateInstance());
        }
Esempio n. 18
0
        /// <summary>
        /// Creates a new <see cref="BinderTypeModelBinder"/>.
        /// </summary>
        /// <param name="binderType">The <see cref="Type"/> of the <see cref="IModelBinder"/>.</param>
        public BinderTypeModelBinder(Type binderType)
        {
            if (binderType == null)
            {
                throw new ArgumentNullException(nameof(binderType));
            }

            if (!typeof(IModelBinder).GetTypeInfo().IsAssignableFrom(binderType.GetTypeInfo()))
            {
                throw new ArgumentException(
                    Resources.FormatBinderType_MustBeIModelBinder(
                        binderType.FullName,
                        typeof(IModelBinder).FullName),
                    nameof(binderType));
            }

            _factory = ActivatorUtilities.CreateFactory(binderType, Type.EmptyTypes);
        }
        public RolesListUseCase(
            // Get the ViewToRegionBinder that the baseclass needs
            IViewToRegionBinder viewtoToRegionBinder
            , IRegionManager regionManager
            // Get the factories that can create the viewmodels
            , ObjectFactory<RolesListViewModel> rolesViewModel
             , ObjectFactory<RolesToolbarViewModel> rolesToolbarViewModel
           , IApplicationModel applicationModel)
            : base(viewtoToRegionBinder)
        {
            this._applicationModel = applicationModel;

            // Just before the view is initialized for the first time
            this.AddInitializationMethods(
                // Create the emailViewModel and assign it to this variable
               () => this._rolesListViewModel = rolesViewModel.CreateInstance()
               , () => this._rolesToolbarViewModel = rolesToolbarViewModel.CreateInstance());
       }
        public NewProjectUseCase(
            // Get the ViewToRegionBinder that the baseclass needs
            IViewToRegionBinder viewtoToRegionBinder
            // Get the factories that can create the viewmodels
            , ObjectFactory<ProjectEditViewModel> projectEditViewModel
            , IApplicationModel applicationModel
            , IModelVisualizationRegistry modelVisualizationRegistry)
            : base(viewtoToRegionBinder)
        {
            // Just before the view is initialized for the first time
            this.AddInitializationMethods(
                // Create the emailViewModel and assign it to this variable
               () => this._projectEditViewModel = projectEditViewModel.CreateInstance());

            // Register visualizations for these view models. This means: whenever a viewmodel is displayed, 
            // use this type of view to visualize it. 
            modelVisualizationRegistry.Register<ProjectEditViewModel, ProjectEditView>();
        }
Esempio n. 21
0
        public void CreateTargetObject_TargetTypeIsCollection_ReturnsList()
        {
            //Arrange
            var objectFactory = new ObjectFactory();

            List<MainEntity> list = new List<MainEntity>
            {
                new MainEntity(),
                new MainEntity()
            };

            //Act
            object obj = objectFactory.CreateTargetObject(list, typeof(IEnumerable<MainEntity>), null);

            //Assert
            Assert.AreEqual<System.Type>(typeof(List<MainEntity>), obj.GetType());
            Assert.AreEqual<int>(0, ((List<MainEntity>)obj).Count);
        }
Esempio n. 22
0
 public MapCompiler(ConverterCollection converters, ObjectFactory objectFactory)
 {
     this.converters = converters;
     this.objectFactory = objectFactory;
     getters = new Dictionary<PropertyInfo, Func<object, object>>();
     setters = new Dictionary<PropertyInfo, Action<object, object>>();
     rootCompilers = new Dictionary<Type, Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>>();
     nodeCompilers = new Dictionary<PropertyInfo, Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>>();
     rootCompilers.Add(typeof(TypeMap), new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(TypeMap));
     rootCompilers.Add(typeof(ReversiveTypeMap), new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(ReversiveTypeMap));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<TypeMap, Action<object, object, TypeMappingContext>>((TypeMap o) => o.Mapper) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(MapWithMapper));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<TypeMap, ICollection<PropertyMap>>((TypeMap o) => o.PropertyMaps) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(TypeMapWithPropertyMaps));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<PropertyMap, Action<object, object, TypeMappingContext>>((PropertyMap o) => o.Mapper) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(MapWithMapper));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<PropertyMap, ICollection<TypeMap>>((PropertyMap o) => o.InheritanceMaps) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(PropertyMapWithInheritanceMaps));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<ReversiveTypeMap, Action<object, object, TypeMappingContext>>((ReversiveTypeMap o) => o.Mapper) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(ReversiveTypeMapWithMapper));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<ReversiveTypeMap, ICollection<ReversivePropertyMap>>((ReversiveTypeMap o) => o.PropertyMaps) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(ReversiveTypeMapWithPropertyMaps));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<ReversivePropertyMap, Action<object, object, TypeMappingContext>>((ReversivePropertyMap o) => o.Mapper) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(ReversivePropertyMapWithMapper));
     nodeCompilers.Add(ReflectionHelper.GetMemberInfo<ReversivePropertyMap, ICollection<ReversiveTypeMap>>((ReversivePropertyMap o) => o.InheritanceMaps) as PropertyInfo, new Func<MapCompiler.CompilationContext, MapCompiler.CompilationResult>(ReversivePropertyMapWithInheritanceMaps));
 }
Esempio n. 23
0
		private static void UseObjectFactoryDirectly()
		{
			ApplicationContext.DataPortalActivator =
				new ObjectActivator(Program.CreateContainer());

			var person = new ObjectFactory<IPerson>().Create();
			person.Age = 40;
			person.Name = "Joe Smith";

			Console.Out.WriteLine("Name: " + person.Name);
			Console.Out.WriteLine("Age: " + person.Age);

			var dependentPerson = new ObjectFactory<IDependentPerson>().Create();
			dependentPerson.Age = 45;
			dependentPerson.Name = "Jane Smith";

			Console.Out.WriteLine("Dependent Name: " + dependentPerson.Name);
			Console.Out.WriteLine("Dependent Age: " + dependentPerson.Age);
		}
Esempio n. 24
0
        public void CreateTargetObject_TargetTypeIsArray_ReturnsArray()
        {
            //Arrange
            var objectFactory = new ObjectFactory();

            List<MainEntity> list = new List<MainEntity>
            {
                new MainEntity(),
                new MainEntity()
            };

            //Act
            object obj = objectFactory.CreateTargetObject(list, typeof(MainEntity[]), null);

            //Assert
            Assert.AreEqual<System.Type>(typeof(MainEntity[]), obj.GetType());
            Assert.AreEqual<int>(list.Count, ((System.Array)obj).Length);

            foreach (object current in (System.Array)obj)
            {
                Assert.IsNull(current);
            }
        }
Esempio n. 25
0
        public static Action<object, object, TypeMappingContext> GetMapperFromRootType(
			Type toPropertyType, Action<object, object> toPropertySetter,
			MapperCollection mappers, ObjectFactory objectFactory)
        {
            return delegate(object from, object to, TypeMappingContext context)
            {
                var action = mappers.Get(from.GetType(), toPropertyType);

                Error.MappingException_IfMapperIsNull(action, from.GetType());

                object obj = objectFactory.CreateTargetObject(from, toPropertyType, context.MappingContext);

                var arg = new TypeMappingContext
                {
                    From = from,
                    To = obj,
                    MappingContext = context.MappingContext
                };

                action(from, obj, arg);

                toPropertySetter(to, obj);
            };
        }
 public SubjectController(ObjectFactory objectFactory)
 {
     _subjectManager = new SubjectManager(objectFactory);
 }
Esempio n. 27
0
        public TerrainMesh(RenderSystem rs, int x, int y, int size)
            : base(TerrainMeshManager.Instance, GetHashString(x, y, size))
        {
            this.opBuffer = new FastList<RenderOperation>();

            this.terrEdgeSize = size;
            this.tileX = x;
            this.tileY = y;

            renderSystem = rs;
            factory = rs.ObjectFactory;

            material = new Material(rs);
            material.CullMode = CullMode.None;


            material.Ambient = new Color4F(1, 0.5f, 0.5f, 0.5f);
            material.Diffuse = new Color4F(1f, 1f, 1f, 1f);
            material.Specular = new Color4F(0, 0, 0, 0);
            material.Power = 1;
            material.PriorityHint = RenderPriority.Second;


            PlanetEarth.TileCoord2CoordNew(x, y, out tileCol, out tileLat);

            // 估算包围球
            {
                float radtc = MathEx.Degree2Radian(tileCol);
                float radtl = MathEx.Degree2Radian(tileLat);
                float rad5 = PlanetEarth.DefaultTileSpan * 0.5f;

                BoundingSphere.Center = PlanetEarth.GetPosition(radtc + rad5, radtl - rad5);
                BoundingSphere.Radius = MathEx.Root2 * PlanetEarth.GetTileHeight(rad5 * 2);

                if (ObjectSpaceChanged != null)
                    ObjectSpaceChanged(Transformation, BoundingSphere);
            }
        }
 public MarkController(ObjectFactory objectFactory)
 {
     _markManager = new MarkManager(objectFactory);
 }
Esempio n. 29
0
 public CreateObjectRequestEventArgs( ObjectFactory.ObjectTypes objectType, string options)
 {
     type = objectType;
     parameters = options;
 }
Esempio n. 30
0
 public PhotoController(ObjectFactory objectFactory)
 {
     this.photoManager = new UserPhotoManager(objectFactory);
 }