Example #1
0
        /// <summary>
        /// 创建多媒体网址
        /// </summary>
        /// <param name="ParsedMedia">多媒体网址实体</param>
        /// <returns>Url别名</returns>
        public string Create(ParsedMedia ParsedMedia)
        {
            ShortUrlService shortUrlService = new ShortUrlService();
            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);
        }
Example #2
0
        /// <summary>
        /// 更新多媒体网址
        /// </summary>
        /// <param name="ParsedMedia">多媒体网址实体</param>
        public void Update(ParsedMedia ParsedMedia)
        {
            EventBus <ParsedMedia> .Instance().OnBefore(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Update()));

            ParsedMediaRepository.Update(ParsedMedia);
            EventBus <ParsedMedia> .Instance().OnAfter(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
Example #3
0
 /// <summary>
 /// 解析Url
 /// </summary>
 /// <returns></returns>
 private string UrlTagGenerate(string url, long associateId, long userId, ParsedMedia parsedMedia)
 {
     if (parsedMedia == null)
         return string.Empty;
     if (parsedMedia != null)
     {
         var microblog = new MicroblogService().Get(associateId);
         if (parsedMedia.MediaType == MediaType.Video)
             microblog.VideoAlias = parsedMedia.Alias;
         else if (parsedMedia.MediaType == MediaType.Audio)
             microblog.AudioAlias = parsedMedia.Alias;
     }
     if (parsedMedia.MediaType == MediaType.Video)
     {
         return string.Format("<a id=\"attachmentsListLiVideo-{0}\" href=\"{3}\" target=\"_blank\" data-microblogId=\"{1}\">{2}<span class=\"tn-icon tn-icon-movie tn-icon-inline\"></span></a>", parsedMedia.Alias, associateId, url, SiteUrls.Instance()._Microblog_Attachments_Video(userId, associateId, parsedMedia.Alias));
     }
     else if (parsedMedia.MediaType == MediaType.Audio)
     {
         return string.Format("<a id=\"attachmentsListLiMusic-{0}\" href=\"{3}\" target=\"_blank\" data-microblogId=\"{1}\" >{2}<span class=\"tn-icon tn-icon-music tn-icon-inline\"></span></a>", parsedMedia.Alias, associateId, url, SiteUrls.Instance()._Microblog_Attachments_Music(userId, associateId, parsedMedia.Alias));
     }
     else
     {
         return string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", parsedMedia.Url, DIContainer.Resolve<ISettingsManager<ShortUrlSettings>>().Get().ShortUrlDomain + url);
     }
 }
Example #4
0
        /// <summary>
        /// 解析内容中的多媒体内容
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="TagGenerate">url生成对应标签的方法</param>
        public string ResolveBodyForHtmlDetail(string body, Func <string, ParsedMedia, string> TagGenerate)
        {
            if (string.IsNullOrEmpty(body))
            {
                return(body);
            }

            Regex           rg      = new Regex(@"(\<img(.[^\<]*)?(alt=""(?<alias>[a-zA-Z0-9]*)"")(.[^\<]*)?\>)", RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches = rg.Matches(body);

            if (matches != null)
            {
                string          alias = string.Empty, preAlias = string.Empty, imgHtml = string.Empty, shortUrl = string.Empty;
                ParsedMedia     parsedMedia     = null;
                ShortUrlService shortUrlService = new ShortUrlService();
                string          urlDomain       = ShortUrlService.GetUrlDomain();

                foreach (Match m in matches)
                {
                    if (m.Groups["alias"] == null || string.IsNullOrEmpty(m.Groups["alias"].Value))
                    {
                        continue;
                    }

                    alias = m.Groups["alias"].Value;

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

                    imgHtml = m.Value;
                    if (alias.Length == 6)
                    {
                        ShortUrlEntity entity = null;
                        shortUrl = shortUrlService.GetShortUrl(alias, out entity, urlDomain);
                        if (entity != null)
                        {
                            parsedMedia = Get(alias);
                            if (parsedMedia == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }

                    body = body.Replace(imgHtml, TagGenerate(shortUrl, parsedMedia));
                }
            }

            return(body);
        }
Example #5
0
        /// <summary>
        /// 创建示例
        /// </summary>
        /// <param name="alias">Url别名</param>
        /// <returns></returns>
        public static ParsedMedia New(string alias = "")
        {
            ParsedMedia parsedMedia = new ParsedMedia()
            {
                Url           = string.Empty,
                Description   = string.Empty,
                ThumbnailUrl  = string.Empty,
                PlayerUrl     = string.Empty,
                SourceFileUrl = string.Empty,
                DateCreated   = DateTime.UtcNow
            };

            return(parsedMedia);
        }
        /// <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;
        }
Example #7
0
        /// <summary>
        /// 删除多媒体网址
        /// </summary>
        /// <param name="alias">多媒体网址别名</param>
        public void Delete(string alias)
        {
            if (string.IsNullOrEmpty(alias))
            {
                return;
            }

            ParsedMedia entity = ParsedMediaRepository.Get(alias);

            if (entity != null)
            {
                EventBus <ParsedMedia> .Instance().OnBefore(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

                ParsedMediaRepository.Delete(entity);
                EventBus <ParsedMedia> .Instance().OnAfter(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
Example #8
0
        /// <summary>
        /// 生成多媒体内容标签
        /// </summary>
        /// <param name="shrotUrl">短网址</param>
        /// <param name="parsedMedia">多媒体连接实体</param>
        private string ParsedMediaTagGenerate(string shrotUrl, ParsedMedia parsedMedia)
        {
            if (parsedMedia == null)
                return string.Empty;

            if (parsedMedia.MediaType == MediaType.Audio)
            {
                string musicHtml = "<p><a href=\"{0}\" ntype=\"mediaPlay\">{1}<span class=\"tn-icon tn-icon-music tn-icon-inline\"></span></a><br />"
                                   + "<a  href=\"{0}\" ntype=\"mediaPlay\" class=\"tn-button tn-corner-all tn-button-default tn-button-text-icon-primary\">"
                                   + "<span class=\"tn-icon tn-icon-triangle-right\"></span><span class=\"tn-button-text\">音乐播放</span></a></p>";
                return string.Format(musicHtml, SiteUrls.Instance()._MusicDetail(parsedMedia.Alias), shrotUrl);
            }
            else if (parsedMedia.MediaType == MediaType.Video)
            {
                string videoHtml = "<p><a  href=\"{0}\" ntype=\"mediaPlay\">{1}<span class=\"tn-icon tn-icon-movie tn-icon-inline\"></span></a><br />"
                                    + "<a ntype=\"mediaPlay\" href=\"{0}\"><img src=\"{2}\"></a></p>";
                return string.Format(videoHtml, SiteUrls.Instance()._VideoDetail(parsedMedia.Alias), shrotUrl, parsedMedia.ThumbnailUrl);
            }

            return string.Empty;
        }
 /// <summary>
 /// 解析Url
 /// </summary>
 /// <returns></returns>
 private string UrlTagGenerateForMobile(string url, long associateId, long userId, ParsedMedia parsedMedia)
 {
     if (parsedMedia == null)
         return string.Empty;
     if (parsedMedia != null)
     {
         var microblog = new MicroblogService().Get(associateId);
         if (parsedMedia.MediaType == MediaType.Video)
             microblog.VideoAlias = parsedMedia.Alias;
         else if (parsedMedia.MediaType == MediaType.Audio)
             microblog.AudioAlias = parsedMedia.Alias;
     }
     string fullUrl = DIContainer.Resolve<ISettingsManager<SiteSettings>>().Get().MainSiteRootUrl + "/" + parsedMedia.Alias;
     return string.Format("{0}", fullUrl);
 }
Example #10
0
 /// <summary>
 /// 更新多媒体网址
 /// </summary>
 /// <param name="ParsedMedia">多媒体网址实体</param>
 public void Update(ParsedMedia ParsedMedia)
 {
     EventBus<ParsedMedia>.Instance().OnBefore(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Update()));
     ParsedMediaRepository.Update(ParsedMedia);
     EventBus<ParsedMedia>.Instance().OnAfter(ParsedMedia, new CommonEventArgs(EventOperationType.Instance().Update()));
 }
Example #11
0
        /// <summary>
        /// 解析内容中的AtUser用户展示展示
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="associateId">关联项Id</param>
        /// <param name="userId">关联项作者Id</param>
        /// <param name="UrlGenerate">url生成对应标签的方法</param>
        public string ResolveBodyForDetail(string body, long associateId, long userId, Func <string, long, long, ParsedMedia, string> UrlGenerate)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("http://"))
            {
                return(body);
            }

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

            if (matches != null)
            {
                string          strUrl = string.Empty, preUrl = string.Empty, shortUrl = string.Empty;
                string          urlDomain       = ShortUrlService.GetUrlDomain().Substring(7);
                ParsedMedia     parsedMedia     = null;
                ShortUrlService shortUrlService = new ShortUrlService();

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

                    strUrl = m.Value;

                    if (string.IsNullOrEmpty(strUrl) || strUrl.Equals(preUrl, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    preUrl = strUrl;

                    if (strUrl.StartsWith(urlDomain))
                    {
                        string temalias = strUrl.Substring(strUrl.LastIndexOf('/') + 1);
                        if (temalias.Length != 6)
                        {
                            continue;
                        }

                        parsedMedia = Get(temalias);
                        if (parsedMedia == null)
                        {
                            continue;
                        }

                        shortUrl = shortUrlService.GetShortUrl(temalias, "http://" + urlDomain);
                    }
                    else if (strUrl.Length == 6)
                    {
                        ShortUrlEntity entity = null;
                        shortUrl = shortUrlService.GetShortUrl(strUrl, out entity, "http://" + urlDomain);
                        if (entity == null)
                        {
                            continue;
                        }

                        parsedMedia = Get(strUrl);
                        if (parsedMedia == null)
                        {
                            parsedMedia           = ParsedMedia.New();
                            parsedMedia.MediaType = MediaType.Other;
                            parsedMedia.Alias     = entity.Alias;
                            parsedMedia.Url       = entity.Url;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    body = body.Replace("http://" + strUrl, UrlGenerate(shortUrl, associateId, userId, parsedMedia));
                }
            }

            return(body);
        }
Example #12
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);
        }
Example #13
0
        /// <summary>
        /// 生成多媒体内容标签
        /// </summary>
        /// <param name="shrotUrl">短网址</param>
        /// <param name="parsedMedia">多媒体连接实体</param>
        private string ParsedMediaTagGenerateForMobile(string shrotUrl, ParsedMedia parsedMedia)
        {
            if (parsedMedia == null)
                return string.Empty;

            if (parsedMedia.MediaType == MediaType.Audio)
            {
                string musicHtml = "<p><a href=\"{1}\" ntype='mediaPlay'>点击播放音乐</a></p>";
                ShortUrlEntity shortUrlEntity = new ShortUrlService().Get(parsedMedia.Alias);
                return string.Format(musicHtml, SiteUrls.FullUrl(SiteUrls.Instance()._MusicDetail(parsedMedia.Alias)), shortUrlEntity == null ? null : shortUrlEntity.Url);
            }
            else if (parsedMedia.MediaType == MediaType.Video)
            {
                string videoHtml = "<p><a  href=\"{1}\" ntype=\"mediaPlay\">{1}<img src=\"{2}\"></a></p>";
                ShortUrlEntity shortUrlEntity = new ShortUrlService().Get(parsedMedia.Alias);
                return string.Format(videoHtml, SiteUrls.FullUrl(SiteUrls.Instance()._VideoDetail(parsedMedia.Alias)), shortUrlEntity == null ? null : shortUrlEntity.Url, parsedMedia.ThumbnailUrl);
            }

            return string.Empty;
        }
Example #14
0
 /// <summary>
 /// 创建示例
 /// </summary>
 /// <param name="alias">Url别名</param>
 /// <returns></returns>
 public static ParsedMedia New(string alias = "")
 {
     ParsedMedia parsedMedia = new ParsedMedia()
     {
         Name = string.Empty,
         Alias = alias,
         Url = string.Empty,
         Description = string.Empty,
         ThumbnailUrl = string.Empty,
         PlayerUrl = string.Empty,
         SourceFileUrl = string.Empty,
         DateCreated = DateTime.UtcNow
     };
     return parsedMedia;
 }