private void ReadSkinStructure() { Node[] nodes; if (RepositoryInstance.ContentQueryIsAllowed) { var query = new NodeQuery(); query.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, RepositoryStructure.SkinRootFolderPath)); query.Add(new TypeExpression(NodeType.GetByName("Skin"))); nodes = query.Execute().Nodes.ToArray(); } else { nodes = NodeQuery.QueryNodesByTypeAndPath(NodeType.GetByName("Skin"), false, RepositoryStructure.SkinRootFolderPath, false).Nodes.ToArray(); } try { _skinMapLock.TryEnterWriteLock(RepositoryEnvironment.DefaultLockTimeout); foreach (Node n in nodes) { _skinMap.Add(n.Name, MapSkin(n)); } } finally { if (_skinMapLock.IsWriteLockHeld) { _skinMapLock.ExitWriteLock(); } } }
public int[] GetNotIndexedNodeTypes() { return(new AllContentTypes() .Where(c => !c.IndexingEnabled) .Select(c => NodeType.GetByName(c.Name).Id) .ToArray()); }
private void ReadSkinStructure() { //CONDITIONAL EXECUTE Node[] nodes; if (StorageContext.Search.IsOuterEngineEnabled && StorageContext.Search.SearchEngine != InternalSearchEngine.Instance) { var query = new NodeQuery(); query.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, Repository.SkinRootFolderPath)); query.Add(new TypeExpression(NodeType.GetByName("Skin"))); nodes = query.Execute().Nodes.ToArray(); } else { nodes = NodeQuery.QueryNodesByTypeAndPath(NodeType.GetByName("Skin"), false, Repository.SkinRootFolderPath, false).Nodes.ToArray(); } try { _skinMapLock.TryEnterWriteLock(LockHandler.DefaultLockTimeOut); foreach (Node n in nodes) { _skinMap.Add(n.Name, MapSkin(n)); } } finally { if (_skinMapLock.IsWriteLockHeld) { _skinMapLock.ExitWriteLock(); } } }
private ActionResult SearchNodeQuery(string searchStr, string searchRoot, string contentTypes) { if (!string.IsNullOrEmpty(searchStr)) { // simple nodequery var query = new NodeQuery(); query.Add(new SearchExpression(searchStr)); var nodes = query.Execute().Nodes; // filter with path if (!string.IsNullOrEmpty(searchRoot)) { nodes = nodes.Where(n => n.Path.StartsWith(searchRoot)); } // filter with contenttypes if (!string.IsNullOrEmpty(contentTypes)) { var contentTypesArr = GetContentTypes(contentTypes); nodes = nodes.Where(n => contentTypesArr.Contains(n.NodeType.Name)); } var contents = nodes.Where(n => n != null).Select(n => new Content(n, true, false, false, false, 0, 0)); return(Json(contents.ToArray(), JsonRequestBehavior.AllowGet)); } else { if (string.IsNullOrEmpty(searchRoot) && string.IsNullOrEmpty(contentTypes)) { return(Json(null, JsonRequestBehavior.AllowGet)); } var query = new NodeQuery(); var andExpression = new ExpressionList(ChainOperator.And); query.Add(andExpression); // filter with path if (!string.IsNullOrEmpty(searchRoot)) { andExpression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, searchRoot)); } // filter with contenttypes if (!string.IsNullOrEmpty(contentTypes)) { var contentTypesArr = GetContentTypes(contentTypes); var orExpression = new ExpressionList(ChainOperator.Or); foreach (var contentType in contentTypesArr) { orExpression.Add(new TypeExpression(NodeType.GetByName(contentType), true)); } andExpression.Add(orExpression); } var nodes = query.Execute().Nodes; var contents = nodes.Select(n => new Content(n, true, false, false, false, 0, 0)); return(Json(contents.ToArray(), JsonRequestBehavior.AllowGet)); } }
private PropertyType GetPropertyTypeFromFullName(string fullName, out string fieldName) { //fullName: "GenericContent.DisplayName", "ContentList.#ListField1", "Rating" var names = fullName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); var typeName = names.Length == 2 ? names[0] : string.Empty; fieldName = names.Length == 1 ? names[0] : names[1]; if (fieldName.StartsWith("#")) { //try to get the ContentList field property type name ("#String_0") if (this.Content != null) { var cl = this.Content.ContentHandler as ContentList; if (cl != null) { return(PropertyType.GetByName(cl.GetPropertySingleId(fieldName))); } } } //without type, return from the active schema if (string.IsNullOrEmpty(typeName)) { return(PropertyType.GetByName(fieldName)); } //return by the given content type var fn = fieldName; return((from pt in NodeType.GetByName(typeName).PropertyTypes where pt.Name.CompareTo(fn) == 0 select pt).FirstOrDefault()); }
private void SetQuestions() { ChoiceFieldSettings = new List <ChoiceFieldSetting>(); var currentSurvey = ContentRepository.Content.Create(PortalContext.Current.ContextNode); var customFields = currentSurvey.Fields["FieldSettingContents"] as ReferenceField; if (customFields == null) { Controls.Add(new Literal { Text = SenseNetResourceManager.Current.GetString("Survey", "ReferenceFieldError") }); return; } var questions = customFields.OriginalValue as List <Node>; if (questions == null) { Controls.Add(new Literal { Text = SenseNetResourceManager.Current.GetString("Survey", "OriginalValueError") }); return; } var cfs = NodeType.GetByName("ChoiceFieldSetting"); var choiceTypeIds = cfs.GetAllTypes().ToIdArray(); var pbfs = NodeType.GetByName("PageBreakFieldSetting"); DdlSurveyQuestions.Items.Add(new ListItem("Choose a question!", "-100")); for (var i = questions.Count - 1; i >= 0; i--) { var questionTypeId = questions[i].NodeType.Id; if (choiceTypeIds.Contains(questionTypeId)) { if (!(questions[i] is FieldSettingContent q)) { continue; } DdlSurveyQuestions.Items.Add( q.FieldSetting.DisplayName.Length > 15 ? new ListItem(q.FieldSetting.DisplayName.Substring(0, 15) + "...", q.Name) : new ListItem(q.FieldSetting.DisplayName, q.Name)); if (q.FieldSetting is ChoiceFieldSetting chfs) { ChoiceFieldSettings.Add(chfs); } } if (questions[i].NodeType == pbfs) { continue; } } }
public static SecurityConsistencyResult CheckSecurityConsistency(Content content) { var groups = NodeQuery.QueryNodesByType(NodeType.GetByName("Group"), false).Identifiers; var ous = NodeQuery.QueryNodesByType(NodeType.GetByName("OrganizationalUnit"), false).Identifiers; var allGroups = groups.Union(ous).ToArray(); var allIds = NodeQuery.QueryNodesByPath("/", false).Identifiers; return(CheckSecurityConsistency(allIds, allGroups)); }
public static IEnumerable <Node> GetPortletsFromRepo() { var query = new NodeQuery(); var expression = new ExpressionList(ChainOperator.And); expression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, PortletsFolderPath)); expression.Add(new TypeExpression(NodeType.GetByName("Portlet"))); query.Add(expression); return(query.Execute().Nodes); }
private bool MustCache(int nodeTypeId) { var nodeType = Providers.Instance.StorageSchema.NodeTypes.GetItemById(nodeTypeId); if (CacheConfiguration.CacheContentAfterSaveMode != CacheConfiguration.CacheContentAfterSaveOption.Containers) { return(CacheConfiguration.CacheContentAfterSaveMode == CacheConfiguration.CacheContentAfterSaveOption.All); } return(nodeType.IsInstaceOfOrDerivedFrom(NodeType.GetByName("Folder"))); }
private static void WriteBlobs(StreamWriter writer) { var template = @" #region {0}.{1} {{ ""Binary:{2}"", @""{3} ""}}, #endregion"; var files = NodeQuery.QueryNodesByType(NodeType.GetByName("File"), false).Nodes; var count = 0; foreach (var file in files) { writer.WriteLine(template, ++count, file.Name, file.Path, GetFileContent((File)file)); } }
public void Cache_Builtin_TypeDependency() { Test((builder) => { builder.UseCacheProvider(new SnMemoryCache()); }, () => { var cache = DistributedApplication.Cache; var root = CreateTestFolder(Repository.Root); // create node1 and cache it with it own NodeIdDependency var folder1 = CreateTestFolder(root, true); var file11 = CreateTestFile(folder1); var folder11 = CreateTestFolder(folder1); var file111 = CreateTestFile(folder11); cache.Reset(); var rootKey = InsertCacheWithTypeDependency(cache, root); var folder1Key = InsertCacheWithTypeDependency(cache, folder1); var file11Key = InsertCacheWithTypeDependency(cache, file11); var folder11Key = InsertCacheWithTypeDependency(cache, folder11); var file111Key = InsertCacheWithTypeDependency(cache, file111); // pre-check: all nodes are in the cache Assert.IsTrue(IsInCache(rootKey)); Assert.IsTrue(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsTrue(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); // TEST: Remove the folder type tree var before = WhatIsInTheCache(cache); foreach (var nodeType in NodeType.GetByName("Folder").GetAllTypes()) { NodeTypeDependency.FireChanged(nodeType.Id); } var after = WhatIsInTheCache(cache); // check: all folders are removed Assert.IsFalse(IsInCache(rootKey)); Assert.IsFalse(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsFalse(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); }); }
public void Cache_Builtin_TypeDependency() { Test2((services) => { services.AddSingleton <ISnCache, SnMemoryCache>(); }, () => { var root = CreateTestFolder(Repository.Root); // create node1 and cache it with it own NodeIdDependency var folder1 = CreateTestFolder(root, true); var file11 = CreateTestFile(folder1); var folder11 = CreateTestFolder(folder1); var file111 = CreateTestFile(folder11); Cache.Reset(); var rootKey = InsertCacheWithTypeDependency(root); var folder1Key = InsertCacheWithTypeDependency(folder1); var file11Key = InsertCacheWithTypeDependency(file11); var folder11Key = InsertCacheWithTypeDependency(folder11); var file111Key = InsertCacheWithTypeDependency(file111); // pre-check: all nodes are in the cache Assert.IsTrue(IsInCache(rootKey)); Assert.IsTrue(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsTrue(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); // TEST: Remove the folder type tree var before = WhatIsInTheCache(); foreach (var nodeType in NodeType.GetByName("Folder").GetAllTypes()) { NodeTypeDependency.FireChanged(nodeType.Id); } var after = WhatIsInTheCache(); // check: all folders are removed Assert.IsFalse(IsInCache(rootKey)); Assert.IsFalse(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsFalse(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); }); }
private void ReadSkinStructure() { Node[] nodes; nodes = NodeQuery.QueryNodesByTypeAndPath(NodeType.GetByName("Skin"), false, RepositoryStructure.SkinRootFolderPath, false).Nodes.ToArray(); try { _skinMapLock.TryEnterWriteLock(RepositoryEnvironment.DefaultLockTimeout); foreach (Node n in nodes) { _skinMap.Add(n.Name, MapSkin(n)); } } finally { if (_skinMapLock.IsWriteLockHeld) { _skinMapLock.ExitWriteLock(); } } }
// ================================================================================ Inbox feature protected void AssertEmail() { var email = (string)this["ListEmail"]; if (string.IsNullOrEmpty(email)) { return; } int count; using (new SystemAccount()) { if (SearchManager.ContentQueryIsAllowed) { count = Content.All.OfType <ContentList>().Count(cl => (string)cl["ListEmail"] == email && cl.Id != this.Id); } else { count = NodeQuery.QueryNodesByTypeAndPathAndProperty(NodeType.GetByName("ContentList"), false, "/Root", false, new List <QueryPropertyData> { new QueryPropertyData { PropertyName = "ListEmail", QueryOperator = Operator.Equal, Value = email }, new QueryPropertyData { PropertyName = "Id", QueryOperator = Operator.NotEqual, Value = this.Id } }).Count; } } if (count > 0) { throw new InvalidContentException(SR.GetString(SR.Exceptions.ContentList.Error_EmailIsTaken)); } }
// gets the portal NodeType corresponding to the AD object type public static NodeType GetNodeType(ADObjectType adObjectType) { switch (adObjectType) { case ADObjectType.User: return(NodeType.GetByName(typeof(User).Name)); case ADObjectType.Group: return(NodeType.GetByName(typeof(Group).Name)); case ADObjectType.OrgUnit: case ADObjectType.Organization: return(NodeType.GetByName(typeof(OrganizationalUnit).Name)); case ADObjectType.Domain: return(NodeType.GetByName(typeof(Domain).Name)); case ADObjectType.Container: return(NodeType.GetByName("ADFolder")); default: return(null); } }
protected override void CreateChildControls() { if (this.ContextNode == null) { return; } if (ShowExecutionTime) { Timer.Start(); } // gather posts for this content List <PostInfo> posts; posts = DataLayer.GetPostsForContent(this.ContextNode).ToList(); string postsMarkup; postsMarkup = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts); CommentInfo contentCommentInfo; LikeInfo contentLikeInfo; var settings = new QuerySettings() { EnableAutofilters = FilterStatus.Disabled }; var allCommentsAndLikes = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings, this.ContextNode.Path, new[] { "Comment", "Like" }).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; var commentsForPost = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); var likesForPostAndComments = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == this.ContextNode.Path).ToList(); var commentMarkupStr = WallHelper.GetCommentMarkupStr(); // get comments for this content contentCommentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); // get likes for this content contentLikeInfo = new LikeInfo(likesForPost, this.ContextNode.Id); var markupStr = WallHelper.GetContentWallMarkup( this.ContextNode, contentCommentInfo.HiddenCommentsMarkup, contentCommentInfo.CommentsMarkup, contentCommentInfo.CommentCount, contentLikeInfo, postsMarkup); this.Controls.Add(new Literal { Text = markupStr }); if (ShowExecutionTime) { Timer.Stop(); } base.CreateChildControls(); this.ChildControlsCreated = true; }
protected override void CreateChildControls() { if (this.ContextNode == null) { return; } if (ShowExecutionTime) { Timer.Start(); } // gather posts for this content List <PostInfo> posts; using (new OperationTrace("Wall - Gather posts")) { posts = DataLayer.GetPostsForContent(this.ContextNode).ToList(); } string postsMarkup; using (new OperationTrace("Wall - Posts markup")) { postsMarkup = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts); } CommentInfo contentCommentInfo; LikeInfo contentLikeInfo; using (new OperationTrace("Wall - Gather content comments")) { var commentsAndLikesQuery = "+TypeIs:(Comment Like) +InTree:\"" + this.ContextNode.Path + "\""; var settings = new QuerySettings() { EnableAutofilters = false }; var allCommentsAndLikes = ContentQuery.Query(commentsAndLikesQuery, settings).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; var commentsForPost = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); var likesForPostAndComments = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == this.ContextNode.Path).ToList(); var commentMarkupStr = WallHelper.GetCommentMarkupStr(); // get comments for this content contentCommentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); // get likes for this content contentLikeInfo = new LikeInfo(likesForPost, this.ContextNode.Id); } using (new OperationTrace("Wall - Content comments markup")) { var markupStr = WallHelper.GetContentWallMarkup( this.ContextNode, contentCommentInfo.HiddenCommentsMarkup, contentCommentInfo.CommentsMarkup, contentCommentInfo.CommentCount, contentLikeInfo, postsMarkup); this.Controls.Add(new Literal { Text = markupStr }); } if (ShowExecutionTime) { Timer.Stop(); } base.CreateChildControls(); this.ChildControlsCreated = true; }
public static IEnumerable <Node> GetPortletsFromRepo() { var cql = $"+TypeIs:{NodeType.GetByName("Portlet").Name} +InTree:{PortletsFolderPath}"; return(ContentQuery.Query(cql, QuerySettings.AdminSettings).Nodes); }
public static string GetWallPostsMarkup(string contextPath, List <PostInfo> posts) { if (posts.Count == 0) { return(string.Empty); } // create query for comments and likes var csb = new StringBuilder(); var paths = new List <string>(); foreach (var postInfo in posts) { if (postInfo.IsJournal) { continue; } paths.Add(postInfo.Path); } List <Node> allComments; List <Node> allLikes; if (paths.Count == 0) // only non-persisted journal posts are there to show (no comments or likes) { allComments = new List <Node>(); allLikes = new List <Node>(); } else { var settings = new QuerySettings() { EnableAutofilters = FilterStatus.Disabled }; var allCommentsAndLikes = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings, paths, new[] { "Comment", "Like" }).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; allComments = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); allLikes = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); } var bigPostMarkupStr = GetBigPostMarkupStr(); var smallPostMarkupStr = GetSmallPostMarkupStr(); var commentMarkupStr = GetCommentMarkupStr(); var commentSectionStr = GetCommentSectionMarkupStr(); PostInfo prevPost = null; var sb = new StringBuilder(); foreach (var postInfo in posts) { // get comments and likes for post CommentInfo commentInfo; LikeInfo likeInfo; if (postInfo.IsJournal) { commentInfo = new CommentInfo(); likeInfo = new LikeInfo(); } else { var commentsForPost = allComments.Where(c => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(c.Path)) == postInfo.Path).ToList(); var likesForPostAndComments = allLikes.Where(l => l.Path.StartsWith(postInfo.Path)).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == postInfo.Path).ToList(); commentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); likeInfo = new LikeInfo(likesForPost, postInfo.Id); } var drawBoundary = (prevPost != null) && (prevPost.Type != PostType.BigPost) && (postInfo.Type == PostType.BigPost); var markup = WallHelper.GetPostMarkup( postInfo.Type == PostType.BigPost ? bigPostMarkupStr : smallPostMarkupStr, commentSectionStr, postInfo, contextPath, commentInfo.HiddenCommentsMarkup, commentInfo.CommentsMarkup, commentInfo.CommentCount, likeInfo, drawBoundary); prevPost = postInfo; sb.Append(markup); } return(sb.ToString()); }