Exemple #1
0
        public Task UpdateAsync(string container, string id, Document document)
        {
            var path = FilePathProvider.GetPathFor(container, id);

            if (!FileHandler.Exists(path))
            {
                throw new DocumentDoesNotExistException(container, id);
            }

            FileHandler.Update(path, JsonConvert.SerializeObject(document, Formatting.Indented));

            return(Task.CompletedTask);
        }
Exemple #2
0
        public Task DeleteAsync(string container, string id)
        {
            var path = FilePathProvider.GetPathFor(container, id);

            if (!FileHandler.Exists(path))
            {
                return(Task.CompletedTask);
            }

            FileHandler.Delete(path);

            return(Task.CompletedTask);
        }
Exemple #3
0
        public Task CreateDocumentAsync(string container, Document document)
        {
            var path = FilePathProvider.GetPathFor(container, document.Id);

            if (FileHandler.Exists(path))
            {
                throw new DocumentAlreadyExistsException(container, document.Id);
            }

            FileHandler.Create(path, JsonConvert.SerializeObject(document, Formatting.Indented));

            return(Task.CompletedTask);
        }
Exemple #4
0
        public Task Create(string container, Document document)
        {
            var path = FilePathProvider.GetPathFor(container, document.Id);

            if (FileHandler.Exists(path))
            {
                throw new DocumentAlreadyExistsException(container, document.Id);
            }

            FileHandler.Create(path, DocumentSerializer.Serialize(document));

            return(Task.CompletedTask);
        }
Exemple #5
0
        public Task <Document> GetAsync(string container, string id)
        {
            var path = FilePathProvider.GetPathFor(container, id);

            if (!FileHandler.Exists(path))
            {
                return(Task.FromResult <Document>(null));
            }

            string contents = FileHandler.Get(path);

            return(Task.FromResult(DocumentDeserializer.Deserialize(contents)));
        }
Exemple #6
0
        public Task <IEnumerable <Document> > GetResultAsync()
        {
            var result = new List <Document>();

            foreach (var document in FileHandler.List(FilePathProvider.GetPathFor(Container)).Select(c => DocumentDeserializer.Deserialize(c)))
            {
                if (Criteria.All(c => c(document)))
                {
                    result.Add(document);
                }
            }

            return(Task.FromResult((IEnumerable <Document>)result.AsReadOnly()));
        }
Exemple #7
0
        public Task <IEnumerable <Document> > ListAsync(string container)
        {
            var path = FilePathProvider.GetPathFor(container);

            if (!FileHandler.Exists(path))
            {
                return(Task.FromResult(Enumerable.Empty <Document>()));
            }

            var result = new List <Document>();

            foreach (var file in FileHandler.List(path))
            {
                result.Add(JsonConvert.DeserializeObject <Document>(file));
            }

            return(Task.FromResult((IEnumerable <Document>)result.AsReadOnly()));
        }