Esempio n. 1
0
        public static List <Packet> LoadPackets()
        {
            List <Packet> list     = new List <Packet>();
            MetaData      metaData = MetaDataLoader.Load();

            Grouper.GroupingSuperKeyword(metaData);
            foreach (SuperKeyword sk in metaData.superKeywords)
            {
                Packet packet = new Packet();
                if (sk.simple)
                {
                    packet.title = sk.keyword;
                }
                else if (sk.keyword == "*")
                {
                    packet.title = string.Format("【{0}】的作品集", sk.authors[0]);
                }
                else if (sk.authors[0] == "*")
                {
                    packet.title = string.Format("专题:【{0}】", sk.keyword);
                }
                else
                {
                    packet.title = string.Format("【{0}】系列", sk.keyword);
                }
                packet.author   = sk.authors[0];
                packet.simple   = sk.simple;
                packet.chapters = new List <Chapter>();
                foreach (Group g in sk.groupedTids)
                {
                    BBSThread example  = metaData.threads[g.exampleId];
                    string    filename = example.siteId + "/" + example.threadId;
                    Chapter   ch       = new Chapter();
                    ch.id        = filename;
                    ch.title     = example.title;
                    ch.author    = example.author;
                    ch.source    = Constants.SITE_DEF[example.siteId].siteName;
                    ch.savePath  = filename;
                    ch.timestamp = Utils.GetTimestamp(example.postTime);
                    packet.chapters.Add(ch);
                }
                packet.chapters.Sort((x1, x2) => x2.timestamp.CompareTo(x1.timestamp));
                packet.timestamp = packet.chapters[0].timestamp;
                packet.key       = Utils.CalcKey(packet.title, packet.author, sk.simple);
                packet.summary   = Utils.CalcSumary(packet.title, packet.author, sk.simple, packet.chapters, null);
                packet.source    = "Forum";
                list.Add(packet);
            }
            list.Sort((x1, x2) => x2.timestamp.CompareTo(x1.timestamp));
            string packetFolder = Constants.LOCAL_PATH + "packets";

            foreach (string f in Directory.EnumerateFiles(packetFolder))
            {
                Packet packet = LoadPacketFromZip(f);
                list.Add(packet);
            }
            return(list);
        }
Esempio n. 2
0
        private void ReloadArticles()
        {
            dynamic      item = topics[currentId];
            List <Group> list;
            int          read;

            if (item.Favorite)
            {
                SuperKeyword sk = metaData.superKeywords[item.FavoriteId];
                list = sk.groupedTids;
                read = sk.read;
            }
            else
            {
                string title = item.Title;
                list = metaData.tags[title].ConvertAll(x => new Group {
                    exampleId = x, tooltips = "Not Download."
                });
                read = list.Count;
            }

            articles.Clear();
            list.ForEach(x =>
            {
                int i       = list.Count - list.IndexOf(x) - 1;
                BBSThread t = metaData.threads[x.exampleId];
                if (searchingKeyword == null || t.title.Contains(searchingKeyword))
                {
                    string siteName = Constants.SITE_DEF[t.siteId].siteName;
                    string fPath    = Constants.LOCAL_PATH + t.siteId + "/" + t.threadId + ".txt";
                    bool downloaded = File.Exists(fPath);
                    articles.Add(new
                    {
                        Title      = t.title,
                        Author     = t.author,
                        Time       = t.postTime,
                        Url        = t.link,
                        ThreadId   = t.threadId,
                        Source     = siteName,
                        SiteId     = t.siteId,
                        Favorite   = false,
                        Simple     = true,
                        FavoriteId = -1,
                        IsFolder   = false,
                        Downloaded = downloaded,
                        Read       = i <= read,
                        Tooltip    = x.tooltips
                    });
                }
            });
        }
