/// <summary> /// Maps data table to object list. /// </summary> /// <typeparam name = "T">The destination object type. Must have a default constructor.</typeparam> /// <param name = "source">The source data table.</param> /// <param name = "dataTypeTriggers">The generic data triggers (null for no trigger).</param> /// <param name = "aliases">Property name aliases ([destination name, source name]) Can be null.</param> /// <param name = "exclusions">Source object properties that should not be mapped. Can be null.</param> /// <param name="ignoreMissingField"></param> /// <returns></returns> public static IEnumerable <T> MapToObjectList <T>(this DataTable source, DataTypeTriggers dataTypeTriggers, Aliases aliases, Exclusions exclusions, bool ignoreMissingField) where T : new() { var list = new List <T>(); var properties = GenericTypeHelper.GetProperties <T>(); foreach (DataRow row in source.Rows) { var destination = new T(); foreach (var targetProperty in properties) { var targetValue = GetColumnValue(aliases, targetProperty, exclusions, row, ignoreMissingField); if (!(targetValue is NoValue)) { var type = source.Columns[GetColumnName(targetProperty.Name, aliases)].DataType; if (dataTypeTriggers != null && dataTypeTriggers.Keys.Contains(type)) { if (targetValue != DBNull.Value) { targetValue = dataTypeTriggers[type](targetValue); } } SetValue(aliases, targetProperty, targetValue, destination); } } list.Add(destination); } return(list); }
public void RegistActionSet(Type actinoSetType, object[] acts = null, IPolicyAccess policyAccess = null) { Type genericType = typeof(ApiExecutor <>); object[] ctorParameters = new object[] { acts, policyAccess }; var genericObject = GenericTypeHelper.CreateInstance(genericType, new Type[] { actinoSetType }, ctorParameters); apiExecutorMap[actinoSetType.FullName] = (IApiExecutor)genericObject; }
private IAstTypeReference ApplyArgumentTypes(GenericTypeHelper genericHelper, IAstTypeReference type, IAstTypeReference[] genericParameterTypes) { return(genericHelper.RemapArgumentTypes(type, t => { var parameterIndex = genericParameterTypes.IndexOf(t); if (parameterIndex < 0) { return t; } return this.GenericArgumentTypes[parameterIndex]; })); }
/// <summary> /// Maps data table to object list. /// </summary> /// <typeparam name = "T">The destination object type. Must have a default constructor.</typeparam> /// <param name = "source">The source data table.</param> /// <param name = "propertyNameTriggers">The column name triggers. Key is based on the column name.</param> /// <param name = "aliases">Property name aliases ([destination name, source name]) Can be null.</param> /// <param name = "exclusions">Source object properties that should not be mapped. Can be null.</param> /// <param name="ignoreMissingField">Field yoksa ignore et</param> /// <returns></returns> public static IEnumerable <T> MapToObjectList <T>(this DataTable source, PropertyNameTriggers propertyNameTriggers, Aliases aliases, Exclusions exclusions, bool ignoreMissingField) where T : new() { //if (useparallel) //{ // var results = new List<T>(); // var chunkedList = ConvertionExtensions.BreakIntoChunks<DataRow>(source.AsEnumerable().ToList(), 5000);//biner biner parcala // Parallel.ForEach(chunkedList, t => // { // var result = Map<T>(t); // lock (results) // { // results.AddRange(result); // } // }); // return results; //} var list = new List <T>(); var properties = GenericTypeHelper.GetProperties <T>(); foreach (DataRow row in source.Rows) { var destination = new T(); foreach (var targetProperty in properties) { var targetValue = GetColumnValue(aliases, targetProperty, exclusions, row, ignoreMissingField); if (!(targetValue is NoValue)) { var columnName = GetColumnName(targetProperty.Name, aliases); if (propertyNameTriggers != null && propertyNameTriggers.Keys.Contains(columnName)) { if (targetValue != DBNull.Value) { targetValue = propertyNameTriggers[columnName](targetValue); } } SetValue(aliases, targetProperty, targetValue, destination); } } list.Add(destination); } return(list); }
public T Get <T>(string key) where T : class { var cache = CacheFactory.GetCache(CacheFactoryName); try { var ttt = (T)GenericTypeHelper.Convert <object, T>(cache[key], () => new GenericConverter <T>()); //(T)cache[key]; return(ttt); //return (T)GenericTypeHelper.Convert<object, T>(cache[key], () => new GenericConverter<T>()); } finally { cache.Release(); } }
/// <summary> /// Gets the source property /// </summary> private static object GetColumnValue(Aliases aliases, PropertyInfo targetProperty, Exclusions exclusions, DataRow sourceRow, bool ignoreMissingField) { object value = new NoValue(); if (aliases != null && aliases.Keys.Contains(targetProperty.Name)) { //Excluded properties should not be mapped... even if aliased if (!(exclusions != null && GenericTypeHelper.ContainsExclusion(aliases[targetProperty.Name], exclusions))) { value = sourceRow[aliases[targetProperty.Name]]; } } else { // If target property is already aliased then do not match on source property of the same name... this will cause a double mapping if (aliases == null || (!aliases.Values.Contains(targetProperty.Name))) { //do not map excluded properties if (!(exclusions != null && GenericTypeHelper.ContainsExclusion(targetProperty.Name, exclusions))) { if (sourceRow.Table.Columns.Contains(targetProperty.Name)) { value = sourceRow[targetProperty.Name]; } else if (ignoreMissingField) { return(value); } else { throw new MissingFieldException(string.Format("{0} field does not exist", targetProperty.Name)); } } } } return(value); }
public static IList <TO> MapToAnOtherObjectAsList <TFrom, TO>(this IEnumerable <TFrom> from) where TO : new() { var list = new List <TO>(); var properties = GenericTypeHelper.GetProperties <TO>().ToArray(); foreach (var itemFrom in from) { var destination = new TO(); var propertiesTarget = GenericTypeHelper.GetProperties <TFrom>(); foreach (var propertyInfo in propertiesTarget) { var prop = properties.FirstOrDefault(p => p.Name.ToLower().Equals(propertyInfo.Name.ToLower()) && p.PropertyType == propertyInfo.PropertyType); if (prop != null) { prop.SetValue(destination, propertyInfo.GetValue(itemFrom)); } } list.Add(destination); } return(list); }
public AstGenericMethodWithTypeArguments(IAstMethodReference actual, IList <IAstTypeReference> typeArguments, GenericTypeHelper genericHelper) { Argument.RequireNotNull("actual", actual); Argument.RequireNotNull("typeArguments", typeArguments); this.Actual = actual; this.GenericArgumentTypes = typeArguments.AsReadOnly(); var genericParameterTypes = actual.GetGenericParameterTypes().ToArray(); this.ParameterTypes = actual.ParameterTypes.Select(t => ApplyArgumentTypes(genericHelper, t, genericParameterTypes)).ToArray().AsReadOnly(); this.ReturnType = ApplyArgumentTypes(genericHelper, actual.ReturnType, genericParameterTypes); }
public void Build(ISchema schema) { ValueConverter.Register <ExpOrderAddress, Optional <ExpOrderAddress> >(x => new Optional <ExpOrderAddress>(x)); _ = schema.Query.AddField(new FieldType { Name = "order", Arguments = AbstractTypeFactory <OrderQueryArguments> .TryCreateInstance(), Type = GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>(), Resolver = new AsyncFieldResolver <object>(async context => { var request = context.ExtractQuery <GetOrderQuery>(); context.CopyArgumentsToUserContext(); var orderAggregate = await _mediator.Send(request); var authorizationResult = await _authorizationService.AuthorizeAsync(context.GetCurrentPrincipal(), orderAggregate.Order, new CanAccessOrderAuthorizationRequirement()); if (!authorizationResult.Succeeded) { throw new AuthorizationError($"Access denied"); } var allCurrencies = await _currencyService.GetAllCurrenciesAsync(); //Store all currencies in the user context for future resolve in the schema types context.SetCurrencies(allCurrencies, request.CultureName); //store order aggregate in the user context for future usage in the graph types resolvers context.SetExpandedObjectGraph(orderAggregate); return(orderAggregate); }) }); var orderConnectionBuilder = GraphTypeExtenstionHelper .CreateConnection <CustomerOrderType, object>() .Name("orders") .PageSize(20) .Arguments(); orderConnectionBuilder.ResolveAsync(async context => await ResolveOrdersConnectionAsync(_mediator, context)); schema.Query.AddField(orderConnectionBuilder.FieldType); var paymentsConnectionBuilder = GraphTypeExtenstionHelper .CreateConnection <PaymentInType, object>() .Name("payments") .PageSize(20) .Arguments(); paymentsConnectionBuilder.ResolveAsync(async context => await ResolvePaymentsConnectionAsync(_mediator, context)); schema.Query.AddField(paymentsConnectionBuilder.FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("createOrderFromCart") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputCreateOrderFromCartType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <CreateOrderFromCartCommand>(); var response = (CustomerOrderAggregate)await _mediator.Send(context.GetArgument(type, _commandName)); context.SetExpandedObjectGraph(response); return(response); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, bool>(typeof(BooleanGraphType)) .Name("changeOrderStatus") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputChangeOrderStatusType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <ChangeOrderStatusCommand>(); var command = (ChangeOrderStatusCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, ProcessPaymentRequestResult>(typeof(ProcessPaymentRequestResultType)) .Name("processOrderPayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputProcessOrderPaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <ProcessOrderPaymentCommand>(); var command = (ProcessOrderPaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .DeprecationReason("Obsolete. Use 'initializePayment' mutation") .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, InitializePaymentResult>(typeof(InitializePaymentResultType)) .Name("initializePayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputInitializePaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <InitializePaymentCommand>(); var command = (InitializePaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, AuthorizePaymentResult>(typeof(AuthorizePaymentResultType)) .Name("authorizePayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputAuthorizePaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <AuthorizePaymentCommand>(); var command = (AuthorizePaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderDynamicPropertiesCommand>(); var command = (UpdateOrderDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderItemDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderItemDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderItemDynamicPropertiesCommand>(); var command = (UpdateOrderItemDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderPaymentDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderPaymentDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderPaymentDynamicPropertiesCommand>(); var command = (UpdateOrderPaymentDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderShipmentDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderShipmentDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderShipmentDynamicPropertiesCommand>(); var command = (UpdateOrderShipmentDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("addOrUpdateOrderPayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputAddOrUpdateOrderPaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <AddOrUpdateOrderPaymentCommand>(); var command = (AddOrUpdateOrderPaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); var response = await _mediator.Send(command); context.SetExpandedObjectGraph(response); return(response); }) .FieldType); }
public static T GetCartCommand <T>(this IResolveFieldContext <CartAggregate> context) where T : CartCommand => (T)context.GetArgument(GenericTypeHelper.GetActualType <T>(), PurchaseSchema._commandName);
public CoerceDelegateArgumentsToCorrectGenericTypes(GenericTypeHelper genericHelper) : base(ProcessingStage.TypeResolution) { this.genericHelper = genericHelper; }
public T GetData <T>() { return(GenericTypeHelper.GetData <T>(_rawData)); }
public T GetEventData <T>() { return(GenericTypeHelper.GetData <T>(EventData)); }