/// <summary>
        /// Calculate term counts
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Bookmarks.Common.TagCount> CalculateTermCounts(int bufferSize = TAG_COUNTS_PAGE_SIZE)
        {
            var bookmarks = _database.GetCollection <BsonDocument>(BookmarksCollection);
            var aggregate = bookmarks.Aggregate(BuildTagCountsPipelineDefinition(0, bufferSize));

            return(aggregate.ToList().Select(tc => MapperObj.Map <Bookmarks.Common.TagCount>(tc)).ToList());
        }
        public IEnumerable <Bookmarks.Common.Bookmark> BackupBookmarks()
        {
            var bookmarks = _database.GetCollection <Bookmarks.Mongo.Data.Bookmark>(BookmarksCollection);

            return(bookmarks.Find(new BsonDocument()).ToList()
                   .Select(bm => MapperObj.Map <Bookmarks.Common.Bookmark>(bm)));
        }
        public Bookmarks.Common.User GetUserByUsername(string userName)
        {
            var users = _database.GetCollection <Bookmarks.Mongo.Data.User>(USERS_COLLECTION);

            return(MapperObj.Map <Bookmarks.Common.User>
                       (users.Find(u => u.Name == userName /*&& u.PasswordHash == passwordHash*/).FirstOrDefault()));
        }
        public IEnumerable <Bookmarks.Common.BookmarksCollections> GetBookmarksCollections()
        {
            var bookmarksCollections = _database.GetCollection
                                       <Bookmarks.Mongo.Data.BookmarksCollections>(BOOKMARKS_COLLECTIONS);

            return(bookmarksCollections.Find(new BsonDocument()).ToList()
                   .Select(bmc => MapperObj.Map <Bookmarks.Common.BookmarksCollections>(bmc)));
        }
Example #5
0
        public Bookmarks.Common.TagBundle GetTagBundleById(string objId)
        {
            var tagBundles = _database.GetCollection
                             <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);

            var builder = Builders <Bookmarks.Mongo.Data.TagBundle> .Filter;
            var filter  = builder.Eq(t => t.Id, objId);

            var resultTask = tagBundles.Find(filter).FirstAsync();

            var bundle = MapperObj.Map <Bookmarks.Common.TagBundle>(resultTask.Result);

            return(bundle);
        }
        public IEnumerable <Bookmarks.Common.Bookmark> GetBookmarksByTagBundle
            (Bookmarks.Common.TagBundle tagBundle, int?skip, int?take)
        {
            if (tagBundle == null)
            {
                throw new ApplicationException("tagBundle not found");
            }
            //should be in tagBundle.Tags
            //HACK!
            var filterDef = string.Format("{{ 'Tags': {{$elemMatch: {{$in: ['{0}'] }} }} }}"
                                          , string.Join("','", tagBundle.Tags));

            return(FilterBookmarks(filterDef, skip, take).ToList()
                   .Select(bm => MapperObj.Map <Bookmarks.Common.Bookmark>(bm)));
        }
        public void CreateTagBundle(Bookmarks.Common.TagBundle tagBundle)
        {
            if (tagBundle == null)
            {
                throw new ArgumentNullException("tagBundle");
            }

            var tagBundles = _database.GetCollection
                             <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);

            if (tagBundles == null)
            {
                throw new ArgumentNullException("tagBundleS collection");
            }

            tagBundles.InsertOne(MapperObj.Map <Bookmarks.Mongo.Data.TagBundle>(tagBundle));
        }
        /// <summary>
        /// gets tag bundle(s)
        /// </summary>
        /// <param name="name">if this is null or empty then get all</param>
        /// <returns></returns>
        public IEnumerable <Bookmarks.Common.TagBundle> GetTagBundles(string name)
        {
            IEnumerable <Bookmarks.Mongo.Data.TagBundle> result = null;
            var tagBundles = _database.GetCollection <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);

            if (string.IsNullOrEmpty(name))
            {
                result = tagBundles.Find(new BsonDocument()).ToList();
            }
            else
            {
                var builder = Builders <Bookmarks.Mongo.Data.TagBundle> .Filter;
                var filter  = builder.Eq(t => t.Name, name);
                result = tagBundles.Find(filter).ToList();
            }

            return(result.Select(tb => MapperObj.Map <Bookmarks.Common.TagBundle>(tb)));
        }
        public IEnumerable <Bookmarks.Common.TagCount> CalculateRemainingTermCounts(int bufferSize, string[] excludeTagBundles)
        {
            if (excludeTagBundles == null)
            {
                throw new ArgumentNullException("excludeTagBundles");
            }

            var bookmarks = _database.GetCollection <BsonDocument>(BookmarksCollection);
            var aggregate = bookmarks.Aggregate(BuildTagCountsPipelineDefinition(0, bufferSize));

            var tagCounts = aggregate.ToList().Select(tc => MapperObj.Map <Bookmarks.Common.TagCount>(tc)).ToList();

            IEnumerable <string> excludedTags = CompileExcludeTags(excludeTagBundles);

            var filteredTags = tagCounts.Where(tc => !excludedTags.Contains(tc.Tag))
                               .OrderByDescending(tc => tc.Count).ToList();

            return(filteredTags);
        }
        public Bookmarks.Common.TagBundle GetTagBundleById(string objId)
        {
            var tagBundles = _database.GetCollection
                             <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);

            var builder = Builders <Bookmarks.Mongo.Data.TagBundle> .Filter;
            var filter  = builder.Eq(t => t.Id, objId);

            var resultTask = tagBundles.Find(filter).FirstAsync();

            var bundle = MapperObj.Map <Bookmarks.Common.TagBundle>(resultTask.Result);

            var excludedTags = CompileExcludeTags(bundle.ExcludeTagBundles);

            if (excludedTags.Count() > 0)
            {
                bundle.ExcludeTags = bundle.ExcludeTags.Except(excludedTags).ToArray();
            }

            return(bundle);
        }