Documentation

Overview

This documentation is designed to provide detail on the many features of SeedPacket, including the Generators, the Datasources, the Funcs, Interfaces, Exceptions, etc.

Debugging is turned ON by default and writes useful information to the Debug output window in Visual Studio. The name of each property (with type) that data was generated for, is shown with the name of rule that it matched.

The SeedPacket source code is available on GitHub.

The default XML datasource file to download.
XmlGeneratorSource.xml

The default JSON datasource file to download.
JsonGeneratorSource.json

SeedPacket.Extensions Namespace

  • SeedExtensions static class

    Purpose: This collection of static extension methods adds LINQ-like data generation onto many IEnumerable<T> implementations. It is the main entry into SeedPacket .Seed() data generation and with 4 overloads for common scenarios. If the IGenerator is not specified, the MultiGenerator is used by default, and in turn it uses the MultiDataSource if not specified. The MultiDataSource loads its data from an embedded XML resource if an external source is not specified.

    Note that some classes that implement IEnumerable may not be supported. All implementations are constrained so that the type T must implement a parameterless constructor at this time. Single value IEnumerables such as List<string> do not implement new() and will throw an error. IEnumerables Dictionaries are also not supported.

    Be sure to import the SeedPacket.Extensions namespace.
    // Creates 10 rows (default) var users = new List<User>().Seed(); // Creates 20 rows using new IGenerator var users = new List<User>().Seed(1, 20, new MultiGenerator()); // Create 1000 rows by count var users = new List<User>().Seed(1000); // Create rows starting with 100 to 200 with custom datasource file, either XML or JSON. var users = new List<User>().Seed(100, 200, "~/Sources/JSONSource.json");
    Extension Methods on IEnumerable<T>
    • .Seed <T>(this IEnumerable<T> iEnumerable, int count) : returns IEnumerable<T>

      Seeds {count} rows of data using the MultiGenerator.

    • .Seed <T>(this IEnumerable<T> iEnumerable, int seedBegin = 1, int seedEnd = 10, IGenerator generator = null) : returns IEnumerable<T>

      If no parameters are provided, creates 10 rows from 1 to 10. If IGenerator is null, defaults to the MultiGenerator.

    • .Seed <T>(IGenerator generator) : returns IEnumerable<T>

      Seeds rows totally based on the IGenerator and its parameters that is passed in.

    • .Seed <T>(int seedBegin, int seedEnd, string filePath) : returns IEnumerable<T>

      Seeds rows beginning with {SeedBegin} to {SeedEnd}, passing in the path to an external file of data, either XML or JSON (which it will automatically detect).

    Extension Methods on IDictionary<TKey, TValue>
    • .Seed <TKey, TValue>(int seedBegin = 1, int seedEnd = 10, IGenerator generator = null) : returns IEnumerable<T>

      If no parameters are provided, creates 10 rows from 1 to 10. If IGenerator is null, defaults to the MultiGenerator.

    • .Seed <TKey, TValue>(int count) : returns IEnumerable<T>

      Seeds {count} rows of data using the MultiGenerator.

    • .Seed <TKey, TValue>(IGenerator generator) : returns IEnumerable<T>

      Seeds rows totally based on the IGenerator and its parameters that is passed in.

    • .Seed <TKey, TValue>(int seedBegin, int seedEnd, string filePath) : returns IEnumerable<T>

      Seeds rows beginning with {SeedBegin} to {SeedEnd}, passing in the path to an external file of data, either XML or JSON (which it will automatically detect).

