Пример #1
0
 protected MappingCollection(IResourceMapper <TContext> mapper,
                             MemberInfo[] fromPrefix,
                             MemberInfo[] toPrefix,
                             IList <MemberEntry> setters,
                             int setOrder)
 {
     _setOrder   = setOrder;
     _fromPrefix = fromPrefix;
     _toPrefix   = toPrefix;
     _setters    = setters;
     foreach (var property in typeof(TTo).GetProperties()
              .Where(p => p.IsWritable() && !_setters.Any(s => s.IsForMember(_toPrefix, p))))
     {
         _setters.Add(new MemberEntry {
             DestinationMember = _toPrefix.Union(new MemberInfo[] { property }).ToArray(),
             DestinationType   = property.PropertyType,
             IsMapped          = false,
         });
     }
     _fromList = typeof(TFrom).GetProperties().Where(p => p.GetGetMethod() != null).Cast <MemberInfo>().ToList();
     _unmapped = new AvailablePropertiesClass(_fromList.ToArray,
                                              () => _setters.Where(s => !s.IsMapped &&
                                                                   s.DestinationMember.Length == _toPrefix.Length + 1 &&
                                                                   s.IsForPrefix(_toPrefix))
                                              .Select(s => s.DestinationMember[_toPrefix.Length]).ToArray());
     _mapper = mapper;
 }
Пример #2
0
 protected IRelationship <TEntity> HasMany <TOtherResource, TOtherEntity>(
     IResourceMapper <TOtherResource, TOtherEntity> otherResourceMapper,
     Expression <Func <TOtherEntity, string> > getFieldExpr)
     where TOtherResource : class, IResource
     where TOtherEntity : class, IEntity
 {
     return(new HasManyRelationship <TEntity, TOtherResource, TOtherEntity>(otherResourceMapper, getFieldExpr));
 }
Пример #3
0
 public HasOneRelationship(IResourceMapper <TOtherResource, TOtherEntity> otherResourceMapper,
                           Expression <Func <TThisEntity, string> > getFieldExpr, bool updateAllowed = true)
 {
     _otherResourceMapper = otherResourceMapper;
     _getFieldExpr        = getFieldExpr;
     _updateAllowed       = updateAllowed;
     _getField            = _getFieldExpr.Compile();
 }
Пример #4
0
 protected IRelationship <TEntity> HasOne <TOtherResource, TOtherEntity>(
     IResourceMapper <TOtherResource, TOtherEntity> otherResourceMapper,
     Expression <Func <TEntity, string> > getFieldExpr, bool updateAllowed = true)
     where TOtherResource : class, IResource
     where TOtherEntity : class, IEntity
 {
     return(new HasOneRelationship <TEntity, TOtherResource, TOtherEntity>(otherResourceMapper, getFieldExpr,
                                                                           updateAllowed));
 }
Пример #5
0
 public ResourceController(IResourceService resourceService, 
     IDocumentSession documentSession,
     ISessionStateRepository sessionStateRepository,
     IResourceMapper resourceMapper,
     IResourceListViewProcessor resourceListViewProcessor)
     : base(sessionStateRepository)
 {
     ResourceService = resourceService;
     DocumentSession = documentSession;
     ResourceMapper = resourceMapper;
     ResourceListViewProcessor = resourceListViewProcessor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserResourceController"/> class.
 /// </summary>
 /// <param name="logger">Logs errors and information.</param>
 /// <param name="telemetryClient">The Application Insights telemetry client.</param>
 /// <param name="unitOfWork">User learning module repository for working with user learning module data.</param>
 /// <param name="usersService">Instance of user service to get user data.</param>
 /// <param name="resourceMapper">The instance of resource mapper class to work with models.</param>
 public UserResourceController(
     ILogger <UserResourceController> logger,
     TelemetryClient telemetryClient,
     IUnitOfWork unitOfWork,
     IUsersService usersService,
     IResourceMapper resourceMapper)
     : base(telemetryClient)
 {
     this.logger         = logger;
     this.unitOfWork     = unitOfWork;
     this.resourceMapper = resourceMapper;
     this.usersService   = usersService;
 }
Пример #7
0
 public static void LoadConverters <TContext>(this IResourceMapper <TContext> resourceMapper, Type type, params Func <MethodInfo, bool>[] verify)
 {
     foreach (var methodInfo in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.ExactBinding).Where(m => m.IsPublic &&
                                                                                                                                                             m.ReturnType != null &&
                                                                                                                                                             m.IsStatic &&
                                                                                                                                                             m.GetParameters().Length == 1 &&
                                                                                                                                                             verify.Aggregate(true, (seed, check) => seed && check(m))))
     {
         var fromType = methodInfo.GetParameters()[0].ParameterType;
         var toType   = methodInfo.ReturnType;
         var info     = methodInfo;
         resourceMapper.ConvertUsing(fromType, toType, from => info.Invoke(null, new [] { from }));
     }
 }
