示例#1
0
        private async Task ClearFileWeightsCache(String path)
        {
            var paths = path.Split(PathSep);

            if (paths.Length < 2)
            {
                return;
            }
            var rootName = paths[1];
            var cacheKey = FileWeightsVersionCacheKey(rootName);
            var version  = await _cache.GetStringAsync(cacheKey);

            if (!string.IsNullOrWhiteSpace(version))
            {
                await _cache.RemoveAsync(cacheKey);

                try
                {
                    await _contentService.Delete(version);
                }
                catch
                {
                    //
                }
            }
        }
        public override async Task <AddOrUpdateReply> AddOrUpdate(ContentTemplate request, ServerCallContext context)
        {
            var reply = new AddOrUpdateReply();
            var user  = await _userService.GetUser(context.GetHttpContext());

            if (user == null)
            {
                reply.Error = Error.NeedLogin;
                return(reply);
            }

            if (!user.HasWritePermission())
            {
                reply.Error = Error.NoPermission;
                return(reply);
            }

            if (!string.IsNullOrWhiteSpace(request.Id))
            {
                if (!Guid.TryParse(request.Id, out var id))
                {
                    reply.Error = Error.InvalidArguments;
                    return(reply);
                }

                var item = await _service.All().Include(c => c.ContentCaches).Where(c => c.Id == id)
                           .FirstOrDefaultAsync();

                item.Data    = request.Data;
                item.Updated = DateTime.Now;
                reply.Id     = request.Id;
                var files = item.ContentCaches?.Select(c => c.Content).ToList();
                item.ContentCaches = new List <Domain.Models.ContentCache>();
                await _service.Update(item);

                if (files != null && files.Count > 0)
                {
                    files.ForEach(f => _fileService.Delete(f));
                }

                return(reply);
            }

            var newItem = await _service.Add(new Domain.Models.ContentTemplate
            {
                Id      = Guid.NewGuid(),
                Name    = request.Name,
                Data    = request.Data,
                Updated = DateTime.Now
            });

            reply.Id = newItem.Id.ToString();
            return(reply);
        }
示例#3
0
        public async Task Delete(string id)
        {
            if (Guid.TryParse(id, out var gid))
            {
                var content = await _entitiesService.All().Include(c => c.ContentCaches).Where(c => c.Id == gid).FirstOrDefaultAsync();

                if (content == null)
                {
                    return;
                }
                var files = content.ContentCaches == null ? null : content.ContentCaches.Select(c => c.Content).ToList();
                await _entitiesService.Delete(content);

                if (files != null && files.Count > 0)
                {
                    files.ForEach(f => _fileService.Delete(f));
                }
            }
        }