Example #1
0
        public DataSource <T> DataSource <T>()
        {
            ClientSideTypeDescription typeDescription = TypeDescriptionsCache.GetDescription(typeof(T));

            typeDescription = Client.RegisterType(typeof(T), typeDescription);

            return(new DataSource <T>(Client, typeDescription));
        }
Example #2
0
 public void Commit()
 {
     foreach (var type in _types)
     {
         var description = TypeDescriptionsCache.GetDescription(type);
         _client.RegisterType(type, description);
     }
     _client.ExecuteTransaction(_itemsToPut, _conditions, _itemsToDelete);
 }
Example #3
0
        /// <summary>
        /// Declare collection with implicit schema (inferred from the type)
        /// If the collection name is not specified, the name of the type is used
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collectionName"></param>
        public void DeclareCollection <T>(string collectionName = null)
        {
            collectionName ??= typeof(T).Name;

            var description = TypeDescriptionsCache.GetDescription(typeof(T));

            var schema = description;

            Client.DeclareCollection(collectionName, schema);

            lock (_collectionSchema)
            {
                _collectionSchema[collectionName] = schema;
            }
        }
Example #4
0
        /// <summary>
        ///     Conditional update. The condition is applied server-side on the previous version of the item
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="newValue"></param>
        /// <param name="test"></param>
        public void UpdateIf <T>(T newValue, Expression <Func <T, bool> > test)
        {
            var desc = TypeDescriptionsCache.GetDescription(typeof(T));

            var packed = Pack(newValue);

            _itemsToPut.Add(packed);

            var dataSource  = new DataSource <T>(_client, desc);
            var testAsQuery = dataSource.PredicateToQuery(test);

            _conditions.Add(testAsQuery);

            _types.Add(typeof(T));
        }
Example #5
0
        public Connector(ClientConfig config)
        {
            if (Client == null)
            {
                if (config.Servers == null || config.Servers.Count == 0)
                {
                    var channel = new InProcessChannel();
                    Client = new CacheClient {
                        Channel = channel
                    };

                    _server = new Server.Server(new NodeConfig {
                        IsPersistent = config.IsPersistent
                    })
                    {
                        Channel = channel
                    };

                    _server.Start();
                }
                else if (config.Servers.Count == 1)
                {
                    var serverCfg = config.Servers[0];

                    var channel = new TcpClientChannel(new TcpClientPool(4, 1, serverCfg.Host, serverCfg.Port));

                    Client = new CacheClient {
                        Channel = channel
                    };
                }
                else // multiple servers
                {
                    var aggregator = new Aggregator();

                    var index = 0;
                    foreach (var serverConfig in config.Servers)
                    {
                        var channel =
                            new TcpClientChannel(new TcpClientPool(4, 1, serverConfig.Host, serverConfig.Port));

                        var client = new CacheClient
                        {
                            Channel     = channel,
                            ShardIndex  = index,
                            ShardsCount = config.Servers.Count
                        };
                        aggregator.CacheClients.Add(client);
                        index++;
                    }


                    Client = aggregator;
                }
            }


            // register types from client configuration
            foreach (var description in config.TypeDescriptions)
            {
                var type            = Type.GetType(description.Value.FullTypeName + ", " + description.Value.AssemblyName);
                var typeDescription = Client.RegisterTypeIfNeeded(type, description.Value);

                TypeDescriptionsCache.AddExplicitTypeDescription(type, typeDescription);
            }
        }
Example #6
0
        private CachedObject Pack <T>(T item)
        {
            var packed = CachedObject.Pack(item, TypeDescriptionsCache.GetDescription(typeof(T)));

            return(packed);
        }