Exemplo n.º 1
0
        static public async Task <CommunityNewsViewModel> Create(
            string communityId,
            string title,
            string authorName,
            DateTime postAt,
            string contentHtml,
            PageManager pageManager,
            AppearanceSettings appearanceSettings
            )
        {
            ApplicationTheme appTheme;

            if (appearanceSettings.ApplicationTheme == ElementTheme.Dark)
            {
                appTheme = ApplicationTheme.Dark;
            }
            else if (appearanceSettings.ApplicationTheme == ElementTheme.Light)
            {
                appTheme = ApplicationTheme.Light;
            }
            else
            {
                appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme();
            }

            var id  = $"{communityId}_{postAt.ToString("yy-MM-dd-H-mm")}";
            var uri = await HtmlFileHelper.PartHtmlOutputToCompletlyHtml(id, contentHtml, appTheme);

            return(new CommunityNewsViewModel(communityId, title, authorName, postAt, uri, pageManager));
        }
Exemplo n.º 2
0
        //
        public async Task <Uri> MakeLiveSummaryHtmlUri()
        {
            if (PlayerStatusResponse == null)
            {
                return(null);
            }

            var desc = PlayerStatusResponse.Program.Description;

            return(await HtmlFileHelper.PartHtmlOutputToCompletlyHtml(LiveId, desc));
        }
Exemplo n.º 3
0
        public ActionResult GetFileContent(string filePathEnglish, string languageCode)
        {
            try
            {
                if (!System.IO.File.Exists(HttpUtility.UrlDecode(filePathEnglish)))
                {
                    return(Json
                           (
                               new
                    {
                        BodyContent = "No File Selected",
                        BodyContentEnglish = "No File Selected",
                        Path = "",
                        PathEnglish = "",
                        HtmlTitle = "No File Selected",
                    }
                               , JsonRequestBehavior.AllowGet));
                }


                // Get the english path from the multilingual path if necessary
                List <Language> languageList     = Language.GetLanguages(Request.PhysicalApplicationPath + "LanguagesConfig.xml");
                var             selectedLanguage = languageList.Find(i => i.Id == languageCode);
                var             pathEditFile     = "";
                pathEditFile = GetMultilingualPath(selectedLanguage, filePathEnglish);

                var htmlTitle          = "";
                var htmlTitleEnglish   = "";
                var bodyContent        = "";
                var bodyContentEnglish = "";

                if (System.IO.File.Exists(HttpUtility.UrlDecode(pathEditFile)))
                {
                    bodyContent = System.IO.File.ReadAllText(pathEditFile);
                    htmlTitle   = HtmlFileHelper.GetTitle(bodyContent);
                    // Only load the English read only content if necessary
                    if (selectedLanguage.Name.ToLower() != "english")
                    {
                        bodyContentEnglish = System.IO.File.ReadAllText(filePathEnglish);
                        htmlTitleEnglish   = HtmlFileHelper.GetTitle(bodyContentEnglish);
                    }
                }
                else
                {
                    // TODO Spanish note below
                    bodyContent = "Note: Spanish is not ready yet. ERROR: Multilingual file does not exist: " + pathEditFile;
                }

                return(Json
                       (
                           new
                {
                    BodyContent = bodyContent,
                    BodyContentEnglish = bodyContentEnglish,
                    Path = pathEditFile,
                    PathEnglish = filePathEnglish,
                    HtmlTitle = htmlTitle,
                    HtmlTitleEnglish = htmlTitleEnglish,
                }
                           , JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var log = new LogFile();
                log.LogLine("Home Controller GetFileContent Error: ", "Message: " + ex.Message + "Source: " + ex.Source);

                return(Json
                       (
                           new
                {
                    BodyContent = "Error loading file content: " + filePathEnglish,
                }
                           , JsonRequestBehavior.AllowGet));
            }
        }
        private async Task RefreshHtmlDescriptionAsync(string htmlDescription)
        {
            if (htmlDescription != null)
            {
                ApplicationTheme appTheme;
                if (_appearanceSettings.ApplicationTheme == ElementTheme.Dark)
                {
                    appTheme = ApplicationTheme.Dark;
                }
                else if (_appearanceSettings.ApplicationTheme == ElementTheme.Light)
                {
                    appTheme = ApplicationTheme.Light;
                }
                else
                {
                    appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme();
                }

                HtmlDescription = await HtmlFileHelper.ToCompletlyHtmlAsync(htmlDescription, appTheme);

                try
                {
                    HtmlParser htmlParser = new HtmlParser();
                    using var document = await htmlParser.ParseDocumentAsync(htmlDescription);

                    var anchorNodes = document.QuerySelectorAll("a");

                    foreach (var anchor in anchorNodes)
                    {
                        var    url   = new Uri(anchor.Attributes["href"].Value);
                        string label = null;
                        var    text  = anchor.TextContent;
                        if (string.IsNullOrWhiteSpace(text) || text.Contains('\n') || text.Contains('\r'))
                        {
                            label = url.OriginalString;
                        }
                        else
                        {
                            label = new string(anchor.TextContent.TrimStart(' ', '\n', '\r').TakeWhile(c => c != ' ' || c != ' ').ToArray());
                        }

                        DescriptionHyperlinkItems.Add(new HyperlinkItem()
                        {
                            Label = label,
                            Url   = url
                        });

                        Debug.WriteLine($"{anchor.TextContent} : {anchor.Attributes["href"].Value}");
                    }

                    /*
                     * var matches = GeneralUrlRegex.Matches(HtmlDescription);
                     * foreach (var match in matches.Cast<Match>())
                     * {
                     *  if (!VideoDescriptionHyperlinkItems.Any(x => x.Url.OriginalString == match.Value))
                     *  {
                     *      VideoDescriptionHyperlinkItems.Add(new HyperlinkItem()
                     *      {
                     *          Label = match.Value,
                     *          Url = new Uri(match.Value)
                     *      });
                     *
                     *      Debug.WriteLine($"{match.Value} : {match.Value}");
                     *  }
                     * }
                     */

                    OnPropertyChanged(nameof(DescriptionHyperlinkItems));
                }
                catch
                {
                    Debug.WriteLine("動画説明からリンクを抜き出す処理に失敗");
                }
            }
        }