Пример #8
0
        public DrNuClient(IResourceUriScraper resourceUriScraper, IResourceScraper resourceScraper, IResourceMapper resourceMapper, IProgramSlugScraper programSlugScraper, IProgramUriScraper programUriScraper)
        {
            if (resourceUriScraper == null) throw new ArgumentNullException("resourceUriScraper");
            if (resourceScraper == null) throw new ArgumentNullException("resourceScraper");
            if (resourceMapper == null) throw new ArgumentNullException("resourceMapper");
            if (programSlugScraper == null) throw new ArgumentNullException("programSlugScraper");
            if (programUriScraper == null) throw new ArgumentNullException("programUriScraper");

            _resourceUriScraper = resourceUriScraper;
            _programUriScraper = programUriScraper;
            _resourceScraper = resourceScraper;
            _resourceMapper = resourceMapper;
            _programSlugScraper = programSlugScraper;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceController"/> class.
 /// </summary>
 /// <param name="unitOfWork">The instance of unit of work to access repository.</param>
 /// <param name="telemetryClient">The Application Insights telemetry client.</param>
 /// <param name="logger">Logs errors and information.</param>
 /// <param name="usersService">Instance of user service to get user data.</param>
 /// <param name="resourceMapper">The instance of resource mapper class to work with models.</param>
 /// <param name="memberValidationService">Instance of MemberValidationService to validate member of a security group.</param>
 /// <param name="securityGroupOptions">Security group configuration settings.</param>
 public ResourceController(
     IUnitOfWork unitOfWork,
     TelemetryClient telemetryClient,
     ILogger <ResourceController> logger,
     IUsersService usersService,
     IResourceMapper resourceMapper,
     IMemberValidationService memberValidationService,
     IOptions <SecurityGroupSettings> securityGroupOptions)
     : base(telemetryClient)
 {
     this.unitOfWork              = unitOfWork;
     this.logger                  = logger;
     this.resourceMapper          = resourceMapper;
     this.usersService            = usersService;
     this.memberValidationService = memberValidationService;
     this.securityGroupOptions    = securityGroupOptions;
 }
 public ApiController(IMediator mediator, IResourceMapper resourceMapper)
 {
     Mediator       = mediator;
     ResourceMapper = resourceMapper;
 }
Пример #11
0
 public static void LoadConverters <TContext>(this IResourceMapper <TContext> resourceMapper, Type type)
 {
     resourceMapper.LoadConverters(type, method => true);
 }
Пример #12
0
 public MapArray(IResourceMapper <TContext> mapper)
 {
     _mapper = mapper;
 }
Пример #13
0
 public MapList(IResourceMapper <TContext> mapper)
 {
     _mapper = mapper;
 }
Пример #14
0
 public MappingCollection(IResourceMapper <TContext> mapper)
     : this(mapper, new MemberInfo[0], new MemberInfo[0], new List <MemberEntry>(), 0)
 {
 }
Пример #15
0
 public CustomersController(
     IResourceMapper resourceMapper,
     IMediator mediator) : base(resourceMapper, mediator)
 {
 }
Пример #16
0
 public ApiController(IResourceMapper resourceMapper, IMediator mediator)
 {
     ResourceMapper = resourceMapper;
     Mediator       = mediator;
 }
Пример #17
0
        public static DestinationMemberSetter <TContext> CreateConstructingAccessorChain <TContext>(this IEnumerable <MemberInfo> members,
                                                                                                    IResourceMapper <TContext> mapper)
        {
            if (members.Count() < 1)
            {
                throw new ArgumentException("Collection must have at least one member", "members");
            }
            var accessors = members.Select(prop => prop.GetAccessor()).ToList();

            accessors.Reverse();
            DestinationMemberSetter <TContext> setter = null;

            foreach (var propertyAccessor in accessors)
            {
                var accessor = propertyAccessor;
                // a = (((b = ((c = (d = 4)))) : Given a, get or create b and set this equal to c...
                if (setter == null)
                {
                    setter = (target, value, context) =>
                    {
                        accessor.Set(target, value);
                        return(target);
                    };
                }
                else
                {
                    var localSetter = setter;
                    setter = (target, value, context) =>
                    {
                        var destination = accessor.Get(target);
                        if (destination == null)
                        {
                            destination = mapper.ConstructOrThrow(accessor.MemberType);
                            accessor.Set(target, destination);
                        }
                        return(localSetter(destination, value, context));
                    };
                }
            }
            return(setter);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserDataController"/> class.
 /// </summary>
 public UserDataController(IResourceMapper resourceMapper, IMediator mediator)
     : base(resourceMapper, mediator)
 {
 }
Пример #19
0
 public static void Convert_SourceWithEnum_DestWithInt(SourceWithEnum source, DestWithInt destination,
                                                       IResourceMapper <object> mapper, object context)
 {
     destination      = destination ?? new DestWithInt();
     destination.Enum = mapper.Map(SourceWithEnum_DestWithInt_0(source, destination, context), destination.Enum, context);
 }
 public MapNonNullableToNullable(IResourceMapper <TContext> mapper)
 {
     _mapper = mapper;
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatbotController"/> class.
 /// </summary>
 /// <param name="resourceMapper"></param>
 /// <param name="mediator"></param>
 public ChatbotController(
     IResourceMapper resourceMapper,
     IMediator mediator)
     : base(resourceMapper, mediator)
 {
 }
Пример #22
0
 public void SetUp()
 {
     _mapper = new ResourceMapper <object>();
 }
Пример #23
0
 public DetachedDisplayMetadataConfigureOptions(IResourceMapper resourceMapper = null, IStringLocalizerFactory stringLocalizer = null)
 {
     _stringLocalizer = stringLocalizer;
     _resourceMapper  = resourceMapper;
 }
Пример #24
0
 public CashierController(IResourceMapper resourceMapper, IMediator mediator)
     : base(resourceMapper, mediator)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserTestResultsController"/> class.
 /// </summary>
 public UserTestResultsController(
     IResourceMapper resourceMapper,
     IMediator mediator)
     : base(resourceMapper, mediator)
 {
 }
Пример #26
0
 public EmitBuilder(IResourceMapper <TContext> mapper) : base(mapper)
 {
     _type        = DynamicAssemblyManager.DefineMapperType("ResourceMapper");
     _mapperField = _type.DefineField("Mapper", typeof(IResourceMapper <TContext>), FieldAttributes.Public | FieldAttributes.Static);
     _constructorValues.Add(_mapperField.Name, _mapper);
 }
Пример #27
0
 public ResourceSteps()
 {
     _repository = ObjectFactory.GetInstance<IResourceRepository>();
     _resourceMapper = ObjectFactory.GetInstance<IResourceMapper>();
 }
 public DetachedDisplayMetadataProvider(IResourceMapper resourceMapper, IStringLocalizerFactory stringLocalizerFactory)
 {
     _resourceMapper         = resourceMapper;
     _stringLocalizerFactory = stringLocalizerFactory;
 }
Пример #29
0
 public BetsController(IMediator mediator, IResourceMapper resourceMapper)
     : base(mediator, resourceMapper)
 {
 }
 public LoanController(ILoanPlannerBuilder loanPlannerBuilder, IResourceMapper resourceMapper)
 {
     _loanPlannerBuilder = loanPlannerBuilder;
     _resourceMapper     = resourceMapper;
 }
 public ResourceListViewProcessor(IResourceMapper resourceMapper)
 {
     ResourceMapper = resourceMapper;
 }
Пример #32
0
 public AuthController(IResourceMapper resourceMapper, IMediator mediator)
     : base(resourceMapper, mediator)
 {
 }
Пример #33
0
 public DelegateBuilder(IResourceMapper <TContext> mapper) : base(mapper)
 {
 }
Пример #34
0
 /// <summary>
 /// Loads standard type converters from the System.Convert class.  This detects all methods that start with
 /// "To", and have a single input and a single output
 /// </summary>
 /// <param name="resourceMapper">
 /// A <see cref="IResourceMapper<TContext>"/>
 /// </param>
 public static void LoadStandardConverters <TContext>(this IResourceMapper <TContext> resourceMapper)
 {
     resourceMapper.LoadConverters(typeof(Convert), method => method.Name.StartsWith("To") &&
                                   !((method.ReturnType.IsValueType || method.ReturnType == typeof(string)) && method.ReturnType == method.GetParameters()[0].ParameterType));
 }