public void ApiTest()
        {
            ParsedMedia parsedMedia = _filenameParser.Parse("The.Secret.Life.of.Walter.Mitty.2013.1080p.BluRay.x264.YIFY");

            MediaSearchResult searchResult = _apiSearchService.SearchMultiByQuery(parsedMedia.Title)[0];
            MediaDetail       apiResult    = _apiSearchService.GetItemDetail(searchResult.MediaType, searchResult.Id);

            Console.WriteLine(apiResult);
        }
        private void HandleDeletePermanently(Media item)
        {
            if (!FrameworkSettings.CurrentUser.HasPermission(PermissionsEnum.Delete))
            {
                throw new Exception("You do not have the appropriate permissions to delete items permanently");
            }

            if (item == null)
            {
                return;
            }

            MediaDetail detail      = (MediaDetail)GetAtleastOneByMedia(item);
            Media       parentMedia = null;

            if (item.ParentMediaID != null)
            {
                parentMedia = MediasMapper.GetByID((long)item.ParentMediaID);
            }

            Return returnObj = BaseMapper.GenerateReturn("No action performed");

            if (detail == null)
            {
                if (item.ChildMedias.Count == 0)
                {
                    returnObj = MediasMapper.DeletePermanently(item);
                }
            }
            else
            {
                item = BaseMapper.GetObjectFromContext(item);
                if ((item.MediaDetails.Count == 1) && (item.ChildMedias.Count > 0))
                {
                    throw new Exception("You cannot delete this item because it has child items");
                }

                detail    = BaseMapper.GetObjectFromContext(detail);
                returnObj = MediaDetailsMapper.DeletePermanently(detail);

                if (!returnObj.IsError)
                {
                    ContextHelper.ClearAllMemoryCache();
                    detail.RemoveFromCache();
                }
            }
        }
