public async virtual Task <IEnumerable <SpeedWagonContent> > Descendants(SpeedWagonContent model, IDictionary <string, string> filters)
        {
            var descendants = await Descendants(model);

            var filteredDescendants = new List <SpeedWagonContent>();

            foreach (var descendant in descendants)
            {
                var include = true;

                foreach (var filter in filters)
                {
                    var key   = filter.Key;
                    var value = filter.Value;

                    if (
                        (descendant.Content.ContainsKey(key) && descendant.Content[key] != value)
                        ||
                        (HasProperty(descendant, key) && GetPropertyValue(descendant, key) != value)
                        )
                    {
                        include = false;
                    }
                }

                if (include)
                {
                    filteredDescendants.Add(descendant);
                }
            }
            return(filteredDescendants);
        }
Beispiel #2
0
        public async Task <IActionResult> Add(ContentTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ContentTypes = await this._speedWagon.ContentTypeService.List();

                return(View("~/Views/SpeedWagon/ContentType/List.cshtml", model));
            }


            this._speedWagon.ContentTypeService.Add(model.Name, User.Identity.Name.MaskEmail(), model.Root, model.Children);

            if (!string.IsNullOrEmpty(model.CopyProperties))
            {
                SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(model.Name);

                SpeedWagonContent master = await this._speedWagon.ContentTypeService.Get(model.CopyProperties);

                contentType.Content["Editors"] = master.Content["Editors"];

                this._speedWagon.ContentTypeService.Save(contentType, User.Identity.Name.MaskEmail());
            }

            return(RedirectToAction("List", new { id = model.Name }));
        }
        public async Task <IActionResult> Edit(string url = null)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(RedirectToAction("List"));
            }

            SpeedWagonContent content = await this._speedWagon.GetContent(url);

            SpeedWagonContent parent = await this._speedWagon.ContentService.Parent(content);

            SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(content.Type);

            IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List();

            IEnumerable <ContentTypeEditor> properties = this._speedWagon.ContentTypeService.GetEditors(contentType);

            EditContentViewModel viewModel = new EditContentViewModel();

            viewModel.Url                   = content.RelativeUrl;
            viewModel.Parent                = parent.RelativeUrl;
            viewModel.Content               = content;
            viewModel.Editors               = editors;
            viewModel.ContentType           = contentType;
            viewModel.ContentTypeProperties = properties;
            viewModel.ViewEngine            = this._viewEngine;
            viewModel.Values                = this._speedWagon.WebContentService.GetValues(content, properties);

            return(View("~/Views/SpeedWagon/Content/Edit.cshtml", viewModel));
        }
        public async Task <IActionResult> List(string url = null)
        {
            SpeedWagonContent contentRoot = await this._speedWagon.WebContentService.GetContent(url);

            IEnumerable <SpeedWagonContent> contents = await this._speedWagon.ContentService.Children(contentRoot);

            contents = contents.OrderBy(x => x.SortOrder);

            IEnumerable <SpeedWagonContent> contentTypes = null;


            if (string.IsNullOrEmpty(url) || url == "/content")
            {
                contentTypes = await this._speedWagon.ContentTypeService.ListRootTypes();
            }
            else
            {
                contentTypes = await this._speedWagon.ContentTypeService.ListAllowedChildren(contentRoot.Type);
            }

            IList <SelectListItem> contentTypeSelct = SelectListHelper.GetSelectList(contentTypes);

            ContentViewModel viewModel = new ContentViewModel();

            viewModel.AvailableContentTypes = contentTypeSelct;
            viewModel.Content        = contentRoot;
            viewModel.Contents       = contents;
            viewModel.ContentService = this._speedWagon.ContentService;

            return(View("~/Views/SpeedWagon/Content/List.cshtml", viewModel));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(EditContentTypeViewModel viewModel)
        {
            SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(viewModel.Name);

            if (!ModelState.IsValid)
            {
                IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List();

                IEnumerable <SpeedWagonContent> contentTypes = await this._speedWagon.ContentTypeService.List();

                viewModel.ContentType = contentType;
                viewModel.Root        = contentType.GetValue <bool>("Root");
                viewModel.Children    = contentType.GetValue <string[]>("Children");
                viewModel.Name        = contentType.Name;
                viewModel.Url         = contentType.RelativeUrl;

                viewModel.AvailableContentTypes = SelectListHelper.GetSelectList(contentTypes);
                viewModel.AvailableEditors      = SelectListHelper.GetSelectList(editors);
                viewModel.Editors = this._speedWagon.ContentTypeService.GetEditors(contentType);

                return(View(viewModel));
            }


            contentType.Content["Root"]     = viewModel.Root;
            contentType.Content["Children"] = viewModel.Children;
            this._speedWagon.ContentTypeService.Save(contentType, User.Identity.Name.MaskEmail());

            return(RedirectToAction("Edit", new { url = contentType.Name, operation = "edited" }));
        }
        public async Task <IActionResult> MoveDown(ContentOperationViewModel model)
        {
            SpeedWagonContent content = await this._speedWagon.ContentService.GetContent(model.Url);

            SpeedWagonContent parent = await this._speedWagon.ContentService.Parent(content);

            IEnumerable <SpeedWagonContent> children = await this._speedWagon.ContentService.Children(parent);

            children = children.OrderBy(x => x.SortOrder);

            SpeedWagonContent[] childArray = children.ToArray();

            for (int index = 0; index < childArray.Length; index++)
            {
                if (childArray[index].Url == content.Url && index < childArray.Length - 1)
                {
                    childArray[index + 1].SortOrder--;
                    childArray[index].SortOrder++;

                    this._speedWagon.WebContentService.Save(childArray[index + 1], User.Identity.Name.MaskEmail());
                    this._speedWagon.WebContentService.Save(childArray[index], User.Identity.Name.MaskEmail());
                }
            }

            return(RedirectToAction("List"));
        }
Beispiel #7
0
        public void Save(SpeedWagonContent contentType, string user)
        {
            contentType.WriterName = user;
            contentType.UpdateDate = DateTime.Now;

            this._cachelessContentService.AddContent(contentType);
        }
        private Document GetLuceneDocument(SpeedWagonContent content)
        {
            var d = new Document();

            d.Add(new Field("Url", content.Url, Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new TextField("Name", content.Name, Field.Store.YES));

            d.Add(new Field("CreateDate", content.CreateDate.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("UpdateDate", content.UpdateDate.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            d.Add(new Field("Type", content.Type, Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("CreatorName", content.CreatorName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("WriterName", content.WriterName, Field.Store.YES, Field.Index.NOT_ANALYZED));

            d.Add(new Field("RelativeUrl", content.RelativeUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("Template", SafeFieldValue(content.Template), Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("SortOrder", content.SortOrder.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            d.Add(new Field("Level", content.Level.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            foreach (var property in content.Content)
            {
                var value = property.Value == null ? string.Empty : property.Value.ToString();
                value = StripHtml(value);
                string key = property.Key.Replace(" ", "");
                d.Add(new TextField(key, value, Field.Store.YES));
            }

            return(d);
        }
        public async virtual Task <SpeedWagonContent> Parent(SpeedWagonContent model)
        {
            string parentUrl = model.Url.Substring(0, model.Url.LastIndexOf("/"));
            IEnumerable <SpeedWagonContent> content = await FromUrls(new[] { parentUrl });

            return(content.FirstOrDefault());
        }
        public async virtual Task <IEnumerable <SpeedWagonContent> > TopNavigation(SpeedWagonContent model)
        {
            var urls = await TopNavigationUrls(model);

            IEnumerable <SpeedWagonContent> content = await FromUrls(urls);

            return(content.Where(x => x != null));
        }
Beispiel #11
0
        public async Task <IEnumerable <SpeedWagonContent> > List()
        {
            SpeedWagonContent contentTypeRoot = await this._cachelessContentService.GetContent(RationalisePath(Root));

            IEnumerable <SpeedWagonContent> content = await this._cachelessContentService.Children(contentTypeRoot);

            return(content.OrderBy(x => x.Name));
        }
Beispiel #12
0
        public void DeleteEditor(SpeedWagonContent contentType, string editor)
        {
            IEnumerable <ContentTypeEditor> editors = GetEditors(contentType).ToList();

            editors = editors.Where(x => x.Name != editor);

            SetEditors(contentType, editors.ToArray());
        }
Beispiel #13
0
        public async Task <IActionResult> DeleteEditor(ContentTypeEditor model)
        {
            SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(model.Name);

            this._speedWagon.ContentTypeService.DeleteEditor(contentType, model.Editor);
            this._speedWagon.ContentTypeService.Save(contentType, User.Identity.Name.MaskEmail());

            return(RedirectToAction("Edit", new { url = model.Name }));
        }
Beispiel #14
0
        void PlaceInCache(string url, SpeedWagonContent content)
        {
            if (content == null)
            {
                return;
            }

            content.CacheTime = DateTime.Now;
            this._customCache.Set <SpeedWagonContent>(url, content);
        }
Beispiel #15
0
        public async Task <IEnumerable <SpeedWagonContent> > ListAllowedChildren(string type)
        {
            IEnumerable <SpeedWagonContent> contentTypes = await List();

            SpeedWagonContent contentType = await Get(type);

            IEnumerable <string> children = contentType.GetValue <string[]>("Children");

            return(contentTypes.Where(x => children.Contains(x.Name)));
        }
        public void Add(string name, string user)
        {
            SpeedWagonContent editor = new SpeedWagonContent(name.ToTitleCasedName(), RationalisePath(name), "editor", user);

            string viewName = name.ToTitleCasedName().Replace("-", "") + ".cshtml";

            editor.Template = "~/Views/SpeedWagon/Editors/" + viewName;

            this._cachelessContentService.AddContent(editor);
        }
Beispiel #17
0
        public static string WebUrl(this SpeedWagonContent content)
        {
            string[] segments = content.RelativeUrl.Split('/');

            if (segments.Length < 3)
            {
                return(content.RelativeUrl);
            }

            return("/" + string.Join("/", segments.Skip(3)));
        }
Beispiel #18
0
 private void SetEditors(SpeedWagonContent contentType, ContentTypeEditor[] editors)
 {
     if (!contentType.Content.ContainsKey("Editors"))
     {
         contentType.Content.Add("Editors", editors);
     }
     else
     {
         contentType.Content["Editors"] = editors;
     }
 }
        public void Add(string parent, string name, string type, string user)
        {
            string urlName = RationalisePath(parent) + "/" + name.ToUrlName();

            SpeedWagonContent content  = new SpeedWagonContent(name.ToTitleCasedName(), urlName, "content", user);
            string            viewName = type.ToTitleCasedName();

            content.Template = viewName;
            content.Type     = type;

            this._cachelessContentService.AddContent(content);
        }
Beispiel #20
0
        public async Task <SpeedWagonContent> ContentFor(HttpRequest request, string path)
        {
            string url = SPEEDWAGON_HOST + "/content/" + request.Host.Host + path;

            SpeedWagonContent content = await this._cachedContentService.GetContent(url);

            if (content == null)
            {
                return(new SpeedWagonContent("404NotFound", request.Path));
            }

            return(content);
        }
Beispiel #21
0
        public ContentTypeEditor[] GetEditors(SpeedWagonContent contentType)
        {
            if (contentType.Content.ContainsKey("Editors"))
            {
                return(((JArray)contentType.Content["Editors"]).ToObject <ContentTypeEditor[]>());
            }
            else
            {
                contentType.Content.Add("Editors", new List <ContentTypeEditor>());
            }

            return(new ContentTypeEditor[] { });
        }
        public async virtual Task <IEnumerable <SpeedWagonContent> > BreadCrumb(SpeedWagonContent model)
        {
            IList <SpeedWagonContent> crumb  = new List <SpeedWagonContent>();
            SpeedWagonContent         parent = model;

            while (parent != null && parent.Level > 0)
            {
                crumb.Add(parent);
                parent = await Parent(parent);
            }

            return(crumb.Reverse());
        }
Beispiel #23
0
        public static string GetValue(this SpeedWagonContent model, string key)
        {
            if (model == null || model.Content == null || !model.Content.ContainsKey(key))
            {
                return(string.Empty);
            }

            if (model.Content[key] == null)
            {
                return(string.Empty);
            }

            return(model.Content[key].ToString());
        }
        private async Task <IEnumerable <SpeedWagonContent> > FromUrls(IEnumerable <string> urls)
        {
            var content = new List <SpeedWagonContent>();

            foreach (var url in urls)
            {
                SpeedWagonContent c = await GetContent(url);

                content.Add(c);

                // var p = Path.Combine(_pathMapper.ContentFolder(path), _pathMapper.GetContentFileName());
                // content.Add(FromFile(p));
            }

            return(content);
        }
        public void Index(SpeedWagonContent model)
        {
            var doc = GetLuceneDocument(model);

            using (Directory directory = FSDirectory.Open(this._directory))
            {
                using (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LuceneVersion.LUCENE_CURRENT, SetupAnalyzer())))
                {
                    writer.DeleteDocuments(new Term("Url", doc.Get("Url")));
                    writer.Commit();

                    writer.AddDocument(doc);
                    writer.Commit();
                }
            }
        }
        public async Task <IActionResult> Edit(EditContentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("List", "SpeedWagonContent", new { url = model.Url }));
            }

            SpeedWagonContent content = await this._speedWagon.GetContent(model.Url);

            this._speedWagon.WebContentService.SetValues(content, model.Values);

            this._speedWagon.WebContentService.Save(content, User.Identity.Name.MaskEmail());
            SpeedWagonContent parent = await this._speedWagon.ContentService.Parent(content);

            return(RedirectToAction("List", "SpeedWagonContent", new { url = parent.RelativeUrl }));
        }
Beispiel #27
0
        public void MoveEditorDown(SpeedWagonContent contentType, string editor)
        {
            ContentTypeEditor[] editors = GetEditors(contentType);

            int index = Array.FindIndex(editors, row => row.Name == editor);

            if (index < editors.Length - 1)
            {
                ContentTypeEditor src = editors[index + 1];
                ContentTypeEditor dst = editors[index];

                editors[index + 1] = dst;
                editors[index]     = src;
            }

            SetEditors(contentType, editors);
        }
Beispiel #28
0
        public void Add(string name, string user, bool root, string[] children)
        {
            SpeedWagonContent contentType = new SpeedWagonContent(name.ToTitleCasedName(), RationalisePath(name), "content-type", user);
            string            viewName    = name.ToTitleCasedName() + ".cshtml";

            contentType.Template = "~/Views/SpeedWagon/ContentType/" + viewName;

            if (children == null)
            {
                children = new string[] { };
            }

            contentType.Content.Add("Root", root);
            contentType.Content.Add("Children", children);

            this._cachelessContentService.AddContent(contentType);
        }
Beispiel #29
0
        public static T GetValue <T>(this SpeedWagonContent model, string key)
        {
            var v = model.GetValue(key);

            if (v == null || !CanChangeType(v, typeof(T)))
            {
                return((T)Activator.CreateInstance(typeof(T)));
            }

            try
            {
                return((T)Convert.ChangeType(v, typeof(T)));
            } catch (Exception ex)
            {
                return(JsonConvert.DeserializeObject <T>(v));
            }
        }
Beispiel #30
0
        public async Task <IActionResult> EditProperty(string name, string property)
        {
            SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(name);

            ContentTypeEditor[]             properties = this._speedWagon.ContentTypeService.GetEditors(contentType);
            IEnumerable <SpeedWagonContent> editors    = await this._speedWagon.EditorService.List();

            ContentTypeEditor prop = properties.FirstOrDefault(x => x.Name == property);

            EditProperty model = new EditProperty();

            model.ContentTypeName  = contentType.Name;
            model.Property         = prop;
            model.AvailableEditors = SelectListHelper.GetSelectList(editors);

            return(View("~/Views/SpeedWagon/ContentType/EditProperty.cshtml", model));
        }