SeedPacket Namespace

  • SeedCore class

    Purpose: As it's name suggests, the SeedCore class is the heart of SeedPacket data generation and is responsible for taking the rules engine and pairing it with the generator that is passed to it when it is initialized. Internally, it creates multiple rows of data based on a particular type, goes through the public properties on that type one by one and finds the best rule matching that property's name and datatype. Then uses that rule to generate data to fill that property's value.

    Generally, the default method of seeding data is to use the .Seed() extension methods on IEnumerable in the SeedPacket.Extensions namespace to seed data. The functionality of the SeedCore class has intentionally been kept separate from the extension method logic in so that writing custom extension methods is trivial.

    TIP: Customize your own .Seed() extension methods with your own defaults, rules, and customizations as in the example below. Now you can easily add your own rules and data, or even clear all the rules and start over from scratch! See the Extending page for more details.

    Constructor:
    • new SeedCore (IGenerator generator = null)

      The constructor for a new SeedCore excepts an optional IGenerator. If one is not passed in, it will default to a new MultiGenerator.

    Methods:
    • SeedList<T> (IEnumerable<T> iEnumerable, IGenerator generator = null) : returns IEnumerable<T>

      The basic call to seed data, you will generally wrap it in a convenience extension method.

  • SimpleSeed class

    Purpose: The SimpleSeed class uses an alternative, simpler way to seed data. While less powerful, it may meet your needs for some basic purposes. It does away with the Rules engine and uses a more manual, and Linq-focused, way of creating data, while still leveraging the DataSource classes to utilize XML / JSON files and strings. SimpleSeed Info

    Be sure to import the SeedPacket namespace.
    // Gets data from the referenced .xml file var ss = new SimpleSeed("~/SourceFiles/seedsource.xml"); var userList = Enumerable.Range(100, 20) .Select(n => new User { UserId = n, FirstName = ss.Inject("FirstName", n), LastName = ss.Inject("LastName", n) }).ToList();
    Constructor:
    • new SimpleSeed(string sourcefilepath = null, string sourcestring = null, DataInputType seedinputtype = DataInputType.Auto)

      A simple class that allows you to manually poplate data from an external XML or JSON string or file. The method will throw an error if both the sourcefilepath and the sourcestring are both populated.

    Properties:
    • Default : string

      The string returned if no data is found for the Inject or Random that matches the "Identifier" property.

    • DefaultRandom: Random

      For the SimpleSeed.Random(), sets the initial seed for random data. If a seed is set in the random, as: new Random(3456), then the random sequences generated will always be the same. If a non-seeded random is used, such as new Random(), then the values will be different every time.

    Methods:
    • Next(string identifier, int number, string ifNull = null) : returns string

      Returns the next value in the datasource for that identifier, if it exists. The number is required and is usually created with a LINQ.Range variable. The sequence will loop back if the number parameter is greater than the elments in the list. The ifNull is an optional parameter that will be returned if no elements match the identifier in the datasource.

    • Randomize(string identifier, string ifNull = null) : returns string

      Returns a random value from the datasource for that identifier, if it exists. Is slower that the Next() call. the ifNull is an optional parameter that will be returned if no elements match the identifier in the datasource.

  • Rules class

    Purpose: The Rules class is a wrapper for a Collection of Rule objects, with additional methods to help manage the Rule classes.

    Inherits:
    • Collection<Rule>
    Implements:
    • IRules
    Constructor:
    • new Rules()

      A fairly generic constructor with no parameters.

    Methods:
    • GetRuleByTypeAndName(Type propertyType, string propertyName) : returns Rule

      This method gets the first Rule that matches the Type and Property name for the property that is being processed. The Rules are processed from last added to the first. Once a rule match is found for a particular property, it is stored in a cache and re-used. See the Rule class for additional information.

    • Add(Rule rule, bool overwrite = true): returns void

      Adds a Rules element to the Rules collection. If overwrite is set to true, it will delete the Rule that has the same name if it exists before adding the Rule to the end of the Rules collection. If overwrite is set to false and a Rule already exists, an exception will be thrown. RuleNames must be at least 3 characters in length.

    • AddRange(IEnumerable<Rule>rules, bool overwrite = true) : returns void

      Applies the Add Rule to all the Rules elements in the IEnumerable.

    • RemoveRuleByName(string ruleName) : returns void

      Removes a Rule that matches the ruleName, if one exists.

  • Rule class

    Purpose: The Rules class encapsulates functionality for matching against a property and it's type, a function that wil be processed, if there is a match. The ruleName and decription tells what the rule is for. The function is a Func that takes an IGenerator and returns a Dynamic type. If the run-time type returned does not match a compatible type, an exception will be thrown.

    Anatomy of a SeedPacket.Rule
    // 1st parameter is the type that you want the Rule to match // 2nd parameter is the string pattern that you want the Rule to match. "" matches all // 3rd parameter is lambda function passing the SeedPacket generator and passing out a dynamic type // 4th parameter is the name of the Rule // 5th parameter is the optional description of the Rule var rule = new Rule(typeof(string), "ItemName", g => Funcs.GetNextElement(g, "ProductName"), "ItemName")
    Constructor:
    • new Rule(Type typeMatch, string nameMatch, Func<IGenerator, dynamic> rule, string ruleName, string description = "")

      The typeMatch parameter is a .net Type that must match the property type being filled for a Rule to be valid for that property. The typeMatch can be an interface that the property type implements.

      If the nameMatch parameter is non-null and non-empty, and the typeMatch has matched, the nameMatch parameter is compared to the seeded property's name. A match occurs if a case-insensitive comparison is true. A wildcard character % can be used for the match either on the beginning, end, or both. Multiple matches can be added to the nameMatch string if separated by a comma.

      The func parameter is a c# Func<IGenerator, dynamic>, which is to say it takes a function that takes in the generator and uses it to generate the seed data. As the rule is filtered to a specific Type, it is generally true that the returned Dyanmic is the correct type at run-time, but the rule creator should be careful to check that this is true. If the rule has any sort of complexity it is ususally better to encapsulate the logic in an external function call, particularily for debugging purposes. The SeedPacket.Functions namespace has many examples that have been used to build existing Rules in the funcs partial classes. Often you can find an existing Rule in the source code on GitHub to pattern your code after.

      The ruleName parameter gives a specific name to the rule and must be unique.

      The optional description parameter provides a way to give additional descriptive information about the rules intent .

    Properties:
    • RuleName : returns string

      The name of the Rule. Must be at between 3 and 30 characters in length.

    • Description : returns string

      An optional description of the purpose for the rule.

    Methods:
    • IsMatch (Type propType, string propName) : returns bool

      The Rules class method GetRuleByTypeAndName() runs the IsMatch() method on each rule in the collection until it gets a true boolean value or has run all rules in the colletion. When a true value is returned then that rule is used to seed that particular property. The rule is cached and used for all the subsequent rows that are generated.

    • ApplyRule (IGenerator generator) : returns dynamic

      After a rule has been selected as the match, the ApplyRule() method is run to actually generate a value using the generator and the Func() passed in with the rule.

      The return signature is a c# dynamic variable, as it is not decided until run-time. Generally, as the rule will only match a particular datatype, you will not encounter any run-time errors if you return the same datatype from the Func() that you pass in. Nevertheless, some thought needs to be given in designing rules to make sure the correct datatype is returned, especially if the rule matches an Interface.

  • RuleExtensions static class

    Purpose: This collection of static extension methods on the Rules class provides easily discoverable groups of Rules that can be added to the Rules collection. This class is declared as partial so that additional extension methods can be added on in other files if necessary. Keep in mind that the last rules added in are checked for specific matches first.

    Extension Methods:
    • static AddBasicRules (this Rules rules) : returns void

      Adds a group of rules to the current Rules collection, that apply to basic primitive types, such as string, int, decimal, etc. There are also nullable versions of these types where some values returned are null.

    • static AddAdvancedRules (this Rules rules) : returns void

      Adds a different set of more specific rules for things like address, zip codes, phone numbers, company names, usernames, emails, etc.

  • RulesSet Enum

    Purpose: Contains a short list of common sets of Rules. In the MultiGenerator, this enum governs which groups of Rules are loaded.

  • DataTypeInput Enum

    Purpose: Contains a list of possible data sources referencing a xml or json file, xml or json string, automatically pick the type, or use the embedded default data embedded in the project.