Ejemplo n.º 3
0
        private IMediaDetail CreateHistory(MediaDetail fromItem, bool isDraft)
        {
            if (fromItem == null)
            {
                return(null);
            }

            IMediaDetail history = null;

            if ((selectedItem.ID != 0) && (historyVersion == 0))
            {
                history = MediaDetailsMapper.CreateObject(fromItem.MediaTypeID, fromItem.Media, fromItem.Media.ParentMedia, false);
                history.CopyFrom(BaseMapper.GetObjectFromContext(fromItem));
                history.IsDraft = isDraft;

                CopyProperties(history, fromItem);
            }

            return(history);
        }
        private Return SetPublishStatus(MediaDetail detail, bool publishStatus)
        {
            if ((detail == null) || (detail.IsPublished == publishStatus))
            {
                return(new Return());
            }

            detail = BaseMapper.GetObjectFromContext(detail);

            if (publishStatus)
            {
                detail.PublishDate = DateTime.Now;
            }
            else
            {
                detail.PublishDate = null;
            }

            Return returnObj = MediaDetailsMapper.Update(detail);

            if (returnObj.IsError)
            {
                return(returnObj);
            }
            else
            {
                ContextHelper.ClearAllMemoryCache();
                FileCacheHelper.DeleteCacheDir("generatenav");

                if (publishStatus)
                {
                    detail.PublishDate = DateTime.Now;

                    returnObj = detail.RunOnPublishExecuteCode();

                    return(returnObj);
                }

                return(returnObj);
            }
        }
        private void SetShowInMenuStatus(MediaDetail detail, bool showInMenu)
        {
            if ((detail == null) || (detail.ShowInMenu == showInMenu))
            {
                return;
            }

            detail            = BaseMapper.GetObjectFromContext(detail);
            detail.ShowInMenu = showInMenu;

            Return returnObj = MediaDetailsMapper.Update(detail);

            if (returnObj.IsError)
            {
                throw returnObj.Error.Exception;
            }
            else
            {
                ContextHelper.ClearAllMemoryCache();
                FileCacheHelper.DeleteCacheDir("generatenav");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 命令执行
        /// </summary>
        /// <param name="context"></param>
        public override void Execute(DataContext context)
        {
            byte[] cmdData = context.CmdData;
            if (cmdData.Length == 0)
            {
                context.Flush(RespondCode.CmdDataLack);
                return;
            }

            MediaDetail iconData = cmdData.ProtoBufDeserialize <MediaDetail>();

            if (Compiled.Debug)
            {
                iconData.Debug("=== User.SetHeadIcon 上行数据===");
            }

            if (iconData.Data != null && iconData.Data.Length > 0)
            {
                string extName = (iconData.Name ?? ".jpg").ToLower();
                string iconUrl = UserBiz.SetUserHeadIcon(context.UserId, iconData.Data, extName);

                if (!string.IsNullOrEmpty(iconUrl))
                {
                    context.Flush <StringSingle>(new StringSingle {
                        Data = iconUrl
                    });
                }
                else
                {
                    context.Flush(RespondCode.ExecError);
                }
            }
            else
            {
                context.Flush(RespondCode.DataInvalid);
            }
        }
Ejemplo n.º 7
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            RedisCacheHelper.SetRedisCacheConnectionString(AppSettings.RedisCacheConnectionString);
            FileCacheHelper.SetFileSystemCacheDirPath(AppSettings.FileSystemCacheDirPath);

            virtualPath = URIHelper.GetCurrentVirtualPath().ToLower();

            var queryString = HttpContext.Current.Request.QueryString.ToString();

            queryString = System.Web.HttpUtility.UrlDecode(queryString);


            if (!Request.Path.EndsWith("/") || ((virtualPath != "~/") && (!virtualPath.EndsWith("/"))))
            {
                var path = Request.Path + "/";

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                HttpContext.Current.Response.RedirectPermanent(path);
            }

            Settings cmsSettings            = null;
            bool     isAttemptingAdminLogin = false;

            if ((virtualPath != "~/login/") && (virtualPath != "~/admin/") && string.IsNullOrEmpty(Request.QueryString["format"]))
            {
                cmsSettings = SettingsMapper.GetSettings();

                if (cmsSettings != null)
                {
                    var isSiteOnline = cmsSettings.IsSiteOnline();

                    if (isSiteOnline)
                    {
                        if (virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect("~/");
                        }

                        AttemptToLoadFromCache();
                    }
                    else
                    {
                        if (!virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect(cmsSettings.SiteOfflineUrl);
                        }
                    }
                }
                else
                {
                    AttemptToLoadFromCache();
                }
            }
            else
            {
                isAttemptingAdminLogin = true;
            }

            var languageSegment = FrameworkSettings.GetCurrentLanguage().UriSegment;

            if (LanguagesMapper.GetAllActive().Count() > 1 && !Request.Url.PathAndQuery.Contains($"/{languageSegment}/"))
            {
                var url = URIHelper.ConvertToAbsUrl("/" + languageSegment + Request.Url.PathAndQuery);
                Response.RedirectPermanent(url, true);
            }

            var segments = URIHelper.GetUriSegments(virtualPath).ToList();

            string firstSegment = "";

            if (segments.Count > 0)
            {
                firstSegment = segments[0];

                var language = LanguagesMapper.GetAllActive().SingleOrDefault(i => i.UriSegment == firstSegment);

                if (language != null)
                {
                    FrameworkSettings.SetCurrentLanguage(language);
                }
            }

            if (!isAttemptingAdminLogin && AppSettings.EnableUrlRedirectRules)
            {
                var path = virtualPath;

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                var redirectRule = UrlRedirectRulesMapper.GetRuleForUrl(path);

                if (redirectRule != null)
                {
                    var newUrl = redirectRule.RedirectToUrl;

                    if (newUrl.Contains("{"))
                    {
                        newUrl = MediaDetailsMapper.ParseSpecialTags(redirectRule, newUrl);
                    }

                    newUrl = URIHelper.ConvertToAbsUrl(newUrl);

                    var possibleLoopRules      = UrlRedirectRulesMapper.GetRulesFromUrl(URIHelper.ConvertAbsUrlToTilda(newUrl));
                    var foundActiveVirtualPath = MediaDetailsMapper.GetByVirtualPath(path);

                    if (possibleLoopRules.Any())
                    {
                        foreach (var rule in possibleLoopRules)
                        {
                            var returnObj = MediaDetailsMapper.DeletePermanently(rule);
                        }
                    }

                    if (foundActiveVirtualPath != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(redirectRule);
                    }

                    if (Request.QueryString.Count > 0)
                    {
                        newUrl += "?" + Request.QueryString;
                    }

                    if (redirectRule.Is301Redirect)
                    {
                        Response.RedirectPermanent(newUrl);
                    }
                    else
                    {
                        Response.Redirect(newUrl);
                    }
                }
            }

            if (!File.Exists(HttpContext.Current.Server.MapPath(virtualPath)) && !virtualPath.Contains(ParserHelper.OpenToken) && !virtualPath.Contains(ParserHelper.CloseToken))
            {
                string viewPath = "";

                long mediaDetailId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaDetailID"], out mediaDetailId);

                long mediaId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaID"], out mediaId);

                MediaDetail detail = null;

                if (mediaDetailId == 0 && mediaId == 0)
                {
                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath(virtualPath, true);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaDetailId != 0)
                {
                    var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(mediaDetail);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaId != 0)
                {
                    var media = MediasMapper.GetByID(mediaId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMedia(media);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }

                /*if (detail != null && !detail.CanUserAccessSection(FrameworkSettings.CurrentUser))
                 * {
                 *  FormsAuthentication.RedirectToLoginPage();
                 * }*/

                /*if (detail != null)
                 * {
                 *  var absUrlBase = URIHelper.ConvertAbsUrlToTilda(detail.AbsoluteUrl).Replace("~", "");
                 *  var absPathBase = URIHelper.ConvertAbsUrlToTilda(Request.Url.AbsolutePath).Replace("~", "");
                 *
                 *  if (absUrlBase != absPathBase)
                 *  {
                 *      Response.Redirect(detail.AbsoluteUrl + Request.Url.Query);
                 *  }
                 * }*/

                if (detail != null)
                {
                    if (detail.ForceSSL || AppSettings.ForceSSL)
                    {
                        URIHelper.ForceSSL();
                    }
                }
                else
                {
                    var currentLanguageId = FrameworkSettings.GetCurrentLanguage().ID;

                    var historyVersion = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.LanguageID == currentLanguageId && i.CachedVirtualPath == virtualPath && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber != 0 && i.HistoryForMediaDetail != null);

                    if (historyVersion != null && historyVersion.VirtualPath != historyVersion.HistoryForMediaDetail.VirtualPath)
                    {
                        var foundRedirectUrl = UrlRedirectRulesMapper.GetRuleForUrl(virtualPath);

                        if (foundRedirectUrl == null)
                        {
                            var urlRedirectRule = UrlRedirectRulesMapper.CreateUrlRedirect(virtualPath, historyVersion.HistoryForMediaDetail.Media);

                            if (urlRedirectRule != null)
                            {
                                var returnObj = UrlRedirectRulesMapper.Insert(urlRedirectRule);
                                HttpContext.Current.Response.RedirectPermanent(historyVersion.HistoryForMediaDetail.CachedVirtualPath);
                            }
                            else
                            {
                                HttpContext.Current.Response.RedirectPermanent("/");
                            }
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.RedirectPermanent("/");
                    }
                }

                if ((detail == null) || (!IsValidRequest(detail)))
                {
                    detail = null;
                    if (cmsSettings != null)
                    {
                        if (!string.IsNullOrEmpty(cmsSettings.PageNotFoundUrl))
                        {
                            ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));

                            Response.Redirect(cmsSettings.PageNotFoundUrl);

                            /*FrameworkSettings.CurrentFrameworkBaseMedia = null;
                             *
                             * FrameworkSettings.CurrentFrameworkBaseMedia = FrameworkBaseMedia.GetInstanceByVirtualPath(cmsSettings.PageNotFoundUrl, true);
                             * detail = (MediaDetail)FrameworkSettings.CurrentFrameworkBaseMedia.CurrentMediaDetail;
                             *
                             * ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));*/

                            //Response.StatusCode = 301;
                        }
                    }
                }

                if (detail != null)
                {
                    var draft = detail.GetLatestDraft();

                    if (draft != null && (draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10) && draft.CanRender)
                    {
                        var returnObj = draft.PublishLive();

                        if (!returnObj.IsError)
                        {
                            detail.RemoveFromCache();
                            draft.RemoveFromCache();

                            FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(draft);
                            detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                        }
                    }

                    if (detail.RedirectToFirstChild)
                    {
                        var child = detail.ChildMediaDetails.FirstOrDefault();

                        if (child != null)
                        {
                            var redirectPath = child.AutoCalculatedVirtualPath;

                            if (!string.IsNullOrEmpty(queryString))
                            {
                                redirectPath = redirectPath + "?" + queryString;
                            }

                            HttpContext.Current.Response.Redirect(redirectPath);
                        }
                    }

                    viewPath = FrameworkSettings.Current.CurrentMediaDetail.Handler;

                    if ((viewPath == null) || (viewPath.Trim() == ""))
                    {
                        viewPath = MediaTypesMapper.GetByID(FrameworkSettings.Current.CurrentMediaDetail.MediaTypeID).MediaTypeHandler;
                    }

                    viewPath = URIHelper.ConvertAbsUrlToTilda(viewPath);

                    if (!string.IsNullOrEmpty(Request.QueryString["format"]))
                    {
                        FrontEndBasePage.HandleFormatQueryString(detail, Request.QueryString["format"], Request.QueryString["depth"]);
                    }

                    return(CreateInstanceFromVirtualPath(viewPath, typeof(BasePage)));
                }
            }

            return(new DefaultHttpHandler());
        }
