Exemplo n.º 1
0
        public static BcatTopic GetBcatTopic(string TopicID)
        {
            BcatTopic topic = new BcatTopic
            {
                Icon    = GetTopicIcon(TopicID),
                Details = GetTopicDetail(TopicID)
            };

            return(topic);
        }
Exemplo n.º 2
0
 private void SetCurrentTopic(BcatTopic topic)
 {
     CurrentTopicId             = topic.Details.topic_id;
     pictureBox_topicIcon.Image = topic.Icon;
     textBox_topicDesc.Text     = topic.Details.description;
 }
Exemplo n.º 3
0
        public static List <BcatTopic> RefreshCatalog(ProgressBar pb, Label lbl)
        {
            string catalogPath = $"{CATALOG_CACHE_PATH}.bin";

            byte[]             rawCatalog = BCAT.GetRawNewsCatalog();
            List <BcatChannel> catalog    = MsgPack.Deserialize <List <BcatChannel> >(rawCatalog);

            List <BcatChannel> cached = (File.Exists(catalogPath))
                ? MsgPack.Deserialize <List <BcatChannel> >(File.ReadAllBytes(catalogPath))
                : null;

            pb.Invoke(new Action(() => {
                pb.Value   = 0;
                pb.Maximum = catalog.Count;
            }));

            List <BcatTopic> topics = new List <BcatTopic>();

            for (int i = 0; i < catalog.Count; i++)
            {
                lbl.Invoke(new Action(() => lbl.Text = $"Processing... {i}/{catalog.Count} ({catalog[i].topic_id})"));
                pb.Invoke(new Action(() => pb.Value  = i));

                string dir        = $"{CATALOG_CACHE_PATH}/{catalog[i].topic_id}";
                string iconPath   = $"{dir}/icon.jpg";
                string detailPath = $"{dir}/detail.bin";

                bool redownload = true;

                if (cached != null)
                {
                    foreach (var item in cached)
                    {
                        if (item.topic_id == catalog[i].topic_id)
                        {
                            redownload = !(item.Equals(catalog[i]) && File.Exists(iconPath) && File.Exists(detailPath));
                            break;
                        }
                    }
                }

                if (redownload)
                {
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    File.WriteAllBytes(iconPath, BCAT.GetRawTopicIcon(catalog[i].topic_id));
                    File.WriteAllBytes(detailPath, BCAT.GetRawTopicDetail(catalog[i].topic_id));
                }

                BcatTopic t = new BcatTopic()
                {
                    Icon    = Utils.GetBitmap(File.ReadAllBytes(iconPath)),
                    Details = MsgPack.Deserialize <TopicDetail>(File.ReadAllBytes(detailPath))
                };
                topics.Add(t);
            }

            //if (cached == null)
            File.WriteAllBytes(catalogPath, rawCatalog);

            lbl.Invoke(new Action(() => lbl.Text = "..."));
            pb.Invoke(new Action(() => pb.Value  = 0));


            topics = topics.OrderBy(item => item.Details.important).ThenBy(item => item.Details.last_posted_at).Reverse().ToList();

            return(topics);
        }