Acceleratio.SPDG.Generator.SampleData.GetSampleValueRandom C# (CSharp) Method

GetSampleValueRandom() public static method

public static GetSampleValueRandom ( IList sampleCollection ) : string
sampleCollection IList
return string
        public static string GetSampleValueRandom(IList<string> sampleCollection)
        {
            try
            {
                int randomNumber = _randomGen.Next(0, sampleCollection.Count - 1);

                return sampleCollection[randomNumber];
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

Usage Example

Exemplo n.º 1
0
        internal static byte[] CreatePDF(int minKB, int maxKB)
        {
            PdfDocument pdfDoc = new PdfDocument();

            pdfDoc.Info.Title   = "SPDG created document";
            pdfDoc.Info.Author  = "SPDG";
            pdfDoc.Info.Subject = "Sample SharePoint document";

            PdfPage page = pdfDoc.AddPage();

            page.Orientation = PdfSharp.PageOrientation.Portrait;
            XGraphics gfx = XGraphics.FromPdfPage(page);


            DrawText(gfx, 30, 30, page.Width, 20, XFontStyle.Bold, 20, SampleData.GetSampleValueRandom(SampleData.BusinessDocsTypes));

            DrawText(gfx, 30, 60, page.Width, 20, XFontStyle.Regular, 12, "Date: " + SampleData.GetRandomDate(1990, 2015).ToShortDateString());
            DrawText(gfx, 30, 80, page.Width, 20, XFontStyle.Regular, 12, "Author: " + SampleData.GetSampleValueRandom(SampleData.FirstNames) + " " + SampleData.GetSampleValueRandom(SampleData.LastNames));
            DrawText(gfx, 30, 100, page.Width - 60, 20, XFontStyle.Regular, 12, "ID: " + SampleData.GetRandomNumber(100000, 1000000).ToString());

            string lore = File.ReadAllText("SampleData\\loreIpsum.txt");

            DrawText(gfx, 30, 120, page.Width, page.Height - 100, XFontStyle.Regular, 12, lore);
            gfx.Dispose();

            int minRepeat   = minKB / 13;
            int maxRepeat   = maxKB / 13;
            int finalRepeat = 1;

            if (minRepeat > 20 && maxRepeat > 20 && minRepeat < maxKB)
            {
                finalRepeat = SampleData.GetRandomNumber(minRepeat, maxRepeat);
            }

            for (int i = 0; i < finalRepeat; i++)
            {
                page             = pdfDoc.AddPage();
                page.Orientation = PdfSharp.PageOrientation.Portrait;
                gfx = XGraphics.FromPdfPage(page);
                DrawText(gfx, 30, 30, page.Width - 60, page.Height - 100, XFontStyle.Regular, 12, lore);
                gfx.Dispose();
            }

            MemoryStream memoryStream = new MemoryStream();

            pdfDoc.Save(memoryStream);

            return(memoryStream.ToArray());
        }
All Usage Examples Of Acceleratio.SPDG.Generator.SampleData::GetSampleValueRandom