예제 #1
0
 /// <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;
 }
예제 #2
0
 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;
 }
예제 #3
0
        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);
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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;
            }

        }
예제 #6
0
        public virtual ActionResult Index(string folderName, string parentUUID, string parentFolder, string search
            , IEnumerable<WhereClause> whereClause, int? page, int? pageSize, string orderField = null, string direction = 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 = ServiceFactory.TextFolderManager.ChildFolders(textFolder, search).Select(it => it.AsActual());
                }
            }

            IContentQuery<TextContent> query = textFolder.CreateQuery();
            if (string.IsNullOrEmpty(orderField))
            {
                query = query.DefaultOrder();
            }
            else
            {
                if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "desc")
                {
                    query = query.OrderByDescending(orderField);
                }
                else
                {
                    query = query.OrderBy(orderField);
                }
            }
            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.VisibleOnSidebarMenu == null || it.VisibleOnSidebarMenu.Value == true)
                    .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 = ServiceFactory.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
            });
        }
예제 #7
0
        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);
        }
예제 #8
0
        public virtual ActionResult Edit(string folderName, string parentFolder, 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 = ServiceFactory.WorkflowManager.GetPendWorkflowItemForContent(Repository, content, User.Identity.Name);
            }
            return View(content);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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 = schema.DefaultContent();
            content = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.Bind(schema, content, Request.QueryString, true, false);

            return View(content);
        }
예제 #11
0
        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;

                    content = TextContentManager.Update(Repository, textFolder, uuid, form,
                    Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name);

                    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);
        }
예제 #12
0
 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;
 }
예제 #13
0
 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;
 }
예제 #14
0
 /// <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));
 }
예제 #15
0
        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));
        }
예제 #16
0
        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);
        }
예제 #17
0
        public virtual ActionResult SelectCategories(string folderName, string selected, int? page, int? pageSize, string search, IEnumerable<WhereClause> whereClause)
        {
            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().DefaultOrder();

            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);
                }
            }
            if (whereClause != null && whereClause.Count() > 0)
            {
                var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider));
                query = query.Where(expression);
            }

            var contents = query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize);
            SelectableViewModel viewModel = new SelectableViewModel() { 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);
        }
예제 #18
0
        public virtual ActionResult Create(string folderName, string parentFolder, string LikeUUID)
        {
            TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
            var schema = textFolder.GetSchema().AsActual();

            SchemaPath schemaPath = new SchemaPath(schema);
            ViewData["Folder"] = textFolder;
            ViewData["Schema"] = schema;
            ViewData["Menu"] = textFolder.GetFormTemplate(FormType.Create_Menu);
            ViewData["Template"] = textFolder.GetFormTemplate(FormType.Create);
            SetPermissionData(textFolder);

            var content = Binder.Default(schema);
            content = Binder.Bind(schema, content, Request.QueryString, true, false);

            // copy categories and parentUUID - TODO
            if (!String.IsNullOrEmpty(LikeUUID))
            {
                // želimo kategorije iz zadanog itema
                var contentLike = schema.CreateQuery().WhereEquals("UUID", LikeUUID).FirstOrDefault();

                // sve kategorije za ovaj folder
                List<TextContent> addedCategories = new List<TextContent>();
                foreach (CategoryFolder cf in textFolder.Categories)
                {
                    addedCategories.AddRange(contentLike.Categories(cf.FolderName));
                }

                // copy parentUUID
                content.ParentUUID = contentLike.ParentUUID;

                var cb = TextContentManager.Add(Repository, textFolder, content.ParentFolder, content.ParentUUID, content.ToNameValueCollection(), Request.Files, addedCategories, User.Identity.Name);
                content = new TextContent(cb);
            }

            return View(content);
        }