public void CreateWithFlagsTrueAppCollectionTest() { AppCollection appCollection = new AppCollection { Default = true, Dated = true, }; Assert.IsNotNull(appCollection); Assert.AreEqual(true, appCollection.Default); Assert.AreEqual(true, appCollection.Dated); }
public static IEnumerable<AppCollection> ReplaceById(this IEnumerable<AppCollection> collections, AppCollection replaceItem) { if (collections == null) { return null; } List<AppCollection> result = new List<AppCollection>(collections); int index = result.IndexOfId(replaceItem.Id); if (index >= 0) { result[index] = replaceItem; } return result; }
internal static List<AppCollection> MakeAppCollections(int count) { List<AppCollection> result = new List<AppCollection>(); for (int loopIndex = 0; loopIndex < count; loopIndex++) { AppCollection appCollection = new AppCollection() { Default = true, Dated = true, }; result.Add(appCollection); } return result; }
public AppCollection RemoveCollection(AppCollection c) { var cs = Collections.ToList(); cs.Remove(c); Collections = cs; return c; }
public AppCollection AddCollection(AppCollection c) { var cs = Collections.ToList(); cs.Add(c); Collections = cs; return c; }
public ActionResult NewCollection(string workspace, AdminSettingsCollectionModel m) { try { if (string.IsNullOrEmpty(m.Owner)) throw new Exception("Owner is required."); if (!string.IsNullOrEmpty(workspace) && workspace != Atom.DefaultWorkspaceName) { if (!m.Owner.StartsWith(workspace)) throw new Exception("Owner must start with workspace name: workspace.example.com"); } if (string.IsNullOrEmpty(m.Name)) throw new Exception("Name is required."); if (m.Name.ToLowerInvariant() != m.Name.CleanSlug().ToLowerInvariant()) throw new Exception("Name has invalid characters."); string collection = m.Name.ToLowerInvariant(); if (Workspace.Collections.Where(coll => coll.Id.Collection == collection).Count() > 0) throw new Exception("The collection already exists. Please choose a different name."); AppWorkspace w = AppService.GetWorkspace(workspace); bool @default = w.Collections.Count() == 0; AppCollection c = new AppCollection() { Id = new Id(m.Owner, collection), Dated = m.Dated ?? false, Default = @default }; if (string.IsNullOrEmpty(m.Title)) throw new Exception("Title is required."); c.Title = new AtomTitle() { Text = m.Title }; c.Subtitle = string.IsNullOrEmpty(m.Subtitle) ? null : new AtomSubtitle() { Text = m.Subtitle }; c.AnnotationsOn = m.AnnotationsOn ?? false; c.Visible = m.Visible ?? false; c.SyndicationOn = m.SyndicationOn ?? false; c.Href = new Uri(collection + ".atom", UriKind.Relative); w.AddCollection(c); AtomPubService.UpdateService(AppService); ServerApp.Restart(); TempData["new"] = "New Collection"; return RedirectToAction("Settings", new { workspace = workspace, collection = collection }); } catch (Exception ex) { LogService.Error(ex); m.Errors.Add(ex.Message); } return View("AdminSettingsCollection", "Admin", m); }
public static AtomFeed BuildFeed(AppCollection coll, IEnumerable<AtomEntry> entries, int total)//, int pageIndex, int pageSize), Func<string, Id, RouteValueDictionary, Uri> routeUri, //string atomRouteName, string webRouteName, bool addPaging) { AtomFeed feed = new AtomFeed(); feed.Generator = new AtomGenerator { Text = "atomsite.net" }; feed.Title = coll.Title; feed.Subtitle = coll.Subtitle; feed.Id = coll.Id; feed.Logo = coll.Logo; feed.Icon = coll.Icon; feed.Rights = coll.Rights; feed.Updated = DateTimeOffset.UtcNow; feed.TotalResults = total; feed.Entries = entries; //refresh links in case they change //foreach (AtomEntry e in feed.Entries) e.UpdateLinks(routeUri); //use newest updated date as feed updated date if (feed.Entries.Count() > 0) feed.Updated = feed.Entries.Max().Updated; //feed.GenerateLinks(routeUri, atomRouteName, webRouteName, pageIndex, pageSize, addPaging); //TODO: ensure all entries have author //NOTE: the below two statements would break any Views built on a FeedModel //TODO: save bandwidth, add author at feed level if all authors are the same, remove from entries //TODO: save bandwidth, add contrib at feed level if all contrib are the same, remove from entries return feed; }
private AppCollection MakeTestCollection(string collectionTitle) { string owner = MakeOwnerFromWorkspaceName(TestWorkspaceName); var result = new AppCollection { Title = new AtomText { Text = collectionTitle, Type = "text" }, Id = new Id(owner, DateTime.Now, collectionTitle, ""), Theme = "aTheme" }; result.Categories = MakeCollectionCategories(); return result; }
protected virtual bool CollectionFilter(AppCollection coll) { return true; }
void ImportCategories(BlogMLBlog blog, AppCollection coll) { var cats = coll.Categories.FirstOrDefault(); if (cats == null) { cats = new AppCategories(); coll.Categories = Enumerable.Repeat(cats, 1); } foreach (BlogMLCategory cat in blog.Categories) { LogProgress("Processing blog category with ID={0}", cat.ID); if (cats.AddCategory(new AtomCategory() { Term = cat.Title })) LogProgress("Adding blog category with ID={0}", cat.ID); else LogProgress("Blog category with ID={0} already exists", cat.ID); } }
protected override bool CollectionFilter(AppCollection coll) { return new RaterAppCollection(coll).RatingsOn; }
public void FullCreateAppCollectionTest() { AppCollection appCollection = new AppCollection { Title = new AtomTitle { Text = "A title" }, Href = new Uri("http://www.foo.com"), Default = false, Dated = true, Accepts = new List<AppAccept> { new AppAccept("text"), new AppAccept("html")}, Categories = new List<AppCategories>(), Id = new Id("test", DateTime.Now, "test", "test"), Subtitle = new AtomSubtitle { Text = "A subtitle" }, Icon = new Uri("http://www.icon.com"), Logo = new Uri("http://www.logo.com"), Rights = new AtomRights { Text = "All rights reversed" }, Theme = "bTheme", //TODO: Authors = new List<AtomPerson>(), //TODO: Contributors = new List<AtomPerson>() }; Assert.IsNotNull(appCollection); Assert.IsNotNull(appCollection.Title, "No title found"); Assert.AreEqual("A title", appCollection.Title.Text); Assert.IsNotNull(appCollection.Href); Assert.AreEqual(new Uri("http://www.foo.com"), appCollection.Href); // default set false but is now true - is this expected ? Assert.AreEqual(false, appCollection.Default); Assert.AreEqual(true, appCollection.Dated); Assert.IsNotNull(appCollection.Accepts); Assert.AreEqual(2, appCollection.Accepts.Count()); Assert.IsNotNull(appCollection.Categories); Assert.IsNotNull(appCollection.Id); Assert.IsNotNull(appCollection.Subtitle); Assert.AreEqual("A subtitle", appCollection.Subtitle.Text); Assert.IsNotNull(appCollection.Icon); Assert.AreEqual(new Uri("http://www.icon.com"), appCollection.Icon); Assert.IsNotNull(appCollection.Logo); Assert.AreEqual(new Uri("http://www.logo.com"), appCollection.Logo); Assert.IsNotNull(appCollection.Rights); Assert.AreEqual("All rights reversed", appCollection.Rights.Text); Assert.AreEqual("bTheme", appCollection.Theme); Assert.IsNotNull(appCollection.Authors); Assert.AreEqual(0, appCollection.Authors.Count()); Assert.IsNotNull(appCollection.Contributors); Assert.AreEqual(0, appCollection.Contributors.Count()); }
public void SimpleCreateAppCollectionTest() { AppCollection appCollection = new AppCollection(); Assert.IsNotNull(appCollection); }
public void CreateWithCategoriesTest() { AppCollection appCollection = new AppCollection { Categories = TestHelper.MakeAppCategoriesList(5) }; Assert.IsNotNull(appCollection); Assert.IsNotNull(appCollection.Categories); Assert.AreEqual(5, appCollection.Categories.Count()); }
public void CreateWithContributorsTest() { AppCollection appCollection = new AppCollection { //TODO: Contributors = TestHelper.MakePersonList(5, Atom.AtomNs+"contributor") Contributors = Enumerable.Repeat<string>("contributor", 5) }; Assert.IsNotNull(appCollection); Assert.IsNotNull(appCollection.Contributors); // contribs are not present - is this expected? Assert.AreEqual(5, appCollection.Contributors.Count()); }
protected override bool CollectionFilter(AppCollection coll) { return new BlogAppCollection(coll).TrackbacksOn; }
public int GetMetric(AppCollection c, string metricName) { return Metrics.Where(m => m.Scope.Workspace == c.Id.Workspace && m.Scope.Collection == c.Id.Collection) .SelectMany(m => m.Metrics).Where(m => m.Key == metricName).Sum(m => m.Value); }
protected override bool CollectionFilter(AppCollection coll) { return new BlogAppCollection(coll).BloggingOn; }
public virtual AnnotationState GetAnnotationState(AppCollection coll, Id entryId) { LogService.Info("AnnotateService.GetAnnotationState entryId={0}", entryId); if (!coll.AnnotationsOn) { return AnnotationState.Off; } else if (!AuthorizeService.IsAuthorized(GetUser(), entryId.ToScope(), AuthAction.Annotate)) { return AnnotationState.Unauthorized; } else if (!AtomEntryRepository.GetEntry(entryId).AllowAnnotate) { return AnnotationState.Closed; } //TODO: handle expired return AnnotationState.On; }
public static AppCollection MakeTestAppCollection() { // containing a collection string collectionTitle = "Test collection title " + Guid.NewGuid(); AppCollection result = new AppCollection { Title = new AtomText { Text = collectionTitle, Type = "text" }, Icon = new Uri("http://www.icon.com/" + Guid.NewGuid().ToString()), Href = new Uri("http://www.href.com/" + Guid.NewGuid().ToString()), Theme = "aTheme", Dated = true, Default = false, Id = new Id("test", DateTime.Now, RandomChars(12), "") }; return result; }
public RaterAppCollection(AppCollection coll) : base(coll.Xml) { }
public BlogAppCollection(AppCollection coll) : base(coll.Xml) { }