Beispiel #1
0
        /// <summary>
        /// Generate a Number of Paragraphs
        /// </summary>
        /// <param name="Kind"></param>
        /// <param name="ParagraphsNumber"></param>
        /// <param name="Language"></param>
        /// <returns></returns>
        public static string GenerateParagraphs(Kinds Kind, int ParagraphsNumber, Languages Language = Languages.English)
        {
            //Se il numero di paragrafi è minore di 1 torno vuoto
            if (ParagraphsNumber < 1)
            {
                return("");
            }

            int minWordsInParagraph = 70;
            int maxWordsInParagraph = 110;

            string resp = String.Empty;

            for (int i = 0; i < ParagraphsNumber; i++)
            {
                if (resp != String.Empty)
                {
                    resp = resp + Environment.NewLine + Environment.NewLine + WordsHelper.FirstCharToUpper(GenerateText(Kind,
                                                                                                                        random.Next(minWordsInParagraph, maxWordsInParagraph), Language));
                }
                else
                {
                    //primo passaggio, non metto il separatore
                    resp = resp + WordsHelper.FirstCharToUpper(GenerateText(Kind, random.Next(minWordsInParagraph, maxWordsInParagraph), Language)) + ".";
                }
            }
            return(resp);
        }
Beispiel #2
0
        /// <summary>
        /// Return a text
        /// </summary>
        /// <param name="Kind"></param>
        /// <param name="WordsNumber"></param>
        /// <param name="Language"></param>
        /// <param name="UseSeparatorLogic"></param>
        /// <returns></returns>
        public static string GenerateText(Kinds Kind, int?WordsNumber = null, Languages Language = Languages.English,
                                          bool UseSeparatorLogic      = true)
        {
            //Se il numero di parole è negativo torno vuoto
            if (WordsNumber.HasValue)
            {
                if (WordsNumber.Value < 1)
                {
                    return("");
                }
            }

            //Recupero le parole
            var words = GetWords(Kind, Language);

            //torno tutte le parole
            if (WordsNumber == null)
            {
                if (UseSeparatorLogic)
                {
                    string resp = String.Empty;
                    foreach (var word in words)
                    {
                        if (resp != String.Empty)
                        {
                            var separator = GetSeparator();

                            if (separator.Contains("."))
                            {
                                resp = resp + separator + WordsHelper.FirstCharToUpper(word.ToLower());
                            }
                            else
                            {
                                resp = resp + separator + word.ToLower();
                            }
                        }
                        else
                        {
                            //primo passaggio, non metto il separatore
                            resp = resp + word.ToLower();
                        }
                    }
                    return(WordsHelper.FirstCharToUpper(resp).Trim());
                }
                else
                {
                    return(WordsHelper.FirstCharToUpper(string.Join(" ", words.ToArray())).Trim());
                }
            }

            //torno solo 1 parola
            if (WordsNumber == 1)
            {
                return(WordsHelper.FirstCharToUpper(words[random.Next(0, words.Count - 1)].ToLower()).Trim());
            }

            //Torno il numero di parole specificato
            if (UseSeparatorLogic)
            {
                string resp = String.Empty;
                for (int i = 0; i < WordsNumber; i++)
                {
                    if (resp != String.Empty)
                    {
                        var separator = GetSeparator();
                        if (separator.Contains("."))
                        {
                            resp = resp + separator + WordsHelper.FirstCharToUpper(words[random.Next(0, words.Count - 1)].ToLower());
                        }
                        else
                        {
                            resp = resp + separator + words[random.Next(0, words.Count - 1)].ToLower();
                        }
                    }
                    else
                    {
                        //primo passaggio, non metto il separatore
                        resp = resp + words[random.Next(0, words.Count - 1)].ToLower();
                    }
                }
                return(WordsHelper.FirstCharToUpper(resp).Trim());
            }
            else
            {
                string resp = String.Empty;
                for (int i = 0; i < WordsNumber; i++)
                {
                    resp = resp + words[random.Next(0, words.Count - 1)].ToLower() + " ";
                }
                return(WordsHelper.FirstCharToUpper(resp).Trim());
            }
        }