Пример #1
0
        public virtual async Task <IEnumerable <TEntity> > GetAsync <TEntity>(Expression <Func <TEntity, bool> > filter = null) where TEntity : IEntity
        {
            var promise = new TaskCompletionSource <string>();
            RepositoryObserver observer = new RepositoryObserver();

            observer.onMessage = data => promise.TrySetResult(data);
            observer.Subscribe(_context);

            string message = _context.GetTypeName(typeof(TEntity));

            message += ":Get::";

            await _context.SendAsync(message);

            string data = await promise.Task;

            lock (_lock)
            {
                IQueryable <TEntity> entities = _context.DeserializeList <TEntity>(data).AsQueryable();
                if (filter != null)
                {
                    return(entities.Where(filter));
                }

                //observer.OnCompleted();

                return(entities);
            }
        }
Пример #2
0
        public virtual async Task InsertAsync <TEntity>(TEntity entity) where TEntity : IEntity
        {
            var promise = new TaskCompletionSource <string>();
            RepositoryObserver observer = new RepositoryObserver();

            observer.onMessage = data => promise.TrySetResult(data);
            observer.Subscribe(_context);

            string message;

            lock (_lock)
            {
                message  = _context.GetTypeName(typeof(TEntity));
                message += ":Insert:";
                message += _context.Serialize(typeof(TEntity), entity);
            }

            await _context.SendAsync(message);

            string data = await promise.Task;
        }