/// <summary>
        /// This view will be rendered if answer is in the URL string.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> MyContent()
        {
            var culture     = this.Culture;
            var requestPath = this.RequestPathNoCulture;
            // Now try to parse the request path into known words.
            var commonStrings = _resourcesService.GetCommonStrings(culture);
            var answer        = LinkingHelper.ParseUrlToAnswer(commonStrings, requestPath);

            // Were we able to parse?
            if (answer == null)
            {
                return(RedirectToAction("Index"));
            }
            // Let's try to find that answer
            answer = await _answerService.FindExact(answer.LeftWord, answer.RightWord, answer.Phrase);

            // Go to home index if not found
            if (answer == null)
            {
                return(RedirectToAction("Index"));
            }
            // Get data
            var answerDetails = FillInDetails(answer, _answerDescriptionService, _userService, _voteService, _resourcesService,
                                              culture, _appSettings.Value.FullDomainAddress);

            // Do a bit more playing with data
            answerDetails.EnableFacebookSharing = _appSettings.Value.EnableFacebookSharing;

            answerDetails.DebugReactControls = ReadUrlParameterAsBoolean(DEBUG_REACTJS_URL_PARAMETER_NAME);

            return(View(answerDetails));
        }
        public void LinkingHelperTests_Nulls_ReturnsNull()
        {
            var answerDto = new AnswerDto()
            {
                LeftWord  = "a",
                RightWord = "b",
                Phrase    = "c"
            };

            var result = LinkingHelper.ParseUrlToAnswer(null);

            Assert.Null(result);

            result = LinkingHelper.ParseUrlToAnswer("    ");
            Assert.Null(result);

            result = LinkingHelper.ParseUrlToAnswer("random");
            Assert.Null(result);

            result = LinkingHelper.ParseUrlToAnswer(null, null);
            Assert.Null(result);

            result = LinkingHelper.ParseUrlToAnswer(null, "    ");
            Assert.Null(result);

            var commonStrings = new CommonStringsDto()
            {
                Best = "x", For = "y", Is = "z"
            };

            result = LinkingHelper.ParseUrlToAnswer(commonStrings, "random");
            Assert.Null(result);
        }
        public void LinkingHelperTests_ParseUrlToAnswer_Parses()
        {
            var answerDto = new AnswerDto()
            {
                LeftWord  = "a",
                RightWord = "b",
                Phrase    = "c"
            };

            var url = "/best-a-for-b-is-c";

            var result = LinkingHelper.ParseUrlToAnswer(url);

            Assert.Equal(result.LeftWord, answerDto.LeftWord);
            Assert.Equal(result.RightWord, answerDto.RightWord);
            Assert.Equal(result.Phrase, answerDto.Phrase);

            var commonStrings = new CommonStringsDto()
            {
                Best = "x", For = "y", Is = "z"
            };

            url = "/x-a-y-b-z-c";

            result = result = LinkingHelper.ParseUrlToAnswer(commonStrings, url);
            Assert.Equal(result.LeftWord, answerDto.LeftWord);
            Assert.Equal(result.RightWord, answerDto.RightWord);
            Assert.Equal(result.Phrase, answerDto.Phrase);
        }
        public void LinkingHelperTests_ConvertAnswerToUrl_Converts()
        {
            var answerDto = new AnswerDto()
            {
                LeftWord  = "a",
                RightWord = "b",
                Phrase    = "c"
            };

            var result = LinkingHelper.ConvertAnswerToUrl(answerDto);

            Assert.Equal(result, "/best-a-for-b-is-c");

            result = LinkingHelper.ConvertAnswerToText(answerDto);

            Assert.Equal(result, "Best a for b is c");

            var commonStrings = new CommonStringsDto()
            {
                Best = "x", For = "y", Is = "z"
            };

            result = LinkingHelper.ConvertAnswerToText(commonStrings, answerDto);
            Assert.Equal(result, "x a y b z c");

            result = LinkingHelper.ConvertAnswerToUrl(commonStrings, answerDto);
            Assert.Equal(result, "/x-a-y-b-z-c");

            result = LinkingHelper.ConvertAnswerToUrlWithCulture("f", commonStrings, answerDto);
            Assert.Equal(result, "/f/x-a-y-b-z-c");
        }
        public ChatClientManager()
        {
            SearchRange         = 30;
            ChatClients         = new Dictionary <IPAddress, ChatClient>();
            ReadOnlyChatClients = ChatClients;

            LinkingHelper = new LinkingHelper(ChatClients);
        }
        public void LinkingHelper_ParseAnswerUrl_Fail()
        {
            string data = "/best-girl-f or-the-dance-is-alice";

            var answer = LinkingHelper.ParseUrlToAnswer(data);

            Assert.Null(answer);
        }
        public void LinkingHelper_ParseAnswerUrl_Success()
        {
            string data = "/best-girl-for-the-dance-is-alice";

            var answer = LinkingHelper.ParseUrlToAnswer(data);

            Assert.Equal(answer.LeftWord, "girl");
            Assert.Equal(answer.RightWord, "the dance");
            Assert.Equal(answer.Phrase, "alice");
        }
        /// <summary>
        /// Fill in answer details for content page.
        /// Reuse the logic between controllers. Also used by AnswerActionController.
        /// </summary>
        /// <param name="answer"></param>
        /// <param name="answerDescriptionService"></param>
        /// <param name="userManager"></param>
        /// <param name="voteService"></param>
        /// <param name="resourcesService"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public static AnswerDetailsDto FillInDetails(AnswerDto answer, IAnswerDescriptionService answerDescriptionService,
                                                     IUserService userService, IVoteService voteService, IResourcesService resourcesService, string culture, string fullDomainName)
        {
            // Load answer descriptions
            // Have to do the list otherwise setting description.UserDisplayName below will not work.
            var searchResult = answerDescriptionService.FindByAnswerId(answer.Id);
            List <AnswerDescriptionDto> descriptions = searchResult == null ? null : searchResult.ToList();

            // Set the username for each description
            if (descriptions != null)
            {
                foreach (var description in descriptions)
                {
                    GetUserDisplayName(description, userService);
                }
            }

            // Fill in result
            var data = new AnswerDetailsDto()
            {
                Answer        = answer,
                CommonStrings = resourcesService.GetCommonStrings(culture),
                Descriptions  = descriptions,
                NumberVotes   = voteService.CountAnswerVotes(answer.Id)
            };

            GetUserDisplayName(data.Answer, userService);

            // Fill in link to this page and other usefull data.
            data.ThisAnswerLink            = LinkingHelper.ConvertAnswerToUrlWithCulture(culture, data.CommonStrings, answer);
            data.ThisAnswerFullLink        = fullDomainName.EndsWith("/") ? fullDomainName.Substring(0, fullDomainName.Length - 1) : fullDomainName + data.ThisAnswerLink;
            data.ThisAnswerText            = LinkingHelper.ConvertAnswerToText(data.CommonStrings, answer);
            data.ThisAnswerFullLinkEscaped = System.Uri.EscapeDataString(data.ThisAnswerFullLink);

            return(data);
        }
