Example #1
0
        private static string FormatLetters(char character, int index, GenDataTransfer options)
        {
            string output = string.Empty;

            if (index == 0)
            {
                switch (options.Output)
                {
                case TextOutput.HTML:
                    output += "<p>";
                    break;

                default:
                    break;
                }
            }

            output += character;

            if (index == options.Quantity - 1)
            {
                switch (options.Output)
                {
                case TextOutput.HTML:
                    output += "</p>";
                    break;

                default:
                    break;
                }
            }

            return(output);
        }
Example #2
0
        private static string FormatWords(string text, int index, GenDataTransfer options)
        {
            string output = string.Empty;

            if (index == 0)
            {
                switch (options.Output)
                {
                case TextOutput.HTML:
                    output += "<p>";
                    break;

                default:
                    break;
                }
            }

            output += string.Format("{0}{1}", text, index == options.Quantity - 1 ? "" : " ");

            if (index == options.Quantity - 1)
            {
                switch (options.Output)
                {
                case TextOutput.HTML:
                    output += "</p>";
                    break;

                default:
                    break;
                }
            }

            return(output);
        }
Example #3
0
        private static IOutput GenerateTextItem(GenDataTransfer options, int index)
        {
            IOutput output;

            int iterationIndex = index;
            int textIndex      = 0;

            while (iterationIndex >= Count(Texts.text[textIndex], options.Type))
            {
                iterationIndex -= Count(Texts.text[textIndex], options.Type);
                if (textIndex < Texts.text.Length - 1)
                {
                    textIndex++;
                }
                else
                {
                    textIndex = 0;
                }
            }

            switch (options.Type)
            {
            case GenerateType.Lists:
                Lists lists = new Lists();
                if (options.TitleOption == TitleOptions.WithTitles)
                {
                    if (iterationIndex == 0)
                    {
                        lists.Title = Texts.titles[textIndex];
                    }
                }
                lists.ListItems.Add(GetTextLine(Texts.text[textIndex], iterationIndex));
                output = lists;
                break;

            case GenerateType.Paragraphs:
                Paragraphs paragraph = new Paragraphs();
                if (options.TitleOption == TitleOptions.WithTitles)
                {
                    if (iterationIndex == 0)
                    {
                        paragraph.Title = Texts.titles[textIndex];
                    }
                }
                paragraph.Body.Add(GetParagraph(Texts.text[textIndex], iterationIndex));
                output = paragraph;
                break;

            default:
                throw new ArgumentOutOfRangeException("Options - Type", "Not a valid text type.");
            }

            return(output);
        }
Example #4
0
        private static string GenerateSegment(GenDataTransfer options, int index)
        {
            string output = string.Empty;

            int iterationIndex = index;
            int textIndex      = 0;

            while (iterationIndex >= Count(Texts.text[textIndex], options.Type))
            {
                iterationIndex -= Count(Texts.text[textIndex], options.Type);
                if (textIndex < Texts.text.Length - 1)
                {
                    textIndex++;
                }
                else
                {
                    textIndex = 0;
                }
            }

            if (options.TitleOption == TitleOptions.WithTitles)
            {
                if (iterationIndex == 0)
                {
                    output += FormatTitle(Texts.titles[textIndex], index, options);
                }
            }

            switch (options.Type)
            {
            case GenerateType.Letters:
                output += FormatLetters(Texts.text[textIndex][iterationIndex], index, options);
                break;

            case GenerateType.Lists:
                bool start = iterationIndex == 0 ? true : false;
                bool end   = iterationIndex == CountLines(Texts.text[textIndex]) - 1 || index == options.Quantity - 1 ? true : false;
                output += FormatLists(GetTextLine(Texts.text[textIndex], iterationIndex), index, start, end, options);
                break;

            case GenerateType.Paragraphs:
                output += FormatParagraphs(GetParagraph(Texts.text[textIndex], iterationIndex), index, options);
                break;

            default:
                output += FormatWords(GetWord(Texts.text[textIndex], iterationIndex), index, options);
                break;
            }

            return(output);
        }
Example #5
0
        private static string GenerateText(GenDataTransfer options)
        {
            string output = string.Empty;

            for (int i = 0; i < options.Quantity; i++)
            {
                output += GenerateSegment(options, i);
            }
            if (options.Quantity == 0)
            {
                return(string.Empty);
            }
            return(StringEndFormat(output));
        }
Example #6
0
        public static string Generate(GenDataTransfer options)
        {
            string output = string.Empty;

            switch (options.Output)
            {
            //case TextOutput.XML:
            case TextOutput.Json:
                output = GenerateObject(options);
                break;

            default:
                output = GenerateText(options);
                break;
            }

            return(output);
        }