SeedPacket.Generators Namespace

  • Generator abstract class

    Purpose: The base class for all SeedPacket generators provide much of the functionality for generating data, inclding how many rows, which datasource to use, caching data for other rules to use, base default, and information and helpers for the current row being processed.

    Implements:
    • IGenerator
    Properties:
    • SeedBegin : int

      Provides the basic beginning value used for seeding the rownumber. The number does not have to be 0 or 1 but can be any integer, even one with a negative value. Seed progression always proceeds in a positive direction, so this value will need to be less than or equal to the SeedEnd value in order to produce any rows.

    • SeedEnd : int

      Provides the top end of the range of rownumbers in the rows produced. The rownumbers are less than or equal to this value so if the SeedBegin is equal to the SeedEnd, exactly on record is produced.

    • Datasource : readOnly IDataSource

      The data source that data is fetched from, usually a class that wraps an xml/json file or string. The default MultiDataSource wraps both the JsonDataSource and the XmlDataSources and utilizes whichever is more appropriate depending on the data.

    • dynamic Cache { get; set; }

      As it's name implies, the cache is used to store data for later use in a subsequent Rule using a c# dynamic ExpandoObject object that works similar to an asp.net web forms viewbag. This is helpful so you can store an instance of a list that has seeded with data, then retrieve items from that list either sequentially or randomly.

      To assign to the Cache, you simple write: generator.Cache.Items = new List<Items>().Seed()

      To retrieve a cache list by string name, the CacheExtensions method GetByItemName() is provided so use: var list = generator.cache.GetByItemName<List<T>>(cacheListName)

      To retrieve a cached list directly use: var list = generator.Cache.Items.

    • Rules : Rules

      This Rules collection of Rule objects is what is picked from when selecting how to generate seed data. See the Rules entry for more information.

    • BaseRandom : Random

      This c# Random serves as the basis for all the other Random calls that SeedPacket uses. The Generator constructor creates a default new Random() using a default seed number of 123456789. As a seed value is used when the Random is created, the sequences of numbers that it produces will be determinant and always the same. If it is desired for the data to be indeterminant, it is possible to pass in a new Random() value (with no seed number) to this parameter and the data will be different each time it is generated.

    • BaseDateTime : DateTime

      This DateTime value is used as the basis for rules that generates DateTimes. Currently, the default is set to 1/1/2020, but you can change it to any valid DateTime value.

    • Debugging : bool

      Writes debugging information to the Console telling which Rules are being used for each property that is being filled. Is set to true by default as this information can for useful for troubleshooting and is only seen in the Visual Studio Console.

    • RowCount : readOnly int

      Shows the number of rows being generated. Is useful if the range of RowNumbers is something like 1233100 to 1345070...

    • RowNumber : int

      Is number generated for each row, starting with the SeedBegin value, incremented by +1 for each row, and ending with the SeedEnd value.

    • RowRandom : readOnly Random

      A c# Random is generated for each row based on the BaseRandom. If you have a determimate 1000 values based on the default seeded BaseRandom, the generated data will be same if you take the the same number of items for each row. By using the RowRandom as the basis for data for each row, it makes easier to keep the data consistent over time.

    • RowRandomNumber : readOnly int

      Is a random number generated for the row.

    • CurrentRowValues : readOnly Dictionary<string, object>

      This readOnly dictionary stores a list of what values have been generated for this row only. The data can then be accessed by other rules in this row. For instance, if username has already been generated for this row, the value can be used to build an email address. The values are wiped out as when the row finishes processing.

    • CurrentProperty : MetaProperty

      Contains meta information, including dataType, about the current property that the generator is seeding.

    Methods:
    • GetNextRowRandom : returns void

      Fills the RowRandom with the next Random in the BaseRandom sequence. Called at the beginning of row creation.

  • BasicGenerator class

    Purpose: An implementation of a basic IGenerator, using only a set of basic rules for simple data types, without accessing a DataSource. Remains in the project as a simpler version of an IGenerator for testing purposes.

    Inherits:
    • Generator
    Implements:
    • IGenerator
  • MultiGenerator class

    Purpose: The MultiGenerator is currently the default IGenerator implementation and adds access to the default MulitDataSource. This allows for more complex Rules that can access an external data source, such as an XML/JSon file or string.

    Constructor:
    • new MultiGenerator ( string sourceFilepath = null, string sourceString = null, DataInputType dataInputType = DataInputType.Auto, RulesSet rulesSet = RulesSet.Common)

      This constructor defaults to MultiDataSource and passes along the path to a file of data using the sourceFilepath parameter or a string of data using the sourceString parameter. If neither parameter is populated or both parameters are populated, it will throw an exception.

      The DataInputType allows for an explcit selection of possible data sources referencing a xml or json file, xml or json string, automatically pick the type, or use the embedded default data embedded in the project. The default is Auto which will attempt to use the best match.

      The RuleSet parameter controls which sets of rules are loaded on creation. Defaults to Common.

    • MultiGenerator (IDataSource datasource, RulesSet rulesSet = RulesSet.Common)

      For this constructor, you must explicitly pass in an IDatasouce as the first parameter. Optionally, you can also pass in a RuleSet parameter. If one is not passed in, the default Common RuleSet is used.

    Inherits:
    • Generator
    Implements:
    • IGenerator
    Methods:
    • virtual GetRules (RulesSet ruleSet) : returns void

      Uses the parameter ruleSet to load specific sets of Rules. Note that the method is virtual so that derived classes can override which rules are loaded for a particular RuleSet in their own implementation.