Example #9
0
        public ActionResult RegenerateAllEpisodeLinks()
        {
            try
            {
                using (var upd = Repo.Instance.CrossRef_AniDB_Provider.BeginBatchUpdate(() => Repo.Instance.CrossRef_AniDB_Provider.GetByType(Shoko.Models.Enums.CrossRefType.TvDB)))
                {
                    foreach (SVR_CrossRef_AniDB_Provider p in upd)
                    {
                        p.EpisodesList.DeleteAllUnverifiedLinks();
                        if (p.EpisodesList.NeedPersitance)
                        {
                            p.EpisodesList.Persist();
                            upd.Update(p);
                        }
                    }
                    upd.Commit();
                }
                Repo.Instance.AnimeSeries.GetAll().ToList().AsParallel().ForAll(animeseries => LinkingHelper.GenerateEpisodeMatches(animeseries.AniDB_ID, Shoko.Models.Enums.CrossRefType.TvDB, true));
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(APIStatus.InternalError(e.Message));
            }

            return(APIStatus.OK());
        }
Example #10
0
 public List <CrossRef_AniDB_ProviderEpisode> GetTraktEpisodeMatchPreview(int animeID, string traktID)
 {
     return(LinkingHelper.GetMatchPreviewWithOverrides(animeID, traktID, CrossRefType.TraktTV));
 }
Example #11
0
 public List <CrossRef_AniDB_ProviderEpisode> GetTvDBEpisodeMatchPreview(int animeID, int tvdbID)
 {
     return(LinkingHelper.GetMatchPreviewWithOverrides(animeID, tvdbID.ToString(), CrossRefType.TvDB));
 }