Ejemplo n.º 1
0
        /// <summary>
        /// 创建多媒体网址
        /// </summary>
        /// <param name="ParsedMedia">多媒体网址实体</param>
        /// <returns>Url别名</returns>
        public string Create(ParsedMedia ParsedMedia)
        {
            string alias = shortUrlService.Create(ParsedMedia.Url);

            ParsedMedia.Alias = alias;

            EventBus <ParsedMedia> .Instance().OnBefore(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Create()));

            string description = HtmlUtility.StripHtml(ParsedMedia.Description, true, false).Trim();

            if (description.Length > 500)
            {
                ParsedMedia.Description = description.Substring(0, 500) + "…";
            }
            else
            {
                ParsedMedia.Description = description;
            }
            object result = ParsedMediaRepository.Insert(ParsedMedia);

            if ((bool)result)
            {
                EventBus <ParsedMedia> .Instance().OnAfter(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
            return(alias);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解析内容用于创建AtUser
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="videoAlias">视频Url别名</param>
        /// <param name="audioAlias">音乐Url别名</param>
        public string ResolveBodyForEdit(string body, out string videoAlias, out string audioAlias)
        {
            videoAlias = audioAlias = string.Empty;
            if (string.IsNullOrEmpty(body) || !body.Contains("http://"))
            {
                return(body);
            }

            string newBody = body, strUrl = string.Empty, strPreUrl = string.Empty;
            string urlDomain = ShortUrlService.GetUrlDomain();

            urlDomain = urlDomain.Substring(7);

            Dictionary <string, string> urls            = new Dictionary <string, string>();
            ShortUrlService             shortUrlService = new ShortUrlService();

            ParsedMedia     parsedMedia = null;
            Regex           rg          = new Regex(regexRule, RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches     = rg.Matches(body);

            if (matches != null)
            {
                foreach (Match m in matches)
                {
                    if (string.IsNullOrEmpty(m.Value))
                    {
                        continue;
                    }

                    strUrl = m.Value;

                    if (!string.IsNullOrEmpty(strUrl) && !strUrl.Equals(strPreUrl, StringComparison.CurrentCultureIgnoreCase))
                    {
                        strPreUrl = strUrl;
                    }
                    else
                    {
                        continue;
                    }

                    if (strUrl.StartsWith(urlDomain) || strUrl.Length == 6)
                    {
                        string temalias = strUrl.Length == 6 ? strUrl : strUrl.Substring(urlDomain.Length + 1);
                        if (temalias.Length == 6)
                        {
                            parsedMedia = Get(temalias);
                            if (strUrl.Contains(urlDomain))
                            {
                                urls[temalias] = strUrl;
                            }
                        }
                        else
                        {
                            temalias = shortUrlService.Create("http://" + strUrl);
                            if (string.IsNullOrEmpty(temalias))
                            {
                                continue;
                            }

                            urls[temalias] = strUrl;
                        }
                    }

                    if (parsedMedia == null)
                    {
                        continue;
                    }

                    if (parsedMedia.MediaType == MediaType.Video)
                    {
                        if (string.IsNullOrEmpty(videoAlias))
                        {
                            videoAlias = parsedMedia.Alias;
                        }
                    }
                    else if (parsedMedia.MediaType == MediaType.Audio)
                    {
                        if (string.IsNullOrEmpty(audioAlias))
                        {
                            audioAlias = parsedMedia.Alias;
                        }
                    }
                }

                if (urls.Count() > 0)
                {
                    foreach (var url in urls)
                    {
                        body = body.Replace("http://" + url.Value, "http://" + url.Key + " ");
                    }
                }
            }

            return(body);
        }