SeedPacket.DataSources Namespace

  • JsonDataSource class

    Purpose: To provide a way to access external Json files or strings to use as a source for seed data generation.

    Implements:
    • IDataSource
    Methods:
    • Parse(string json) : returns void

      This method takes in a json string and uses it to populate an internal list of string elements.

    • Load(string sourceFilePath) : returns void

      This method takes in a path to a file containing json. If the file is successfully loaded, it popluates an internal list of string elements.

      If the path to the file begins with a tilde "~" and is in a web project, it will will use MapPath to convert into a local path within the project, otherwise an absolute path is used.

    • GetElementList(string identifier) : returns List<string>

      Returns a list of of string elements, that matches the string identifier. If no matches are found for that identifier, an empty list is returned.

  • XmlDataSource class

    Purpose: To provide a way to access external Xml files or strings to use as a source for seed data generation.

    Implements:
    • IDataSource
    Methods:
    • Parse(string xml) : returns void

      This method takes in a xml string and uses it to populate an internal list of string elements.

    • Load(string sourceFilePath) : returns void

      This method takes in a path to a file containing json. If the file is successfully loaded, it popluates an internal list of string elements.

      If the path to the file begins with a tilde "~" and is in a web project, it will will use MapPath to convert into a local path within the project, otherwise an absolute path is used.

    • LoadDefaultData() : returns void

      This method can be used to load the embedded xml resource file that serves as the default data, if no other source is specified.

    • GetElementList(string identifier) : returns List<string>

      Returns a list of of string elements, that matches the string identifier. If no matches are found for that identifier, an empty list is returned.

  • MultiDataSource class

    Purpose: To provide a way to access multiple dataSources, either the XmlDataSource or the JsonDataSource, to retrieve data to use as a source for seed data generation. By default, it works in Auto mode and automatically detects whether the source is Json or Xml.

    Implements:
    • IDataSource
    Constructors:
    • MultiDataSource(string sourcefilepath = null, string sourcestring = null, DataInputType datainputtype = DataInputType.Auto)

      This constructor sets the path to a file of data using the sourceFilepath parameter or a string of data using the sourceString parameter. If neither parameter is populated or both parameters are populated, it will throw an exception.

      The DataInputType allows for an explcit selection of possible data sources referencing a xml or json file, xml or json string, automatically pick the type, or use the embedded default data embedded in the project. The default is Auto which will attempt to use the best match.

    Methods:
    • GetElementList(string identifier) : returns List<string>

      Returns a list of of string elements, that matches the string identifier. If no matches are found for that identifier, an empty list is returned.

