private string newValue(int currentDepth) { if (currentDepth > this.MaxDepth) { return(""); } string value = null; String type = Rando.RandomPick <String>(new String[] { "string", "string", "number", "number", "boolean", "datetime", "array", "object" }); switch (type) { case "string": value = StringGenerator.GetString(StringType.Word); break; case "number": value = Rando.RandomInt(int.MinValue, int.MaxValue).ToString(); break; case "boolean": value = Rando.RandomBoolean().ToString().ToLower(); break; case "datetime": DateTime dt = DateTime.Now .AddYears(Rando.RandomInt(-100, 100)) .AddMonths(Rando.RandomInt(-11, 11)) .AddDays(Rando.RandomInt(-30, 30)) .AddHours(Rando.RandomInt(-23, 23)) .AddMinutes(Rando.RandomInt(-59, 59)) .AddSeconds(Rando.RandomInt(-59, 59)); value = dt.ToString("yyyy-MM-ddTH:mm:ss.fffK"); break; case "array": string key = newKey(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("<{0}>", key); int numItems = Rando.RandomInt(1, this.MaxWidth); string childKey = newKey(); for (int i = 0; i < numItems; i++) { sb.AppendFormat("<{0}>{1}</{0}>", childKey, newValue(currentDepth + 1)); } sb.AppendFormat("</{0}>", key); value = sb.ToString(); break; case "object": value = newObject(currentDepth + 1); break; } return(value); }
private string newValue(int currentDepth) { if (currentDepth > this.MaxDepth) { return("\"" + StringGenerator.GetString(StringType.Word) + "\""); } string value = null; String type = Rando.RandomPick <String>(new String[] { "string", "string", "number", "number", "boolean", "datetime", "array", "object" }); switch (type) { case "string": value = "\"" + StringGenerator.GetString(StringType.Word) + "\""; break; case "number": value = Rando.RandomInt(int.MinValue, int.MaxValue).ToString(); break; case "boolean": value = Rando.RandomBoolean().ToString().ToLower(); break; case "datetime": DateTime dt = DateTime.Now .AddYears(Rando.RandomInt(-100, 100)) .AddMonths(Rando.RandomInt(-11, 11)) .AddDays(Rando.RandomInt(-30, 30)) .AddHours(Rando.RandomInt(-23, 23)) .AddMinutes(Rando.RandomInt(-59, 59)) .AddSeconds(Rando.RandomInt(-59, 59)); value = "\"" + dt.ToString("yyyy-MM-ddTH:mm:ss.fffK") + "\""; break; case "array": value = "["; int numItems = Rando.RandomInt(1, this.MaxWidth); for (int i = 0; i < numItems; i++) { value += newValue(currentDepth + 1); if (i + 1 < numItems) { value += ","; } } value += "]"; break; case "object": value = newObject(currentDepth + 1); break; } return(value); }
protected override void ProcessRecord() { var p = new Person(); p.GivenName = MadLibHelper.madlib.Generate("[name]"); p.SurName = MadLibHelper.madlib.Generate("[lastname]"); p.Email = GenerateEmail(p); if (!Rando.RandomBoolean(3)) { p.MiddleName = StringGenerator.GetString(StringType.UpperCase, 1); } p.PhoneNumber = "(" + StringGenerator.GetString(StringType.Digits, 3) + ") " + StringGenerator.GetString(StringType.Digits, 3) + "-" + StringGenerator.GetString(StringType.Digits, 4); WriteObject(p); }
public static String GetString(StringType type, ulong length) { String ans = null; String charset = null; Boolean useMadLib = false; switch (type) { case StringType.AaZz: case StringType.Digits: case StringType.AlphaNumeric: case StringType.ANSI: case StringType.ASCII: case StringType.Hex: case StringType.UpperCase: case StringType.LowerCase: charset = GetCharSet(type); break; case StringType.Unicode: case StringType.Random: ans = GetUnicodeString(length); break; case StringType.EmailSimple: ans = GetString(StringType.Name, length).Replace(' ', '.') + "@" + GetString(StringType.Domain, length); ans = ans.ToLowerInvariant(); break; case StringType.Email: ans = GetString(StringType.ASCII, length) + "@" + GetString(StringType.Domain, length); break; case StringType.Domain: String tld = "." + GetString(StringType.TLD); ulong l = (Int64)length < (Int64)tld.Length ? 3 : length - (ulong)tld.Length; if (l < 3) { l = 3; } ans = GetString(StringType.AaZz, l) + tld; ans = ans.ConvertWhitespaceToSpaces().Replace(" ", ""); break; case StringType.TLD: ans = GetTLD(); break; case StringType.Name: useMadLib = true; charset = Rando.RandomBoolean() ? "[boyname]" : "[girlname]"; charset += " [lastname]"; break; case StringType.Word: useMadLib = true; charset = "[top5000]"; break; case StringType.Sentence: useMadLib = true; charset = GetSimpleSentenceStructure(); break; case StringType.Uri: ans = GenerateUri(); break; case StringType.IPAddress: if (Rando.RandomBoolean()) { ans = GetString(StringType.IPv4); } else { ans = GetString(StringType.IPv6); } break; case StringType.IPv4: ans = (new System.Net.IPAddress((long)Rando.RandomInt(0, int.MaxValue))).ToString(); break; case StringType.IPv6: { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 8; i++) { if (i != 0) { sb.Append(":"); } if (!Rando.RandomBoolean(10)) { sb.Append(GetString(StringType.Hex, 4)); } } ans = sb.ToString(); } break; } if (useMadLib) { var m = new MadLib(); ans = m.Generate(charset); } else if (!String.IsNullOrEmpty(charset)) { StringBuilder sb = new StringBuilder(); for (ulong i = 0; i < length; i++) { sb.Append(Rando.RandomPick(charset)); } ans = sb.ToString(); } return(ans); }
private static String GenerateUri() { //<scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ] StringBuilder sb = new StringBuilder(); #region Schemes //Taken from perm list at http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml on 2014-09-17 (last updated: 2014-09-16) String[] schemes = new String[] { "aaa", "aaas", "about", "acap", "acct", "cap", "cid", "coap", "coaps", "crid", "data", "dav", "dict", "dns", "file", "ftp", "geo", "go", "gopher", "h323", "http", "https", "iax", "icap", "im", "imap", "info", "ipp", "iris", "iris.beep", "iris.xpc", "iris.xpcs", "iris.lwz", "jabber", "ldap", "mailto", "mid", "msrp", "msrps", "mtqp", "mupdate", "news", "nfs", "ni", "nih", "nntp", "opaquelocktoken", "pop", "pres", "reload", "rtsp", "rtsps", "rtspu", "service", "session", "shttp", "sieve", "sip", "sips", "sms", "snmp", "soap.beep", "soap.beeps", "stun", "stuns", "tag", "tel", "telnet", "tftp", "thismessage", "tn3270", "tip", "turn", "turns", "tv", "urn", "vemmi", "ws", "wss", "xcon", "xcon-userid", "xmlrpc.beep", "xmlrpc.beeps", "xmpp", "z39.50r", "z39.50s" }; #endregion sb.Append(Rando.RandomPick(schemes)); sb.Append(@"://"); if (Rando.RandomInt(0, 20) % 20 == 0) //1 in 20 chance { // UserInfo sb.Append(GetString(StringType.Word)); sb.Append(":"); sb.Append(GetString(StringType.Word)); } if (Rando.RandomInt(0, 5) % 5 == 0) //1 in 5 chance { //Subdomain int num = Rando.RandomInt(1, 5); for (int i = 0; i < num; i++) { sb.Append(GetString(StringType.Word)); sb.Append("."); } } //Domain sb.Append(StringGenerator.GetString(StringType.Word)); sb.Append("."); sb.Append(StringGenerator.GetString(StringType.TLD)); if (Rando.RandomBoolean()) { // Path int num = Rando.RandomInt(1, 5); for (int i = 0; i < num; i++) { sb.Append(@"/"); sb.Append(GetString(StringType.Word)); } } if (Rando.RandomBoolean()) { // File sb.Append(GetString(StringType.Word)); sb.Append("."); sb.Append(GetString(StringType.AlphaNumeric, (ulong)Rando.RandomInt(3, 5))); } if (Rando.RandomInt(0, 3) % 3 == 0) //1 in 3 chance { // Query int num = Rando.RandomInt(1, 10); sb.Append("?"); for (int i = 0; i < num; i++) { if (i > 0) { sb.Append("&"); } sb.Append(GetString(StringType.Word)); sb.Append("="); sb.Append(GetString(StringType.Word)); } } if (Rando.RandomInt(0, 5) % 5 == 0) //1 in 5 chance { // Fragment sb.Append("#"); sb.Append(GetString(StringType.Word)); } return(sb.ToString()); }
public static PointF[] GeneratePoints(Shapes shape, RectangleF bounds) { List <PointF> ans = new List <PointF>(); float cx = bounds.X + (bounds.Width / 2); float cy = bounds.Y + (bounds.Height / 2); float radius = Math.Min(bounds.Width, bounds.Height) / 2; switch (shape) { case Shapes.Rectangle: case Shapes.Square: ans.Add(new PointF(bounds.X, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y)); break; case Shapes.Diamond: ans.Add(new PointF(cx, cy - radius)); ans.Add(new PointF(cx + radius, cy)); ans.Add(new PointF(cx, cy + radius)); ans.Add(new PointF(cx - radius, cy)); break; case Shapes.Triangle_Right: ans.Add(new PointF(bounds.X, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y)); break; case Shapes.Triangle_CenterTop: ans.Add(new PointF(cx, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y + bounds.Height)); ans.Add(new PointF(cx, bounds.Y)); break; case Shapes.Triangle_CenterBottom: ans.Add(new PointF(cx, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y)); ans.Add(new PointF(cx, bounds.Y + bounds.Height)); break; case Shapes.Triangle_CenterLeft: ans.Add(new PointF(bounds.X, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, cy)); ans.Add(new PointF(bounds.X, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, bounds.Y)); break; case Shapes.Triangle_CenterRight: ans.Add(new PointF(bounds.X, cy)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y)); ans.Add(new PointF(bounds.X + bounds.Width, bounds.Y + bounds.Height)); ans.Add(new PointF(bounds.X, cy)); break; case Shapes.RandomPolygon: { int count = Rando.RandomInt(3, 10); for (int i = 0; i < count; i++) { float x, y; Boolean isXBorder = Rando.RandomBoolean(); if (isXBorder) { if (Rando.RandomBoolean()) { x = bounds.X; } else { x = bounds.X + bounds.Width; } y = Rando.RandomFloat(bounds.Y, bounds.Y + bounds.Height); } else { x = Rando.RandomFloat(bounds.X, bounds.X + bounds.Width); if (Rando.RandomBoolean()) { y = bounds.Y; } else { y = bounds.Y + bounds.Height; } } ans.Add(new PointF(x, y)); } } break; default: throw new NotSupportedException(String.Format("Generate Points does not support: {0}", shape.ToString())); } return(ans.ToArray()); }