Esempio n. 3
0
 public static List<BBSThread> ParseThread(String text)
 {
     String[] Row = text.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.None);
     List<BBSThread> threadList = new List<BBSThread>();
     int counter = 0;
     foreach (String line in Row)
     {
         if (line == "") break;
         BBSThread thread = new BBSThread();
         String[] LineSplit = line.Split(new string[] { "<>"}, StringSplitOptions.None);
         thread.DAT = LineSplit[0];
         thread.UnixTime = long.Parse(Regex.Replace(LineSplit[0],@"(\.dat|\.cgi)",""));
         thread.createdAt = _2ch.Tools.UnixTime.FromUnixTime(thread.UnixTime);
         MatchCollection mc = Regex.Matches(LineSplit[1],@"(.*.)\((\d+)\)");
         thread.ResCount = int.Parse(mc[0].Groups[2].Value);
         thread.Title = System.Web.HttpUtility.HtmlDecode(mc[0].Groups[1].Value);
         thread.Number = counter;
         counter++;
         threadList.Add(thread);
     }
     return threadList;
 }
Esempio n. 4
0
        private void ReloadTopics()
        {
            List <string> tags          = new List <string>(metaData.tags.Keys);
            var           superkeywords = new List <SuperKeyword>(metaData.superKeywords);

            if (searchingKeyword != null)
            {
                tags.RemoveAll(x =>
                {
                    if (x.Contains(searchingKeyword))
                    {
                        return(false);
                    }
                    BBSThread exampleX = metaData.threads[metaData.tags[x][0]];
                    return(!exampleX.author.Contains(searchingKeyword));
                });
                superkeywords.RemoveAll(x =>
                {
                    if (x.keyword.Contains(searchingKeyword))
                    {
                        return(false);
                    }
                    foreach (string author in x.authors)
                    {
                        if (author.Contains(searchingKeyword))
                        {
                            return(false);
                        }
                    }
                    return(true);
                });
            }

            List <ListItem> items = new List <ListItem>();

            tags.ForEach(x =>
            {
                var item = new ListItem
                {
                    Title = x
                };

                BBSThread example = metaData.threads[metaData.tags[x][0]];
                item.Author       = example.author;
                item.Time         = example.postTime;
                item.Url          = example.link;
                item.Source       = "";
                item.SiteId       = example.siteId;
                item.ThreadId     = example.threadId;
                item.Favorite     = false;
                item.Simple       = true;
                item.FavoriteId   = -1;
                item.IsFolder     = true;
                item.Downloaded   = false;
                item.Read         = true;

                items.Add(item);
            });

            superkeywords.ForEach(x =>
            {
                string author  = x.authors[0];
                string keyword = x.keyword;

                var item = new ListItem();

                if (x.simple)
                {
                    item.Title = x.keyword;
                }
                else if (keyword == "*")
                {
                    item.Title = ("【" + author + "】的作品集");
                }
                else if (author == "*")
                {
                    item.Title = ("专题:【" + keyword + "】");
                }
                else
                {
                    item.Title = ("【" + keyword + "】系列");
                }
                item.Author = author;

                BBSThread example = x.groupedTids.Count > 0 ?  metaData.threads[x.groupedTids[0].exampleId] : new BBSThread {
                    postTime = "1970-01-01", threadId = "0"
                };
                item.Time       = example.postTime;
                item.Url        = example.link;
                item.Source     = "";
                item.SiteId     = example.siteId;
                item.ThreadId   = example.threadId;
                item.Favorite   = true;
                item.Simple     = x.simple;
                item.FavoriteId = metaData.superKeywords.IndexOf(x);
                item.IsFolder   = true;
                item.Downloaded = false;
                item.Read       = x.groupedTids.Count <= x.read + 1;
                item.Tooltip    = null;

                items.Add(item);
            });

            items.Sort((x, y) =>
            {
                if (x.Favorite && !y.Favorite)
                {
                    return(-1);
                }
                else if (!x.Favorite && y.Favorite)
                {
                    return(1);
                }
                DateTime xdate = DateTime.ParseExact(x.Time, "yyyy-M-d", CultureInfo.InvariantCulture);
                DateTime ydate = DateTime.ParseExact(y.Time, "yyyy-M-d", CultureInfo.InvariantCulture);
                int dc         = DateTime.Compare(ydate, xdate);
                if (dc != 0)
                {
                    return(dc);
                }
                else
                {
                    return(int.Parse(y.ThreadId) - int.Parse(x.ThreadId));
                }
            });

            topics.Clear();
            items.ForEach(x =>
            {
                topics.Add(new { x.Title, x.Author, x.Time, x.Url, x.ThreadId, x.Source, x.SiteId, x.Favorite, x.Simple, x.FavoriteId, x.IsFolder, x.Downloaded, x.Read, x.Tooltip });
            });
        }