public virtual ActionResult Selectable(string categoryFolder, int?page, int?pageSize, string orderField = null, string direction = null) { var textFolder = (TextFolder)(FolderHelper.Parse <TextFolder>(Repository, categoryFolder).AsActual()); Schema schema = new Schema(Repository, textFolder.SchemaName).AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Selectable); IContentQuery <TextContent> query = textFolder.CreateQuery(); if (string.IsNullOrEmpty(orderField)) { query = query.DefaultOrder(); } else { if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "asc") { query = query.OrderBy(orderField); } else { query = query.OrderByDescending(orderField); } } return(View(query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize))); }
public static string GetCustomTemplatePhysicalPath(this Schema schema, FormType type) { var schemaPath = new SchemaPath(schema); string filePhysicalPath = Path.Combine(schemaPath.PhysicalPath, CUSTOM_TEMPLATES, string.Format("{0}.cshtml", type)); return(filePhysicalPath); }
public virtual Schema Create(Repository repository, string schemaName, Stream templateStream) { Schema schema = new Schema(repository, schemaName); SchemaPath path = new SchemaPath(schema); if (path.Exists()) { throw new KoobooException("The item is already exists."); } GetLocker().EnterReadLock(); try { using (ZipFile zipFile = ZipFile.Read(templateStream)) { ExtractExistingFileAction action = ExtractExistingFileAction.OverwriteSilently; zipFile.ExtractAll(path.PhysicalPath, action); } Providers.DefaultProviderFactory.GetProvider <ISchemaProvider>().Initialize(schema); } finally { GetLocker().ExitReadLock(); } return(schema); }
public virtual void ResetForm(Repository repository, string schemaName, FormType formType) { Schema schema = new Schema(repository, schemaName).AsActual(); SchemaPath path = new SchemaPath(schema); if ((formType & FormType.Grid) == FormType.Grid) { ResetForm(schema, path, FormType.Grid); } if ((formType & FormType.Create) == FormType.Create) { ResetForm(schema, path, FormType.Create); } if ((formType & FormType.Detail) == FormType.Detail) { ResetForm(schema, path, FormType.Detail); } if ((formType & FormType.List) == FormType.List) { ResetForm(schema, path, FormType.List); } if ((formType & FormType.Selectable) == FormType.Selectable) { ResetForm(schema, path, FormType.Selectable); } if ((formType & FormType.Update) == FormType.Update) { ResetForm(schema, path, FormType.Update); } schema.TemplateBuildByMachine = true; Update(repository, schema, schema); }
public int ResetSchema(Repository repository, Schema[] schemas) { var root = SchemaPath.GetBaseDir(repository); var paths = schemas.Select(it => Path.Combine(root, it.Name)); return(ResetSchema(repository, schemas, paths)); }
private static void ResetForm(Schema schema, SchemaPath path, FormType formType) { var formFilePhysicalPath = schema.GetFormFilePhysicalPath(formType); string form = schema.GenerateForm(formType); IO.IOUtility.SaveStringToFile(formFilePhysicalPath, form); }
public int ResetSchema(Repository repository) { var root = SchemaPath.GetBaseDir(repository); var paths = Directory.GetDirectories(root); var schemas = Kooboo.CMS.Content.Services.ServiceFactory.SchemaManager.All(repository, "").ToArray(); return(ResetSchema(repository, schemas, paths)); }
private static string GetCustomTemplateFileVirtualPath(Schema schema, FormType type) { var schemaPath = new SchemaPath(schema); string fileVirtualPath = ""; var filePhysicalPath = GetCustomTemplatePhysicalPath(schema, type); if (System.IO.File.Exists(filePhysicalPath)) { fileVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, CUSTOM_TEMPLATES, string.Format("{0}.cshtml", type)); } return fileVirtualPath; }
/// <summary> /// 取得Schema的模板相对路径 /// </summary> /// <param name="schema">The schema.</param> /// <param name="formType">Type of the form.</param> /// <returns></returns> public static string GetFormTemplate(this Schema schema, FormType formType) { var schemaPath = new SchemaPath(schema); var virtualPath = GetCustomTemplateFileVirtualPath(schemaPath, formType); if (string.IsNullOrEmpty(virtualPath)) { virtualPath = GetFormFileVirtualPath(schema, formType); } return(virtualPath); }
private static string GetCustomTemplateFileVirtualPath(SchemaPath schemaPath, FormType type) { string fileVirtualPath = ""; string filePhysicalPath = Path.Combine(schemaPath.PhysicalPath, CUSTOM_TEMPLATES, string.Format("{0}.cshtml", type)); if (System.IO.File.Exists(filePhysicalPath)) { fileVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, CUSTOM_TEMPLATES, string.Format("{0}.cshtml", type)); } return(fileVirtualPath); }
public virtual ActionResult Edit(string folderName, string parentFolder, string uuid, FormCollection form, bool?localize) { JsonResultEntry resultEntry = new JsonResultEntry() { Success = true }; try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; //if (textFolder != null) //{ content = ServiceFactory.TextContentManager.Update(Repository, textFolder, uuid, form, Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name); if (localize.HasValue && localize.Value == true) { ServiceFactory.TextContentManager.Localize(textFolder, uuid); } //} //else //{ // content = ServiceFactory.TextContentManager.Update(Repository, schema, uuid, form, // Request.Files, User.Identity.Name); //} resultEntry.Success = true; } } catch (RuleViolationException violationException) { foreach (var item in violationException.Issues) { ModelState.AddModelError(item.PropertyName, item.ErrorMessage); } resultEntry.Success = false; } catch (Exception e) { resultEntry.SetFailed().AddException(e); } resultEntry.AddModelState(ViewData.ModelState); return(Json(resultEntry)); }
public virtual void Import(Repository repository, Stream zipStream, bool @override) { GetLocker().EnterWriteLock(); try { ImportHelper.Import(SchemaPath.GetBaseDir(repository), zipStream, @override); } finally { GetLocker().ExitWriteLock(); } }
private static string GetFormFileVirtualPath(Schema schema, FormType type) { var razorTemplate = GetFormFilePhysicalPath(schema, type); var schemaPath = new SchemaPath(schema); var templateVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, string.Format("{0}.ascx", type)); if (System.IO.File.Exists(razorTemplate)) { templateVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, string.Format("{0}.cshtml", type)); } return(templateVirtualPath); }
public IEnumerable <Schema> AllEnumerable(Repository repository) { var baseDir = SchemaPath.GetBaseDir(repository); List <Schema> list = new List <Schema>(); if (Directory.Exists(baseDir)) { foreach (var item in IO.IOUtility.EnumerateDirectoriesExludeHidden(baseDir)) { list.Add(new Schema(repository, item.Name)); } } return(list); }
public void TestPhysicalPath() { var repositoryName = "repository1"; var schemaName = "schema1"; var expected = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cms_Data", "Contents", repositoryName, "schemas", schemaName); SchemaPath path = new SchemaPath(new Schema(new Repository(repositoryName), schemaName)); Assert.AreEqual(expected, path.PhysicalPath, true); var settingFile = Path.Combine(expected, "setting.config"); Assert.AreEqual(settingFile, path.SettingFile, true); }
public virtual ActionResult Edit(string folderName, string uuid, FormCollection form, string @return, bool localize = false) { var data = new JsonResultData(); try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; TextContent previous = Session["EditableObject"] as TextContent; TextContentManager.Update(Repository, textFolder, uuid, form, Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name, previous: previous); if (localize == true) { TextContentManager.Localize(textFolder, uuid); } data.RedirectToOpener = true; data.RedirectUrl = @return; } } catch (RuleViolationException violationException) { foreach (var item in violationException.Issues) { ModelState.AddModelError(item.PropertyName, item.ErrorMessage); } data.Success = false; } catch (Exception e) { data.AddException(e); } data.AddModelState(ModelState); return(Json(data)); }
public Schema Copy(Repository repository, string sourceName, string destName) { SchemaPath sourcePath = new SchemaPath(new Schema(repository, sourceName)); var destSchema = new Schema(repository, destName); var destPath = new SchemaPath(destSchema); Kooboo.IO.IOUtility.CopyDirectory(sourcePath.PhysicalPath, destPath.PhysicalPath); Providers.DefaultProviderFactory.GetProvider <ISchemaProvider>().Initialize(destSchema); return(destSchema); }
public virtual ActionResult Create(string folderName, string parentFolder) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Create); SetPermissionData(textFolder); var content = Binder.Default(schema); content = Binder.Bind(schema, content, Request.QueryString, true, false); return(View(content)); }
public virtual ActionResult InlineEdit(string folderName, string uuid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Update); SetPermissionData(textFolder); var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (content != null) { content = WorkflowManager.GetPendWorkflowItemForContent(Repository, content, User.Identity.Name); } return(View(content)); }
public virtual ActionResult Create(string folderName, string parentFolder, string parentUUID, FormCollection form) { JsonResultEntry resultEntry = new JsonResultEntry() { Success = true }; try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; content = ServiceFactory.TextContentManager.Add(Repository, textFolder, parentFolder, parentUUID, form, Request.Files, addedCategories, User.Identity.Name); resultEntry.ReloadPage = true; resultEntry.Success = true; } } catch (RuleViolationException ruleEx) { foreach (var item in ruleEx.Issues) { resultEntry.AddFieldError(item.PropertyName, item.ErrorMessage); } } catch (Exception e) { resultEntry.SetFailed().AddException(e); } resultEntry.AddModelState(ViewData.ModelState); return(Json(resultEntry)); }
public TextContentPath(TextContent content) { var repository = new Repository(content.Repository); var textContent = content; if (string.IsNullOrEmpty(textContent.FolderName)) { var schemaPath = new SchemaPath(new Schema(repository, textContent.SchemaName)); // Compatible with the ContentFolderName has been change (_contents=>.contents) //this.PhysicalPath = Path.Combine(schemaPath.PhysicalPath, ContentFolderName, content.UUID); //this.VirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, ContentFolderName, content.UUID); //if (!Directory.Exists(this.PhysicalPath)) //{ this.PhysicalPath = Path.Combine(schemaPath.PhysicalPath, ContentAttachementFolder, content.UUID); this.VirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, ContentAttachementFolder, content.UUID); //} } else { FolderPath folderPath = null; folderPath = new FolderPath(FolderHelper.Parse<TextFolder>(repository, content.FolderName)); //// Compatible with the ContentFolderName has been change (_contents=>.contents) //this.PhysicalPath = Path.Combine(folderPath.PhysicalPath, ContentFolderName, content.UUID); //this.VirtualPath = UrlUtility.Combine(folderPath.VirtualPath, ContentFolderName, content.UUID); //if (!Directory.Exists(this.PhysicalPath)) //{ this.PhysicalPath = Path.Combine(folderPath.PhysicalPath, ContentAttachementFolder, content.UUID); this.VirtualPath = UrlUtility.Combine(folderPath.VirtualPath, ContentAttachementFolder, content.UUID); //} } var sysFolderName = Path.GetDirectoryName(this.PhysicalPath); if (!Directory.Exists(sysFolderName)) { Directory.CreateDirectory(sysFolderName); var sysFolder = new DirectoryInfo(sysFolderName); sysFolder.Attributes = sysFolder.Attributes | FileAttributes.Hidden; } }
public IEnumerable <Schema> AllEnumerable(Repository repository) { var baseDir = SchemaPath.GetBaseDir(repository); List <Schema> list = new List <Schema>(); if (Directory.Exists(baseDir)) { foreach (var item in IO.IOUtility.EnumerateDirectoriesExludeHidden(baseDir)) { list.Add(new Schema(repository, item.Name)); } //Include link directories // foreach (var item in Directory.GetFiles(baseDir, "*.lnk")) { list.Add(new Schema(repository, LinkHelper.GetDirectoryInfo(LinkHelper.ResolveShortcut(item)).Name)); } } return(list); }
public virtual ActionResult Create(string folderName, string parentFolder, string parentUUID, FormCollection form, string @return) { var data = new JsonResultData(); try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; content = TextContentManager.Add(Repository, textFolder, parentFolder, parentUUID, form, Request.Files, addedCategories, User.Identity.Name); data.RedirectUrl = @return; } } catch (RuleViolationException ruleEx) { foreach (var item in ruleEx.Issues) { data.AddFieldError(item.PropertyName, item.ErrorMessage); } } catch (Exception e) { data.AddException(e); } data.AddModelState(ModelState); return(Json(data)); }
/// <summary> /// 取得Schema的模板物理路径 /// </summary> /// <param name="schema">The schema.</param> /// <param name="type">The type.</param> /// <returns></returns> public static string GetFormFilePhysicalPath(this Schema schema, FormType type) { var schemaPath = new SchemaPath(schema); return Path.Combine(schemaPath.PhysicalPath, string.Format("{0}.cshtml", type)); }
private static string GetFormFileVirtualPath(Schema schema, FormType type) { var razorTemplate = GetFormFilePhysicalPath(schema, type); var schemaPath = new SchemaPath(schema); var templateVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, string.Format("{0}.ascx", type)); if (System.IO.File.Exists(razorTemplate)) { templateVirtualPath = UrlUtility.Combine(schemaPath.VirtualPath, string.Format("{0}.cshtml", type)); } return templateVirtualPath; }
public virtual ActionResult Index(string folderName, string parentUUID, string parentFolder, string search , IEnumerable <WhereClause> whereClause, int?page, int?pageSize, string sortField = null, string sortDir = null) { //compatible with the Folder parameter changed to FolderName. folderName = folderName ?? this.ControllerContext.RequestContext.GetRequestValue("Folder"); TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Grid); ViewData["WhereClause"] = whereClause; SetPermissionData(textFolder); IEnumerable <TextFolder> childFolders = new TextFolder[0]; //Skip the child folders on the embedded folder grid. if (string.IsNullOrEmpty(parentFolder)) { if (!page.HasValue || page.Value <= 1) { childFolders = TextFolderManager.ChildFolders(textFolder, search).Select(it => it.AsActual()); } } IContentQuery <TextContent> query = textFolder.CreateQuery(); query = SortByField(sortField, sortDir, query); bool showTreeStyle = schema.IsTreeStyle; //如果有带搜索条件,则不输出树形结构 if (!string.IsNullOrEmpty(search)) { IWhereExpression exp = new FalseExpression(); foreach (var item in schema.Columns.Where(it => it.ShowInGrid)) { exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search))); } if (exp != null) { query = query.Where(exp); } showTreeStyle = false; } if (whereClause != null && whereClause.Count() > 0) { var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider)); query = query.Where(expression); showTreeStyle = false; } if (!string.IsNullOrWhiteSpace(parentUUID)) { query = query.WhereEquals("ParentUUID", parentUUID); } else { //有两种情况需要考虑要不要查询所有的数据(ParentUUID=null) //1.树形结构数据,第一次查询需要过滤ParentUUID==null //2.自嵌套的目前结构,也需要过滤ParentUUID==null var selfEmbedded = textFolder.EmbeddedFolders != null && textFolder.EmbeddedFolders.Contains(textFolder.FullName, StringComparer.OrdinalIgnoreCase); if (showTreeStyle || selfEmbedded) { query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", ""))); } } if (childFolders != null) { childFolders = childFolders .Select(it => it.AsActual()) .Where(it => it.Visible) .Where(it => Kooboo.CMS.Content.Services.ServiceFactory.WorkflowManager.AvailableViewContent(it, User.Identity.Name)); } page = page ?? 1; pageSize = pageSize ?? textFolder.PageSize; //var pagedList = query.ToPageList(page.Value, pageSize.Value); //IEnumerable<TextContent> contents = pagedList.ToArray(); //if (Repository.EnableWorkflow == true) //{ // contents =WorkflowManager.GetPendWorkflowItemForContents(Repository, contents.ToArray(), User.Identity.Name); //} //var workflowContentPagedList = new PagedList<TextContent>(contents, page.Value, pageSize.Value, pagedList.TotalItemCount); //ViewData["ContentPagedList"] = workflowContentPagedList; return(View(new TextContentGrid() { ChildFolders = childFolders.ToArray(), ContentQuery = query, PageIndex = page.Value, PageSize = pageSize.Value, ShowTreeStyle = showTreeStyle })); }
public virtual ActionResult SelectCategories(string folderName, string selected, int?page, int?pageSize, string search, IEnumerable <WhereClause> whereClause , string sortField = null, string sortDir = null) { var textFolder = (TextFolder)(FolderHelper.Parse <TextFolder>(Repository, folderName).AsActual()); var singleChoice = string.Equals("True", Request.RequestContext.GetRequestValue("SingleChoice"), StringComparison.OrdinalIgnoreCase); Schema schema = new Schema(Repository, textFolder.SchemaName).AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Selectable); ViewData["WhereClause"] = whereClause; IEnumerable <TextFolder> childFolders = new TextFolder[0]; //Skip the child folders on the embedded folder grid. if (!page.HasValue || page.Value <= 1) { childFolders = ServiceFactory.TextFolderManager.ChildFoldersWithSameSchema(textFolder).Select(it => it.AsActual()); } var query = textFolder.CreateQuery(); query = SortByField(sortField, sortDir, query); bool showTreeStyle = schema.IsTreeStyle; if (showTreeStyle) { query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", ""))); } if (!string.IsNullOrEmpty(search)) { IWhereExpression exp = new FalseExpression(); foreach (var item in schema.Columns.Where(it => it.ShowInGrid)) { exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search))); } if (exp != null) { query = query.Where(exp); } showTreeStyle = false; } if (whereClause != null && whereClause.Count() > 0) { var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider)); query = query.Where(expression); showTreeStyle = false; } var contents = query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize, textFolder.EnablePaging.HasValue ? textFolder.EnablePaging.Value : true); SelectableViewModel viewModel = new SelectableViewModel() { ShowTreeStyle = showTreeStyle, ChildFolders = childFolders, Contents = contents, SingleChoice = singleChoice }; if (Request.IsAjaxRequest()) { return(PartialView("", viewModel)); } else { IEnumerable <TextContent> selectedContents = new TextContent[0]; if (!string.IsNullOrEmpty(selected)) { string[] selectedArr = selected.Split(','); IContentQuery <TextContent> selectedQuery = textFolder.CreateQuery().DefaultOrder(); foreach (var userKey in selectedArr) { selectedQuery = selectedQuery.Or((IWhereExpression)textFolder.CreateQuery().DefaultOrder().WhereEquals("UUID", userKey).Expression); } selectedContents = selectedQuery; } viewModel.Selected = selectedContents; } return(View(viewModel)); }
public static string GetCustomTemplatePhysicalPath(this Schema schema, FormType type) { var schemaPath = new SchemaPath(schema); string filePhysicalPath = Path.Combine(schemaPath.PhysicalPath, CUSTOM_TEMPLATES, string.Format("{0}.cshtml", type)); return filePhysicalPath; }
/// <summary> /// 取得Schema的模板物理路径 /// </summary> /// <param name="schema">The schema.</param> /// <param name="type">The type.</param> /// <returns></returns> public static string GetFormFilePhysicalPath(this Schema schema, FormType type) { var schemaPath = new SchemaPath(schema); return(Path.Combine(schemaPath.PhysicalPath, string.Format("{0}.cshtml", type))); }