SeedPacket.Interfaces Namespace

  • IGenerator

    Purpose: An interface to provide all the necessary functionality to support data generation and seeding.

    Members:
    • int SeedBegin { get; set; }
    • int SeedEnd { get; set; }
    • IDataSource Datasource { get; }
    • IRules Rules { get; }
    • Random BaseRandom { get; }
    • DateTime BaseDateTime { get; }
    • bool Debugging { get; set; }
    • dynamic Cache { get; set; }
    • int RowCount { get; }
    • int RowNumber { get; set; }
    • Random RowRandom { get; }
    • int RowRandomNumber { get; }
    • Dictionary<string, object> CurrentRowValues { get; }
    • void GetNextRowRandom ()
    • MetaProperty CurrentProperty { get; set; }
    • string CurrentPropertyName { get; set; }
  • IDataSource

    Purpose: An interface to provide access external files or strings to use as a source for seed data generation.

    Members:
    • List<string> GetElementList(string identifier)

      A method to get a list of string elements matching the identifier category.

  • IRules : ICollection

    Purpose: An interface for managing a collection of rule objects and how those rules are selected.

    Inherits:
    • Collection<Rule>
    Members:
    • Rule GetRuleByTypeAndName(Type ruleType, string propertyName)
    • void Add (Rule rule)
    • void AddRange (IEnumerable rules, bool overwrite = false)
    • void RemoveRuleByName (string ruleName)
    • void Clear()

