コード例 #1
0
 public Tags(TagPage page)
 {
     this.page = page;
     if (!page.metaData.ContainsKey("tags"))
     {
         page.metaData.Add("tags", "");
     }
     tags = new HashSet <string>(page.metaData["tags"].Split(';').Where(x => !String.IsNullOrEmpty(x)));
 }
コード例 #2
0
 public void MoveToIndex()
 {
     if (index < 0 || index >= pageInfos.Length)
     {
         return;
     }
     current = new one.TagPage(one.App.GetPage(pageInfos[index].ID));
     tags    = new ObservableCollection <string>(current.tags);
     OnPropertyChanged();
 }
コード例 #3
0
 public PageBrowser(one.Section section)
 {
     this.section = section;
     pageInfos    = section.PageInfos.ToArray();
     if (pageInfos.Length != 0)
     {
         current = new one.TagPage(one.App.GetPage(pageInfos[0].ID));
         tags    = new ObservableCollection <string>(current.tags);
     }
     commonTags = new List <string>();
 }
コード例 #4
0
        public void UpdateFilters(string filterText)
        {
            //转换格式
            string[] filterTags = filterText.Split(' ', ';').Where(x => x.Length != 0).ToArray();
            //连接数据库
            var client     = new MongoClient("mongodb://127.0.0.1:27017");
            var database   = client.GetDatabase("xyals");
            var collection = database.GetCollection <BsonDocument>("medium");

            //如果字符串为空,应当不设置任何筛选条件
            if (filterTags.Length != 0)
            {
                //查询标签数组包含所有指定标签的页面时间
                var query = collection
                            .Find(Builders <BsonDocument> .Filter.All <String>("tags", filterTags))
                            .Project(Builders <BsonDocument> .Projection.Include("time").Exclude("_id"));
                var cursor = query.ToCursor();
                var times  = new HashSet <DateTime>(from doc in cursor.ToEnumerable() select DateTime.Parse(doc["time"].ToString()));
                //根据时间确定是否是所需页面
                pageInfos = (from page in section.PageInfos where times.Any(x => x == page.DateTime.ToLocalTime()) select page).ToArray();
            }
            else
            {
                pageInfos = section.PageInfos.ToArray();
            }
            if (pageInfos.Length != 0)
            {
                current = new one.TagPage(one.App.GetPage(pageInfos[0].ID));
                tags    = new ObservableCollection <string>(current.tags);
            }
            else
            {
                current = null;
                tags    = null;
            }
            index = 0;
            OnPropertyChanged();
        }