Example #1
0
        void post_initialize(bool arrange_tokens , InitializeParam param)
        {
            tokens = text.Parse();
            var f = tokens.ElementAtOrDefault(0);
            Debug.Assert(f != null);

            //正文的第一行作为标题
            if(f.tag == TokenTypes.Part && f.text.Length < 20)//不要很长的标题
            {
                topic_source = WeiboTopicSource.FirstSentence;
                topic = f.text.Trim();
            }
           // var url = string.Empty;
            //正文有标题
            foreach(var t in tokens)
            {
                if (t.tag == TokenTypes.Topic)
                {
                    topic = t.text;
                    topic_source = WeiboTopicSource.Trend;
                    //break;
                }
                if(t.tag == TokenTypes.Quote && topic_source == WeiboTopicSource.Reserved)
                {
                    topic_source = WeiboTopicSource.Quote;
                    topic = t.text.Trim();
                }
                if(t.tag == TokenTypes.Hyperlink && t.text.Contains("http://t.cn/"))
                {
                    if (param.url == null)
                        param.url = t.text;
                }
            }
            if(retweeted_status != null)
            {
                //使用rt中的标题
                if(retweeted_status.topic_source != WeiboTopicSource.Reserved)
                {
                    topic_source = WeiboTopicSource.Retweeted;
                    topic = retweeted_status.topic;
                }

                if (retweeted_status.has_pic && !has_pic)
                {
                    has_pic = true;
                    bmiddle_pic = retweeted_status.bmiddle_pic;
                    thumbnail_pic = retweeted_status.thumbnail_pic;

                    thumb_pic_width = retweeted_status.thumb_pic_width;
                    thumb_pic_height = retweeted_status.thumb_pic_height;
                }
                
            }

            //在使用正文首行作为标题前,如果有url的标题,就用url标题
            if(!string.IsNullOrEmpty(param.url))
                fetch_url_info(param.url);

            if (arrange_tokens == false)
                return;

            if(retweeted_status != null)
            {
                if(tokens.Count > 0)
                    tokens.Insert(0,new Token{tag = TokenTypes.Writer, text = user.screen_name});
                tokens.Insert(0, new Token { tag = TokenTypes.Break });
                tokens.Insert(0, new Token { tag = TokenTypes.Break });
                tokens.InsertRange(0,retweeted_status.tokens);
            }

            //从正文中删除标题内容
            if (tokens.Count > 0 && topic == tokens[0].text)
            {
                tokens.RemoveAt(0);//去掉第一句
            }
            //去除正文开始的标点
            while (tokens.Count > 0)
            {
                var tag =tokens[0].tag;
                if ( (tag== TokenTypes.Punctuation || tag == TokenTypes.Break) && tokens[0].text != "《")
                    tokens.RemoveAt(0);
                else
                    break;
            }
        }
Example #2
0
 public void assign_sina(Status data)
 {
     assign_sina_data(data);
     var para = new InitializeParam();
     if(data.retweeted_status != null)
     {
         retweeted_status = new WeiboStatus();
         retweeted_status.assign_sina_data(data.retweeted_status);
         retweeted_status.post_initialize(false,para);
     }
     post_initialize(true, para);
     if (url.has_media)
         Messenger.Default.Send(url);
 }