/// <summary>
        ///     Explicitly registers a type on the client and the server. In order to use this version of the method
        ///     the type need to be tagged(attributes need to be associated to its public properties used as keys)
        ///     Explicit type registration is not required.
        ///     It is done automatically when the first Put() is executed for an item of the specified type
        ///     or when a query is first built
        ///     <br />
        ///     As type registration is an expensive operation, you may want to do it during the client initialization.
        /// </summary>
        /// <param name="type"></param>
        public ClientSideTypeDescription RegisterTypeIfNeeded(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (KnownTypes.TryGetValue(type.FullName ?? throw new InvalidOperationException(), out var typeDescription))
            {
                return(typeDescription);
            }

            typeDescription = ClientSideTypeDescription.RegisterType(type);
            KnownTypes[typeDescription.FullTypeName] = typeDescription;


            var request = new RegisterTypeRequest(typeDescription.AsTypeDescription, ShardIndex, ShardsCount);

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while registering a type on the server", exResponse.Message,
                                         exResponse.CallStack);
            }

            return(typeDescription);
        }
Exemple #2
0
        public ClientSideTypeDescription RegisterType(Type type, bool forceReindex = false)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }


            var typeDescription = ClientSideTypeDescription.RegisterType(type);

            KnownTypes[typeDescription.FullTypeName] = typeDescription;


            var request = new RegisterTypeRequest(typeDescription.AsTypeDescription, ShardIndex, ShardsCount);

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while registering a type on the server", exResponse.Message,
                                         exResponse.CallStack);
            }

            return(typeDescription);
        }
        /// <summary>
        ///     Register a type as cacheable with an external description
        ///     Cacheable type descriptions can be provided by attributes on the public properties
        ///     or as <see cref="TypeDescriptionConfig" />.
        ///     If an external description is required, the type must be explicitly registered.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="description"></param>
        public ClientSideTypeDescription RegisterTypeIfNeeded(Type type, TypeDescriptionConfig description)
        {
            if (KnownTypes.TryGetValue(description.FullTypeName, out var typeDescription))
            {
                return(typeDescription);
            }

            typeDescription = ClientSideTypeDescription.RegisterType(type, description);

            KnownTypes[typeDescription.FullTypeName] = typeDescription;


            var request = new RegisterTypeRequest(typeDescription.AsTypeDescription, ShardIndex, ShardsCount);

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while registering a type on the server", exResponse.Message,
                                         exResponse.CallStack);
            }

            return(typeDescription);
        }