Example #7
0
        private static string FormatParagraphs(string text, int index, GenDataTransfer options)
        {
            string output = string.Empty;

            switch (options.Output)
            {
            case TextOutput.HTML:
                output += string.Format("{1}<p>{0}</p>\n", text, options.TitleOption == TitleOptions.WithTitles ? "\t" : "");
                break;

            case TextOutput.Raw:
                output += string.Format("{0}\n", text);
                break;

            default:
                throw new ArgumentOutOfRangeException("Options - Output Format", "Not a valid output format.");
            }

            return(output);
        }
Example #8
0
        private static string FormatTitle(string text, int index, GenDataTransfer options)
        {
            string output = string.Empty;

            switch (options.Output)
            {
            case TextOutput.HTML:
                output += string.Format("<h2>{0}</h2>\n", text);
                break;

            case TextOutput.Raw:
                output += string.Format("{0}\n", text);
                break;

            default:
                throw new ArgumentOutOfRangeException("Options - Output Format", "Not a valid output format.");
            }

            return(output);
        }
Example #9
0
        private static string GenerateObject(GenDataTransfer options)
        {
            Output output = new Output();

            switch (options.Type)
            {
            case GenerateType.Paragraphs:
            case GenerateType.Lists:
                string        title = string.Empty;
                List <string> list  = new List <string>();
                for (int i = 0; i < options.Quantity; i++)
                {
                    int iterationIndex = i;
                    int textIndex      = 0;
                    while (iterationIndex >= Count(Texts.text[textIndex], options.Type))
                    {
                        iterationIndex -= Count(Texts.text[textIndex], options.Type);
                        if (textIndex < Texts.text.Length - 1)
                        {
                            textIndex++;
                        }
                        else
                        {
                            textIndex = 0;
                        }
                    }
                    if (iterationIndex == 0)
                    {
                        list = new List <string>();
                        if (options.TitleOption == TitleOptions.WithTitles)
                        {
                            title = Texts.titles[textIndex];
                        }
                    }
                    if (options.Type == GenerateType.Paragraphs)
                    {
                        list.Add(GetParagraph(Texts.text[textIndex], iterationIndex));
                    }
                    else
                    {
                        list.Add(GetTextLine(Texts.text[textIndex], iterationIndex));
                    }
                    if (iterationIndex == Count(Texts.text[textIndex], options.Type) - 1 || i == options.Quantity - 1)
                    {
                        if (options.Type == GenerateType.Paragraphs)
                        {
                            Paragraphs item = new Paragraphs
                            {
                                Title = title,
                                Body  = list
                            };
                            output.Text.Add(item);
                        }
                        else
                        {
                            Lists item = new Lists
                            {
                                Title     = title,
                                ListItems = list
                            };
                            output.Text.Add(item);
                        }
                    }
                }
                break;

            default:
                string body = string.Empty;
                for (int i = 0; i < options.Quantity; i++)
                {
                    body += GenerateSegment(options, i);
                }
                switch (options.Type)
                {
                case GenerateType.Words:
                    output.Text.Add(new Words
                    {
                        Body = StringEndFormat(body)
                    });
                    break;

                case GenerateType.Letters:
                    output.Text.Add(new Letters
                    {
                        Body = StringEndFormat(body)
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Option - Type", "Not a valid text type.");
                }
                break;
            }


            switch (options.Output)
            {
            //case TextOutput.XML:
            //    using (StringWriter reader = new StringWriter())
            //    {
            //        Type[] childrenTypes = { typeof(Letters), typeof(Words), typeof(Paragraphs), typeof(Lists) };
            //        XmlSerializer xml = new XmlSerializer(typeof(Output), childrenTypes);
            //        xml.Serialize(reader, output);
            //        return reader.ToString();
            //    }
            case TextOutput.Json:
                return(JsonConvert.SerializeObject(output, Formatting.Indented));

            default:
                throw new ArgumentOutOfRangeException("Options - Output Format", "Not a valid output format.");
            }
        }
Example #10
0
        private static string FormatLists(string text, int index, bool isListStart, bool isListEnd, GenDataTransfer options)
        {
            string output = string.Empty;

            switch (options.Output)
            {
            case TextOutput.HTML:
                output += string.Format("{1}\t<li>{0}</li>\n{2}", text, isListStart ? "<ul>\n" : "", isListEnd ? "</ul>\n" : "");
                break;

            case TextOutput.Raw:
                output += string.Format("- {0}\n", text);
                break;

            default:
                throw new ArgumentOutOfRangeException("Options - Output Format", "Not a valid output format.");
            }

            return(output);
        }