Ejemplo n.º 8
0
        public override IMetacriticData Parse(UrlResponsePair urlResponsePair)
        {
            string html = urlResponsePair.Response;

            if (String.IsNullOrEmpty(m_thirdLevelRequest))
            {
                TVShow tvShow = new TVShow();
                tvShow.Title  = ParseItem(ref html, @"<h1>", @"</h1>");
                tvShow.Season = Int32.Parse(ParseItem(ref html, @"Season ", @"</h2>"));

                tvShow.Studio = ParseItem(ref html, @"<span itemprop=""name"">", @"</span>");

                short?criticRating      = null;
                short?criticRatingCount = null;
                if (short.TryParse(ParseItem(ref html, @"<span itemprop=""ratingValue"">", @"</span>"), out short tempCriticRating))
                {
                    criticRating      = tempCriticRating;
                    criticRatingCount = Int16.Parse(ParseItem(ref html, @"<span itemprop=""reviewCount"">", @"</span>"));
                }

                float?userRating      = null;
                short?userRatingCount = null;
                int   userRatingIdx   = html.IndexOf("metascore_w user large");
                if (userRatingIdx != -1)
                {
                    html = html.Substring(userRatingIdx);
                    if (float.TryParse(ParseItem(ref html, @""">", @"</div>"), out float tempUserRating))
                    {
                        userRating      = tempUserRating;
                        userRatingCount = Int16.Parse(ParseItem(ref html, @"user-reviews"">", @" Ratings"));
                    }
                }

                tvShow.Rating = new Rating(criticRating, userRating, criticRatingCount, userRatingCount);

                string   releaseDateStr = ParseItem(ref html, @"<span class=""data"" itemprop=""startDate"">", @"</span>");
                DateTime releaseDate;
                if (DateTime.TryParse(releaseDateStr, out releaseDate))
                {
                    tvShow.ReleaseDate = releaseDate.ToString("MM/dd/yyyy");
                }

                if (UrlImagePath != null)
                {
                    string key = UrlImagePath.Keys.FirstOrDefault(k => urlResponsePair.Url.Contains(k));
                    if (key != null)
                    {
                        string imgPath;
                        if (UrlImagePath.TryGetValue(key, out imgPath))
                        {
                            tvShow.ImageUrl = imgPath;
                        }
                    }
                }

                return(tvShow);
            }
            else if (m_thirdLevelRequest == "details")
            {
                MediaDetail mediaDetails = new MediaDetail();

                while (html.Contains(@"<th scope=""row"">"))
                {
                    string desc  = ParseItem(ref html, @"<th scope=""row"">", @":</th>");
                    string value = ParseItem(ref html, @"<td>", @"</td>");
                    if (value.Contains("</a>"))
                    {
                        value = ParseItem(ref value, @""">", @"</a>");
                    }

                    if (desc == "Seasons")
                    {
                        value = value.Replace(" ", String.Empty);
                    }

                    if (desc.Contains("Genre"))
                    {
                        Regex rgx = new Regex("\\s+");
                        value = rgx.Replace(value, " ");
                    }

                    DetailItem detail = new DetailItem(desc, value);
                    mediaDetails.Details.Add(detail);
                }

                while (html.Contains(@"<td class=""person"">"))
                {
                    html = html.Substring(html.IndexOf(@"<td class=""person"">") +
                                          @"<td class=""person"">".Length);
                    string      name   = ParseItem(ref html, @""">", @"</a>");
                    string      role   = ParseItem(ref html, @"<td class=""role"">", @"</td>");
                    MediaCredit credit = new MediaCredit(name, role);
                    mediaDetails.Credits.Add(credit);
                }

                return(mediaDetails);
            }

            return(null);
        }
Ejemplo n.º 9
0
        public override IMetacriticData Parse(UrlResponsePair urlResponsePair)
        {
            string html = urlResponsePair.Response;

            if (String.IsNullOrEmpty(m_thirdLevelRequest))
            {
                Album album = new Album();
                album.Title         = ParseItem(ref html, @"<h1>", @"</h1>");
                album.PrimaryArtist = ParseItem(ref html, @"<span class=""band_name"" itemprop=""name"">", @"</span>");
                string   releaseDateStr = ParseItem(ref html, @"<span class=""data"" itemprop=""datePublished"">", @"</span>");
                DateTime releaseDate;
                if (DateTime.TryParse(releaseDateStr, out releaseDate))
                {
                    album.ReleaseDate = releaseDate.ToString("MM/dd/yyyy");
                }

                short?criticRating      = null;
                short?criticRatingCount = null;
                if (short.TryParse(ParseItem(ref html, @"<span itemprop=""ratingValue"">", @"</span>"), out short tempCriticRating))
                {
                    criticRating      = tempCriticRating;
                    criticRatingCount = Int16.Parse(ParseItem(ref html, @"<span itemprop=""reviewCount"">", @"</span>"));
                }

                float?userRating      = null;
                short?userRatingCount = null;
                int   userRatingIdx   = html.IndexOf("metascore_w user large");
                if (userRatingIdx != -1)
                {
                    html = html.Substring(userRatingIdx);
                    if (float.TryParse(ParseItem(ref html, @""">", @"</div>"), out float tempUserRating))
                    {
                        userRating      = tempUserRating;
                        userRatingCount = Int16.Parse(ParseItem(ref html, @"user-reviews"">", @" Ratings"));
                    }
                }

                album.Rating = new Rating(criticRating, userRating, criticRatingCount, userRatingCount);

                if (UrlImagePath != null)
                {
                    string imgPath;
                    if (UrlImagePath.TryGetValue(urlResponsePair.Url, out imgPath))
                    {
                        album.ImageUrl = imgPath;
                    }
                }

                return(album);
            }
            else if (m_thirdLevelRequest == "details")
            {
                MediaDetail mediaDetail = new MediaDetail();
                html = html.Substring(html.IndexOf(@"""new_details"""));
                while (html.Contains(@"span class=""label"">"))
                {
                    string desc  = ParseItem(ref html, @"span class=""label"">", @":</span>");
                    string value = string.Empty;

                    int nextIdx;
                    int valueIdx;
                    do
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            value = ParseItem(ref html, @"span class=""data"">", @"</span>");
                        }
                        else
                        {
                            value = string.Format("{0}, {1}", value,
                                                  ParseItem(ref html, @"span class=""data"">", @"</span>"));
                        }

                        nextIdx  = html.IndexOf(@"<span class=""label"">");
                        valueIdx = html.IndexOf(@"span class=""data"">");
                    } while (nextIdx != -1 && valueIdx < nextIdx);

                    DetailItem detail = new DetailItem(desc, value);
                    mediaDetail.Details.Add(detail);
                }

                return(mediaDetail);
            }

            return(null);
        }
Ejemplo n.º 10
0
        private void CompareLocalAndRemoteMediaDetail(MediaDetail localMediaDetail, MediaDetail remoteMediaDetail)
        {
            if (localMediaDetail.CachedVirtualPath != remoteMediaDetail.CachedVirtualPath)
            {
                if (localMediaDetail.ShowInMenu)
                {
                    AddMessage("Url's are different - Show In Menu", $"Local: '{localMediaDetail.CachedVirtualPath}' | Remote: '{remoteMediaDetail.CachedVirtualPath}'");
                }
                else
                {
                    AddMessage("Url's are different", $"Local: '{localMediaDetail.CachedVirtualPath}' | Remote: '{remoteMediaDetail.CachedVirtualPath}'");
                }
            }

            if (localMediaDetail.UseMediaTypeLayouts != remoteMediaDetail.UseMediaTypeLayouts)
            {
                AddMessage("UseMediaTypeLayouts values are different", $"Local: '{localMediaDetail.CachedVirtualPath}' is <strong>'{localMediaDetail.UseMediaTypeLayouts}'</strong> | Remote: '{remoteMediaDetail.CachedVirtualPath}' is <strong>'{remoteMediaDetail.UseMediaTypeLayouts}'</strong>");
            }

            if (localMediaDetail.MediaType.Name != remoteMediaDetail.MediaType.Name)
            {
                AddMessage("Media Types are different", $"Local: '{localMediaDetail.CachedVirtualPath}' is <strong>'{localMediaDetail.MediaType.Name}'</strong> | Remote: '{remoteMediaDetail.CachedVirtualPath}' is <strong>'{remoteMediaDetail.MediaType.Name}'</strong>");
            }

            foreach (var localField in localMediaDetail.Fields)
            {
                var remoteField = remoteMediaDetail.Fields.FirstOrDefault(i => i.FieldCode == localField.FieldCode);

                if (remoteField == null)
                {
                    AddMessage(localMediaDetail.CachedVirtualPath, $"<strong>Missing Field:</strong> {localField.FieldCode}");
                }
                else
                {
                    if (localField.FrontEndLayout != remoteField.FrontEndLayout)
                    {
                        AddMessage(localMediaDetail.CachedVirtualPath, $"<strong>Field</strong> {localField.FieldCode} has a <strong>different FrontEndLayout</strong>");
                    }

                    if (localField.FieldValue != remoteField.FieldValue)
                    {
                        AddMessage(localMediaDetail.CachedVirtualPath, $"<strong>Field</strong> {localField.FieldCode} has a <strong>different Field Value</strong>");
                    }

                    if (localField.FieldSettings != remoteField.FieldSettings)
                    {
                        AddMessage(localMediaDetail.CachedVirtualPath, $"<strong>Field</strong> {localField.FieldCode} has a <strong>different Field FieldSettings</strong>");
                    }
                }
            }

            if (!localMediaDetail.UseMediaTypeLayouts)
            {
                if (localMediaDetail.MainLayout != remoteMediaDetail.MainLayout)
                {
                    AddMessage(localMediaDetail.CachedVirtualPath, $"MainLayout is different");
                }

                if (localMediaDetail.SummaryLayout != remoteMediaDetail.SummaryLayout)
                {
                    AddMessage(localMediaDetail.CachedVirtualPath, $"SummaryLayout is different");
                }

                if (localMediaDetail.FeaturedLayout != remoteMediaDetail.FeaturedLayout)
                {
                    AddMessage(localMediaDetail.CachedVirtualPath, $"FeaturedLayout is different");
                }

                if (localMediaDetail.Media.ParentMediaID != remoteMediaDetail.Media.ParentMediaID)
                {
                    var remoteParent = remoteMediaDetail.Media?.ParentMedia?.GetLiveMediaDetail();

                    if (remoteParent != null)
                    {
                        AddMessage("Moved Pages", $"Parent of the local page is {localMediaDetail.Media.ParentMedia?.GetLiveMediaDetail().CachedVirtualPath} | remote parent is '{remoteParent.CachedVirtualPath}'");
                    }
                }
            }
            else
            {
                if (localMediaDetail.MediaType.MainLayout != remoteMediaDetail.MediaType.MainLayout)
                {
                    AddMessage("MediaType Layouts", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> MainLayout is different");
                }

                if (localMediaDetail.MediaType.SummaryLayout != remoteMediaDetail.MediaType.SummaryLayout)
                {
                    AddMessage("MediaType Layouts", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> SummaryLayout is different");
                }

                if (localMediaDetail.MediaType.FeaturedLayout != remoteMediaDetail.MediaType.FeaturedLayout)
                {
                    AddMessage("MediaType Layouts", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> FeaturedLayout is different");
                }

                foreach (var localField in localMediaDetail.MediaType.Fields)
                {
                    var remoteField = remoteMediaDetail.MediaType.Fields.FirstOrDefault(i => i.FieldCode == localField.FieldCode);

                    if (remoteField == null)
                    {
                        AddMessage("MediaType Fields", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> is <strong>Missing</strong> Media Type Field <strong>'{localField.FieldCode}'</strong>");
                    }
                    else
                    {
                        if (localField.FrontEndLayout != remoteField.FrontEndLayout)
                        {
                            AddMessage("MediaType Fields", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> Media Type Field <strong>'{localField.FieldCode}'</strong> has a <strong>different FrontEndLayout</strong>");
                        }

                        if (localField.FieldValue != remoteField.FieldValue)
                        {
                            AddMessage("MediaType Fields", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> Media Type Field <strong>{localField.FieldCode}</strong> has a <strong>different Field Value</strong>");
                        }

                        if (localField.FieldSettings != remoteField.FieldSettings)
                        {
                            AddMessage("MediaType Fields", $"MediaType <strong>'{localMediaDetail.MediaType.Name}'</strong> Media Type Field <strong>{localField.FieldCode}</strong> has a <strong>different Field FieldSettings</strong>");
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public override IMetacriticData Parse(UrlResponsePair urlResponsePair)
        {
            string html = urlResponsePair.Response;

            if (String.IsNullOrEmpty(m_thirdLevelRequest))
            {
                Movie movie      = new Movie();
                int   startIndex = html.IndexOf(@"<script type=""application/ld+json"">");
                if (startIndex != -1)
                {
                    string infoString = html.Substring(startIndex);
                    int    endIndex   = infoString.IndexOf(@"</script>");
                    if (endIndex != -1)
                    {
                        infoString  = infoString.Substring(0, endIndex);
                        movie.Title = ParseItem(ref infoString, @"""name"" : """, @"""");

                        string   releaseDateStr = ParseItem(ref infoString, @"""datePublished"" : """, @"""");
                        DateTime releaseDate;
                        if (DateTime.TryParse(releaseDateStr, out releaseDate))
                        {
                            movie.ReleaseDate = releaseDate.ToString("MM/dd/yyyy");;
                        }

                        short?criticRating      = null;
                        short?criticRatingCount = null;
                        if (infoString.Contains(@"""ratingValue"" : """))
                        {
                            if (short.TryParse(ParseItem(ref infoString, @"""ratingValue"" : """, @""""), out short tempCriticRating))
                            {
                                criticRating      = tempCriticRating;
                                criticRatingCount = Int16.Parse(ParseItem(ref infoString, @"""ratingCount"" : """, @""""));
                            }

                            // Critic
                            html = html.Substring(html.IndexOf("Critics</span>"));
                        }

                        // User
                        float?userRating      = null;
                        short?userRatingCount = null;
                        if (html.Contains(@">based on "))
                        {
                            html = html.Substring(html.IndexOf(">based on "));

                            if (short.TryParse(ParseItem(ref html, @">based on ", " Ratings"), out short tempUserRatingCount))
                            {
                                userRatingCount = tempUserRatingCount;
                                html            = html.Substring(html.IndexOf("metascore_w user"));
                                userRating      = float.Parse(ParseItem(ref html, @">", @"</span>"));
                            }
                        }

                        movie.Rating = new Rating(criticRating, userRating, criticRatingCount, userRatingCount);


                        infoString     = infoString.Substring(infoString.IndexOf(@"""director"""));
                        movie.Director = ParseItem(ref infoString, @"""name"": """, @"""");
                    }
                }

                if (UrlImagePath != null)
                {
                    string imgPath;
                    if (UrlImagePath.TryGetValue(urlResponsePair.Url, out imgPath))
                    {
                        movie.ImageUrl = imgPath;
                    }
                }

                return(movie);
            }
            else if (m_thirdLevelRequest == "details")
            {
                MediaDetail mediaDetail = new MediaDetail();
                while (html.Contains(@"<td class=""label"">"))
                {
                    string desc  = ParseItem(ref html, @"<td class=""label"">", @":</td>");
                    string value = ParseItem(ref html, @"<td class=""data"">", @"</td>");
                    if (value.Contains("</a>"))
                    {
                        value = ParseItem(ref value, @""">", @"</a>");
                    }

                    if (value.Contains("<span>"))
                    {
                        value = value.Replace("<span>", "").Replace("</span>", "");
                    }

                    if (desc == "Genres" || desc == "Languages" || desc == "Countries")
                    {
                        Regex rgx = new Regex("\\s+");
                        value = rgx.Replace(value, " ");
                    }

                    DetailItem detail = new DetailItem(desc, value);
                    mediaDetail.Details.Add(detail);
                }

                while (html.Contains(@"<td class=""person"">"))
                {
                    string name = ParseItem(ref html, @"<td class=""person"">", @"</td>");
                    if (name.Contains("</a>"))
                    {
                        name = ParseItem(ref name, @""">", @"</a>");
                    }

                    string role = ParseItem(ref html, @"<td class=""role"">", @"</td>");

                    MediaCredit credit = new MediaCredit(name, role);
                    mediaDetail.Credits.Add(credit);
                }

                return(mediaDetail);
            }

            return(null);
        }