示例#1
0
        public string CreateOrUpdate(TemplateFile model)
        {
            string name         = model.Name;
            string relativePath = model.RelativePath;

            if (relativePath.IsNullOrWhiteSpace())
            {
                return("文件相对路径错误");
            }

            if (name.EndsWith(_cshtml.Substring(1)) || name.EndsWith(_fluid.Substring(1)))
            {
                relativePath = relativePath.TrimStart('~');
                model.Path   = _env.MapWebRootPath(relativePath.Split('/'));
                if (model.Id > 0)
                {
                    var old = Get(model.Id);
                    if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //model.Path = _env.MapWebRootPath(_themeName, model.ThemeName, _viewName, model.Name);
                        //model.RelativePath = GetRelativePath(model.Path, _env.WebRootPath.Length);
                        ExtFile.DeleteFile(old.Path);
                    }
                }
                ExtFile.WriteFile(model.Path, model.Content);
                _cacheMgr.Remove(_templateFilesCacheKey);
                return(string.Empty);
            }
            return("文件名称格式错误");
        }
示例#2
0
        public void Delete(int id)
        {
            var model = Get(id);

            ExtFile.DeleteFile(model.Path);
            _cacheMgr.Remove(_templateFilesCacheKey);
        }
示例#3
0
        public virtual ServiceResult <TemplateFile> CreateOrUpdate(TemplateFile model)
        {
            string name         = model.Name;
            string relativePath = model.RelativePath;
            ServiceResult <TemplateFile> result = new ServiceResult <TemplateFile>();
            string ext = Path.GetExtension(name);

            if (GetSupportFileExtensions().Contains(ext))
            {
                relativePath = relativePath.TrimStart('~');
                model.Path   = _webHostEnvironment.MapWebRootPath(relativePath.Split('/'));
                if (model.Id > 0)
                {
                    var old = Get(model.Id);
                    if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ExtFile.DeleteFile(old.Path);
                    }
                }
                ExtFile.WriteFile(model.Path, model.Content);
                EnsureHasViewImports(model.Path);
                _cacheMgr.Remove(_templateFilesCacheKey);
                result.Result = GetTemplateFiles().First(m => m.RelativePath == model.RelativePath);
            }
            else
            {
                result.RuleViolations.Add(new RuleViolation("Name", "File not support"));
            }
            return(result);
        }
示例#4
0
        public ServiceResult <TemplateFile> CreateOrUpdate(TemplateFile model)
        {
            string name         = model.Name;
            string relativePath = model.RelativePath;
            ServiceResult <TemplateFile> result = new ServiceResult <TemplateFile>();

            if (name.EndsWith(_cshtml.Substring(1)))
            {
                relativePath = relativePath.TrimStart('~');
                model.Path   = _webHostEnvironment.MapWebRootPath(relativePath.Split('/'));
                if (model.Id > 0)
                {
                    var old = Get(model.Id);
                    if (!old.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ExtFile.DeleteFile(old.Path);
                    }
                }
                ExtFile.WriteFile(model.Path, model.Content);
                _cacheMgr.Remove(_templateFilesCacheKey);
                result.Result = GetTemplateFiles().First(m => m.Name == name);
            }
            else
            {
                result.RuleViolations.Add(new RuleViolation("Name", "文件名称格式错误"));
            }
            return(result);
        }
示例#5
0
        public void Delete(int id)
        {
            var model = Get(id);

            if (model.Name != _viewImportsFileName)
            {
                ExtFile.DeleteFile(model.Path);
                _cacheMgr.Remove(_templateFilesCacheKey);
            }
        }