internal string GenerateMessage()
        {
            Logger.LogInformation(Name, $"generating message for word {{{Definition}}}", Logger.Method.Start);

            var sb = new StringBuilder();
            var hr = new string('-', 39);

            sb.Append($"{hr}\n");

            if (Definition != null)
            {
                sb.Append($"\nNEW WORD\n{Definition}\n\n");
                sb.Append($"{hr}\n");
            }

            if (PhoneticSpelling != null)
            {
                sb.Append($"\nPHONETIC SPELLING\n{PhoneticSpelling}\n\n");
                sb.Append($"{hr}\n");
            }

            if (Etymologies?.Any() ?? false)
            {
                sb.Append("\nETYMOLOGIES\n");
                foreach (var etymology in Etymologies)
                {
                    sb.Append($"\u2022 {etymology}\n\n");
                }
                sb.Append($"{hr}\n");
            }

            if (Senses?.Any() ?? false)
            {
                sb.Append("\nSENSES\n");
                foreach (var sense in Senses)
                {
                    sb.Append($"\u2022 {sense}\n\n");
                }
                sb.Append($"{hr}\n");
            }

            if (SubSenses?.Any() ?? false)
            {
                sb.Append("\nSUBSENSES\n");
                foreach (var subSense in SubSenses)
                {
                    sb.Append($"\u2022 {subSense}\n\n");
                }
                sb.Append($"{hr}\n");
            }

            if (AudioFile != null)
            {
                sb.Append($"\nAUDIO\n{AudioFile}\n\n");
                sb.Append($"{hr}\n");
            }

            Logger.LogInformation(Name, $"generating message for word {{{Definition}}}", Logger.Method.End);

            return(sb.ToString());
        }
예제 #2
0
        public string GenerateHtmlString()
        {
            var sb = new StringBuilder();

            sb.Append("<!DOCTYPE html><html><head><meta charset='utf-8'></head><body>");

            if (Correct)
            {
                sb.Append($"<h2>Requested word: {Word}</h2></br>");
                sb.Append("<label style='color: gray;'>Etymologies</label>");

                if (Etymologies?.Any() ?? false)
                {
                    sb.Append("<ul>");
                    foreach (var etymologie in Etymologies)
                    {
                        if (etymologie != null)
                        {
                            sb.Append($"<li>{etymologie}</li>");
                        }
                    }
                    sb.Append("</ul>");
                }
                else
                {
                    sb.Append("<p>No data</p>");
                }

                sb.Append("<label style='color: gray;'>Senses</label>");

                if (Senses?.Any() ?? false)
                {
                    sb.Append("<ul>");
                    foreach (var sense in Senses)
                    {
                        if (sense != null)
                        {
                            sb.Append($"<li>{sense}</li>");
                        }
                    }
                    sb.Append("</ul>");
                }
                else
                {
                    sb.Append("<p>No data</p>");
                }

                sb.Append("<label style='color: gray;'>Subsenses</label>");

                if (Subsenses?.Any() ?? false)
                {
                    sb.Append("<ul>");
                    foreach (var subsense in Subsenses)
                    {
                        if (subsense != null)
                        {
                            sb.Append($"<li>{subsense}</li>");
                        }
                    }
                    sb.Append("</ul>");
                }
                else
                {
                    sb.Append("<p>No data</p>");
                }
            }
            else
            {
                sb.Append(String.IsNullOrEmpty(Word)
                    ? "<h2 style='color: red;'>You requested empty string</h2>"
                    : $"<h2 style='color: red;'>Request failed with word: {Word}</h2>");

                sb.Append($"<p><strong>Error message: </strong>{ErrorMessage}</p>");
            }

            sb.Append($"<h4>Requested date: {DateTime.Now.ToShortDateString()}</h4>");
            sb.Append("</body></html>");

            return(sb.ToString());
        }