public EntryCollection GetCategoryEntries(string categoryName) { CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == categoryName) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { foreach (DayEntry day in data.Days) { if (day.Date == detail.DayDate) { day.Load(); foreach (Entry entry in day.Entries) { if (entry.EntryId == detail.EntryId) { entryList.Add(entry); } } } } } } } entryList.Sort(new EntrySorter()); return(entryList); }
protected override EntryCollection LoadEntries() { if (WeblogEntryId.Length == 0) { Response.StatusCode = 404; Response.SuppressContent = true; Response.End(); return(null); //save us all the time } EntryCollection entryCollection = new EntryCollection(); Entry entry = DataService.GetEntry(WeblogEntryId); ILoggingDataService logService = this.LoggingService; if (entry != null) { entryCollection.Add(entry); if (NotModified(entryCollection)) { Response.End(); return(null); } } return(entryCollection); }
private void WebForm1_PreRender(object sender, System.EventArgs e) { Control root = content; string category = Request.QueryString["category"]; if (category != null && category.Length > 0) { category = category.ToUpper(); } else { category = Request.PathInfo.Substring(1).ToUpper(); } CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == category) { title.Controls.Clear(); title.Controls.Add(new LiteralControl(catEntry.Name)); foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { foreach (DayEntry day in data.Days) { if (day.Date == detail.DayDate) { day.Load(); foreach (Entry entry in day.Entries) { if (entry.EntryId == detail.EntryId) { entryList.Add(entry); } } } } } } } entryList.Sort(new EntrySorter()); foreach (Entry entry in entryList) { EntryView view = (EntryView)LoadControl("EntryView.ascx"); view.DateFormat = "MM/dd/yyyy h:mm tt"; view.Data = data; // UNDONE : perf problem! view.Extra = data.GetDayExtra(entry.Created.Date); view.Entry = entry; root.Controls.Add(view); } }
public static IEntryCollection Wrap(this SearchResultCollection wrapped) { var result = new EntryCollection(); if(wrapped != null) { foreach(SearchResult searchResult in wrapped) { result.Add(searchResult.Wrap()); } } return result; }
public void GetAllRoles_AddTwoRolesThatWillBeReturnedFromAdapter_ReturnsRoleSortedAlphabetical() { var roleEntries = new EntryCollection(); var roleEntry1 = A.Fake <IEntry>(); var roleEntry2 = A.Fake <IEntry>(); A.CallTo(() => roleEntry1.Name).Returns("role z"); A.CallTo(() => roleEntry2.Name).Returns("role a"); roleEntries.Add(roleEntry1); roleEntries.Add(roleEntry2); A.CallTo(() => container.GroupEntryAdapter.GetAllRoleEntries()).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A <IEntry> .Ignored)).ReturnsLazily(c => c.GetArgument <IEntry>(0).Name); var result = provider.GetAllRoles(); Assert.AreEqual("role a", result[0]); Assert.AreEqual("role z", result[1]); }
public void VerifyContains() { Entry entry1, entry2; entry1 = BlogDataService.GetEntry("ebd3060-b3b0-4ab1-baea-cd12ae34a575"); EntryCollection entries = new EntryCollection(); entries.Add(entry1); Assert.IsTrue(entries.Contains(entry1), "Unexpectedly the entry did not exist."); entry2 = BlogDataService.GetEntry("ebd3060-b3b0-4ab1-baea-cd12ae34a575"); // The entries returned are identical (ReferenceEquals) Assert.AreSame(entry1, entry2, "Unexpectedly and entirely different entry instance was returned."); Assert.IsTrue(entries.Contains(entry2), "Unexpectedly the entry did not exist."); }
/// <summary> /// Gets the media files /// </summary> public void GetMediaFiles(TextReader reader, string playlistDirectory, EntryCollection entries, uint startIndex, uint requestedCount) { Initialize(); string line; File mediaFile = new File(); File newFile; int idx = 0; while ((line = reader.ReadLine()) != null) { line = line.Trim(); try { newFile = null; if (AnalyzeLine(playlistDirectory, mediaFile, line, () => newFile = new File())) { if (idx >= startIndex && entries.Count < requestedCount) { entries.Add(mediaFile); if (entries.Count == requestedCount) { break; } mediaFile = newFile ?? new File(); } idx += 1; } } catch (Exception) { } } if (idx >= startIndex && entries.Count > 0 && entries.Count < requestedCount && entries[entries.Count - 1] != mediaFile && !String.IsNullOrWhiteSpace(mediaFile.Path) && !String.IsNullOrWhiteSpace(mediaFile.Label)) { entries.Add(mediaFile); } }
public void GetRolesForUser_AddTwoRoles_ReturnRolesSortedAlphabetial() { var roleEntries = new EntryCollection(); var roleEntry1 = A.Fake <IEntry>(); var roleEntry2 = A.Fake <IEntry>(); A.CallTo(() => roleEntry1.Name).Returns("role z"); A.CallTo(() => roleEntry2.Name).Returns("role a"); roleEntries.Add(roleEntry1); roleEntries.Add(roleEntry2); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupsWithEntryAsMemebership(A <IEntry> .Ignored)).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role z", true)).Returns(roleEntry1); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role a", true)).Returns(roleEntry2); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A <IEntry> .Ignored)).ReturnsLazily(c => c.GetArgument <IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(A <IEntry> .Ignored, "rdnattribute")).Returns(new[] { "username" }); var result = provider.GetRolesForUser("username"); Assert.AreEqual("role a", result[0]); Assert.AreEqual("role z", result[1]); }
public static IEntryCollection Wrap(this SearchResultCollection wrapped) { var result = new EntryCollection(); if (wrapped != null) { foreach (SearchResult searchResult in wrapped) { result.Add(searchResult.Wrap()); } } return(result); }
public void CreateCollection_PassCollectionWithOneEntry_ReturnsMembershipUserCollectionWithOneUser() { var config = A.Fake <ILdapConfig>(); var factory = new TestableLdapMembershipUserFactory("providername", config); var entries = new EntryCollection(); var entry = A.Fake <IEntry>(); A.CallTo(() => entry.Name).Returns("uniqueusername"); entries.Add(entry); var result = factory.CreateCollection(entries); Assert.AreEqual(1, result.Count); }
public void GetAllRoles_GetOneRoleEntriyFromAdapter_ReturnsRoleWithSameNameAsInAdapter() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake <IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetAllRoleEntries()).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A <IEntry> .Ignored)).ReturnsLazily(c => c.GetArgument <IEntry>(0).Name); var result = provider.GetAllRoles(); Assert.AreEqual("role", result[0]); }
public void GetUsersInRole_NoRangeRetrievalSupportSoGetUserEntriesFromGroupMembershipAttribute_ReturnUserInRole() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake <IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role", true)).Returns(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A <IEntry> .Ignored)).ReturnsLazily(c => c.GetArgument <IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(roleEntry, "rdnattribute")).Returns(new[] { "username" }); var result = provider.GetUsersInRole("role"); Assert.AreEqual("username", result[0]); }
public void GetRolesForUser_UsersMembershipAttributeIsNotConfigured_RetrunsRolesFromAllRolesComparedToUsersRoles() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake <IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupsWithEntryAsMemebership(A <IEntry> .Ignored)).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role", true)).Returns(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A <IEntry> .Ignored)).ReturnsLazily(c => c.GetArgument <IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(roleEntry, "rdnattribute")).Returns(new[] { "username" }); var result = provider.GetRolesForUser("username"); Assert.AreEqual("role", result[0]); }
private CategoryListViewModel GetCategoryListFromCategoryManager(string category) { var entries = !string.IsNullOrEmpty(category) ? categoryManager.GetEntries(category, httpContextAccessor.HttpContext.Request.Headers["Accept-Language"]) : categoryManager.GetEntries(); var entryList = new EntryCollection(); foreach (var entry in entries?.ToList()?.Where(e => e.IsPublic)) { entryList.Add(entry); } var viewModel = CategoryListViewModel.Create(entryList, category); DefaultPage(CATEGORY); return(viewModel); }
protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount) { var entryList = new EntryCollection(); if (category != null) { int entryCount = dasBlogSettings.SiteConfiguration.RssEntryCount; category = category.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, " "); foreach (var catEntry in dataService.GetCategories()) { if (string.Compare(catEntry.Name, category, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { Entry entry = dataService.GetEntry(detail.EntryId); if (entry != null) { entryList.Add(entry); entryCount--; } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntryDetail } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntry } else { entryList = dataService.GetEntriesForDay(dasBlogSettings.GetContentLookAhead(), dasBlogSettings.GetConfiguredTimeZone(), null, maxDayCount, maxEntryCount, null); } entryList.Sort(new EntrySorter()); return(entryList); }
protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount) { EntryCollection entryList = new EntryCollection(); if (category != null) { int entryCount = dasBlogSettings.SiteConfiguration.RssEntryCount; category = category.ToUpper(); foreach (CategoryCacheEntry catEntry in dataService.GetCategories()) { if (catEntry.Name.ToUpper() == category) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { Entry entry = dataService.GetEntry(detail.EntryId); if (entry != null) { entryList.Add(entry); entryCount--; } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntryDetail } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntry } else { entryList = dataService.GetEntriesForDay(dasBlogSettings.GetContentLookAhead(), dasBlogSettings.GetConfiguredTimeZone(), null, maxDayCount, maxEntryCount, null); } entryList.Sort(new EntrySorter()); return(entryList); }
protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount) { EntryCollection entryList = new EntryCollection(); if (category != null) { int entryCount = _dasBlogSettings.SiteConfiguration.RssEntryCount; category = category.ToUpper(); foreach (CategoryCacheEntry catEntry in _dataService.GetCategories()) { if (catEntry.Name.ToUpper() == category) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { Entry entry = _dataService.GetEntry(detail.EntryId); if (entry != null) { entryList.Add(entry); entryCount--; } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntryDetail } if (entryCount <= 0) { break; } } // foreach (CategoryCacheEntry } else { entryList = _dataService.GetEntriesForDay(DateTime.Now.AddDays(_dasBlogSettings.SiteConfiguration.ContentLookaheadDays).ToUniversalTime(), new newtelligence.DasBlog.Util.UTCTimeZone(), null, maxDayCount, maxEntryCount, null); } entryList.Sort(new EntrySorter()); return(entryList); }
/// <summary> /// Parse a json string containing an array of <seealso cref="EventEntry"/> /// </summary> /// <param name="apiResponse">json string containing an array</param> /// <returns>Collection of EventEntry objects</returns> public EntryCollection <EventEntry> Parse(object apiResponse) { string json = ParserResponseHelper.GetResponseString(apiResponse); EntryCollection <EventEntry> events = new EntryCollection <EventEntry>(); JObject jo = JsonConvert.DeserializeObject(json) as JObject; if (jo != null) { foreach (var property in jo["events"]) { try { events.Add(Parse(property)); } catch (Exception e) { Debug.WriteLine(e); GwApi.Logger.Error(e); } } } return(events); }
private bool Build(DataManager data) { EntryCollection entriesCacheCopy = new EntryCollection(); Dictionary<string, DateTime> entryIdToDateCopy = new Dictionary<string, DateTime>(StringComparer.InvariantCultureIgnoreCase); Dictionary<string, DateTime> compressedTitleToDateCopy = new Dictionary<string, DateTime>(StringComparer.InvariantCultureIgnoreCase); try { foreach (DayEntry day in data.Days) { day.Load(data); foreach (Entry entry in day.Entries) { // create a lite entry for faster searching Entry copy = entry.Clone(); copy.Content = ""; copy.Description = ""; copy.AttachmentsArray = null; copy.CrosspostArray = null; entriesCacheCopy.Add(copy); entryIdToDateCopy.Add(copy.EntryId, copy.CreatedUtc.Date); //SDH: Only the first title is kept, in case of duplicates // TODO: should be able to fix this, but it's a bunch of work. string compressedTitle = copy.CompressedTitle; compressedTitle = compressedTitle.Replace("+", ""); if (compressedTitleToDateCopy.ContainsKey(compressedTitle) == false) { compressedTitleToDateCopy.Add(compressedTitle, copy.CreatedUtc.Date); } } } } //TODO: SDH: Temporary, as sometimes we get collection was modified from the EntryCollection...why does this happen? "Database" corruption? // Misaligned Entries? catch (InvalidOperationException) //something wrong enumerating the entries? { //set flags to start over to prevent getting stuck... booting = true; changeNumber = 0; throw; } //try to be a little more "Atomic" as others have been enumerating this list... entryIDToDate.Clear(); entryIDToDate = entryIdToDateCopy; compressedTitleToDate.Clear(); compressedTitleToDate = compressedTitleToDateCopy; entriesCache = entriesCacheCopy; changeNumber = data.CurrentEntryChangeCount; return true; }
public EntryCollection SearchEntries(string searchString) { StringCollection searchWords = new StringCollection(); string[] splitString = Regex.Split(searchString, @"(""[^""]*"")", RegexOptions.IgnoreCase | RegexOptions.Compiled); for (int index = 0; index < splitString.Length; index++) { if (splitString[index] != "") { if (index == splitString.Length - 1) { foreach (string s in splitString[index].Split(' ')) { if (s != "") searchWords.Add(s); } } else { searchWords.Add(splitString[index].Substring(1, splitString[index].Length - 2)); } } } EntryCollection matchEntries = new EntryCollection(); foreach (Entry entry in requestPage.DataService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), new UTCTimeZone(), Request.Headers["Accept-Language"], int.MaxValue, int.MaxValue, null)) { string entryTitle = entry.Title; string entryDescription = entry.Description; string entryContent = entry.Content; foreach (string searchWord in searchWords) { if (entryTitle != null) { if (searchEntryForWord(entryTitle, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryDescription != null) { if (searchEntryForWord(entryDescription, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryContent != null) { if (searchEntryForWord(entryContent, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } } } // log the search to the event log ILoggingDataService logService = requestPage.LoggingService; string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : Request.ServerVariables["REMOTE_ADDR"]; logService.AddEvent( new EventDataItem(EventCodes.Search, String.Format("{0}", searchString), referrer)); return matchEntries; }
/// <summary> /// Returns an EntryCollection whose entries all fit the criteria /// specified by include. /// </summary> /// <param name="dayEntryCriteria">A delegate that specifies which days should be included.</param> /// <param name="entryCriteria">A delegate that specifies which entries should be included.</param> /// <param name="maxDays">The maximum number of days to include.</param> /// <param name="maxEntries">The maximum number of entries to return.</param> /// <returns></returns> public EntryCollection /*IBlogDataService*/ GetEntries( Predicate<DayEntry> dayEntryCriteria, Predicate<Entry> entryCriteria, int maxDays, int maxEntries) { EntryCollection entries = new EntryCollection(); DayEntryCollection days = this.InternalGetDayEntries(dayEntryCriteria, maxDays); int entryCount = 0; foreach (DayEntry day in days) { day.Load(data); foreach (Entry entry in day.GetEntries(entryCriteria)) { if (entryCount < maxEntries) { entries.Add(entry); entryCount++; } else { break; } } if (entryCount >= maxEntries) { break; } } return entries; }
EntryCollection IBlogDataService.GetEntriesForUser(string user) { Predicate<Entry> entryCriteria = null; EntryCollection entries = new EntryCollection(); entryCriteria += EntryCollectionFilter.DefaultFilters.IsFromUser(user); DayEntryCollection dayEntries = InternalGetDayEntries(null, int.MaxValue); foreach (DayEntry dayEntry in dayEntries) { foreach (Entry entry in dayEntry.GetEntries(entryCriteria)) entries.Add(entry); } return entries; }
// TODO: Consider refactoring to use InternalGetDayEntries that takes delegates. It is slightly more // complicated because this method uses CategoryCache(). EntryCollection IBlogDataService.GetEntriesForCategory(string categoryName, string acceptLanguages) { CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); Entry entry; if (cache.UrlSafeCategories.ContainsKey(categoryName)) { categoryName = cache.UrlSafeCategories[categoryName]; } CategoryCacheEntry catEntry = cache.Entries[categoryName]; if (catEntry != null) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { DayEntry day = data.Days[detail.DayDateUtc]; if (day != null) { Predicate<Entry> entryCriteria = null; if (acceptLanguages != null && acceptLanguages.Length > 0) { entryCriteria += EntryCollectionFilter.DefaultFilters.IsInAcceptedLanguagesOrMultiLingual(acceptLanguages); } day.Load(data); entry = day.GetEntries(entryCriteria)[detail.EntryId]; if (entry != null) { entryList.Add(entry); } } } } entryList.Sort((left, right) => right.CreatedUtc.CompareTo(left.CreatedUtc)); return entryList; }
public void CreateCollection_PassCollectionWithOneEntry_ReturnsMembershipUserCollectionWithOneUser() { var config = A.Fake<ILdapConfig>(); var factory = new TestableLdapMembershipUserFactory("providername", config); var entries = new EntryCollection(); var entry = A.Fake<IEntry>(); A.CallTo(() => entry.Name).Returns("uniqueusername"); entries.Add(entry); var result = factory.CreateCollection(entries); Assert.AreEqual(1, result.Count); }
public void ProcessRequest(HttpContext context) { SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService loggingService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), loggingService); string referrer = context.Request.UrlReferrer != null?context.Request.UrlReferrer.AbsoluteUri:""; if (ReferralBlackList.IsBlockedReferrer(referrer)) { if (siteConfig.EnableReferralUrlBlackList404s) { context.Response.StatusCode = 404; context.Response.End(); return; } } else { loggingService.AddReferral( new LogDataItem( context.Request.RawUrl, referrer, context.Request.UserAgent, context.Request.UserHostName)); } context.Response.ContentType = "application/x-cdf"; //Create the XmlWriter around the Response XmlTextWriter xw = new XmlTextWriter(context.Response.Output); xw.Formatting = Formatting.Indented; EntryCollection entriesAll = dataService.GetEntriesForDay( DateTime.Now.ToUniversalTime(), new Util.UTCTimeZone(), null, siteConfig.RssDayCount, siteConfig.RssMainEntryCount, null); EntryCollection entries = new EntryCollection(); foreach (Entry e in entriesAll) { if (e.IsPublic == true) { entries.Add(e); } } entries.Sort(new EntrySorter()); //Write out the boilerplate CDF xw.WriteStartDocument(); xw.WriteStartElement("CHANNEL"); xw.WriteAttributeString("HREF", SiteUtilities.GetBaseUrl(siteConfig)); foreach (Entry current in entries) { xw.WriteAttributeString("LASTMOD", FormatLastMod(current.ModifiedLocalTime)); } /*IEnumerator enumerator = entries.GetEnumerator(); * if(enumerator.MoveNext()) * { * xw.WriteAttributeString("LASTMOD", * FormatLastMod(((Entry)enumerator.Current).ModifiedLocalTime)); * }*/ xw.WriteAttributeString("LEVEL", "1"); xw.WriteAttributeString("PRECACHE", "YES"); xw.WriteElementString("TITLE", siteConfig.Title); xw.WriteElementString("ABSTRACT", siteConfig.Subtitle); foreach (Entry entry in entries) { xw.WriteStartElement("ITEM"); xw.WriteAttributeString("HREF", SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)entry)); xw.WriteAttributeString("LASTMOD", FormatLastMod(entry.ModifiedLocalTime)); xw.WriteAttributeString("LEVEL", "1"); xw.WriteAttributeString("PRECACHE", "YES"); xw.WriteElementString("TITLE", entry.Title); if (entry.Description != null && entry.Description.Length > 0) { xw.WriteElementString("ABSTRACT", entry.Description); } xw.WriteEndElement(); } xw.WriteEndElement(); //channel xw.WriteEndDocument(); }
public EntryCollection SearchEntries(string searchString) { StringCollection searchWords = new StringCollection(); string[] splitString = Regex.Split(searchString, @"(""[^""]*"")", RegexOptions.IgnoreCase | RegexOptions.Compiled); for (int index = 0; index < splitString.Length; index++) { if (splitString[index] != "") { if (index == splitString.Length - 1) { foreach (string s in splitString[index].Split(' ')) { if (s != "") { searchWords.Add(s); } } } else { searchWords.Add(splitString[index].Substring(1, splitString[index].Length - 2)); } } } EntryCollection matchEntries = new EntryCollection(); foreach (Entry entry in requestPage.DataService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), new UTCTimeZone(), Request.Headers["Accept-Language"], int.MaxValue, int.MaxValue, null)) { string entryTitle = entry.Title; string entryDescription = entry.Description; string entryContent = entry.Content; foreach (string searchWord in searchWords) { if (entryTitle != null) { if (searchEntryForWord(entryTitle, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryDescription != null) { if (searchEntryForWord(entryDescription, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryContent != null) { if (searchEntryForWord(entryContent, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } } } // log the search to the event log ILoggingDataService logService = requestPage.LoggingService; string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : Request.ServerVariables["REMOTE_ADDR"]; logService.AddEvent( new EventDataItem(EventCodes.Search, String.Format("{0}", searchString), referrer)); return(matchEntries); }
/// <summary> /// Adds the underlying model to the entry collection /// </summary> /// <param name="models">collection of items</param> public virtual void AddModel(EntryCollection models) { models.Add(Model); }
public void GetRolesForUser_AddTwoRoles_ReturnRolesSortedAlphabetial() { var roleEntries = new EntryCollection(); var roleEntry1 = A.Fake<IEntry>(); var roleEntry2 = A.Fake<IEntry>(); A.CallTo(() => roleEntry1.Name).Returns("role z"); A.CallTo(() => roleEntry2.Name).Returns("role a"); roleEntries.Add(roleEntry1); roleEntries.Add(roleEntry2); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupsWithEntryAsMemebership(A<IEntry>.Ignored)).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role z", true)).Returns(roleEntry1); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role a", true)).Returns(roleEntry2); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A<IEntry>.Ignored)).ReturnsLazily(c => c.GetArgument<IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(A<IEntry>.Ignored, "rdnattribute")).Returns(new[]{ "username" }); var result = provider.GetRolesForUser("username"); Assert.AreEqual("role a", result[0]); Assert.AreEqual("role z", result[1]); }
public void GetUsersInRole_NoRangeRetrievalSupportSoGetUserEntriesFromGroupMembershipAttribute_ReturnUserInRole() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake<IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role", true)).Returns(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A<IEntry>.Ignored)).ReturnsLazily(c => c.GetArgument<IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(roleEntry, "rdnattribute")).Returns(new[]{ "username" }); var result = provider.GetUsersInRole("role"); Assert.AreEqual("username", result[0]); }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { var entries = new EntryCollection(); entries.AddRange(Children); if (!String.IsNullOrWhiteSpace(Path)) { try { bool isFreeboxV5 = (userAgent == UserAgent.FreeboxV5); foreach (var file in Directory.GetFiles(Path, "*.*", SearchOption.TopDirectoryOnly)) { try { var f = FileFactory.CreateFile(file); if (f is IContainer) { var entry = ((IContainer)f).GetContent(isFreeboxV5); if (entry == null) { continue; } if (!(entry is IMedia)) { entries.Add(entry); continue; } f = (IMedia)entry; } if (f.MediaKind != null && (f.MediaKind & MediaKind) > 0) { entries.Add((Entry)f); } } catch (Exception ex) { Utils.WriteException(ex); } } } catch (Exception ex) { Utils.WriteException(ex); } try { foreach (var directory in Directory.GetDirectories(Path, "*.*", SearchOption.TopDirectoryOnly)) { try { var folder = new Folder() { UsePathAsId = true, Path = directory }; if (!folder.IsHidden) { entries.Add(folder); } } catch (Exception ex) { Utils.WriteException(ex); } } } catch (Exception ex) { Utils.WriteException(ex); } } entries.Sort(new Comparison <Entry>((e1, e2) => { if (e1 is FolderBase && !(e2 is FolderBase)) { return(-1); } if (e2 is FolderBase && !(e1 is FolderBase)) { return(1); } if (e1.Label == null) { return(e2.Label == null ? 0 : -1); } return(e1.Label.CompareTo(e2.Label)); })); var browseResult = new BrowseResult() { TotalCount = entries.Count }; int i = 0; foreach (Entry entry in entries) { if (i == startIndex) { if (browseResult.Entries.Count < requestedCount) { browseResult.Entries.Add(entry); } else { break; } } else { i += 1; } } return(browseResult); }
protected override EntryCollection LoadEntries() { if (WeblogEntryId.Length == 0) { Response.StatusCode = 404; Response.SuppressContent = true; Response.End(); return null; //save us all the time } EntryCollection entryCollection = new EntryCollection(); Entry entry = DataService.GetEntry(WeblogEntryId); ILoggingDataService logService = this.LoggingService; if (entry != null) { entryCollection.Add(entry); if (NotModified(entryCollection)) { Response.End(); return null; } } return entryCollection; }
public void GetAllRoles_GetOneRoleEntriyFromAdapter_ReturnsRoleWithSameNameAsInAdapter() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake<IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetAllRoleEntries()).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A<IEntry>.Ignored)).ReturnsLazily(c => c.GetArgument<IEntry>(0).Name); var result = provider.GetAllRoles(); Assert.AreEqual("role", result[0]); }
private EntryCollection BuildEntries(BlogXData data, string category, int maxDayCount) { EntryCollection entryList = new EntryCollection(); if (category != null) { int entryCount = SiteConfig.GetSiteConfig().RssEntryCount; category = category.ToUpper(); CategoryCache cache = new CategoryCache(); cache.Ensure(data); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == category) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { foreach (DayEntry day in data.Days) { if (day.Date == detail.DayDate) { day.Load(); foreach (Entry entry in day.Entries) { if (entry.EntryId == detail.EntryId) { entryCount--; entryList.Add(entry); if (entryCount < 0) { break; } } } } if (entryCount < 0) { break; } } // foreach (DayEntry day if (entryCount < 0) { break; } } // foreach (CategoryCacheEntryDetail } if (entryCount < 0) { break; } } // foreach (CategoryCacheEntry } else { int dayCount = 0; data.Days.Sort(new DaySorter()); foreach (DayEntry day in data.Days) { day.Load(); dayCount++; foreach (Entry entry in day.Entries) { entryList.Add(entry); } if (dayCount >= maxDayCount) { break; } } } entryList.Sort(new EntrySorter()); return(entryList); }
private void ProcessScoreList(int semesters, List <string> printEntries) { //統計有成績的學期 if (semesters <= 0) { semesters = int.MaxValue; } List <int> semesterlist = new List <int>(); foreach (SemesterSubjectScoreInfo info in _student.SemesterSubjectScoreList) { if (info.Detail.GetAttribute("不需評分") == "是") { continue; } if (!semesterlist.Contains((info.GradeYear - 1) * 2 + info.Semester)) { semesterlist.Add((info.GradeYear - 1) * 2 + info.Semester); } } foreach (SemesterEntryScoreInfo info in _student.SemesterEntryScoreList) { if (!semesterlist.Contains((info.GradeYear - 1) * 2 + info.Semester)) { semesterlist.Add((info.GradeYear - 1) * 2 + info.Semester); } } semesterlist.Sort(); foreach (SemesterSubjectScoreInfo info in _student.SemesterSubjectScoreList) { if (info.Detail.GetAttribute("不需評分") == "是") { continue; } //超過統計學期當沒看到 if (semesterlist.Count > semesters && (info.GradeYear - 1) * 2 + info.Semester > semesterlist[semesters - 1]) { continue; } if (!_subjects.ContainsKey(info.Subject)) { SubjectInfo new_info = new SubjectInfo(info.Subject); _subjects.Add(info.Subject, new_info); new_info.AddSemsScore(info.GradeYear, info.Semester, SelectScore(info)); } else { _subjects[info.Subject].AddSemsScore(info.GradeYear, info.Semester, SelectScore(info)); } } foreach (SemesterEntryScoreInfo info in _student.SemesterEntryScoreList) { //超過統計學期當沒看到 if (semesterlist.Count > semesters && (info.GradeYear - 1) * 2 + info.Semester > semesterlist[semesters - 1]) { continue; } //不是要列印的分項當沒看到 if (!printEntries.Contains(info.Entry)) { continue; } if (!_entries.ContainsKey(info.Entry)) { EntryInfo new_info = new EntryInfo(info.Entry); _entries.Add(info.Entry, new_info); new_info.AddSemsScore(info.GradeYear, info.Semester, info.Score); } else { _entries[info.Entry].AddSemsScore(info.GradeYear, info.Semester, info.Score); } } }
public void GetAllRoles_AddTwoRolesThatWillBeReturnedFromAdapter_ReturnsRoleSortedAlphabetical() { var roleEntries = new EntryCollection(); var roleEntry1 = A.Fake<IEntry>(); var roleEntry2 = A.Fake<IEntry>(); A.CallTo(() => roleEntry1.Name).Returns("role z"); A.CallTo(() => roleEntry2.Name).Returns("role a"); roleEntries.Add(roleEntry1); roleEntries.Add(roleEntry2); A.CallTo(() => container.GroupEntryAdapter.GetAllRoleEntries()).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A<IEntry>.Ignored)).ReturnsLazily(c => c.GetArgument<IEntry>(0).Name); var result = provider.GetAllRoles(); Assert.AreEqual("role a", result[0]); Assert.AreEqual("role z", result[1]); }
public EntryCollection SearchEntries(string searchString, string acceptLanguageHeader) { var searchWords = GetSearchWords(searchString); var entries = dataService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), dasBlogSettings.GetConfiguredTimeZone(), acceptLanguageHeader, int.MaxValue, int.MaxValue, null); // no search term provided, return all the results if (searchWords.Count == 0) { return(entries); } EntryCollection matchEntries = new EntryCollection(); foreach (Entry entry in entries) { string entryTitle = entry.Title; string entryDescription = entry.Description; string entryContent = entry.Content; foreach (string searchWord in searchWords) { if (entryTitle != null) { if (searchEntryForWord(entryTitle, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryDescription != null) { if (searchEntryForWord(entryDescription, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } if (entryContent != null) { if (searchEntryForWord(entryContent, searchWord)) { if (!matchEntries.Contains(entry)) { matchEntries.Add(entry); } continue; } } } } // log the search to the event log /* * ILoggingDataService logService = requestPage.LoggingService; * string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : Request.ServerVariables["REMOTE_ADDR"]; * logger.LogInformation( * new EventDataItem(EventCodes.Search, String.Format("{0}", searchString), referrer)); */ return(matchEntries); }
public void GetRolesForUser_UsersMembershipAttributeIsNotConfigured_RetrunsRolesFromAllRolesComparedToUsersRoles() { var roleEntries = new EntryCollection(); var roleEntry = A.Fake<IEntry>(); A.CallTo(() => roleEntry.Name).Returns("role"); roleEntries.Add(roleEntry); A.CallTo(() => providerConfig.LdapConfig.Groups.MembershipAttribute).Returns("rdnattribute"); A.CallTo(() => container.GroupEntryAdapter.GetGroupsWithEntryAsMemebership(A<IEntry>.Ignored)).Returns(roleEntries); A.CallTo(() => container.GroupEntryAdapter.GetGroupEntry("role", true)).Returns(roleEntry); A.CallTo(() => container.GroupEntryAdapter.GetGroupName(A<IEntry>.Ignored)).ReturnsLazily(c => c.GetArgument<IEntry>(0).Name); A.CallTo(() => container.UserEntryAdapter.GetUsersFromEntry(roleEntry, "rdnattribute")).Returns(new[]{ "username" }); var result = provider.GetRolesForUser("username"); Assert.AreEqual("role", result[0]); }