示例#1
0
        private static void OnAfterApplyDefaultBehaviour(object sender, TypeAddedEventArgs args)
        {
            if (GrpcServiceClient.IsRequestDto(args.Type))
            {
                // query DTO; we'll flatten the query *into* this type, shifting everything
                // by some reserved number per level, starting at the most base level

                // walk backwards up the tree; at each level, offset everything by 100
                // and copy over from the default model
                var  log     = LogManager.GetLogger(typeof(MetaTypeConfig <>).MakeGenericType(args.Type));
                Type current = args.Type.BaseType;
                var  mt      = args.MetaType;
                while (current != null && current != typeof(object))
                {
                    try
                    {
                        mt.ApplyFieldOffset(100);
                    }
                    catch (Exception e)
                    {
                        log.Error($"Error in CreateMetaType() for '{current.Name}' when 'ApplyFieldOffset(100)': {e.Message}", e);
                        throw;
                    }
                    var source = RuntimeTypeModel.Default[current]?.GetFields();
                    foreach (var field in source)
                    {
                        try
                        {
                            AddField(mt, field);
                        }
                        catch (Exception e)
                        {
                            log.Error($"Error in CreateMetaType() for '{current.Name}' when adding field '{field.Name}': {e.Message}", e);
                            throw;
                        }
                    }

                    // keep going down the hierarchy
                    current = current.BaseType;
                }
            }
示例#2
0
 public ServiceStackClientInterceptor(GrpcChannel channel, GrpcClientConfig config)
 {
     Config         = config ?? throw new ArgumentNullException(nameof(config));
     Config.Channel = channel;
     client         = new GrpcServiceClient(Config);
 }