SeedPacket.Functions Namespace

  • CacheExtensions (static)

    Purpose: A collection of extension method helpers used for accessing the Dynamic Cache. Note that they are purposefully included in the SeedPacket.Functions namespace as they relate to the Cache and how it is used in the Funcs methods.

    Extension Methods:
    • static TakeRandomItems<T> (this IList<T> sourceList, Random random, int count = 1, bool remove = true) : returns IList<T>

      Will randomly take {count} number of items from the sourceList and return them in the new destinationList. If {remove} = true, which is the default, then they are removed from the sourceList. This method is useful for populating seed data from pre-existing seeded lists in the cache. Be mindful that picking data randomly from a big list of data can be slower (1/2 as fast) as retrieving sequencial data and may not be necessary, particularily if the data is random to begin with.

    • static Get<TKey, TVal> (this Dictionary<TKey, TVal> dictionary, TKey key, TVal defaultVal = default(TVal)) : returns TVal

      This helpful extension method is useful for conditionally getting values from a dictionary. If the key does not exist in the Dictionary, it returns the defaultValue for that type. A custom default value for that type can be passed in using the defaultVal parameter.

    • static T GetByItemName<T> (this ExpandoObject expando, string name) : returns T

      This extension method takes advantage of the fact that the ExpandoObject is actually an IDictionary, which allows us to extract items by a string name. Note:  The Generator.Cache is a dynamic and needs to be cast as an ExpandoObject to access this extension method.

    • static T AddItemByName<T> (this ExpandoObject expando, string name, T value) : returns void

      This extension method also takes advantage of the fact that the ExpandoObject is actually an IDictionary, and adds an item {value} of type T to the key {name}. If the value is null, then the value will be the default for T. If the ExpandoObject already has a key for {name}, then it will update that key with {value}. Note:  The Generator.Cache is a dynamic and needs to be cast as an ExpandoObject to access this extension method.

    • static T RemoveItemByName<T> (this ExpandoObject expando, string name) : returns void

      This extension method casts it's ExpandoObject to an IDictionary so that it can remove an item when the key is {name}. Note:  The Generator.Cache is a dynamic and needs to be cast as an ExpandoObject to access this extension method.

  • Funcs (static) - marked partial

    Purpose: A collection of static methods for data generation, particularily useful in the functions passed into a Rule. Note that the static classes are marked partial for organization within the SeedLPacket source code and accessibility using intellisense.

    Methods:
    • static GetCacheItemsNext<T> (IGenerator generator, string cacheListName, int min, int max, bool remove = true) : returns List<T>

      Sequentially gets a number of items, with a minimum of {min} and minimum of {max} items, from a list cached in the generator.Cache where the {cacheListName} parameter is the name of the list. Will not throw an error if the named element does not exist.

      To get a specific number of items, use the same integer for both the {min} and {max}. Note that the {max} parameter is inclusive so min: 1 max: 6 is a value from 1 to 6. This is unlike the c# Random.Next where the value returned is always less than the max.

    • static GetCacheItemsNext<T> (IGenerator generator, dynamic cacheList, int min, int max, bool remove = true) : returns List<T>

      Sequentially gets a number of items, with a minimum of {min} and minimum of {max} items, from a list cached in the generator.Cache where the {cacheListName} parameter is a C# dynamic item. ex: generator.Cache.Invoices. Will throw an error if the element does not exist in the Cache.

      To get a specific number of items, use the same integer for both the {min} and {max}. Note that the {max} parameter is inclusive so min: 1 max: 6 is a value from 1 to 6. This is unlike the c# Random.Next where the value returned is always less than the max.

    • static List<T> GetCacheItemsRandom<T> (IGenerator generator, string cacheListName, int min, int max, bool remove = true) : returns List<T>

      Randomly gets a number of items, with a minimum of {min} and minimum of {max} items, from a list cached in the generator.Cache where the {cacheListName} parameter is the name of the list. Will not throw an error if the named element does not exist.

      To get a specific number of items, use the same integer for both the {min} and {max}. Note that the {max} parameter is inclusive so min: 1 max: 6 is a value from 1 to 6. Particularily in a big list, retrieving items randomly is slower than retrieving the items sequentially.

    • static List<T> GetCacheItemsRandom<T> (IGenerator generator, dynamic cacheList, int min, int max, bool remove = true) : returns List<T>

      Randomly gets a number of items, with a minimum of {min} and minimum of {max} items, from a list cached in the generator.Cache where the {cacheListName} parameter is a C# dynamic item. ex: generator.Cache.Invoices. Will throw an error if the element does not exist in the Cache.

      To get a specific number of items, use the same integer for both the {min} and {max}. Note that the {max} parameter is inclusive so min: 1 max: 6 is a value from 1 to 6. This is unlike the c# Random.Next where the value returned is always less than the max.

    • static DiceRoll (IGenerator generator, int diceSides = 6, int numberOfDice = 1) : returns int

      Simulates rolling a 6-sided dice (16.6%). Use a higher {diceSides} to decrease chances in a linear progression. Increasing {numberOfDice} creates a bell-curve of probability ie: 3d6 is 3 to 18 w/ 7 most likely possiblity.

    • static GetElementNext (IGenerator generator, string identifier) : returns string

      GetElementNext gets the next string from the element list named for the {identifier} from the datasource contained in the IGenerator passed in from {generator} parameter. If no elements exist in the list, null is returned. If the number is greater than what exists in the list, then it wraps back around to a string in the list.

    • static GetElementRandom (IGenerator generator, string identifier = null, bool nullIfEmpty = false) : returns string

      GetElementRandom gets a random string from the element list named for the {identifier} from the datasource contained in the IGenerator passed in from {generator} parameter. If no elements exist in the list, null is returned.

      If the {identifier} parameter is null, then the method will default to the generator.CurrentPropertyName. If no elements are returned from the named element list, then the default will be the generator.CurrentPropertyName + RowNumber. If the {nullIfEmpty} parameter is set to true, then the default will just be null, instead.

    • static GetElementRandom (IGenerator generator, string identifier, TypeCode typeCode) : returns dynamic

      This overload of the GetElementRandom method provides a TypeCode that the string will be converted to. The {nullIfEmpty} parameter has been removed as the type default is always returned as the default.

    • static OnceEvery (IGenerator generator, int count = 10) : returns bool

      As it's names suggests, it returns true once every {count}. Useful in Funcs and derived functions in rules to vary data occasiaonally. The default is 10.

    • static RandomAddress (IGenerator generator) : returns string

      Buids a random address by combining a random int between 1 and 9999, a random "StreetName" and a random "RoadType" from the datasource

    • static RandomCompany (IGenerator generator) : returns string

      Builds a random company name from a random "CompanyName" and a random "CompanySuffix" from the datasource.

    • static RandomCost (IGenerator generator) : returns decimal

      Builds a random decimal combining a whole number from 0 to 999 and a decimal between .00 and .99

    • static RandomDateTime (IGenerator generator, int hoursBefore, int hoursAfter) : returns DateTime

      Returns a DateTime value that is a value {hoursBefore} before to {hoursAfter} the BaseDateTime. For example 2 years before to 2 years after by hour you would use hoursBefore: -17520 hoursAfter: 17521

    • static RandomDateTimeNull (IGenerator generator, int hoursBefore, int hoursAfter, int diceRange = 6) : returns DateTime?

      Works just like the RandomDateTime, except that this version returns a nullable DateTime where a null value will be returned with a likelihood of 1 in {diceRange}.

    • static RandomEmail (IGenerator generator) : returns string

      Creates an email from a random username, with a random company, and a random domain extension from the datasource. If the username, company, and domain, have already been created, they will be stored in the generator.CurrentRowValues, and these values are used.

    • static RandomFee (IGenerator generator) : returns decimal

      Builds a random decimal combining a whole number from 1 to 99 and a decimal between .00 and .99

    • static RandomGuid (IGenerator generator) : returns Guid

      Creates a random guid. It is worth noting that, unlike a new Guid, this Guid is generated base on the random seed.

    • static RandomPhone (IGenerator generator) : returns string

      Generates a random phone number in the form (100 to 999) - 100 to 999 - 1000 to 9999

    • static RandomUserName (IGenerator generator) : returns string

      Creates a username using the first letter of a random FirstName and a random LastName from the datasource. If the firstname and/or lastname have already been created, they will be stored in the generator.CurrentRowValues, and these values are used.

    • static RandomZip (IGenerator generator) : returns string

      Creates random ZipCode between 10001 and 99999

SeedPacket.Exceptions Namespace

  • InvalidDefaultDataException class

    Message: Not able to retrieve valid default data from the embedded resource file. Inherits:
    • Exception
  • InvalidSeedParametersException class

    Message: Invalid Parameters: SeedBegin must be less than or equal to SeedEnd. Inherits:
    • Exception
  • InvalidSourceFileException class

    Message: Not able to retrieve valid {source} data from the supplied file path ("{filepath}"). Inherits:
    • Exception
  • InvalidSourceStringException

    Message: Not able to retrieve valid {source}data from the supplied source string. Inherits:
    • Exception
  • MultipleSourceException class

    Message: You can only define one source, either the path to a file OR explicitly pass in a string. Inherits:
    • Exception
  • NoSourceException class

    Message: You MUST either define the path to a source file OR explicitly pass in a string. Inherits:
    • Exception

© 2018 Will Crowther - SeedPacket