Beispiel #1
0
        public static ActionHandlerResult Invoke <Action>(Action args)
        {
            ActionHandlerResult result = null;

            Type actionType = typeof(Action);

            foreach (PluginBase plugin in s_Plugins)
            {
                if (plugin.Enable == false)
                {
                    continue;
                }

                ActionHandlerInfoCollection <Action> actionHandlerInfos = plugin.ActionHandlers[actionType] as ActionHandlerInfoCollection <Action>;

                if (actionHandlerInfos != null)
                {
                    //处理器已经按优先级排序,优先级值低的先被调用
                    foreach (ActionHandlerInfo <Action> handlerInfo in actionHandlerInfos)
                    {
                        result = handlerInfo.Handler(args);

                        //不冒泡就停止后续处理器的执行
                        if (result != null && result.Bubble == false)
                        {
                            return(result);
                        }
                    }
                }
            }

            if (result == null)
            {
                result = new ActionHandlerResult();
            }

            return(result);
        }
Beispiel #2
0
		//static Regex reg_news_qq_url = new Regex(@"http://news.qq.com/(.*?|\s*?)/[0-9]+/[0-9_]+.htm[l]{0,1}", RegexOptions.IgnoreCase);
		//static Regex reg_news_qq_title = new Regex(@"<div\s+id=""ArticleTit"">(.*?|\s*?)</div>", RegexOptions.IgnoreCase);

		ActionHandlerResult BeforeCreateShareHandler(BeforeCreateShare args)
		{
			ActionHandlerResult result;
			ShareContent share = args.ShareContent;

            string htmlContent = GetContent(share.URL);
            if (htmlContent == null)
			{
				result = new ActionHandlerResult();
				//result.HasError = true;
				result.ErrorMessage = "无法找到该网页";
				return result;
			}

			//视频
			if (reg_video_youtube.IsMatch(share.URL))
			{
				share.Catagory = ShareType.Video;
				share.Content = reg_video_youtube.Match(share.URL).Groups[2].Value;
				share.Domain = "youtube.com";
			}
			else if (reg_video_youku.IsMatch(share.URL))
			{
				share.Catagory = ShareType.Video;
				share.Domain = "youku.com";
				share.Content = reg_video_youku.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_youkutitle, htmlContent);
                ProcessImg(share, reg_video_youkuimgurl, htmlContent);

			}
			else if (reg_video_ku6_url1.IsMatch(share.URL))
			{
				share.Domain = "ku6.com";
				share.Catagory = ShareType.Video;
				share.Content = reg_video_ku6_url1.Match(share.URL).Groups[2].Value;
                ProcessTitle(share, reg_video_ku6_title, htmlContent);
                ProcessImg(share, reg_video_ku6_imgurl, htmlContent);
			}
			else if (reg_video_ku6_url2.IsMatch(share.URL))
			{
				share.Domain = "ku6.com";
				share.Catagory = ShareType.Video;
                share.Content = reg_video_ku6_url2.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_ku6_title, htmlContent);
                ProcessImg(share, reg_video_ku6_imgurl, htmlContent);
			}
            else if (reg_video_tudou.IsMatch(share.URL))
            {
                share.Domain = "tudou.com";
                share.Catagory = ShareType.Video;
                share.Content = reg_video_tudou.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_tudoutitle, htmlContent);
                ProcessImg(share, reg_video_tudouimgurl, htmlContent);
            }
            else if (reg_video_5show_url.IsMatch(share.URL))
            {
                share.Domain = "5show.com";
                return ProcessVideo(share, reg_video_5show_swf, 2, htmlContent);
            }
            else if (reg_video_sina_url.IsMatch(share.URL))
            {
                share.Domain = "sina.com.cn";
                return ProcessVideo(share, reg_video_sina_swf, 2, htmlContent);
            }
            else if (reg_video_sohu_url.IsMatch(share.URL))
            {
                string id = reg_video_sohu_url.Match(share.URL).Groups[1].Value;
                string info = GetContent("http://v.blog.sohu.com/videinfo.jhtml?m=view&id=" + id + "&outType=3", Encoding.ASCII);
                if (info != null)
                {
                    Match match = reg_video_sohu_titleAndImg.Match(info);
                    if (match.Success)
                    {
                        share.ImgUrl = match.Groups["imgurl"].Value + "_1.jpg";
                        share.Title = StringUtil.HexDecode(match.Groups["title"].Value);
                    }
                }
                share.Domain = "sohu.com";
                return ProcessVideo(share, reg_video_sohu_swf, 1, htmlContent);
            }
            else if (reg_video_pomoho_url1.IsMatch(share.URL) || reg_video_pomoho_url2.IsMatch(share.URL))
            {
                share.Domain = "pomoho.com";
                ProcessTitle(share, reg_video_pomoho_title, htmlContent);
                return ProcessVideo(share, reg_video_pomoho_swf, 1, htmlContent);
            }
            else if (reg_video_mofile.IsMatch(share.URL))
            {
                share.Domain = "mofile.com";
                share.Catagory = ShareType.Video;
                Match match = reg_video_mofile_titleAndImgurl.Match(htmlContent);
                if (match.Success)
                {
                    share.Title = match.Groups["title"].Value;
                    share.ImgUrl = "http://" + match.Groups["imgurl"].Value;
                }
                share.Content = reg_video_mofile.Match(share.URL).Groups[1].Value;
            }
            else if (reg_video_mofile_url2.IsMatch(share.URL))
            {
                Match match = reg_video_mofile_titleAndImgurl.Match(htmlContent);
                if (match.Success)
                {
                    share.Title = match.Groups["title"].Value;
                    share.ImgUrl = "http://" + match.Groups["imgurl"].Value;
                }
                share.Domain = "mofile.com";
                share.Catagory = ShareType.Video;
                share.Content = reg_video_mofile_url2.Match(share.URL).Groups[1].Value;
            }
            else if (reg_video_baidu_url.IsMatch(share.URL))
            {
                share.Domain = "tieba.baidu.com";
                return ProcessVideo(share, reg_video_baidu_swf, 1, htmlContent);
            }
            else if (reg_video_ouou_url.IsMatch(share.URL))
            {
                share.Domain = "ouou.com";
                return ProcessVideo(share, reg_video_ouou_swf, 1, htmlContent);
            }

			return null;

		}
Beispiel #3
0
		ActionHandlerResult ProcessVideo(ShareContent share, Regex reg, int valueIndex, string htmlContent)
		{
			if (htmlContent == null)
			{
				ActionHandlerResult result = new ActionHandlerResult();
				//result.HasError = true;
				result.ErrorMessage = "无法找到该网页";
				return result;
			}
			else if (reg.IsMatch(htmlContent))
			{
                //Match title = Regex.Match(content, "<title>.*</title>");

                //if (title.Success)
                //    share.Title = title.Value;
                //else
                //    share.Title = share.URL;
                if (share.Title == null)
                    share.Title = share.URL;
				share.Content = reg.Match(htmlContent).Groups[valueIndex].Value;
				share.Catagory = ShareType.Video;
				return null;
			}
			else
			{
				share = null;
				return null;
			}
		}