├── .gitattributes ├── .github └── workflows │ └── CreateRelease.yml ├── .gitignore ├── Directory.Build.props ├── Example Project Files └── My Project.xml ├── Generate-ReleaseNotes.bat ├── LICENSE ├── README.md ├── ReleaseNotes.md ├── resources ├── IBAN.xlsx ├── icon.ico ├── icon_128x128.png ├── icon_32x32.png ├── icon_512x512.png ├── icon_64x64.png ├── screen-01.png └── screen-02.png ├── src ├── ConsoleApp │ ├── ConsoleApp.csproj │ └── Program.cs ├── ConsoleAppClassic │ ├── App.config │ ├── ConsoleAppClassic.csproj │ ├── MainTest.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── ConsoleAppNetCoreApp1 │ ├── ConsoleAppNetCoreApp1.csproj │ └── Program.cs ├── ConsoleAppNetCoreApp2 │ ├── ConsoleAppNetCoreApp2.csproj │ └── Program.cs ├── RandomDataGenerator Solution.sln ├── RandomDataGenerator Solution.sln.DotSettings ├── RandomDataGenerator.Gui │ ├── App.config │ ├── Data │ │ └── FieldManager.cs │ ├── Entities │ │ ├── DataField.cs │ │ ├── Field.cs │ │ ├── IDataField.cs │ │ ├── IListItem.cs │ │ └── SubField.cs │ ├── Extensions │ │ ├── ControlExtensions.cs │ │ ├── EnumExtensions.cs │ │ ├── LinqExtensions.cs │ │ └── ListBoxExtensions.cs │ ├── FodyWeavers.xml │ ├── Generation │ │ ├── BaseGenerateOptions.cs │ │ ├── Generate.cs │ │ ├── GenerateOptionsSQL.cs │ │ ├── GenerateSQL.cs │ │ └── IGenerate.cs │ ├── MainForm.Designer.cs │ ├── MainForm.Fields.ListBox.cs │ ├── MainForm.Fields.cs │ ├── MainForm.Output.cs │ ├── MainForm.Project.cs │ ├── MainForm.cs │ ├── MainForm.resx │ ├── Program.cs │ ├── Project │ │ ├── ProjectHelper.cs │ │ └── ProjectSettings.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── RandomDataGenerator.Gui.csproj │ ├── Resources │ │ ├── add.png │ │ ├── arrow_down.png │ │ ├── arrow_refresh_small.png │ │ ├── arrow_up.png │ │ ├── delete.png │ │ ├── disk.png │ │ ├── folder_database.png │ │ ├── icon.ico │ │ ├── table_go.ico │ │ ├── table_go.png │ │ └── table_save.png │ ├── UserControls │ │ ├── BaseUserControl.cs │ │ ├── BaseUserControlOutput.cs │ │ ├── IUserControl.cs │ │ ├── UserControlExample.Designer.cs │ │ ├── UserControlExample.cs │ │ ├── UserControlExample.resx │ │ ├── UserControlFactory.cs │ │ ├── UserControlOutputSQL.Designer.cs │ │ ├── UserControlOutputSQL.cs │ │ └── UserControlOutputSQL.resx │ ├── UserControlsFields │ │ ├── UserControlCCN.Designer.cs │ │ ├── UserControlCCN.cs │ │ ├── UserControlCCN.resx │ │ ├── UserControlCity.Designer.cs │ │ ├── UserControlCity.cs │ │ ├── UserControlCity.resx │ │ ├── UserControlCommonOptions.Designer.cs │ │ ├── UserControlCommonOptions.cs │ │ ├── UserControlCommonOptions.resx │ │ ├── UserControlCountry.Designer.cs │ │ ├── UserControlCountry.cs │ │ ├── UserControlCountry.resx │ │ ├── UserControlDateTime.Designer.cs │ │ ├── UserControlDateTime.cs │ │ ├── UserControlDateTime.resx │ │ ├── UserControlEmailAddress.Designer.cs │ │ ├── UserControlEmailAddress.cs │ │ ├── UserControlEmailAddress.resx │ │ ├── UserControlFirstName.Designer.cs │ │ ├── UserControlFirstName.cs │ │ ├── UserControlFirstName.resx │ │ ├── UserControlFullName.Designer.cs │ │ ├── UserControlFullName.cs │ │ ├── UserControlFullName.resx │ │ ├── UserControlGUID.Designer.cs │ │ ├── UserControlGUID.cs │ │ ├── UserControlGUID.resx │ │ ├── UserControlIPv4Address.Designer.cs │ │ ├── UserControlIPv4Address.cs │ │ ├── UserControlIPv6Address.Designer.cs │ │ ├── UserControlIPv6Address.cs │ │ ├── UserControlInteger.Designer.cs │ │ ├── UserControlInteger.cs │ │ ├── UserControlInteger.resx │ │ ├── UserControlLastName.Designer.cs │ │ ├── UserControlLastName.cs │ │ ├── UserControlLastName.resx │ │ ├── UserControlMACAddress.Designer.cs │ │ ├── UserControlMACAddress.cs │ │ ├── UserControlMACAddress.resx │ │ ├── UserControlStringList.Designer.cs │ │ ├── UserControlStringList.cs │ │ ├── UserControlStringList.resx │ │ ├── UserControlText.Designer.cs │ │ ├── UserControlText.cs │ │ ├── UserControlText.resx │ │ ├── UserControlTextNaughtyStrings.Designer.cs │ │ ├── UserControlTextNaughtyStrings.cs │ │ ├── UserControlTextNaughtyStrings.resx │ │ ├── UserControlTextPattern.Designer.cs │ │ ├── UserControlTextPattern.cs │ │ ├── UserControlTextPattern.resx │ │ ├── UserControlTextRegex.Designer.cs │ │ ├── UserControlTextRegex.cs │ │ ├── UserControlTextRegex.resx │ │ ├── UserControlTextWords.Designer.cs │ │ ├── UserControlTextWords.cs │ │ └── UserControlTextWords.resx │ ├── Util │ │ └── StringUtils.cs │ ├── VersionInfo.cs │ └── packages.config ├── RandomDataGenerator.Gui3 │ ├── RandomDataGenerator.Gui3.csproj │ └── app.manifest ├── RandomDataGenerator.Gui6 │ ├── RandomDataGenerator.Gui6.csproj │ └── app.manifest └── RandomDataGenerator │ ├── Compatibility │ ├── ConcurrentDictionary.cs │ ├── CustomIntrospectionExtensions.cs │ └── FrameworkTraits.cs │ ├── CreditCardValidator │ ├── BrandInfo.cs │ ├── CardIssuer.cs │ ├── CreditCardData.cs │ ├── CreditCardValidator.csproj │ ├── LICENSE.txt │ ├── Luhn.cs │ ├── Rule.cs │ └── ValidationHelper.cs │ ├── Data │ ├── ListData.cs │ ├── Models │ │ └── IBAN.cs │ ├── Text │ │ ├── BBAN.txt │ │ ├── CityNames.txt │ │ ├── CountryNames.txt │ │ ├── FemaleNames.txt │ │ ├── IBAN.txt │ │ ├── LastNames.txt │ │ ├── LoremIpsum.txt │ │ ├── LorumIpsumWords.txt │ │ └── MaleNames.txt │ └── TheNaughtyStrings.cs │ ├── Enums │ ├── FieldType.cs │ └── SubFieldType.cs │ ├── Extensions │ └── StringExtensions.cs │ ├── FieldOptions │ ├── FieldOptionsAbstract.cs │ ├── FieldOptionsBoolean.cs │ ├── FieldOptionsByte.cs │ ├── FieldOptionsBytes.cs │ ├── FieldOptionsCCN.cs │ ├── FieldOptionsCity.cs │ ├── FieldOptionsCountry.cs │ ├── FieldOptionsDateTime.cs │ ├── FieldOptionsDouble.cs │ ├── FieldOptionsEmailAddress.cs │ ├── FieldOptionsFactory.cs │ ├── FieldOptionsFirstName.cs │ ├── FieldOptionsFloat.cs │ ├── FieldOptionsFullName.cs │ ├── FieldOptionsGuid.cs │ ├── FieldOptionsIBAN.cs │ ├── FieldOptionsIPv4Address.cs │ ├── FieldOptionsIPv6Address.cs │ ├── FieldOptionsInteger.cs │ ├── FieldOptionsLastName.cs │ ├── FieldOptionsLong.cs │ ├── FieldOptionsMACAddress.cs │ ├── FieldOptionsNumber.cs │ ├── FieldOptionsShort.cs │ ├── FieldOptionsStringList.cs │ ├── FieldOptionsText.cs │ ├── FieldOptionsTextLipsum.cs │ ├── FieldOptionsTextNaughtyStrings.cs │ ├── FieldOptionsTextPattern.cs │ ├── FieldOptionsTextRegex.cs │ ├── FieldOptionsTextWords.cs │ ├── FieldOptionsTimeSpan.cs │ ├── IFieldOptionsBytes.cs │ ├── IFieldOptionsDateTime.cs │ ├── IFieldOptionsGuid.cs │ ├── IFieldOptionsNumber.cs │ ├── IFieldOptionsString.cs │ └── IFieldOptionsTimeSpan.cs │ ├── Generators │ ├── RandomItemFromListGenerator.cs │ ├── RandomItemsFromListGenerator.cs │ ├── RandomStringFromListGenerator.cs │ ├── RandomStringGenerator.cs │ ├── RandomStringsFromListGenerator.cs │ ├── RandomThingsGenerator.cs │ ├── RandomValueGenerator.cs │ └── RandomValueGeneratorFactory.cs │ ├── RandomDataGenerator.csproj │ ├── RandomDataGenerator.snk │ └── Randomizers │ ├── IRandomizerBytes.cs │ ├── IRandomizerDateTime.cs │ ├── IRandomizerGuid.cs │ ├── IRandomizerNumber.cs │ ├── IRandomizerString.cs │ ├── IRandomizerTimeSpan.cs │ ├── RandomizerAbstract.cs │ ├── RandomizerBytes.cs │ ├── RandomizerCCN.cs │ ├── RandomizerCity.cs │ ├── RandomizerCountry.cs │ ├── RandomizerDateTime.cs │ ├── RandomizerEmailAddress.cs │ ├── RandomizerFactory.cs │ ├── RandomizerFirstName.cs │ ├── RandomizerFullName.cs │ ├── RandomizerGuid.cs │ ├── RandomizerIBAN.cs │ ├── RandomizerIPv4Address.cs │ ├── RandomizerIPv6Address.cs │ ├── RandomizerLastName.cs │ ├── RandomizerMACAddress.cs │ ├── RandomizerNumber.cs │ ├── RandomizerStringList.cs │ ├── RandomizerText.cs │ ├── RandomizerTextLipsum.cs │ ├── RandomizerTextNaughtyStrings.cs │ ├── RandomizerTextPattern.cs │ ├── RandomizerTextRegex.cs │ ├── RandomizerTextWords.cs │ └── RandomizerTimeSpan.cs └── tests └── RandomDataGenerator.Tests ├── CityRandomizerTests.cs ├── RandomDataGenerator.Tests.csproj └── Usings.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/CreateRelease.yml: -------------------------------------------------------------------------------- 1 | name: CreateRelease 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*.*.*" 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Release 15 | uses: softprops/action-gh-release@v1 16 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(MsBuildAllProjects);$(MsBuildThisFileFullPath) 4 | 5 | 6 | 7 | 1.0.18 8 | 11 9 | enable 10 | 11 | -------------------------------------------------------------------------------- /Generate-ReleaseNotes.bat: -------------------------------------------------------------------------------- 1 | rem https://github.com/StefH/GitHubReleaseNotes 2 | 3 | SET version=1.0.18 4 | 5 | GitHubReleaseNotes --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version %version% --token %GH_TOKEN% -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Stef Heyenrath 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RandomDataGenerator.Net 2 | This is a simple generator to create random data. 3 | 4 | ## NuGet 5 | 6 | [![NuGet Badge](https://img.shields.io/nuget/v/RandomDataGenerator.Net)](https://www.nuget.org/packages/RandomDataGenerator.Net) 7 | 8 | ## Supported Random Data 9 | 10 | - Bytes 11 | - Cities 12 | - Countries 13 | - Credit Card Numbers 14 | - DateTime 15 | - Email Addresses 16 | - First/Last Names 17 | - Guids 18 | - IBANs 19 | - IP Addresses (V4 and V6) 20 | - Lorum Ipsum Text 21 | - MAC Addresses 22 | - NaughtyStrings 23 | - Numbers (integer, long, float, double, byte, ...) 24 | - Text Regex Patterns 25 | - Words 26 | 27 | ## Usage 28 | 29 | ``` csharp 30 | // Generate a random text with a Regular expression 31 | var randomizerTextRegex = RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{4}[A-Z]{2}" }); 32 | string textRegex = randomizerTextRegex.Generate(); 33 | 34 | // Generate a random first name 35 | var randomizerFirstName = RandomizerFactory.GetRandomizer(new FieldOptionsFirstName()); 36 | string firstName = randomizerFirstName.Generate(); 37 | 38 | // Generate a random text (no numbers or special characters allowed) 39 | var randomizerText = RandomizerFactory.GetRandomizer(new FieldOptionsText { UseNumber = false, UseSpecial = false }); 40 | string text = randomizerText.Generate(); 41 | ``` 42 | 43 | ## Usage (as SQL Data Generator GUI) 44 | You can also use a UI to generate SQL insert table statements. 45 | ![Random Data Generator - 1](https://github.com/StefH/RandomDataGenerator/blob/master/resources/screen-01.png "Screen 1") 46 | 47 | ![Random Data Generator - 2](https://github.com/StefH/RandomDataGenerator/blob/master/resources/screen-02.png "Screen 2") 48 | 49 | 50 | ## Copyright 51 | 52 | ### Referenced files / projects 53 | - https://github.com/gustavofrizzo/CreditCardValidator 54 | - http://www.cambiaresearch.com/articles/13/csharp-randomprovider-class 55 | - http://www.codeproject.com/Articles/423229/CsharpRandomStringGenerator 56 | - https://github.com/SaladLab/NetLegacySupport/tree/master/core/ConcurrentDictionary/System/Collections/Concurrent 57 | - https://raw.githubusercontent.com/SimonCropp/NaughtyStrings/master/src/NaughtyStrings/TheNaughtyStrings.cs 58 | 59 | ### NuGet dependencies 60 | - [Fare](https://github.com/moodmosaic/Fare) -------------------------------------------------------------------------------- /ReleaseNotes.md: -------------------------------------------------------------------------------- 1 | # 1.0.18 (09 October 2024) 2 | - [#27](https://github.com/StefH/RandomDataGenerator/pull/27) - Upgrade System.Text.RegularExpressions to 4.3.1 to solve CVE [bug] contributed by [StefH](https://github.com/StefH) 3 | 4 | # 1.0.17 (30 November 2022) 5 | - [#26](https://github.com/StefH/RandomDataGenerator/pull/26) - Fix for non-uniform random value generators [bug] contributed by [DarekDan](https://github.com/DarekDan) 6 | - [#25](https://github.com/StefH/RandomDataGenerator/issues/25) - Location generator distribution seems to be a bit skewed [bug] 7 | 8 | # 1.0.16 (03 August 2022) 9 | - [#22](https://github.com/StefH/RandomDataGenerator/pull/22) - Use static RandomValueGenerator [feature] contributed by [StefH](https://github.com/StefH) 10 | 11 | # 1.0.15 (21 April 2022) 12 | - [#21](https://github.com/StefH/RandomDataGenerator/pull/21) - Credit Card Number [feature] contributed by [StefH](https://github.com/StefH) 13 | - [#20](https://github.com/StefH/RandomDataGenerator/issues/20) - Credit card numbers [feature] 14 | 15 | # 1.0.14 (24 March 2022) 16 | - [#19](https://github.com/StefH/RandomDataGenerator/pull/19) - Update Fare 2.2.0 to prevent System.Net.Http DoS known issue [feature] contributed by [brunotarghetta](https://github.com/brunotarghetta) 17 | 18 | # 1.0.13 (02 September 2021) 19 | - [#17](https://github.com/StefH/RandomDataGenerator/pull/17) - Use "using" for a the GetResourceAsStream [bug] contributed by [StefH](https://github.com/StefH) 20 | - [#16](https://github.com/StefH/RandomDataGenerator/issues/16) - Memory leak [bug] 21 | 22 | # 1.0.12.0 (24 June 2020) 23 | - [#15](https://github.com/StefH/RandomDataGenerator/pull/15) - Add the Naughty Strings [feature] contributed by [StefH](https://github.com/StefH) 24 | 25 | # 1.0.11.0 (10 April 2020) 26 | - [#14](https://github.com/StefH/RandomDataGenerator/pull/14) - Support custom Random seed value [feature] contributed by [StefH](https://github.com/StefH) 27 | - [#13](https://github.com/StefH/RandomDataGenerator/issues/13) - Initialize RandomizerFactory with supplied Random instance [feature] 28 | 29 | # 1.0.10.0 (10 October 2019) 30 | - [#11](https://github.com/StefH/RandomDataGenerator/pull/11) - Net Core 3.0 contributed by [StefH](https://github.com/StefH) 31 | - [#12](https://github.com/StefH/RandomDataGenerator/pull/12) - RandomizerBytes contributed by [StefH](https://github.com/StefH) 32 | 33 | # 1.0.9.0 (04 August 2019) 34 | - [#10](https://github.com/StefH/RandomDataGenerator/pull/10) - Add Format option to GuidRandomizer [feature] contributed by [vitaliydavydiak](https://github.com/vitaliydavydiak) 35 | 36 | # 1.0.8.0 (05 June 2019) 37 | - [#9](https://github.com/StefH/RandomDataGenerator/pull/9) - Sign Assembly [feature] contributed by [StefH](https://github.com/StefH) 38 | 39 | # 1.0.7.0 (03 December 2018) 40 | - [#8](https://github.com/StefH/RandomDataGenerator/pull/8) - Add BBAN [feature] contributed by [StefH](https://github.com/StefH) 41 | 42 | # 1.0.5.0 (02 December 2018) 43 | - [#7](https://github.com/StefH/RandomDataGenerator/pull/7) - Added Regex and IBAN contributed by [StefH](https://github.com/StefH) 44 | 45 | # 1.0.4.0 (20 November 2018) 46 | - [#6](https://github.com/StefH/RandomDataGenerator/pull/6) - Add Min/Max to IPv4, IPv6 and MAC addresses generation [feature] contributed by [StefH](https://github.com/StefH) 47 | 48 | # 1.0.3.0 (09 November 2018) 49 | - [#5](https://github.com/StefH/RandomDataGenerator/pull/5) - Add Long and TimeSpan [feature] contributed by [StefH](https://github.com/StefH) 50 | 51 | # 1.0.2.0 (09 November 2018) 52 | - [#4](https://github.com/StefH/RandomDataGenerator/pull/4) - RandomizerNumber [feature] contributed by [StefH](https://github.com/StefH) 53 | 54 | # 1.0.1.0 (09 November 2018) 55 | - [#3](https://github.com/StefH/RandomDataGenerator/pull/3) - Updated FieldOptionsFactory [feature] contributed by [StefH](https://github.com/StefH) 56 | 57 | # 1.0.0.0 (08 November 2018) 58 | - [#1](https://github.com/StefH/RandomDataGenerator/pull/1) - Gui contributed by [StefH](https://github.com/StefH) 59 | - [#2](https://github.com/StefH/RandomDataGenerator/pull/2) - Fody and Fody.Costura contributed by [StefH](https://github.com/StefH) 60 | 61 | -------------------------------------------------------------------------------- /resources/IBAN.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/IBAN.xlsx -------------------------------------------------------------------------------- /resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/icon.ico -------------------------------------------------------------------------------- /resources/icon_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/icon_128x128.png -------------------------------------------------------------------------------- /resources/icon_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/icon_32x32.png -------------------------------------------------------------------------------- /resources/icon_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/icon_512x512.png -------------------------------------------------------------------------------- /resources/icon_64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/icon_64x64.png -------------------------------------------------------------------------------- /resources/screen-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/screen-01.png -------------------------------------------------------------------------------- /resources/screen-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/resources/screen-02.png -------------------------------------------------------------------------------- /src/ConsoleApp/ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net6.0 6 | 10.0 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using ConsoleAppClassic; 2 | 3 | namespace ConsoleAppNetCoreApp2; 4 | 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | MainTest.Run(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/ConsoleAppClassic/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ConsoleAppClassic/ConsoleAppClassic.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {FEF862C9-B401-42AB-B753-C877FB11D4CD} 8 | Exe 9 | ConsoleAppClassic 10 | ConsoleAppClassic 11 | v4.6.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {d23eb0aa-1eb0-45d6-8985-14cf01cedd10} 56 | RandomDataGenerator 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/ConsoleAppClassic/Program.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleAppClassic 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | MainTest.Run(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/ConsoleAppClassic/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ConsoleAppClassic")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("Stef Heyenrath")] 11 | [assembly: AssemblyProduct("ConsoleAppClassic")] 12 | [assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2018")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("fef862c9-b401-42ab-b753-c877fb11d4cd")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/ConsoleAppNetCoreApp1/ConsoleAppNetCoreApp1.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp1.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/ConsoleAppNetCoreApp1/Program.cs: -------------------------------------------------------------------------------- 1 | using ConsoleAppClassic; 2 | 3 | namespace ConsoleAppNetCoreApp1 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | MainTest.Run(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/ConsoleAppNetCoreApp2/ConsoleAppNetCoreApp2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/ConsoleAppNetCoreApp2/Program.cs: -------------------------------------------------------------------------------- 1 | using ConsoleAppClassic; 2 | 3 | namespace ConsoleAppNetCoreApp2; 4 | 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | MainTest.Run(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator Solution.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | ASCII 3 | CCN 4 | IBAN 5 | JCB 6 | MAC 7 | SQL 8 | BBAN 9 | IBAN 10 | UTF 11 | True 12 | True 13 | True 14 | True 15 | True 16 | True 17 | True 18 | True 19 | True -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Entities/DataField.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Globalization; 3 | using System.Xml.Serialization; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Randomizers; 6 | 7 | namespace RandomDataGenerator.Gui.Entities 8 | { 9 | public sealed class DataField : IDataField, IListItem, INotifyPropertyChanged 10 | { 11 | public event PropertyChangedEventHandler PropertyChanged; 12 | 13 | public DataField() : this(string.Empty, null, null, null) 14 | { 15 | } 16 | 17 | public DataField(string name, FieldOptionsAbstract fieldOptions, Field field, SubField subField) 18 | { 19 | _name = name; 20 | _field = field; 21 | _subField = subField; 22 | _fieldOptions = fieldOptions?.Clone(); 23 | Id = GetHashCode().ToString(CultureInfo.InvariantCulture); 24 | } 25 | 26 | public dynamic Generate() 27 | { 28 | dynamic randomizer = RandomizerFactory.GetRandomizerAsDynamic(FieldOptions); 29 | 30 | if (randomizer.GetType().GetMethod("GenerateAsString") != null) 31 | { 32 | return randomizer.GenerateAsString(); 33 | } 34 | 35 | return randomizer.Generate(); 36 | } 37 | 38 | [XmlIgnore] 39 | public string Id { get; } 40 | 41 | private string _name; 42 | public string Name 43 | { 44 | get => _name; 45 | set 46 | { 47 | if (value != _name) 48 | { 49 | _name = value; 50 | NotifyPropertyChanged("Name"); 51 | } 52 | } 53 | } 54 | 55 | private FieldOptionsAbstract _fieldOptions; 56 | public FieldOptionsAbstract FieldOptions 57 | { 58 | get => _fieldOptions; 59 | set 60 | { 61 | if (value != _fieldOptions) 62 | { 63 | _fieldOptions = value; 64 | NotifyPropertyChanged("FieldOptions"); 65 | } 66 | } 67 | } 68 | 69 | private Field _field; 70 | public Field Field 71 | { 72 | get => _field; 73 | set 74 | { 75 | if (value != _field) 76 | { 77 | _field = value; 78 | NotifyPropertyChanged("Field"); 79 | } 80 | } 81 | } 82 | 83 | private SubField _subField; 84 | public SubField SubField 85 | { 86 | get => _subField; 87 | set 88 | { 89 | if (value != _subField) 90 | { 91 | _subField = value; 92 | NotifyPropertyChanged("SubField"); 93 | } 94 | } 95 | } 96 | 97 | // NotifyPropertyChanged will raise the PropertyChanged event passing the source property that is being updated. 98 | private void NotifyPropertyChanged(string propertyName) 99 | { 100 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Entities/Field.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml.Serialization; 3 | using RandomDataGenerator.Enums; 4 | using RandomDataGenerator.Gui.Extensions; 5 | 6 | namespace RandomDataGenerator.Gui.Entities; 7 | 8 | public class Field 9 | { 10 | [XmlIgnore] 11 | public string Name => FieldType.GetEnumDescription(); 12 | 13 | public FieldType FieldType { get; set; } 14 | 15 | [XmlIgnore] 16 | public SubField[] SubFields { get; set; } = Array.Empty(); 17 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Entities/IDataField.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.Gui.Entities 3 | { 4 | interface IDataField 5 | { 6 | object Generate(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Entities/IListItem.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.Gui.Entities 3 | { 4 | public interface IListItem 5 | { 6 | string Id { get; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Entities/SubField.cs: -------------------------------------------------------------------------------- 1 | using System.Xml.Serialization; 2 | using RandomDataGenerator.Enums; 3 | using RandomDataGenerator.Gui.Extensions; 4 | 5 | namespace RandomDataGenerator.Gui.Entities 6 | { 7 | public class SubField 8 | { 9 | [XmlIgnore] 10 | public string Name => SubFieldType.GetEnumDescription(); 11 | 12 | public SubFieldType SubFieldType { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Extensions/ControlExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Forms; 3 | 4 | namespace RandomDataGenerator.Gui.Extensions 5 | { 6 | public static class ControlExtensions 7 | { 8 | public static T FindControl(this Control parent) where T : class 9 | { 10 | return parent.Controls.OfType().FirstOrDefault(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Extensions/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace RandomDataGenerator.Gui.Extensions 5 | { 6 | public static class EnumExtensions 7 | { 8 | public static string GetEnumDescription(this Enum value) 9 | { 10 | var fi = value.GetType().GetField(value.ToString()); 11 | 12 | var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); 13 | 14 | if (attributes.Length > 0) 15 | { 16 | return attributes[0].Description; 17 | } 18 | 19 | return value.ToString(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Extensions/LinqExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace RandomDataGenerator.Gui.Extensions 6 | { 7 | public static class LinqExtensions 8 | { 9 | public static int FindIndex1(this IEnumerable items, Predicate predicate) 10 | { 11 | return items.TakeWhile(item => !predicate(item)).Count(); 12 | } 13 | 14 | ///Finds the index of the first item matching an expression in an enumerable. 15 | ///The enumerable to search. 16 | ///The expression to test the items against. 17 | ///The index of the first matching item, or -1 if no items match. 18 | public static int FindIndex(this IEnumerable items, Func predicate) 19 | { 20 | if (items == null) throw new ArgumentNullException("items"); 21 | if (predicate == null) throw new ArgumentNullException("predicate"); 22 | 23 | int retVal = 0; 24 | foreach (var item in items) 25 | { 26 | if (predicate(item)) return retVal; 27 | retVal++; 28 | } 29 | 30 | return -1; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Extensions/ListBoxExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using RandomDataGenerator.Gui.Entities; 3 | 4 | namespace RandomDataGenerator.Gui.Extensions 5 | { 6 | public class ListBoxObjectFindresult 7 | { 8 | public T Item { get; internal set; } 9 | public int Index { get; internal set; } 10 | } 11 | 12 | public static class ListBoxExtensions 13 | { 14 | public static ListBoxObjectFindresult FindItem(this ListBox listBox, string id) where T : IListItem 15 | { 16 | for (int i = 0; i < listBox.Items.Count; i++) 17 | { 18 | if (listBox.Items[i] is T) 19 | { 20 | var existingDataField = (T)listBox.Items[i]; 21 | if (existingDataField.Id == id) 22 | { 23 | return new ListBoxObjectFindresult 24 | { 25 | Item = existingDataField, 26 | Index = i 27 | }; 28 | } 29 | } 30 | } 31 | 32 | return null; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Generation/BaseGenerateOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Xml.Serialization; 2 | 3 | namespace RandomDataGenerator.Gui.Generation 4 | { 5 | [XmlInclude(typeof(GenerateOptionsSQL))] 6 | public abstract class BaseGenerateOptions 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Generation/Generate.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.Gui.Generation 3 | { 4 | public abstract class Generate where T : class, new() 5 | { 6 | protected readonly T Options; 7 | 8 | protected Generate(T options) 9 | { 10 | Options = options; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Generation/GenerateOptionsSQL.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.Gui.Generation 3 | { 4 | public class GenerateOptionsSQL : BaseGenerateOptions 5 | { 6 | public GenerateOptionsSQL() 7 | { 8 | //TotalRecords = 1000; 9 | RecordsPerInsert = 10; 10 | //File = @"C:\Temp\output.sql"; 11 | Table = "My Table"; 12 | IncludeFieldNames = true; 13 | } 14 | 15 | //public int TotalRecords { get; internal set; } 16 | 17 | public int RecordsPerInsert { get; set; } 18 | 19 | //public string File { get; internal set; } 20 | 21 | public string Table { get; set; } 22 | 23 | public bool IncludeFieldNames { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Generation/GenerateSQL.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Text; 5 | using RandomDataGenerator.Gui.Entities; 6 | using RandomDataGenerator.Gui.Util; 7 | 8 | namespace RandomDataGenerator.Gui.Generation 9 | { 10 | public class GenerateSQL : Generate, IGenerate 11 | { 12 | public GenerateSQL(GenerateOptionsSQL options) 13 | : base(options) 14 | { 15 | } 16 | 17 | public void Spawn(List fields, int totalRecords, string fileName) 18 | { 19 | var sb = new StringBuilder(); 20 | 21 | string insertString = $"INSERT INTO [{Options.Table}] "; 22 | string includeFieldNamesString = Options.IncludeFieldNames ? $"({string.Join(", ", fields.Select(f => $"[{f.Name}]"))})" 23 | : string.Empty; 24 | 25 | for (int r = 0; r < totalRecords / Options.RecordsPerInsert; r++) 26 | { 27 | WriteBatch(sb, insertString, includeFieldNamesString, fields, Options.RecordsPerInsert); 28 | } 29 | 30 | int additionalInserts = totalRecords % Options.RecordsPerInsert; 31 | if (additionalInserts > 0) 32 | { 33 | WriteBatch(sb, insertString, includeFieldNamesString, fields, additionalInserts); 34 | } 35 | 36 | File.WriteAllText(fileName, sb.ToString()); 37 | } 38 | 39 | private void WriteBatch(StringBuilder sb, string insertString, string includeFieldNamesString, List fields, int numBatch) 40 | { 41 | sb.Append(insertString); 42 | sb.Append(includeFieldNamesString); 43 | sb.Append(" VALUES "); 44 | 45 | for (int batch = 0; batch < numBatch; batch++) 46 | { 47 | var fieldData = new List(); 48 | foreach (var field in fields) 49 | { 50 | object randomValue = field.Generate(); 51 | string value = field.FieldOptions.ValueAsString ? StringUtils.AddSQLQuotes(randomValue) : StringUtils.MakeSafeSQL(randomValue); 52 | 53 | fieldData.Add(value); 54 | } 55 | 56 | sb.Append($"({string.Join(", ", fieldData)})"); 57 | sb.Append(batch < numBatch - 1 ? ", " : ";"); 58 | } 59 | 60 | sb.AppendLine(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Generation/IGenerate.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using RandomDataGenerator.Gui.Entities; 3 | 4 | namespace RandomDataGenerator.Gui.Generation 5 | { 6 | interface IGenerate 7 | { 8 | void Spawn(List fields, int totalRecords, string fileName); 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/MainForm.Fields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Windows.Forms; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Gui.Entities; 6 | using RandomDataGenerator.Gui.Extensions; 7 | using RandomDataGenerator.Gui.UserControls; 8 | 9 | namespace RandomDataGenerator.Gui 10 | { 11 | public partial class MainForm 12 | { 13 | void cmbFields_SelectedValueChanged(object sender, EventArgs e) 14 | { 15 | var cmb = (ComboBox)sender; 16 | var selectedValue = (Field)cmb.SelectedItem; 17 | 18 | cmbSubFields.DataSource = selectedValue.SubFields; 19 | } 20 | 21 | void cmbSubFields_SelectedValueChanged(object sender, EventArgs e) 22 | { 23 | // Remove Current 24 | var oldControl = panelFieldOptions.FindControl(); 25 | if (oldControl != null) 26 | { 27 | var baseUserControl = oldControl as BaseUserControl; 28 | 29 | if (baseUserControl != null) 30 | { 31 | baseUserControl.OptionsChanged -= UpdateUserControlExampleText; 32 | } 33 | 34 | ((UserControl)oldControl).Dispose(); 35 | } 36 | 37 | var cmb = (ComboBox)sender; 38 | var selectedValue = (SubField)cmb.SelectedItem; 39 | var subFieldType = selectedValue.SubFieldType; 40 | var fieldOptions = FieldOptionsFactory.GetFieldOptions(subFieldType); 41 | var userControl = UserControlFactory.GetUserControl(fieldOptions); 42 | 43 | if (userControl != null) 44 | { 45 | var control = (Control)userControl; 46 | var baseUserControl = (BaseUserControl)userControl; 47 | 48 | baseUserControl.OptionsChanged += UpdateUserControlExampleText; 49 | UpdateUserControlExampleText(userControl, EventArgs.Empty); 50 | 51 | control.Dock = DockStyle.Top; 52 | control.Location = new System.Drawing.Point(0, 0); 53 | control.Name = "userControl_" + baseUserControl.GetType().Name; 54 | control.TabIndex = 2; 55 | 56 | panelFieldOptions.Controls.Add(control); 57 | } 58 | } 59 | 60 | #region Example UserControl 61 | void UpdateUserControlExampleText(object sender, EventArgs e) 62 | { 63 | var baseUserControl = (BaseUserControl)sender; 64 | UpdateUserControlExampleText(baseUserControl); 65 | } 66 | 67 | void UserControlExample_RefreshClicked(object sender, EventArgs e) 68 | { 69 | var baseUserControl = panelFieldOptions.FindControl(); 70 | UpdateUserControlExampleText(baseUserControl); 71 | } 72 | 73 | private void UpdateUserControlExampleText(BaseUserControl baseUserControl) 74 | { 75 | var dummyDataField = new DataField(string.Empty, baseUserControl.GetFieldOptions(), null, null); 76 | 77 | object? value = "N/A"; 78 | try 79 | { 80 | value = dummyDataField.Generate(); 81 | } 82 | catch (Exception e) 83 | { 84 | // Just ignore exception 85 | } 86 | 87 | userControlExample.txtExample.Text = value != null ? value.ToString() : "NULL"; 88 | } 89 | #endregion 90 | } 91 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/MainForm.Output.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Windows.Forms; 4 | using RandomDataGenerator.Gui.Entities; 5 | using RandomDataGenerator.Gui.Extensions; 6 | using RandomDataGenerator.Gui.Generation; 7 | using RandomDataGenerator.Gui.Properties; 8 | using RandomDataGenerator.Gui.UserControls; 9 | 10 | namespace RandomDataGenerator.Gui 11 | { 12 | public partial class MainForm 13 | { 14 | private void ClickBrowseFile(object sender, EventArgs e) 15 | { 16 | var fileBrowser = new SaveFileDialog 17 | { 18 | Filter = Resources.FileFilter_sql_all, 19 | FileName = txtOutputFile.Text, 20 | Title = Resources.SelectOutputFile 21 | }; 22 | 23 | var result = fileBrowser.ShowDialog(); 24 | 25 | if (result == DialogResult.OK) 26 | { 27 | txtOutputFile.Text = fileBrowser.FileName; 28 | } 29 | } 30 | 31 | private void ClickGenerate(object sender, EventArgs e) 32 | { 33 | var userControlSQL = panelOutput.FindControl(); 34 | 35 | var generate = new GenerateSQL(userControlSQL.GetGenerateOptions()); 36 | 37 | var fields = listBoxFields.Items.OfType().ToList(); 38 | generate.Spawn(fields, (int)numTotalRecords.Value, txtOutputFile.Text); 39 | 40 | toolStripStatusLabel1.Text = string.Format(Resources.Output_GeneratedRecords, (int)numTotalRecords.Value, txtOutputFile.Text); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/MainForm.Project.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Windows.Forms; 4 | using RandomDataGenerator.Gui.Entities; 5 | using RandomDataGenerator.Gui.Extensions; 6 | using RandomDataGenerator.Gui.Generation; 7 | using RandomDataGenerator.Gui.Project; 8 | using RandomDataGenerator.Gui.Properties; 9 | using RandomDataGenerator.Gui.UserControls; 10 | 11 | namespace RandomDataGenerator.Gui 12 | { 13 | public partial class MainForm 14 | { 15 | private string _projectSettingsFileName; 16 | 17 | private void ClickEventMenuSave(object sender, EventArgs e) 18 | { 19 | var userControlSQL = (BaseUserControlOutput)panelOutput.FindControl(); 20 | 21 | var settings = new ProjectSettings 22 | { 23 | Date = DateTime.Now, 24 | Name = userControlSQL.GetGenerateOptions().Table, 25 | DataFields = listBoxFields.Items.OfType().ToList(), 26 | GenerateOptions = userControlSQL.GetGenerateOptions(), 27 | OutputFile = txtOutputFile.Text, 28 | TotalRecords = (int)numTotalRecords.Value 29 | }; 30 | 31 | var fileBrowser = new SaveFileDialog 32 | { 33 | Filter = Resources.FileFilter_xml_all, 34 | Title = Resources.SaveThisTable, 35 | FileName = settings.Name + ".xml" 36 | }; 37 | 38 | var result = fileBrowser.ShowDialog(); 39 | 40 | if (result == DialogResult.OK) 41 | { 42 | _projectSettingsFileName = fileBrowser.FileName; 43 | ProjectHelper.Save(settings, _projectSettingsFileName); 44 | 45 | toolStripStatusLabel1.Text = string.Format(Resources.ProjectSettingsSaved, _projectSettingsFileName); 46 | } 47 | } 48 | 49 | private void ClickEventMenuLoad(object sender, EventArgs e) 50 | { 51 | var fileBrowser = new OpenFileDialog 52 | { 53 | Filter = Resources.FileFilter_xml_all, 54 | Title = Resources.LoadSettings, 55 | FileName = _projectSettingsFileName 56 | }; 57 | 58 | var result = fileBrowser.ShowDialog(); 59 | 60 | if (result == DialogResult.OK) 61 | { 62 | _projectSettingsFileName = fileBrowser.FileName; 63 | var settings = ProjectHelper.Load(_projectSettingsFileName); 64 | 65 | txtOutputFile.Text = settings.OutputFile; 66 | numTotalRecords.Value = settings.TotalRecords; 67 | 68 | var generateOptions = (GenerateOptionsSQL)settings.GenerateOptions; 69 | var userControlSQL = (BaseUserControlOutput)panelOutput.FindControl(); 70 | userControlSQL.UpdateControls(generateOptions); 71 | 72 | listBoxFields.SelectedIndexChanged -= listBoxFields_SelectedIndexChanged; 73 | _dataFields.Clear(); 74 | foreach (var dataField in settings.DataFields) 75 | { 76 | // Fix Field and SubField 77 | var field = _fieldManager.GetFields().First(f => f.Name == dataField.Field.Name); 78 | dataField.Field = field; 79 | dataField.SubField = field.SubFields.First(sf => sf.Name == dataField.SubField.Name); 80 | 81 | _dataFields.Add(dataField); 82 | } 83 | listBoxFields.SelectedIndex = -1; 84 | listBoxFields.SelectedIndexChanged += listBoxFields_SelectedIndexChanged; 85 | 86 | toolStripStatusLabel1.Text = string.Format(Resources.ProjectSettingsLoaded, _projectSettingsFileName); 87 | } 88 | } 89 | 90 | private void ClickEventMenuExit(object sender, EventArgs e) 91 | { 92 | Application.Exit(); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/MainForm.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Linq; 3 | using System.Windows.Forms; 4 | using RandomDataGenerator.Gui.Data; 5 | using RandomDataGenerator.Gui.Entities; 6 | using RandomDataGenerator.Gui.Extensions; 7 | using RandomDataGenerator.Gui.Generation; 8 | using RandomDataGenerator.Gui.UserControls; 9 | 10 | namespace RandomDataGenerator.Gui; 11 | 12 | public partial class MainForm : Form, INotifyPropertyChanged 13 | { 14 | public event PropertyChangedEventHandler PropertyChanged; 15 | 16 | private readonly FieldManager _fieldManager = new(); 17 | private readonly BindingList _dataFields = new(); 18 | 19 | public MainForm() 20 | { 21 | InitializeComponent(); 22 | 23 | var userControlSQL = panelOutput.FindControl(); 24 | if (userControlSQL == null) 25 | { 26 | userControlSQL = new UserControlOutputSQL(new GenerateOptionsSQL()) 27 | { 28 | Dock = DockStyle.Top 29 | }; 30 | panelOutput.Controls.Add(userControlSQL); 31 | } 32 | 33 | listBoxFields.DataSource = _dataFields; 34 | _dataFields.ListChanged += DataFields_ListChanged; 35 | 36 | var fields = _fieldManager.GetFields(); 37 | cmbFields.DataSource = fields; 38 | cmbSubFields.DataSource = fields.First().SubFields; 39 | 40 | cmbFields.SelectedValueChanged += cmbFields_SelectedValueChanged; 41 | 42 | userControlExample.btnRefresh.Click += UserControlExample_RefreshClicked; 43 | } 44 | 45 | // NotifyPropertyChanged will raise the PropertyChanged event passing the source property that is being updated. 46 | public void NotifyPropertyChanged(string propertyName) 47 | { 48 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 49 | } 50 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace RandomDataGenerator.Gui 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// The main entry point for the application. 10 | /// 11 | [STAThread] 12 | static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | 17 | var form = new MainForm 18 | { 19 | // Text = $"RandomDataGenerator.Gui {VersionInfo.AssemblyVersion}" 20 | Text = "RandomDataGenerator.Gui" 21 | }; 22 | 23 | #if NETCOREAPP3_0 24 | // https://github.com/dotnet/winforms/issues/135 25 | Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); 26 | #endif 27 | 28 | Application.Run(form); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Project/ProjectHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Windows.Forms; 4 | using System.Xml.Serialization; 5 | using RandomDataGenerator.Gui.Properties; 6 | 7 | namespace RandomDataGenerator.Gui.Project; 8 | 9 | public static class ProjectHelper 10 | { 11 | public static void Save(ProjectSettings settings, string fileName) 12 | { 13 | try 14 | { 15 | var xmlSerializer = new XmlSerializer(settings.GetType()); 16 | 17 | using (var streamWriter = new StreamWriter(fileName)) 18 | { 19 | xmlSerializer.Serialize(streamWriter, settings); 20 | } 21 | } 22 | catch (Exception e) 23 | { 24 | MessageBox.Show(e.ToString(), Resources.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error); 25 | } 26 | } 27 | 28 | public static ProjectSettings Load(string fileName) 29 | { 30 | if (!File.Exists(fileName)) 31 | { 32 | return null; 33 | } 34 | 35 | using (var fileStreamReader = File.OpenText(fileName)) 36 | { 37 | var xmlSerializer = new XmlSerializer(typeof(ProjectSettings)); 38 | 39 | try 40 | { 41 | return (ProjectSettings)xmlSerializer.Deserialize(fileStreamReader); 42 | } 43 | catch (Exception e) 44 | { 45 | MessageBox.Show(e.ToString(), Resources.ErrorLoad, MessageBoxButtons.OK, MessageBoxIcon.Error); 46 | return null; 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Project/ProjectSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using RandomDataGenerator.Gui.Entities; 4 | using RandomDataGenerator.Gui.Generation; 5 | 6 | namespace RandomDataGenerator.Gui.Project 7 | { 8 | public class ProjectSettings 9 | { 10 | public DateTime Date { get; set; } 11 | 12 | public string Name { get; set; } 13 | 14 | public int TotalRecords { get; set; } 15 | 16 | public string OutputFile { get; set; } 17 | 18 | public BaseGenerateOptions GenerateOptions { get; set; } 19 | 20 | public List DataFields { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using RandomDataGenerator.Gui; 4 | 5 | [assembly: AssemblyTitle("RandomDataGenerator.Gui")] 6 | [assembly: AssemblyProduct("RandomDataGenerator.Gui")] 7 | [assembly: AssemblyCopyright(VersionInfo.AssemblyCopyright)] 8 | [assembly: AssemblyTrademark("")] 9 | [assembly: AssemblyCulture("")] 10 | 11 | [assembly: ComVisible(false)] 12 | 13 | [assembly: Guid("8a9214e0-3b23-4c66-9a1b-f06f2ddf70fd")] 14 | 15 | [assembly: AssemblyVersion(VersionInfo.AssemblyVersion)] 16 | [assembly: AssemblyFileVersion(VersionInfo.AssemblyFileVersion)] -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace RandomDataGenerator.Gui.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/add.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/arrow_down.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/arrow_refresh_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/arrow_refresh_small.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/arrow_up.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/delete.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/disk.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/folder_database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/folder_database.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/icon.ico -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/table_go.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/table_go.ico -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/table_go.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/table_go.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Resources/table_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/Resources/table_save.png -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/BaseUserControlOutput.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using RandomDataGenerator.Gui.Generation; 3 | 4 | namespace RandomDataGenerator.Gui.UserControls 5 | { 6 | public abstract class BaseUserControlOutput : UserControl where TOptions : BaseGenerateOptions, new() 7 | { 8 | protected TOptions GenerateOptions; 9 | 10 | protected BaseUserControlOutput() 11 | : this(new TOptions()) 12 | { 13 | } 14 | 15 | protected BaseUserControlOutput(TOptions options) 16 | { 17 | GenerateOptions = options; 18 | } 19 | 20 | public virtual void UpdateControls(TOptions options) 21 | { 22 | GenerateOptions = options; 23 | } 24 | 25 | public virtual TOptions GetGenerateOptions() 26 | { 27 | return GenerateOptions; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/IUserControl.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | 3 | namespace RandomDataGenerator.Gui.UserControls 4 | { 5 | public interface IUserControl 6 | { 7 | void SetOptions(FieldOptionsAbstract options); 8 | 9 | FieldOptionsAbstract GetFieldOptions(); 10 | 11 | void UpdateControls(FieldOptionsAbstract options); 12 | } 13 | 14 | public interface IUserControl 15 | { 16 | TOptions GetFieldOptionsT(); 17 | 18 | void SetOptionsAndUpdateControls(TOptions options); 19 | } 20 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/UserControlExample.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControls 2 | { 3 | partial class UserControlExample 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.lblExample = new System.Windows.Forms.Label(); 32 | this.txtExample = new System.Windows.Forms.TextBox(); 33 | this.btnRefresh = new System.Windows.Forms.Button(); 34 | this.SuspendLayout(); 35 | // 36 | // lblExample 37 | // 38 | this.lblExample.AutoSize = true; 39 | this.lblExample.Location = new System.Drawing.Point(4, 7); 40 | this.lblExample.Name = "lblExample"; 41 | this.lblExample.Size = new System.Drawing.Size(47, 13); 42 | this.lblExample.TabIndex = 0; 43 | this.lblExample.Text = "Example"; 44 | // 45 | // txtExample 46 | // 47 | this.txtExample.BackColor = System.Drawing.SystemColors.ButtonHighlight; 48 | this.txtExample.Location = new System.Drawing.Point(53, 4); 49 | this.txtExample.Name = "txtExample"; 50 | this.txtExample.ReadOnly = true; 51 | this.txtExample.Size = new System.Drawing.Size(310, 20); 52 | this.txtExample.TabIndex = 1; 53 | // 54 | // btnRefresh 55 | // 56 | this.btnRefresh.FlatAppearance.BorderSize = 0; 57 | this.btnRefresh.Image = global::RandomDataGenerator.Gui.Properties.Resources.arrow_refresh_small; 58 | this.btnRefresh.Location = new System.Drawing.Point(365, 4); 59 | this.btnRefresh.Name = "btnRefresh"; 60 | this.btnRefresh.Size = new System.Drawing.Size(21, 21); 61 | this.btnRefresh.TabIndex = 2; 62 | this.btnRefresh.UseVisualStyleBackColor = true; 63 | // 64 | // UserControlExample 65 | // 66 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 67 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 68 | this.Controls.Add(this.btnRefresh); 69 | this.Controls.Add(this.txtExample); 70 | this.Controls.Add(this.lblExample); 71 | this.Name = "UserControlExample"; 72 | this.Size = new System.Drawing.Size(390, 30); 73 | this.ResumeLayout(false); 74 | this.PerformLayout(); 75 | 76 | } 77 | 78 | #endregion 79 | 80 | private System.Windows.Forms.Label lblExample; 81 | public System.Windows.Forms.TextBox txtExample; 82 | public System.Windows.Forms.Button btnRefresh; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/UserControlExample.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | 3 | namespace RandomDataGenerator.Gui.UserControls 4 | { 5 | public partial class UserControlExample : UserControl 6 | { 7 | public UserControlExample() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/UserControlFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | 4 | namespace RandomDataGenerator.Gui.UserControls 5 | { 6 | static class UserControlFactory 7 | { 8 | public static IUserControl GetUserControl(FieldOptionsAbstract fieldOptions) 9 | { 10 | string typeName = fieldOptions.GetType().FullName 11 | .Replace("RandomDataGenerator.FieldOptions.FieldOptions", "RandomDataGenerator.Gui.UserControlsFields.UserControl"); 12 | 13 | var type = Type.GetType(typeName); 14 | if (type != null) 15 | { 16 | var userControl = (IUserControl)Activator.CreateInstance(type, new object[] { }); 17 | userControl.SetOptions(fieldOptions); 18 | 19 | return userControl; 20 | } 21 | 22 | return null; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControls/UserControlOutputSQL.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Gui.Generation; 2 | 3 | namespace RandomDataGenerator.Gui.UserControls 4 | { 5 | public partial class UserControlOutputSQL : UserControlOutputSQLDesignable 6 | { 7 | public UserControlOutputSQL() 8 | { 9 | } 10 | 11 | public UserControlOutputSQL(GenerateOptionsSQL options) 12 | : base(options) 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | public override void UpdateControls(GenerateOptionsSQL options) 18 | { 19 | base.UpdateControls(options); 20 | 21 | numRecordsPerInsert.Value = options.RecordsPerInsert; 22 | chkIncludeFieldNames.Checked = options.IncludeFieldNames; 23 | txtTableName.Text = options.Table; 24 | } 25 | 26 | public override GenerateOptionsSQL GetGenerateOptions() 27 | { 28 | GenerateOptions.IncludeFieldNames = chkIncludeFieldNames.Checked; 29 | GenerateOptions.RecordsPerInsert = (int) numRecordsPerInsert.Value; 30 | GenerateOptions.Table = txtTableName.Text; 31 | 32 | return GenerateOptions; 33 | } 34 | } 35 | 36 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 37 | public class UserControlOutputSQLDesignable : BaseUserControlOutput 38 | { 39 | public UserControlOutputSQLDesignable() 40 | { 41 | } 42 | 43 | public UserControlOutputSQLDesignable(GenerateOptionsSQL options) 44 | : base(options) 45 | { 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCCN.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.CreditCardValidator; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Gui.UserControls; 5 | 6 | namespace RandomDataGenerator.Gui.UserControlsFields 7 | { 8 | public sealed partial class UserControlCCN : UserControlCCNDesignable 9 | { 10 | public UserControlCCN() 11 | { 12 | InitializeComponent(); 13 | 14 | OnOptionsChanged(EventArgs.Empty); 15 | } 16 | 17 | public override void SetOptionsAndUpdateControls(FieldOptionsCCN options) 18 | { 19 | base.SetOptionsAndUpdateControls(options); 20 | 21 | ctrlLength.Value = FieldOptions.Length; 22 | cmbCardIssuer.Text = FieldOptions.CardIssuer.ToString(); 23 | } 24 | 25 | public override FieldOptionsCCN GetFieldOptionsT() 26 | { 27 | FieldOptions = base.GetFieldOptionsT(); 28 | 29 | FieldOptions.Length = (int)ctrlLength.Value; 30 | FieldOptions.CardIssuer = ParseCardIssuer(cmbCardIssuer.Text); 31 | 32 | return FieldOptions; 33 | } 34 | 35 | private void LengthChanged(object sender, EventArgs e) 36 | { 37 | FieldOptions.Length = (int)ctrlLength.Value; 38 | } 39 | 40 | private void CardIssuerSelectedValueChanged(object sender, EventArgs e) 41 | { 42 | FieldOptions.CardIssuer = ParseCardIssuer(cmbCardIssuer.Text); 43 | } 44 | 45 | private static CardIssuer ParseCardIssuer(string text) 46 | { 47 | return (CardIssuer)Enum.Parse(typeof(CardIssuer), text); 48 | } 49 | } 50 | 51 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 52 | public class UserControlCCNDesignable : BaseUserControl 53 | { 54 | } 55 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCity.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | partial class UserControlCity 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // UserControlCity 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.Name = "UserControlCity"; 38 | this.Size = new System.Drawing.Size(350, 20); 39 | this.ResumeLayout(false); 40 | 41 | } 42 | #endregion 43 | } 44 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public partial class UserControlCity : UserControlCityDesignable 8 | { 9 | public UserControlCity() 10 | { 11 | InitializeComponent(); 12 | 13 | base.OnOptionsChanged(EventArgs.Empty); 14 | } 15 | } 16 | 17 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 18 | public class UserControlCityDesignable : BaseUserControl 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCommonOptions.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | sealed partial class UserControlCommonOptions 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.chkAllowNull = new System.Windows.Forms.CheckBox(); 32 | this.lblAllowNullValues = new System.Windows.Forms.Label(); 33 | this.SuspendLayout(); 34 | // 35 | // chkAllowNull 36 | // 37 | this.chkAllowNull.AutoSize = true; 38 | this.chkAllowNull.Location = new System.Drawing.Point(162, 6); 39 | this.chkAllowNull.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 40 | this.chkAllowNull.Name = "chkAllowNull"; 41 | this.chkAllowNull.RightToLeft = System.Windows.Forms.RightToLeft.No; 42 | this.chkAllowNull.Size = new System.Drawing.Size(22, 21); 43 | this.chkAllowNull.TabIndex = 3; 44 | this.chkAllowNull.UseVisualStyleBackColor = true; 45 | // 46 | // lblAllowNullValues 47 | // 48 | this.lblAllowNullValues.AutoSize = true; 49 | this.lblAllowNullValues.Location = new System.Drawing.Point(6, 6); 50 | this.lblAllowNullValues.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 51 | this.lblAllowNullValues.Name = "lblAllowNullValues"; 52 | this.lblAllowNullValues.Size = new System.Drawing.Size(129, 20); 53 | this.lblAllowNullValues.TabIndex = 4; 54 | this.lblAllowNullValues.Text = "Allow Null Values"; 55 | // 56 | // UserControlCommonOptions 57 | // 58 | this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 59 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 60 | this.Controls.Add(this.lblAllowNullValues); 61 | this.Controls.Add(this.chkAllowNull); 62 | this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 63 | this.Name = "UserControlCommonOptions"; 64 | this.Size = new System.Drawing.Size(585, 40); 65 | this.ResumeLayout(false); 66 | this.PerformLayout(); 67 | 68 | } 69 | 70 | #endregion 71 | 72 | private System.Windows.Forms.CheckBox chkAllowNull; 73 | private System.Windows.Forms.Label lblAllowNullValues; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCommonOptions.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlCommonOptions : UserControlCommonOptionsDesignable 7 | { 8 | public UserControlCommonOptions() 9 | { 10 | InitEventsForControls(); 11 | 12 | InitializeComponent(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsAbstract options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | chkAllowNull.Checked = FieldOptions.UseNullValues; 20 | } 21 | 22 | public override FieldOptionsAbstract GetFieldOptionsT() 23 | { 24 | FieldOptions.UseNullValues = chkAllowNull.Checked; 25 | 26 | return FieldOptions; 27 | } 28 | } 29 | 30 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 31 | public class UserControlCommonOptionsDesignable : BaseUserControl 32 | { 33 | } 34 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCountry.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | partial class UserControlCountry 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // UserControlCountry 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.Name = "UserControlCountry"; 38 | this.Size = new System.Drawing.Size(350, 20); 39 | this.ResumeLayout(false); 40 | 41 | } 42 | #endregion 43 | } 44 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlCountry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public partial class UserControlCountry : UserControlCountryDesignable 8 | { 9 | public UserControlCountry() 10 | { 11 | InitializeComponent(); 12 | 13 | base.OnOptionsChanged(EventArgs.Empty); 14 | } 15 | } 16 | 17 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 18 | public class UserControlCountryDesignable : BaseUserControl 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Windows.Forms; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Gui.UserControls; 6 | 7 | namespace RandomDataGenerator.Gui.UserControlsFields 8 | { 9 | public sealed partial class UserControlDateTime : UserControlDateTimeDesignable, INotifyPropertyChanged 10 | { 11 | public event PropertyChangedEventHandler PropertyChanged; 12 | 13 | public UserControlDateTime() 14 | { 15 | InitializeComponent(); 16 | 17 | InitEventsForControls(); 18 | } 19 | 20 | public override void SetOptionsAndUpdateControls(FieldOptionsDateTime options) 21 | { 22 | base.SetOptionsAndUpdateControls(options); 23 | 24 | datePickerFrom.Value = FieldOptions.From; 25 | timePickerFrom.Value = FieldOptions.IncludeTime ? FieldOptions.From : DateTime.Now.Date; 26 | 27 | datePickerTo.Value = FieldOptions.To; 28 | timePickerTo.Value = FieldOptions.IncludeTime ? FieldOptions.To : DateTime.Now.Date; 29 | 30 | IncludeTime = FieldOptions.IncludeTime; 31 | } 32 | 33 | public override FieldOptionsDateTime GetFieldOptionsT() 34 | { 35 | FieldOptions = base.GetFieldOptionsT(); 36 | 37 | FieldOptions.From = datePickerFrom.Value + (chkIncludeTime.Checked ? timePickerFrom.Value.TimeOfDay : new TimeSpan(0)); 38 | FieldOptions.To = datePickerTo.Value + (chkIncludeTime.Checked ? timePickerTo.Value.TimeOfDay : new TimeSpan(0)); 39 | FieldOptions.IncludeTime = chkIncludeTime.Checked; 40 | 41 | return FieldOptions; 42 | } 43 | 44 | // NotifyPropertyChanged will raise the PropertyChanged event passing the source property that is being updated. 45 | public void NotifyPropertyChanged(string propertyName) 46 | { 47 | if (PropertyChanged != null) 48 | { 49 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 50 | } 51 | } 52 | 53 | private bool _includeTime; 54 | public bool IncludeTime 55 | { 56 | get => _includeTime; 57 | set 58 | { 59 | if (value != _includeTime) 60 | { 61 | _includeTime = value; 62 | 63 | if (!value) 64 | { 65 | timePickerFrom.Value = DateTime.Now.Date; 66 | timePickerTo.Value = DateTime.Now.Date; 67 | } 68 | NotifyPropertyChanged("IncludeTime"); 69 | } 70 | } 71 | } 72 | 73 | private void CheckedChangedIncludeTime(object sender, EventArgs e) 74 | { 75 | var checkBox = (CheckBox)sender; 76 | IncludeTime = checkBox.Checked; 77 | } 78 | } 79 | 80 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 81 | public class UserControlDateTimeDesignable : BaseUserControl 82 | { 83 | } 84 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlEmailAddress.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlEmailAddress : UserControlEmailAddressDesignable 7 | { 8 | public UserControlEmailAddress() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsEmailAddress options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | if (FieldOptions.Male && FieldOptions.Female) 20 | { 21 | rbBoth.Checked = true; 22 | } 23 | else 24 | { 25 | rbMale.Checked = FieldOptions.Male; 26 | rbFemale.Checked = FieldOptions.Female; 27 | } 28 | } 29 | 30 | public override FieldOptionsEmailAddress GetFieldOptionsT() 31 | { 32 | FieldOptions = base.GetFieldOptionsT(); 33 | 34 | FieldOptions.Male = rbBoth.Checked || rbMale.Checked; 35 | FieldOptions.Female = rbBoth.Checked || rbFemale.Checked; 36 | 37 | return FieldOptions; 38 | } 39 | } 40 | 41 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 42 | public class UserControlEmailAddressDesignable : BaseUserControl 43 | { 44 | } 45 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlFirstName.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlFirstName : UserControlFirstNameDesignable 7 | { 8 | public UserControlFirstName() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsFirstName options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | if (FieldOptions.Male && FieldOptions.Female) 20 | { 21 | rbBoth.Checked = true; 22 | } 23 | else 24 | { 25 | rbMale.Checked = FieldOptions.Male; 26 | rbFemale.Checked = FieldOptions.Female; 27 | } 28 | } 29 | 30 | public override FieldOptionsFirstName GetFieldOptionsT() 31 | { 32 | FieldOptions = base.GetFieldOptionsT(); 33 | 34 | FieldOptions.Male = rbBoth.Checked || rbMale.Checked; 35 | FieldOptions.Female = rbBoth.Checked || rbFemale.Checked; 36 | 37 | return FieldOptions; 38 | } 39 | } 40 | 41 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 42 | public class UserControlFirstNameDesignable : BaseUserControl 43 | { 44 | } 45 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlFullName.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlFullName : UserControlFullNameDesignable 7 | { 8 | public UserControlFullName() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsFullName options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | if (FieldOptions.Male && FieldOptions.Female) 20 | { 21 | rbBoth.Checked = true; 22 | } 23 | else 24 | { 25 | rbMale.Checked = FieldOptions.Male; 26 | rbFemale.Checked = FieldOptions.Female; 27 | } 28 | } 29 | 30 | public override FieldOptionsFullName GetFieldOptionsT() 31 | { 32 | FieldOptions = base.GetFieldOptionsT(); 33 | 34 | FieldOptions.Male = rbBoth.Checked || rbMale.Checked; 35 | FieldOptions.Female = rbBoth.Checked || rbFemale.Checked; 36 | 37 | return FieldOptions; 38 | } 39 | } 40 | 41 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 42 | public class UserControlFullNameDesignable : BaseUserControl 43 | { 44 | } 45 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlGUID.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public partial class UserControlGuid : UserControlGUIDDesignable 8 | { 9 | public UserControlGuid() 10 | { 11 | InitializeComponent(); 12 | 13 | InitEventsForControls(); 14 | 15 | formatComboBox.DataSource = new List { "N", "D", "B", "P", "X" }; 16 | } 17 | 18 | public override void SetOptionsAndUpdateControls(FieldOptionsGuid options) 19 | { 20 | base.SetOptionsAndUpdateControls(options); 21 | 22 | chkUppercase.Checked = FieldOptions.Uppercase; 23 | 24 | formatComboBox.SelectedItem = FieldOptions.Format; 25 | } 26 | 27 | public override FieldOptionsGuid GetFieldOptionsT() 28 | { 29 | FieldOptions = base.GetFieldOptionsT(); 30 | 31 | FieldOptions.Uppercase = chkUppercase.Checked; 32 | 33 | FieldOptions.Format = formatComboBox.Text; 34 | 35 | return FieldOptions; 36 | } 37 | } 38 | 39 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 40 | public class UserControlGUIDDesignable : BaseUserControl 41 | { 42 | } 43 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlIPv4Address.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | partial class UserControlIPv4Address 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // UserControlCity 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.Name = "UserControlCity"; 38 | this.Size = new System.Drawing.Size(350, 20); 39 | this.ResumeLayout(false); 40 | 41 | } 42 | #endregion 43 | } 44 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlIPv4Address.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public partial class UserControlIPv4Address : UserControlIPv4AddressDesignable 8 | { 9 | public UserControlIPv4Address() 10 | { 11 | InitializeComponent(); 12 | 13 | base.OnOptionsChanged(EventArgs.Empty); 14 | } 15 | } 16 | 17 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 18 | public class UserControlIPv4AddressDesignable : BaseUserControl 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlIPv6Address.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | partial class UserControlIPv6Address 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // UserControlCity 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.Name = "UserControlCity"; 38 | this.Size = new System.Drawing.Size(350, 20); 39 | this.ResumeLayout(false); 40 | 41 | } 42 | #endregion 43 | } 44 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlIPv6Address.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public partial class UserControlIPv6Address : UserControlIPv6AddressDesignable 8 | { 9 | public UserControlIPv6Address() 10 | { 11 | InitializeComponent(); 12 | 13 | base.OnOptionsChanged(EventArgs.Empty); 14 | } 15 | } 16 | 17 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 18 | public class UserControlIPv6AddressDesignable : BaseUserControl 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlInteger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public sealed partial class UserControlInteger : UserControlIntegerDesignable 8 | { 9 | public UserControlInteger() 10 | { 11 | InitializeComponent(); 12 | 13 | InitEventsForControls(); 14 | } 15 | 16 | public override void SetOptionsAndUpdateControls(FieldOptionsInteger options) 17 | { 18 | base.SetOptionsAndUpdateControls(options); 19 | 20 | ctrlMin.Value = FieldOptions.Min; 21 | ctrlMax.Value = FieldOptions.Max; 22 | chkConvertToString.Checked = FieldOptions.ValueAsString; 23 | } 24 | 25 | public override FieldOptionsInteger GetFieldOptionsT() 26 | { 27 | FieldOptions = base.GetFieldOptionsT(); 28 | 29 | FieldOptions.Min = (int)ctrlMin.Value; 30 | FieldOptions.Max = (int)ctrlMax.Value; 31 | FieldOptions.ValueAsString = chkConvertToString.Checked; 32 | 33 | return FieldOptions; 34 | } 35 | 36 | private void MinValueChanged(object sender, EventArgs e) 37 | { 38 | ctrlMax.Minimum = ctrlMin.Value; 39 | } 40 | 41 | private void MaxValueChanged(object sender, EventArgs e) 42 | { 43 | ctrlMin.Maximum = ctrlMax.Value; 44 | } 45 | } 46 | 47 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 48 | public class UserControlIntegerDesignable : BaseUserControl 49 | { 50 | } 51 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlLastName.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | sealed partial class UserControlLastName 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // UserControlLastName 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.Name = "UserControlLastName"; 38 | this.Size = new System.Drawing.Size(350, 20); 39 | this.ResumeLayout(false); 40 | 41 | } 42 | 43 | #endregion 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlLastName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public sealed partial class UserControlLastName : UserControlLastNameDesignable 8 | { 9 | public UserControlLastName() 10 | { 11 | InitializeComponent(); 12 | 13 | OnOptionsChanged(EventArgs.Empty); 14 | } 15 | } 16 | 17 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 18 | public class UserControlLastNameDesignable : BaseUserControl 19 | { 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlMACAddress.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public partial class UserControlMACAddress : UserControlMACAddressDesignable 7 | { 8 | public UserControlMACAddress() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsMACAddress options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | chkAddColons.Checked = FieldOptions.Separator == ":"; 20 | chkUppercase.Checked = FieldOptions.Uppercase; 21 | } 22 | 23 | public override FieldOptionsMACAddress GetFieldOptionsT() 24 | { 25 | FieldOptions = base.GetFieldOptionsT(); 26 | 27 | FieldOptions.Separator = chkAddColons.Checked ? ":" : string.Empty; 28 | FieldOptions.Uppercase = chkUppercase.Checked; 29 | 30 | return FieldOptions; 31 | } 32 | } 33 | 34 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 35 | public class UserControlMACAddressDesignable : BaseUserControl 36 | { 37 | } 38 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlStringList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Linq; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Gui.UserControls; 6 | 7 | namespace RandomDataGenerator.Gui.UserControlsFields 8 | { 9 | public sealed partial class UserControlStringList : UserControlFixedSetDesignable, INotifyPropertyChanged 10 | { 11 | public event PropertyChangedEventHandler PropertyChanged; 12 | 13 | private readonly BindingList _values = new BindingList(); 14 | 15 | public UserControlStringList() 16 | { 17 | InitializeComponent(); 18 | 19 | InitEventsForControls(); 20 | 21 | listBoxValues.DataSource = _values; 22 | _values.ListChanged += ValuesChanged; 23 | } 24 | 25 | void ValuesChanged(object sender, ListChangedEventArgs e) 26 | { 27 | var dataFields = (BindingList)sender; 28 | 29 | ListHasItems = dataFields.Count > 0; 30 | } 31 | 32 | public override void SetOptionsAndUpdateControls(FieldOptionsStringList options) 33 | { 34 | base.SetOptionsAndUpdateControls(options); 35 | 36 | _values.Clear(); 37 | if (options.Values != null) 38 | { 39 | foreach (string value in options.Values) 40 | { 41 | _values.Add(value); 42 | } 43 | } 44 | 45 | chkConvertToString.Checked = FieldOptions.ValueAsString; 46 | } 47 | 48 | public override FieldOptionsStringList GetFieldOptionsT() 49 | { 50 | FieldOptions = base.GetFieldOptionsT(); 51 | 52 | FieldOptions.Values = _values.ToList(); 53 | FieldOptions.ValueAsString = chkConvertToString.Checked; 54 | 55 | return FieldOptions; 56 | } 57 | 58 | private void ButtonAddFieldClick(object sender, EventArgs e) 59 | { 60 | _values.Add(txtValue.Text); 61 | } 62 | 63 | private void ButtonDeleteFieldClick(object sender, EventArgs e) 64 | { 65 | var value = (string)listBoxValues.SelectedItem; 66 | _values.Remove(value); 67 | } 68 | 69 | // NotifyPropertyChanged will raise the PropertyChanged event passing the source property that is being updated. 70 | public void NotifyPropertyChanged(string propertyName) 71 | { 72 | if (PropertyChanged != null) 73 | { 74 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 75 | } 76 | } 77 | 78 | private bool _listHasItems; 79 | public bool ListHasItems 80 | { 81 | get => _listHasItems; 82 | set 83 | { 84 | if (value != _listHasItems) 85 | { 86 | _listHasItems = value; 87 | NotifyPropertyChanged("ListHasItems"); 88 | } 89 | } 90 | } 91 | } 92 | 93 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 94 | public class UserControlFixedSetDesignable : BaseUserControl 95 | { 96 | } 97 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public sealed partial class UserControlText : UserControlTextRandomLengthDesignable 8 | { 9 | public UserControlText() 10 | { 11 | InitializeComponent(); 12 | 13 | InitEventsForControls(); 14 | } 15 | 16 | public override void SetOptionsAndUpdateControls(FieldOptionsText options) 17 | { 18 | base.SetOptionsAndUpdateControls(options); 19 | 20 | ctrlMinLength.Value = FieldOptions.Min; 21 | ctrlMaxLength.Value = FieldOptions.Max; 22 | chkLetter.Checked = FieldOptions.UseLetter; 23 | chkSpace.Checked = FieldOptions.UseSpace; 24 | chkSpecial.Checked = FieldOptions.UseSpecial; 25 | chkNumber.Checked = FieldOptions.UseNumber; 26 | 27 | if (FieldOptions.UseLowercase && FieldOptions.UseUppercase) 28 | { 29 | rbBoth.Checked = true; 30 | } 31 | else 32 | { 33 | rbUpper.Checked = FieldOptions.UseUppercase; 34 | rbLower.Checked = FieldOptions.UseLowercase; 35 | } 36 | } 37 | 38 | public override FieldOptionsText GetFieldOptionsT() 39 | { 40 | FieldOptions = base.GetFieldOptionsT(); 41 | 42 | FieldOptions.Min = (int)ctrlMinLength.Value; 43 | FieldOptions.Max = (int)ctrlMaxLength.Value; 44 | 45 | FieldOptions.UseLowercase = rbLower.Checked; 46 | FieldOptions.UseUppercase = rbUpper.Checked; 47 | FieldOptions.UseLetter = chkLetter.Checked; 48 | FieldOptions.UseNumber = chkNumber.Checked; 49 | FieldOptions.UseSpecial = chkSpecial.Checked; 50 | FieldOptions.UseSpace = chkSpace.Checked; 51 | 52 | return FieldOptions; 53 | } 54 | 55 | private void MinLengthValueChanged(object sender, EventArgs e) 56 | { 57 | ctrlMaxLength.Minimum = ctrlMinLength.Value; 58 | } 59 | 60 | private void MaxLengthValueChanged(object sender, EventArgs e) 61 | { 62 | ctrlMinLength.Maximum = ctrlMaxLength.Value; 63 | } 64 | } 65 | 66 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 67 | public class UserControlTextRandomLengthDesignable : BaseUserControl 68 | { 69 | } 70 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlTextNaughtyStrings.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Gui.UserControlsFields 2 | { 3 | sealed partial class UserControlTextNaughtyStrings 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.lblCategory = new System.Windows.Forms.Label(); 32 | this.txtCategories = new System.Windows.Forms.TextBox(); 33 | this.SuspendLayout(); 34 | // 35 | // lblCategory 36 | // 37 | this.lblCategory.AutoSize = true; 38 | this.lblCategory.Location = new System.Drawing.Point(4, 7); 39 | this.lblCategory.Name = "lblCategory"; 40 | this.lblCategory.Size = new System.Drawing.Size(57, 13); 41 | this.lblCategory.TabIndex = 0; 42 | this.lblCategory.Text = "Categories"; 43 | // 44 | // txtCategories 45 | // 46 | this.txtCategories.Location = new System.Drawing.Point(80, 7); 47 | this.txtCategories.Name = "txtCategories"; 48 | this.txtCategories.Size = new System.Drawing.Size(100, 20); 49 | this.txtCategories.TabIndex = 1; 50 | this.txtCategories.Text = "All"; 51 | // 52 | // UserControlTextNaughtyStrings 53 | // 54 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 55 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 56 | this.Controls.Add(this.txtCategories); 57 | this.Controls.Add(this.lblCategory); 58 | this.Name = "UserControlTextNaughtyStrings"; 59 | this.Size = new System.Drawing.Size(390, 81); 60 | this.ResumeLayout(false); 61 | this.PerformLayout(); 62 | 63 | } 64 | 65 | #endregion 66 | 67 | private System.Windows.Forms.Label lblCategory; 68 | private System.Windows.Forms.TextBox txtCategories; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlTextNaughtyStrings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Gui.UserControls; 4 | 5 | namespace RandomDataGenerator.Gui.UserControlsFields 6 | { 7 | public sealed partial class UserControlTextNaughtyStrings : UserControlTextNaughtyStringsDesignable 8 | { 9 | public UserControlTextNaughtyStrings() 10 | { 11 | InitializeComponent(); 12 | 13 | InitEventsForControls(); 14 | } 15 | 16 | public override void SetOptionsAndUpdateControls(FieldOptionsTextNaughtyStrings options) 17 | { 18 | base.SetOptionsAndUpdateControls(options); 19 | 20 | txtCategories.Text = FieldOptions.Categories; 21 | } 22 | 23 | public override FieldOptionsTextNaughtyStrings GetFieldOptionsT() 24 | { 25 | FieldOptions = base.GetFieldOptionsT(); 26 | 27 | FieldOptions.Categories = txtCategories.Text; 28 | 29 | return FieldOptions; 30 | } 31 | } 32 | 33 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 34 | public class UserControlTextNaughtyStringsDesignable : BaseUserControl 35 | { 36 | } 37 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlTextPattern.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlTextPattern : UserControlTextPatternDesignable 7 | { 8 | public UserControlTextPattern() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsTextPattern options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | txtPattern.Text = FieldOptions.Pattern; 20 | //chkLetter.Checked = FieldOptions.UseLetter; 21 | //chkSpace.Checked = FieldOptions.UseSpace; 22 | //chkSpecial.Checked = FieldOptions.UseSpecial; 23 | //chkNumber.Checked = FieldOptions.UseNumber; 24 | 25 | //if (FieldOptions.UseLowercase && FieldOptions.UseUppercase) 26 | //{ 27 | // rbBoth.Checked = true; 28 | //} 29 | //else 30 | //{ 31 | // rbUpper.Checked = FieldOptions.UseUppercase; 32 | // rbLower.Checked = FieldOptions.UseLowercase; 33 | //} 34 | } 35 | 36 | public override FieldOptionsTextPattern GetFieldOptionsT() 37 | { 38 | FieldOptions = base.GetFieldOptionsT(); 39 | 40 | FieldOptions.Pattern = txtPattern.Text; 41 | //FieldOptions.UseLowercase = rbLower.Checked; 42 | //FieldOptions.UseUppercase = rbUpper.Checked; 43 | //FieldOptions.UseLetter = chkLetter.Checked; 44 | //FieldOptions.UseNumber = chkNumber.Checked; 45 | //FieldOptions.UseSpecial = chkSpecial.Checked; 46 | //FieldOptions.UseSpace = chkSpace.Checked; 47 | 48 | return FieldOptions; 49 | } 50 | } 51 | 52 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 53 | public class UserControlTextPatternDesignable : BaseUserControl 54 | { 55 | } 56 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlTextRegex.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public sealed partial class UserControlTextRegex : UserControlTextRegexDesignable 7 | { 8 | public UserControlTextRegex() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public override void SetOptionsAndUpdateControls(FieldOptionsTextRegex options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | txtPattern.Text = FieldOptions.Pattern ?? "[a-z]{1}"; 20 | } 21 | 22 | public override FieldOptionsTextRegex GetFieldOptionsT() 23 | { 24 | FieldOptions = base.GetFieldOptionsT(); 25 | 26 | FieldOptions.Pattern = txtPattern.Text; 27 | 28 | return FieldOptions; 29 | } 30 | } 31 | 32 | // Workaround http://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol 33 | public class UserControlTextRegexDesignable : BaseUserControl 34 | { 35 | } 36 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/UserControlsFields/UserControlTextWords.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Gui.UserControls; 3 | 4 | namespace RandomDataGenerator.Gui.UserControlsFields 5 | { 6 | public partial class UserControlTextWords : BaseUserControl //UserControlTextWordsDesignable 7 | { 8 | public UserControlTextWords() 9 | { 10 | InitializeComponent(); 11 | 12 | InitEventsForControls(); 13 | } 14 | 15 | public sealed override void SetOptionsAndUpdateControls(FieldOptionsTextWords options) 16 | { 17 | base.SetOptionsAndUpdateControls(options); 18 | 19 | ctrlMin.Value = FieldOptions.Min; 20 | ctrlMax.Value = FieldOptions.Max; 21 | } 22 | 23 | public override FieldOptionsTextWords GetFieldOptionsT() 24 | { 25 | FieldOptions = base.GetFieldOptionsT(); 26 | 27 | FieldOptions.Min = (int)ctrlMin.Value; 28 | FieldOptions.Max = (int)ctrlMax.Value; 29 | 30 | return FieldOptions; 31 | } 32 | 33 | private void EventValueChangedMin(object sender, System.EventArgs e) 34 | { 35 | ctrlMax.Minimum = ctrlMin.Value; 36 | } 37 | 38 | private void EventValueChangedMax(object sender, System.EventArgs e) 39 | { 40 | ctrlMin.Maximum = ctrlMax.Value; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/Util/StringUtils.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.Gui.Util 3 | { 4 | public static class StringUtils 5 | { 6 | public static string MakeSafeSQL(object value) 7 | { 8 | if (value == null) 9 | { 10 | return "NULL"; 11 | } 12 | 13 | string strValue = value.ToString(); 14 | 15 | return !string.IsNullOrEmpty(strValue) ? strValue.Replace("'", "''") : string.Empty; 16 | } 17 | 18 | public static string AddSQLQuotes(object value) 19 | { 20 | if (value == null) 21 | { 22 | return AddSQLQuotes("NULL"); 23 | } 24 | 25 | return $"'{MakeSafeSQL(value)}'"; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/VersionInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator.Gui/VersionInfo.cs -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui3/RandomDataGenerator.Gui3.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | netcoreapp3.1 6 | true 7 | false 8 | RandomDataGenerator.Gui 9 | RandomDataGenerator.Gui 10 | app.manifest 11 | true 12 | 13 | false 14 | win-x64 15 | RandomDataGenerator.Gui.Program 16 | AnyCPU 17 | 18 | 19 | 20 | 21 | %(RecursiveDir)%(FileName)%(Extension) 22 | 23 | 24 | %(RecursiveDir)%(FileName)%(Extension) 25 | 26 | 27 | %(RecursiveDir)%(FileName)%(Extension) 28 | 29 | 30 | %(RecursiveDir)%(FileName)%(Extension) 31 | 32 | 33 | %(RecursiveDir)%(FileName)%(Extension) 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui3/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | 55 | true 56 | 57 | 58 | 59 | 60 | 61 | 75 | 76 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui6/RandomDataGenerator.Gui6.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | true 7 | false 8 | RandomDataGenerator.Gui 9 | RandomDataGenerator.Gui 10 | app.manifest 11 | true 12 | 13 | false 14 | win-x64 15 | RandomDataGenerator.Gui.Program 16 | AnyCPU 17 | 18 | 19 | 20 | 21 | %(RecursiveDir)%(FileName)%(Extension) 22 | 23 | 24 | %(RecursiveDir)%(FileName)%(Extension) 25 | 26 | 27 | %(RecursiveDir)%(FileName)%(Extension) 28 | 29 | 30 | %(RecursiveDir)%(FileName)%(Extension) 31 | 32 | 33 | %(RecursiveDir)%(FileName)%(Extension) 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/RandomDataGenerator.Gui6/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | 55 | true 56 | 57 | 58 | 59 | 60 | 61 | 75 | 76 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/Compatibility/CustomIntrospectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace System.Reflection 5 | { 6 | /// 7 | /// https://github.com/castleproject/Core/blob/netcore/src/Castle.Core/Compatibility/IntrospectionExtensions.cs 8 | /// 9 | internal static class CustomIntrospectionExtensions 10 | { 11 | #if NET20 || NET35 12 | public static Type GetTypeInfo(this Type type) 13 | { 14 | return type; 15 | } 16 | 17 | public static Type[] GetGenericTypeArguments(this Type type) 18 | { 19 | return type.GetGenericArguments(); 20 | } 21 | #else 22 | public static Type[] GetGenericTypeArguments(this TypeInfo typeInfo) 23 | { 24 | return typeInfo.GenericTypeArguments; 25 | } 26 | #endif 27 | 28 | public static PropertyInfo[] GetPublicSettableProperties(this Type type) 29 | { 30 | #if NET20 || NET35 31 | return type.GetProperties(BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.Public); 32 | #else 33 | return type.GetTypeInfo().DeclaredProperties.Where(pi => pi.CanWrite).ToArray(); 34 | #endif 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Compatibility/FrameworkTraits.cs: -------------------------------------------------------------------------------- 1 | // Copied from https://raw.githubusercontent.com/SaladLab/NetLegacySupport/master/core/ConcurrentDictionary/System/Collections/Concurrent/FrameworkTraits.cs 2 | #if NET20 || NET35 3 | using System; 4 | using System.Threading; 5 | 6 | namespace RandomDataGenerator.Compatibility 7 | { 8 | internal static class Volatile 9 | { 10 | public static T Read(ref T location) where T : class 11 | { 12 | // 13 | // The VM will replace this with a more efficient implementation. 14 | // 15 | var value = location; 16 | Thread.MemoryBarrier(); 17 | return value; 18 | } 19 | 20 | public static void Write(ref T location, T value) where T : class 21 | { 22 | // 23 | // The VM will replace this with a more efficient implementation. 24 | // 25 | Thread.MemoryBarrier(); 26 | location = value; 27 | } 28 | } 29 | 30 | internal static class PlatformHelper 31 | { 32 | public static int ProcessorCount 33 | { 34 | get { return Environment.ProcessorCount; } 35 | } 36 | } 37 | 38 | internal static class Monitor 39 | { 40 | public static void Enter(Object obj, ref bool lockTaken) 41 | { 42 | if (lockTaken) 43 | throw new ArgumentException("Argument must be initialized to false", "lockTaken"); 44 | 45 | System.Threading.Monitor.Enter(obj); 46 | lockTaken = true; 47 | } 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/BrandInfo.cs: -------------------------------------------------------------------------------- 1 | // Copied from https://github.com/gustavofrizzo/CreditCardValidator 2 | using System.Collections.Generic; 3 | 4 | namespace RandomDataGenerator.CreditCardValidator; 5 | 6 | internal class BrandInfo 7 | { 8 | public List Rules { get; set; } = new(); 9 | 10 | public string BrandName { get; set; } = "Unknown"; 11 | 12 | public bool SkipLuhn { get; set; } = false; 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/CardIssuer.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.CreditCardValidator; 2 | 3 | /// 4 | /// Accepted Card Issuers Institutes. 5 | /// 6 | public enum CardIssuer 7 | { 8 | Any, // Choose any from below 9 | AmericanExpress, 10 | ChinaUnionPay, 11 | Dankort, 12 | DinersClub, 13 | Discover, 14 | Hipercard, 15 | JCB, 16 | Laser, 17 | Maestro, 18 | MasterCard, 19 | RuPay, 20 | Switch, 21 | Visa 22 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/CreditCardValidator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net35;netstandard1.1;netstandard2.0 5 | CreditCardValidator 6 | CreditCardValidator 7 | CreditCardValidator 8 | CreditCardValidator 9 | 2.0.1 10 | 2.0.1.0 11 | 2.0.1.0 12 | Credit Card Validator 13 | Copyright © Gustavo Frizzo 2020 14 | A library for validating and generating credit card numbers. 15 | 16 | CreditCardValidator helps you implementing validations for the most common credit card brands, verifying length, prefixes and checking the card number through the Luhn algorithm if necessary. 17 | 18 | CreditCardValidator helps you implementing validations for the most common credit card brands, verifying length, prefixes and checking the card number through the Luhn algorithm if needed. 19 | 20 | Gustavo Frizzo and contributors 21 | gustavo.frizzo 22 | MIT 23 | https://github.com/gustavofrizzo/CreditCardValidator 24 | https://github.com/gustavofrizzo/CreditCardValidator 25 | Credit Card Creditcard Check Validator Validations Luhn 26 | 27 | - Fixed issue where generating random card numbers in multiple threads could cause a NullReferenceException. 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Gustavo Frizzo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/Luhn.cs: -------------------------------------------------------------------------------- 1 | // Copied from https://github.com/gustavofrizzo/CreditCardValidator 2 | using System; 3 | using System.Linq; 4 | using RandomDataGenerator.Extensions; 5 | 6 | namespace RandomDataGenerator.CreditCardValidator; 7 | 8 | public static class Luhn 9 | { 10 | // Convert to int. 11 | private static readonly Func CharToInt = c => c - '0'; 12 | 13 | private static readonly Func IsEven = i => i % 2 == 0; 14 | 15 | // New Double Concept => 7 * 2 = 14 => 1 + 4 = 5. 16 | private static readonly Func DoubleDigit = i => (i * 2).ToString().ToCharArray().Select(CharToInt).Sum(); 17 | 18 | public static string CreateCheckDigit(string number) 19 | { 20 | if (!ValidationHelper.IsAValidNumber(number)) 21 | { 22 | throw new ArgumentException("Invalid number. Just numbers and white spaces are accepted in the string."); 23 | } 24 | 25 | var digitsSum = number 26 | .RemoveWhiteSpace() 27 | .ToCharArray() 28 | .Reverse() 29 | .Select(CharToInt) 30 | .Select((digit, index) => IsEven(index) ? DoubleDigit(digit) : digit) 31 | .Sum(); 32 | 33 | digitsSum *= 9; 34 | 35 | return digitsSum 36 | .ToString() 37 | .ToCharArray() 38 | .Last() 39 | .ToString(); 40 | } 41 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/Rule.cs: -------------------------------------------------------------------------------- 1 | // Copied from https://github.com/gustavofrizzo/CreditCardValidator 2 | using System.Collections.Generic; 3 | 4 | namespace RandomDataGenerator.CreditCardValidator; 5 | 6 | internal class Rule 7 | { 8 | public List Lengths { get; set; } = new(); 9 | 10 | public List Prefixes { get; set; }= new(); 11 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/CreditCardValidator/ValidationHelper.cs: -------------------------------------------------------------------------------- 1 | // Copied from https://github.com/gustavofrizzo/CreditCardValidator 2 | 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using RandomDataGenerator.Extensions; 6 | 7 | namespace RandomDataGenerator.CreditCardValidator; 8 | 9 | internal static class ValidationHelper 10 | { 11 | public static bool IsAValidNumber(string number) 12 | { 13 | number = number.RemoveWhiteSpace(); 14 | 15 | return number.ToCharArray().All(char.IsNumber) && !string.IsNullOrEmpty(number); 16 | } 17 | 18 | internal static List GetRulesByLength(CardIssuer cardIssuer, int length) 19 | { 20 | var rules = CreditCardData.BrandsData[cardIssuer].Rules; 21 | 22 | return rules.Where(rule => rule.Lengths.Contains(length)).ToList(); 23 | } 24 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Data/ListData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Reflection; 5 | using System.Text; 6 | using Fare; 7 | using RandomDataGenerator.Data.Models; 8 | 9 | namespace RandomDataGenerator.Data 10 | { 11 | internal sealed class ListData 12 | { 13 | private const char Tab = '\t'; 14 | 15 | public IEnumerable LastNames { get; } 16 | 17 | public IEnumerable MaleNames { get; } 18 | 19 | public IEnumerable FemaleNames { get; } 20 | 21 | public IEnumerable CityNames { get; } 22 | 23 | public IEnumerable CountryNames { get; } 24 | 25 | public IEnumerable Directions { get; } 26 | 27 | public IEnumerable StreetTypes { get; } 28 | 29 | public IEnumerable TopLevelDomains { get; } 30 | 31 | public IEnumerable IBANs { get; } 32 | 33 | public IEnumerable BBANs { get; } 34 | 35 | public IEnumerable LoremIpsum { get; } 36 | 37 | public IEnumerable LoremIpsumWords { get; } 38 | 39 | private ListData() 40 | { 41 | LastNames = GetResourceAsLines("LastNames"); 42 | MaleNames = GetResourceAsLines("MaleNames"); 43 | FemaleNames = GetResourceAsLines("FemaleNames"); 44 | CityNames = GetResourceAsLines("CityNames"); 45 | CountryNames = GetResourceAsLines("CountryNames"); 46 | Directions = new[] { "North", "East", "South", "West" }; 47 | StreetTypes = new[] { "St.", "Ln.", "Ave.", "Way", "Blvd.", "Ct." }; 48 | TopLevelDomains = new[] { "com", "net", "org", "us", "gov", "nl" }; 49 | 50 | Func ibanFunc = (columns) => new IBAN { CountryName = columns[0], CountryCode = columns[1], Generator = new Xeger(columns[2]) }; 51 | IBANs = GetResourceAsItems("IBAN", ibanFunc); 52 | BBANs = GetResourceAsItems("BBAN", ibanFunc); 53 | LoremIpsum = GetResourceAsLines("LoremIpsum"); 54 | LoremIpsumWords = GetResourceAsLines("LorumIpsumWords"); 55 | } 56 | 57 | public static ListData Instance => Nested.TextInstance; 58 | 59 | // ReSharper disable once ClassNeverInstantiated.Local 60 | private class Nested 61 | { 62 | // Explicit static constructor to tell C# compiler not to mark type as before field-init 63 | static Nested() 64 | { 65 | } 66 | 67 | internal static readonly ListData TextInstance = new ListData(); 68 | } 69 | 70 | private static Stream GetResourceAsStream(string resourceName) 71 | { 72 | return typeof(ListData).GetTypeInfo().Assembly.GetManifestResourceStream($"RandomDataGenerator.Data.Text.{resourceName}.txt"); 73 | } 74 | 75 | private static IEnumerable GetResourceAsLines(string fileName) 76 | { 77 | using (var stream = GetResourceAsStream(fileName)) 78 | { 79 | using (var reader = new StreamReader(stream, Encoding.UTF8)) 80 | { 81 | string line; 82 | while ((line = reader.ReadLine()) != null) 83 | { 84 | yield return line; 85 | } 86 | } 87 | } 88 | } 89 | 90 | private static IEnumerable GetResourceAsItems(string fileName, Func convert) 91 | { 92 | var lines = GetResourceAsLines(fileName); 93 | foreach (var line in lines) 94 | { 95 | yield return convert(line.Split(Tab)); 96 | } 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Data/Models/IBAN.cs: -------------------------------------------------------------------------------- 1 | using Fare; 2 | 3 | namespace RandomDataGenerator.Data.Models 4 | { 5 | internal struct IBAN 6 | { 7 | public string CountryName { get; set; } 8 | 9 | public string CountryCode { get; set; } 10 | 11 | public Xeger Generator { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/Data/Text/BBAN.txt: -------------------------------------------------------------------------------- 1 | Albania AL ^\d{8}[0-9A-Z]{16}$ 2 | Andorra AD ^\d{8}[0-9A-Z]{12}$ 3 | Austria AT ^\d{16}$ 4 | Kingdom of Bahrain BH ^[A-Z]{4}[0-9A-Z]{14}$ 5 | Belgium BE ^\d{12}$ 6 | Bosnia and Herzegovina BA ^\d{16}$ 7 | Bulgaria BG ^[A-Z]{4}\d{6}[0-9A-Z]{8}$ 8 | Croatia HR ^\d{17}$ 9 | Cyprus CY ^\d{8}[0-9A-Z]{16}$ 10 | Czech Republic CZ ^\d{20}$ 11 | Denmark DK ^\d{14}$ 12 | Dominican Republic DO ^[0-9A-Z]{4}\d{20}$ 13 | Estonia EE ^\d{16}$ 14 | Finland FI ^\d{14}$ 15 | France FR ^\d{10}[0-9A-Z]{11}\d{2}$ 16 | Georgia GE ^[A-Z]{2}\d{16}$ 17 | Germany DE ^\d{18}$ 18 | Gibraltar GI ^[A-Z]{4}[0-9A-Z]{15}$ 19 | Greece GR ^\d{7}[0-9A-Z]{16}$ 20 | Hungary HU ^\d{24}$ 21 | Iceland IS ^\d{22}$ 22 | Ireland IE ^[A-Z]{4}\d{14}$ 23 | Israel IL ^\d{19}$ 24 | Italy IT ^[A-Z]\d{10}[0-9A-Z]{12}$ 25 | Kazakhstan KZ ^\d{3}[0-9A-Z]{13}$ 26 | KUWAIT KW ^[A-Z]{4}[0-9A-Z]{22}$ 27 | Latvia LV ^[A-Z]{4}[0-9A-Z]{13}$ 28 | LEBANON LB ^\d{4}[0-9A-Z]{20}$ 29 | Liechtenstein (Principality of) LI ^\d{5}[0-9A-Z]{12}$ 30 | Lithuania LT ^\d{16}$ 31 | Luxembourg LU ^\d{3}[0-9A-Z]{13}$ 32 | Macedonia MK ^\d{3}[0-9A-Z]{10}\d{2}$ 33 | Malta MT ^[A-Z]{4}\d{5}[0-9A-Z]{18}$ 34 | Mauritania MR ^\d{23}$ 35 | Mauritius MU ^[A-Z]{4}\d{19}[A-Z]{3}$ 36 | Monaco MC ^\d{10}[0-9A-Z]{11}\d{2}$ 37 | Montenegro ME ^\d{18}$ 38 | The Netherlands NL ^[A-Z]{4}\d{10}$ 39 | Norway NO ^\d{11}$ 40 | Poland PL ^\d{24}$ 41 | Portugal PT ^\d{21}$ 42 | Romania RO ^[A-Z]{4}[0-9A-Z]{16}$ 43 | San Marino SM ^[A-Z]\d{10}[0-9A-Z]{12}$ 44 | Saudi Arabia SA ^\d{2}[0-9A-Z]{18}$ 45 | Serbia RS ^\d{18}$ 46 | Slovak Republic SK ^\d{20}$ 47 | Slovenia SI ^\d{15}$ 48 | Spain ES ^\d{20}$ 49 | Sweden SE ^\d{20}$ 50 | Switzerland CH ^\d{5}[0-9A-Z]{12}$ 51 | Tunisia TN ^\d{20}$ 52 | Turkey TR ^\d{5}[0-9A-Z]{17}$ 53 | United Arab Emirates AE ^\d{19}$ 54 | United Kingdom GB ^[A-Z]{4}\d{14}$ -------------------------------------------------------------------------------- /src/RandomDataGenerator/Data/Text/IBAN.txt: -------------------------------------------------------------------------------- 1 | Albania AL ^AL\d{10}[0-9A-Z]{16}$ 2 | Andorra AD ^AD\d{10}[0-9A-Z]{12}$ 3 | Austria AT ^AT\d{18}$ 4 | Kingdom of Bahrain BH ^BH\d{2}[A-Z]{4}[0-9A-Z]{14}$ 5 | Belgium BE ^BE\d{14}$ 6 | Bosnia and Herzegovina BA ^BA\d{18}$ 7 | Bulgaria BG ^BG\d{2}[A-Z]{4}\d{6}[0-9A-Z]{8}$ 8 | Croatia HR ^HR\d{19}$ 9 | Cyprus CY ^CY\d{10}[0-9A-Z]{16}$ 10 | Czech Republic CZ ^CZ\d{22}$ 11 | Denmark DK ^DK\d{16}$|^FO\d{16}$|^GL\d{16}$ 12 | Dominican Republic DO ^DO\d{2}[0-9A-Z]{4}\d{20}$ 13 | Estonia EE ^EE\d{18}$ 14 | Finland FI ^FI\d{16}$ 15 | France FR ^FR\d{12}[0-9A-Z]{11}\d{2}$ 16 | Georgia GE ^GE\d{2}[A-Z]{2}\d{16}$ 17 | Germany DE ^DE\d{20}$ 18 | Gibraltar GI ^GI\d{2}[A-Z]{4}[0-9A-Z]{15}$ 19 | Greece GR ^GR\d{9}[0-9A-Z]{16}$ 20 | Hungary HU ^HU\d{26}$ 21 | Iceland IS ^IS\d{24}$ 22 | Ireland IE ^IE\d{2}[A-Z]{4}\d{14}$ 23 | Israel IL ^IL\d{21}$ 24 | Italy IT ^IT\d{2}[A-Z]\d{10}[0-9A-Z]{12}$ 25 | Kazakhstan KZ ^[A-Z]{2}\d{5}[0-9A-Z]{13}$ 26 | KUWAIT KW ^KW\d{2}[A-Z]{4}22!$ 27 | Latvia LV ^LV\d{2}[A-Z]{4}[0-9A-Z]{13}$ 28 | LEBANON LB ^LB\d{6}[0-9A-Z]{20}$ 29 | Liechtenstein (Principality of) LI ^LI\d{7}[0-9A-Z]{12}$ 30 | Lithuania LT ^LT\d{18}$ 31 | Luxembourg LU ^LU\d{5}[0-9A-Z]{13}$ 32 | Macedonia MK ^MK\d{5}[0-9A-Z]{10}\d{2}$ 33 | Malta MT ^MT\d{2}[A-Z]{4}\d{5}[0-9A-Z]{18}$ 34 | Mauritania MR ^MR13\d{23}$ 35 | Mauritius MU ^MU\d{2}[A-Z]{4}\d{19}[A-Z]{3}$ 36 | Monaco MC ^MC\d{12}[0-9A-Z]{11}\d{2}$ 37 | Montenegro ME ^ME\d{20}$ 38 | The Netherlands NL ^NL\d{2}[A-Z]{4}\d{10}$ 39 | Norway NO ^NO\d{13}$ 40 | Poland PL ^PL\d{10}[0-9A-Z]{16}$ 41 | Portugal PT ^PT\d{23}$ 42 | Romania RO ^RO\d{2}[A-Z]{4}[0-9A-Z]{16}$ 43 | San Marino SM ^SM\d{2}[A-Z]\d{10}[0-9A-Z]{12}$ 44 | Saudi Arabia SA ^SA\d{4}[0-9A-Z]{18}$ 45 | Serbia RS ^RS\d{20}$ 46 | Slovak Republic SK ^SK\d{22}$ 47 | Slovenia SI ^SI\d{17}$ 48 | Spain ES ^ES\d{22}$ 49 | Sweden SE ^SE\d{22}$ 50 | Switzerland CH ^CH\d{7}[0-9A-Z]{12}$ 51 | Tunisia TN ^TN59\d{20}$ 52 | Turkey TR ^TR\d{7}[0-9A-Z]{17}$ 53 | United Arab Emirates AE ^AE\d{21}$ 54 | United Kingdom GB ^GB\d{2}[A-Z]{4}\d{14}$ -------------------------------------------------------------------------------- /src/RandomDataGenerator/Enums/FieldType.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace RandomDataGenerator.Enums 4 | { 5 | public enum FieldType 6 | { 7 | None, 8 | 9 | [Description("Numbers")] 10 | Numbers, 11 | 12 | [Description("IT")] 13 | IT, 14 | 15 | [Description("Human")] 16 | Human, 17 | 18 | [Description("Location")] 19 | Location, 20 | 21 | [Description("Text")] 22 | Text, 23 | 24 | [Description("Time")] 25 | Time, 26 | 27 | [Description("Set")] 28 | Set 29 | } 30 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Enums/SubFieldType.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace RandomDataGenerator.Enums 4 | { 5 | public enum SubFieldType 6 | { 7 | None, 8 | 9 | // Numbers 10 | [Description("Boolean")] 11 | Boolean, 12 | 13 | [Description("Short")] 14 | Short, 15 | 16 | [Description("Integer")] 17 | Integer, 18 | 19 | [Description("Long")] 20 | Long, 21 | 22 | [Description("Float")] 23 | Float, 24 | 25 | [Description("Double")] 26 | Double, 27 | 28 | [Description("CCN")] 29 | CCN, 30 | 31 | 32 | // IT 33 | [Description("IPv4 Address")] 34 | IPv4Address, 35 | 36 | [Description("IPv6 Address")] 37 | IPv6Address, 38 | 39 | [Description("MAC Address")] 40 | MACAddress, 41 | 42 | [Description("Guid")] 43 | Guid, 44 | 45 | // Human 46 | [Description("Full Name")] 47 | FullName, 48 | 49 | [Description("Last Name")] 50 | LastName, 51 | 52 | [Description("First Name")] 53 | FirstName, 54 | 55 | [Description("Email Address")] 56 | EmailAddress, 57 | 58 | 59 | // Location 60 | [Description("Country")] 61 | Country, 62 | 63 | [Description("City")] 64 | City, 65 | 66 | 67 | // Text 68 | [Description("Words")] 69 | TextWords, 70 | 71 | [Description("Text Pattern")] 72 | TextPattern, 73 | 74 | [Description("Text Regex")] 75 | TextRegex, 76 | 77 | [Description("Text Lipsum")] 78 | TextLipsum, 79 | 80 | [Description("Random Text")] 81 | Text, 82 | 83 | [Description("Naughty Strings")] 84 | TextNaughtyStrings, 85 | 86 | [Description("Date / Time")] 87 | DateTime, 88 | 89 | // Set 90 | [Description("String List")] 91 | StringList 92 | } 93 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace RandomDataGenerator.Extensions; 4 | 5 | internal static class StringExtensions 6 | { 7 | public static string? ToCasedInvariant(this string? str, bool toUpper) 8 | { 9 | if (str == null) 10 | { 11 | return null; 12 | } 13 | 14 | return toUpper ? str.ToUpperInvariant() : str.ToLowerInvariant(); 15 | } 16 | 17 | public static string RemoveWhiteSpace(this string input) 18 | { 19 | return new string(input.ToCharArray() 20 | .Where(c => !char.IsWhiteSpace(c)) 21 | .ToArray()); 22 | } 23 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsAbstract.cs: -------------------------------------------------------------------------------- 1 | #if !NETSTANDARD1_3 2 | using System.Xml.Serialization; 3 | #endif 4 | 5 | namespace RandomDataGenerator.FieldOptions 6 | { 7 | #if !NETSTANDARD1_3 8 | [XmlInclude(typeof(FieldOptionsBytes))] 9 | [XmlInclude(typeof(FieldOptionsCCN))] 10 | [XmlInclude(typeof(FieldOptionsCity))] 11 | [XmlInclude(typeof(FieldOptionsCountry))] 12 | [XmlInclude(typeof(FieldOptionsDateTime))] 13 | [XmlInclude(typeof(FieldOptionsEmailAddress))] 14 | [XmlInclude(typeof(FieldOptionsFirstName))] 15 | [XmlInclude(typeof(FieldOptionsIBAN))] 16 | [XmlInclude(typeof(FieldOptionsNumber))] 17 | [XmlInclude(typeof(FieldOptionsNumber))] 18 | [XmlInclude(typeof(FieldOptionsNumber))] 19 | [XmlInclude(typeof(FieldOptionsNumber))] 20 | [XmlInclude(typeof(FieldOptionsNumber))] 21 | [XmlInclude(typeof(FieldOptionsNumber))] 22 | [XmlInclude(typeof(FieldOptionsFullName))] 23 | [XmlInclude(typeof(FieldOptionsGuid))] 24 | [XmlInclude(typeof(FieldOptionsInteger))] 25 | [XmlInclude(typeof(FieldOptionsIPv4Address))] 26 | [XmlInclude(typeof(FieldOptionsIPv6Address))] 27 | [XmlInclude(typeof(FieldOptionsLastName))] 28 | [XmlInclude(typeof(FieldOptionsMACAddress))] 29 | [XmlInclude(typeof(FieldOptionsTextPattern))] 30 | [XmlInclude(typeof(FieldOptionsTextRegex))] 31 | [XmlInclude(typeof(FieldOptionsTextNaughtyStrings))] 32 | [XmlInclude(typeof(FieldOptionsText))] 33 | [XmlInclude(typeof(FieldOptionsTextWords))] 34 | [XmlInclude(typeof(FieldOptionsStringList))] 35 | #endif 36 | public abstract class FieldOptionsAbstract 37 | { 38 | public bool UseNullValues { get; set; } 39 | 40 | public bool ValueAsString { get; set; } 41 | 42 | public int? Seed { get; set; } 43 | 44 | public FieldOptionsAbstract Clone() 45 | { 46 | return (FieldOptionsAbstract)MemberwiseClone(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsBoolean.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsBoolean : FieldOptionsNumber 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsByte.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsByte : FieldOptionsNumber 5 | { 6 | public override byte Min { get; set; } 7 | 8 | public override byte Max { get; set; } = byte.MaxValue; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsBytes.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsBytes : FieldOptionsAbstract, IFieldOptionsBytes 5 | { 6 | public int Min { get; set; } 7 | 8 | public int Max { get; set; } = 1024; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsCCN.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.CreditCardValidator; 2 | 3 | namespace RandomDataGenerator.FieldOptions; 4 | 5 | public class FieldOptionsCCN : FieldOptionsAbstract, IFieldOptionsString 6 | { 7 | public CardIssuer CardIssuer { get; set; } = CardIssuer.Visa; 8 | 9 | public int Length { get; set; } = 0; 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsCity.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsCity : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsCountry.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsCountry : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.FieldOptions 4 | { 5 | public class FieldOptionsDateTime : FieldOptionsAbstract, IFieldOptionsDateTime 6 | { 7 | public const string DefaultFormat = "s"; // "s" -> sortable date/time pattern 8 | 9 | public string Format { get; set; } = DefaultFormat; 10 | 11 | public DateTime From { get; set; } = DateTime.UtcNow.Date; 12 | 13 | public DateTime To { get; set; } = DateTime.UtcNow.Date.AddYears(1); 14 | 15 | public bool IncludeTime { get; set; } = true; 16 | } 17 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsDouble.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsDouble : FieldOptionsNumber 5 | { 6 | public override double Min { get; set; } 7 | 8 | public override double Max { get; set; } = double.MaxValue; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsEmailAddress.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsEmailAddress : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public bool Male { get; set; } = true; 7 | 8 | public bool Female { get; set; } = true; 9 | 10 | public bool Left2Right { get; set; } = true; 11 | } 12 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using RandomDataGenerator.Enums; 5 | using Stef.Validation; 6 | 7 | namespace RandomDataGenerator.FieldOptions; 8 | 9 | public static class FieldOptionsFactory 10 | { 11 | private const string Namespace = "RandomDataGenerator.FieldOptions"; 12 | 13 | public static FieldOptionsAbstract GetFieldOptions(SubFieldType subFieldType) 14 | { 15 | var type = Type.GetType($"{Namespace}.FieldOptions{subFieldType}", true)!; 16 | 17 | return (FieldOptionsAbstract)Activator.CreateInstance(type); 18 | } 19 | 20 | public static FieldOptionsAbstract GetFieldOptions(string name, Dictionary properties) 21 | { 22 | Guard.NotNullOrEmpty(name); 23 | Guard.NotNull(properties); 24 | 25 | // Generate classname 26 | var className = !name.StartsWith("FieldOptions") ? $"FieldOptions{name}" : name; 27 | 28 | // Create type based on classname 29 | var type = Type.GetType($"{Namespace}.{className}", true)!; 30 | var fieldOptions = (FieldOptionsAbstract)Activator.CreateInstance(type); 31 | 32 | // Loop all settable properties and set value if it's defined as an argument 33 | foreach (var propertyInfo in type.GetPublicSettableProperties()) 34 | { 35 | var exists = properties.ContainsKey(propertyInfo.Name); 36 | if (exists) 37 | { 38 | propertyInfo.SetValue(fieldOptions, properties[propertyInfo.Name], null); 39 | } 40 | } 41 | 42 | return fieldOptions; 43 | } 44 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsFirstName.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public class FieldOptionsFirstName : FieldOptionsAbstract, IFieldOptionsString 4 | { 5 | public bool Male { get; set; } = true; 6 | 7 | public bool Female { get; set; } = true; 8 | } 9 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsFloat.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsFloat : FieldOptionsNumber 5 | { 6 | public override float Min { get; set; } 7 | 8 | public override float Max { get; set; } = float.MaxValue; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsFullName.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsFullName : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public bool Male { get; set; } = true; 7 | 8 | public bool Female { get; set; } = true; 9 | 10 | public bool Left2Right { get; set; } = true; 11 | } 12 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsGuid.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsGuid : FieldOptionsAbstract, IFieldOptionsGuid 5 | { 6 | public bool Uppercase { get; set; } = true; 7 | 8 | public string Format { get; set; } = "D"; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsIBAN.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsIBAN : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public string? CountryCode { get; set; } 7 | 8 | /// 9 | /// The type can be IBAN (default), BBAN or BOTH. In case the value is null, IBAN is used as default. 10 | /// 11 | public string Type { get; set; } = "IBAN"; 12 | } 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsIPv4Address.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsIPv4Address : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public string? Min { get; set; } 7 | 8 | public string? Max { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsIPv6Address.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsIPv6Address : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public bool Uppercase { get; set; } 7 | 8 | public string? Min { get; set; } 9 | 10 | public string? Max { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsInteger.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsInteger : FieldOptionsNumber 5 | { 6 | public override int Min { get; set; } 7 | 8 | public override int Max { get; set; } = int.MaxValue; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsLastName.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsLastName : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsLong.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsLong : FieldOptionsNumber 5 | { 6 | public override long Min { get; set; } 7 | 8 | public override long Max { get; set; } = long.MaxValue; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsMACAddress.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public class FieldOptionsMACAddress : FieldOptionsAbstract, IFieldOptionsString 4 | { 5 | public string Separator { get; set; } = ":"; 6 | 7 | public bool Uppercase { get; set; } = true; 8 | 9 | public string? Min { get; set; } 10 | 11 | public string? Max { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsNumber.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public abstract class FieldOptionsNumber : FieldOptionsAbstract, IFieldOptionsNumber where T : struct 4 | { 5 | public virtual T Min { get; set; } 6 | 7 | public virtual T Max { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsShort.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public class FieldOptionsShort : FieldOptionsNumber 4 | { 5 | public override short Min { get; set; } 6 | 7 | public override short Max { get; set; } = short.MaxValue; 8 | } 9 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsStringList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RandomDataGenerator.FieldOptions; 4 | 5 | public class FieldOptionsStringList : FieldOptionsAbstract, IFieldOptionsString 6 | { 7 | public List Values { get; set; } = new(); 8 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsText.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsText : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public int Min { get; set; } = 8; 7 | public int Max { get; set; } = 8; 8 | public bool UseUppercase { get; set; } = true; 9 | public bool UseLowercase { get; set; } = true; 10 | public bool UseLetter { get; set; } = true; 11 | public bool UseNumber { get; set; } = true; 12 | public bool UseSpace { get; set; } = true; 13 | public bool UseSpecial { get; set; } = true; 14 | } 15 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTextLipsum.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsTextLipsum : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public int Paragraphs { get; set; } = 1; 7 | } 8 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTextNaughtyStrings.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public class FieldOptionsTextNaughtyStrings : FieldOptionsAbstract, IFieldOptionsString 4 | { 5 | internal static string All = "All"; 6 | 7 | /// 8 | /// A comma separated string from one or more from these categories: 9 | /// 10 | /// All 11 | /// Changinglengthwhenlowercased 12 | /// CommandInjectionRuby 13 | /// Emoji 14 | /// FileInclusion 15 | /// Humaninjection 16 | /// JapaneseEmoticons 17 | /// KnownCVEsandVulnerabilities 18 | /// MSDOSWindowsSpecialFilenames 19 | /// NumericStrings 20 | /// OghamText 21 | /// QuotationMarks 22 | /// ReservedStrings 23 | /// RightToLeftStrings 24 | /// SQLInjection 25 | /// ScriptInjection 26 | /// ScunthorpeProblem 27 | /// ServerCodeInjection 28 | /// SpecialCharacters 29 | /// SpecialUnicodeCharactersUnion 30 | /// Stringswhichcontaintwobyteletters 31 | /// Terminalescapecodes 32 | /// TrickUnicode 33 | /// TwoByteCharacters 34 | /// UnicodeNumbers 35 | /// UnicodeSubscriptSuperscriptAccents 36 | /// UnicodeSymbols 37 | /// UnicodeUpsidedown 38 | /// Unicodefont 39 | /// UnwantedInterpolation 40 | /// ZalgoText 41 | /// iOSVulnerabilities 42 | /// 43 | /// When null, the 'All' category is used. 44 | /// 45 | public string Categories { get; set; } = All; 46 | } 47 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTextPattern.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.FieldOptions 4 | { 5 | [Obsolete("Use FieldOptionsTextRegex")] 6 | public class FieldOptionsTextPattern : FieldOptionsAbstract, IFieldOptionsString 7 | { 8 | /// 9 | /// L - for upper case letter 10 | /// l - for lower case letter 11 | /// n - for number 12 | /// s - for special character 13 | /// _ - for space character 14 | /// * - for any character 15 | /// \ - for character as-is 16 | /// 17 | public string Pattern { get; set; } = "*"; 18 | } 19 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTextRegex.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public class FieldOptionsTextRegex : FieldOptionsAbstract, IFieldOptionsString 4 | { 5 | /// 6 | /// Use any valid Regex pattern to generate a string. 7 | /// 8 | public string Pattern { get; set; } = null!; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTextWords.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RandomDataGenerator.FieldOptions 3 | { 4 | public class FieldOptionsTextWords : FieldOptionsAbstract, IFieldOptionsString 5 | { 6 | public int Min { get; set; } = 1; 7 | 8 | public int Max { get; set; } = 10; 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/FieldOptionsTimeSpan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.FieldOptions 4 | { 5 | public class FieldOptionsTimeSpan : FieldOptionsAbstract, IFieldOptionsTimeSpan 6 | { 7 | public const string DefaultFormat = "c"; // "c" -> Constant (invariant) format 8 | 9 | public string Format { get; set; } = DefaultFormat; 10 | 11 | public bool IncludeMilliseconds { get; set; } = true; 12 | 13 | public TimeSpan From { get; set; } 14 | 15 | public TimeSpan To { get; set; } = TimeSpan.MaxValue; 16 | } 17 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsBytes.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public interface IFieldOptionsBytes 4 | { 5 | int Min { get; set; } 6 | 7 | int Max { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.FieldOptions 4 | { 5 | public interface IFieldOptionsDateTime 6 | { 7 | DateTime From { get; set; } 8 | 9 | DateTime To { get; set; } 10 | 11 | bool IncludeTime { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsGuid.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public interface IFieldOptionsGuid 4 | { 5 | bool Uppercase { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsNumber.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions 2 | { 3 | public interface IFieldOptionsNumber where T : struct 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsString.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.FieldOptions; 2 | 3 | public interface IFieldOptionsString 4 | { 5 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/FieldOptions/IFieldOptionsTimeSpan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.FieldOptions 4 | { 5 | public interface IFieldOptionsTimeSpan 6 | { 7 | /// 8 | /// Allowed values are "c", "g" and "G". 9 | /// See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings 10 | /// 11 | string Format { get; set; } 12 | 13 | TimeSpan From { get; set; } 14 | 15 | TimeSpan To { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomItemFromListGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace RandomDataGenerator.Generators; 6 | 7 | internal class RandomItemFromListGenerator 8 | { 9 | private readonly RandomValueGenerator _randomValueGenerator; 10 | private readonly T[] _list; 11 | 12 | public RandomItemFromListGenerator(int? seed, IEnumerable list, Func? predicate = null) 13 | { 14 | _list = predicate == null ? list.ToArray() : list.Where(predicate).ToArray(); 15 | _randomValueGenerator = RandomValueGeneratorFactory.Create(seed); 16 | } 17 | 18 | public T? Generate() 19 | { 20 | return _list.Length > 0 ? _list[_randomValueGenerator.Next(0, _list.Length - 1)] : default; 21 | } 22 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomItemsFromListGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace RandomDataGenerator.Generators; 6 | 7 | internal class RandomItemsFromListGenerator 8 | { 9 | private readonly RandomValueGenerator _randomValueGenerator; 10 | private readonly T[] _list; 11 | 12 | public RandomItemsFromListGenerator(int? seed, IEnumerable list, Func? predicate = null) 13 | { 14 | _list = predicate == null ? list.ToArray() : list.Where(predicate).ToArray(); 15 | _randomValueGenerator = RandomValueGeneratorFactory.Create(seed); 16 | } 17 | 18 | public List Generate(int count) 19 | { 20 | var list = new List(count); 21 | for (int i = 0; i < count; i++) 22 | { 23 | int index = _randomValueGenerator.Next(0, _list.Length - 1); 24 | list.Add(_list[index]); 25 | } 26 | 27 | return list; 28 | } 29 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomStringFromListGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RandomDataGenerator.Generators; 4 | 5 | internal class RandomStringFromListGenerator : RandomItemFromListGenerator 6 | { 7 | public RandomStringFromListGenerator(IEnumerable list, int? seed = null) : base(seed, list) 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomStringsFromListGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RandomDataGenerator.Generators; 4 | 5 | internal class RandomStringsFromListGenerator : RandomItemsFromListGenerator 6 | { 7 | public RandomStringsFromListGenerator(IEnumerable list, int? seed = null) : base(seed, list) 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomThingsGenerator.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Generators; 2 | 3 | internal class RandomThingsGenerator 4 | { 5 | private readonly RandomValueGenerator _randomValueGenerator; 6 | private readonly T _min; 7 | private readonly T _max; 8 | 9 | public RandomThingsGenerator(T min, T max, int? seed) 10 | { 11 | _min = min; 12 | _max = max; 13 | _randomValueGenerator = RandomValueGeneratorFactory.Create(seed); 14 | } 15 | 16 | public T Generate() 17 | { 18 | return _randomValueGenerator.Next(_min, _max); 19 | } 20 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Generators/RandomValueGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.Generators; 4 | 5 | internal static class RandomValueGeneratorFactory 6 | { 7 | private static readonly RandomValueGenerator Value = new(Environment.TickCount); 8 | 9 | public static RandomValueGenerator Create(int? seed) 10 | { 11 | return seed is null ? Value : new RandomValueGenerator(seed.Value); 12 | } 13 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/RandomDataGenerator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Random Data Generator 5 | Random Data Generator 6 | This is a configurable generator to create random data like Lorum Ipsum Text, Words, Text Patterns, First/Last Names, IP-Addresses, Guids, DateTime and more. 7 | Stef Heyenrath 8 | Stef Heyenrath 9 | net35;net45;netstandard1.3;netstandard2.0;netstandard2.1 10 | RandomDataGenerator.Net 11 | Random;Data;Text;Lipsum 12 | See ReleaseNotes.md 13 | https://raw.githubusercontent.com/StefH/RandomDataGenerator/master/resources/icon_64x64.png 14 | https://github.com/StefH/RandomDataGenerator 15 | MIT 16 | git 17 | https://github.com/StefH/RandomDataGenerator 18 | full 19 | true 20 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb 21 | ../../resources/icon.ico 22 | true 23 | RandomDataGenerator.snk 24 | 25 | 26 | 27 | 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | All 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/RandomDataGenerator/RandomDataGenerator.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StefH/RandomDataGenerator/1a5a0d31b2e4b2acfad8311f704ae5dcda8ddabf/src/RandomDataGenerator/RandomDataGenerator.snk -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerBytes.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using JetBrains.Annotations; 3 | 4 | namespace RandomDataGenerator.Randomizers; 5 | 6 | public interface IRandomizerBytes 7 | { 8 | byte[] Generate(); 9 | 10 | string GenerateAsUTF8String(); 11 | 12 | string GenerateAsASCIIString(); 13 | 14 | string GenerateAsBase64String(); 15 | 16 | string GenerateAsString(Encoding? encoding = null); 17 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.Randomizers; 4 | 5 | public interface IRandomizerDateTime 6 | { 7 | DateTime? Generate(); 8 | 9 | string? GenerateAsString(); 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerGuid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.Randomizers; 4 | 5 | public interface IRandomizerGuid 6 | { 7 | Guid? Generate(); 8 | 9 | string? GenerateAsString(); 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerNumber.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Randomizers; 2 | 3 | public interface IRandomizerNumber where T : struct 4 | { 5 | T? Generate(); 6 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerString.cs: -------------------------------------------------------------------------------- 1 | namespace RandomDataGenerator.Randomizers; 2 | 3 | public interface IRandomizerString 4 | { 5 | string? Generate(); 6 | 7 | string? Generate(bool upperCase); 8 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/IRandomizerTimeSpan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RandomDataGenerator.Randomizers; 4 | 5 | public interface IRandomizerTimeSpan 6 | { 7 | TimeSpan? Generate(); 8 | 9 | string? GenerateAsString(); 10 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerAbstract.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Generators; 3 | 4 | namespace RandomDataGenerator.Randomizers; 5 | 6 | public abstract class RandomizerAbstract where TOptions : FieldOptionsAbstract 7 | { 8 | private readonly RandomValueGenerator _randomValueGenerator; 9 | protected readonly TOptions Options; 10 | 11 | protected RandomizerAbstract(TOptions options) 12 | { 13 | Options = options; 14 | _randomValueGenerator = RandomValueGeneratorFactory.Create(options.Seed); 15 | } 16 | 17 | protected virtual bool IsNull() 18 | { 19 | return Options.UseNullValues && _randomValueGenerator.Next(0, 10) == 5; // 10% chance on null 20 | } 21 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerBytes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerBytes : RandomizerAbstract, IRandomizerBytes 9 | { 10 | private readonly RandomValueGenerator _randomValueGenerator; 11 | 12 | public RandomizerBytes(FieldOptionsBytes options) 13 | : base(options) 14 | { 15 | _randomValueGenerator = RandomValueGeneratorFactory.Create(options.Seed); 16 | } 17 | 18 | public byte[] Generate() 19 | { 20 | return _randomValueGenerator.NextBytes(Options.Min, Options.Max); 21 | } 22 | 23 | public string GenerateAsString(Encoding? encoding) 24 | { 25 | return (encoding ?? Encoding.UTF8).GetString(Generate()); 26 | } 27 | 28 | public string GenerateAsUTF8String() 29 | { 30 | return GenerateAsString(Encoding.UTF8); 31 | } 32 | 33 | public string GenerateAsASCIIString() 34 | { 35 | return GenerateAsString(Encoding.ASCII); 36 | } 37 | 38 | public string GenerateAsBase64String() 39 | { 40 | return Convert.ToBase64String(Generate()); 41 | } 42 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerCCN.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using RandomDataGenerator.CreditCardValidator; 4 | using RandomDataGenerator.Extensions; 5 | using RandomDataGenerator.FieldOptions; 6 | using RandomDataGenerator.Generators; 7 | 8 | namespace RandomDataGenerator.Randomizers; 9 | 10 | public class RandomizerCCN : RandomizerAbstract, IRandomizerString 11 | { 12 | private readonly RandomizerNumber _randomizerNumberBetween0And10; 13 | private readonly RandomItemFromListGenerator _randomizerCardIssuer; 14 | 15 | public RandomizerCCN(FieldOptionsCCN options) : base(options) 16 | { 17 | _randomizerNumberBetween0And10 = new RandomizerNumber(new FieldOptionsInteger { Min = 0, Max = 10, Seed = options.Seed }); 18 | _randomizerCardIssuer = new RandomItemFromListGenerator(options.Seed, Enum.GetValues(typeof(CardIssuer)).Cast().Where(c => c != CardIssuer.Any)); 19 | } 20 | 21 | public string? Generate() 22 | { 23 | return IsNull() ? null : GenerateRandomCreditCardNumber(Options.CardIssuer, Options.Length); 24 | } 25 | 26 | public string? Generate(bool upperCase) 27 | { 28 | return Generate().ToCasedInvariant(upperCase); 29 | } 30 | 31 | private string GenerateRandomCreditCardNumber(CardIssuer cardIssuer, int length) 32 | { 33 | cardIssuer = cardIssuer == CardIssuer.Any ? _randomizerCardIssuer.Generate() : cardIssuer; 34 | 35 | var rules = ValidationHelper.GetRulesByLength(cardIssuer, Options.Length); 36 | 37 | if (Options.Length > 0 && rules.Count == 0) 38 | { 39 | throw new ArgumentException($"The card number length [{Options.Length}] is not valid for the card issuer [{cardIssuer}]."); 40 | } 41 | 42 | var rule = rules.Count == 0 ? CreditCardData.BrandsData[cardIssuer].Rules.First() : rules.First(); 43 | 44 | length = length > 0 ? length : rule.Lengths.First(); 45 | 46 | var number = new RandomItemFromListGenerator(Options.Seed, rule.Prefixes).Generate()!; 47 | 48 | var numberLength = number.Length; 49 | for (int i = 0; i < length - 1 - numberLength; i++) 50 | { 51 | number += _randomizerNumberBetween0And10.Generate(); 52 | } 53 | 54 | number += Luhn.CreateCheckDigit(number); 55 | 56 | return number; 57 | } 58 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerCity.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Data; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerCity : RandomizerAbstract, IRandomizerString 9 | { 10 | private readonly RandomStringFromListGenerator _generator; 11 | 12 | public RandomizerCity(FieldOptionsCity options) : base(options) 13 | { 14 | _generator = new RandomStringFromListGenerator(ListData.Instance.CityNames); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() ? null : _generator.Generate(); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerCountry.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Data; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerCountry : RandomizerAbstract, IRandomizerString 9 | { 10 | private readonly RandomStringFromListGenerator _generator; 11 | 12 | public RandomizerCountry(FieldOptionsCountry options) : base(options) 13 | { 14 | _generator = new RandomStringFromListGenerator(ListData.Instance.CountryNames); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() ? null : _generator.Generate(); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerDateTime : RandomizerAbstract, IRandomizerDateTime 9 | { 10 | private readonly RandomThingsGenerator _generator; 11 | 12 | public RandomizerDateTime(FieldOptionsDateTime options) 13 | : base(options) 14 | { 15 | _generator = new RandomThingsGenerator(options.From, options.To, options.Seed); 16 | } 17 | 18 | public DateTime? Generate() 19 | { 20 | if (IsNull()) 21 | { 22 | return null; 23 | } 24 | 25 | DateTime value = _generator.Generate(); 26 | return Options.IncludeTime ? value : value.Date; 27 | } 28 | 29 | public string? GenerateAsString() 30 | { 31 | DateTime? date = Generate(); 32 | 33 | string format = !string.IsNullOrEmpty(Options.Format) ? Options.Format : FieldOptionsDateTime.DefaultFormat; 34 | return date?.ToString(format, CultureInfo.InvariantCulture); 35 | } 36 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerEmailAddress.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using RandomDataGenerator.Data; 4 | using RandomDataGenerator.Extensions; 5 | using RandomDataGenerator.FieldOptions; 6 | using RandomDataGenerator.Generators; 7 | 8 | namespace RandomDataGenerator.Randomizers; 9 | 10 | public class RandomizerEmailAddress : RandomizerAbstract, IRandomizerString 11 | { 12 | private readonly RandomizerTextWords _wordGenerator; 13 | private readonly RandomThingsGenerator _numberGenerator; 14 | private readonly RandomStringFromListGenerator _topLevelDomainGenerator; 15 | private readonly RandomStringFromListGenerator _lastNamesGenerator; 16 | private readonly List _genderSetGenerators = new List(); 17 | 18 | public RandomizerEmailAddress(FieldOptionsEmailAddress options) : base(options) 19 | { 20 | _lastNamesGenerator = new RandomStringFromListGenerator(ListData.Instance.LastNames.Select(l => l.ToLower())); 21 | _topLevelDomainGenerator = new RandomStringFromListGenerator(ListData.Instance.TopLevelDomains.Select(l => l.ToLower())); 22 | 23 | if (options.Male) 24 | { 25 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.MaleNames.Select(l => l.ToLower()))); 26 | } 27 | 28 | if (options.Female) 29 | { 30 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.FemaleNames.Select(l => l.ToLower()))); 31 | } 32 | 33 | _numberGenerator = new RandomThingsGenerator(0, _genderSetGenerators.Count, options.Seed); 34 | _wordGenerator = new RandomizerTextWords(new FieldOptionsTextWords { Min = 1, Max = 1}); 35 | } 36 | 37 | public string? Generate() 38 | { 39 | if (IsNull()) 40 | { 41 | return null; 42 | } 43 | 44 | int maleOrFemale = _numberGenerator.Generate(); 45 | var firstNamesSet = _genderSetGenerators[maleOrFemale]; 46 | 47 | string firstName = firstNamesSet.Generate()!; 48 | string lastname = _lastNamesGenerator.Generate()!; 49 | string company = _wordGenerator.Generate()!; 50 | string domain = _topLevelDomainGenerator.Generate()!; 51 | 52 | return $"{firstName}.{lastname}@{company}.{domain}"; 53 | } 54 | 55 | public string? Generate(bool upperCase) 56 | { 57 | return Generate().ToCasedInvariant(upperCase); 58 | } 59 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Linq; 4 | using System.Reflection; 5 | using RandomDataGenerator.FieldOptions; 6 | using RandomDataGenerator.Generators; 7 | 8 | namespace RandomDataGenerator.Randomizers; 9 | 10 | public static class RandomizerFactory 11 | { 12 | private static readonly ConcurrentDictionary Cache = new(); 13 | 14 | public static IRandomizerBytes GetRandomizer(IFieldOptionsBytes fieldOptions) 15 | { 16 | return Create(fieldOptions); 17 | } 18 | 19 | public static IRandomizerString GetRandomizer(IFieldOptionsString fieldOptions) 20 | { 21 | return Create(fieldOptions); 22 | } 23 | 24 | public static IRandomizerGuid GetRandomizer(IFieldOptionsGuid fieldOptions) 25 | { 26 | return Create(fieldOptions); 27 | } 28 | 29 | public static IRandomizerNumber GetRandomizer(IFieldOptionsNumber fieldOptions) where T : struct 30 | { 31 | return Create>(fieldOptions); 32 | } 33 | 34 | public static IRandomizerDateTime GetRandomizer(IFieldOptionsDateTime fieldOptions) 35 | { 36 | return Create(fieldOptions); 37 | } 38 | 39 | public static IRandomizerTimeSpan GetRandomizer(IFieldOptionsTimeSpan fieldOptions) 40 | { 41 | return Create(fieldOptions); 42 | } 43 | 44 | #if NET20 || NET35 45 | public static object GetRandomizerAsDynamic(FieldOptionsAbstract fieldOptions) 46 | { 47 | return Create(fieldOptions); 48 | } 49 | #else 50 | public static dynamic GetRandomizerAsDynamic(object fieldOptions) 51 | { 52 | return Create(fieldOptions); 53 | } 54 | #endif 55 | private static T Create(object fieldOptions) 56 | { 57 | string key = $"{fieldOptions.GetType().FullName}_{fieldOptions.GetHashCode()}"; 58 | 59 | if (!Cache.ContainsKey(key)) 60 | { 61 | Cache.TryAdd(key, CreateRandomizer(fieldOptions)); 62 | } 63 | 64 | return (T)Cache[key]; 65 | } 66 | 67 | private static object CreateRandomizer(object fieldOptions) 68 | { 69 | Type fieldOptionsType = fieldOptions.GetType(); 70 | string fieldOptionsFullName = fieldOptionsType.FullName ?? string.Empty; 71 | 72 | string typeName; 73 | if (fieldOptionsType.GetTypeInfo().BaseType?.Name.EndsWith("Number`1") == true) 74 | { 75 | var genericType = fieldOptionsType.GetTypeInfo().BaseType.GetTypeInfo().GetGenericTypeArguments().FirstOrDefault(); 76 | if (RandomValueGenerator.SupportedTypes.Contains(genericType)) 77 | { 78 | typeName = fieldOptionsFullName.Replace($"FieldOptions.{fieldOptionsType.Name}", $"Randomizers.RandomizerNumber`1[{genericType}]"); 79 | } 80 | else 81 | { 82 | throw new NotSupportedException($"The type '{genericType}' is not supported."); 83 | } 84 | } 85 | else 86 | { 87 | typeName = fieldOptionsFullName.Replace("FieldOptions.FieldOptions", "Randomizers.Randomizer"); 88 | } 89 | 90 | var type = Type.GetType(typeName, true); 91 | return Activator.CreateInstance(type!, fieldOptions); 92 | } 93 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerFirstName.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using RandomDataGenerator.Data; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Generators; 6 | 7 | namespace RandomDataGenerator.Randomizers; 8 | 9 | public class RandomizerFirstName : RandomizerAbstract, IRandomizerString 10 | { 11 | private readonly RandomThingsGenerator _numberGenerator; 12 | private readonly List _genderSetGenerators = new List(); 13 | 14 | public RandomizerFirstName(FieldOptionsFirstName options) : base(options) 15 | { 16 | if (options.Male) 17 | { 18 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.MaleNames)); 19 | } 20 | 21 | if (options.Female) 22 | { 23 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.FemaleNames)); 24 | } 25 | 26 | _numberGenerator = new RandomThingsGenerator(0, _genderSetGenerators.Count, options.Seed); 27 | } 28 | 29 | public string? Generate() 30 | { 31 | if (IsNull()) 32 | { 33 | return null; 34 | } 35 | 36 | int maleOrFemale = _numberGenerator.Generate(); 37 | 38 | return _genderSetGenerators[maleOrFemale].Generate(); 39 | } 40 | 41 | public string? Generate(bool upperCase) 42 | { 43 | return Generate().ToCasedInvariant(upperCase); 44 | } 45 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerFullName.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using RandomDataGenerator.Data; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Generators; 6 | 7 | namespace RandomDataGenerator.Randomizers; 8 | 9 | public class RandomizerFullName : RandomizerAbstract, IRandomizerString 10 | { 11 | private readonly RandomThingsGenerator _numberGenerator; 12 | private readonly RandomStringFromListGenerator _lastNamesGenerator; 13 | private readonly List _genderSetGenerators = new(); 14 | 15 | public RandomizerFullName(FieldOptionsFullName options) : base(options) 16 | { 17 | _lastNamesGenerator = new RandomStringFromListGenerator(ListData.Instance.LastNames); 18 | 19 | if (options.Male) 20 | { 21 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.MaleNames)); 22 | } 23 | 24 | if (options.Female) 25 | { 26 | _genderSetGenerators.Add(new RandomStringFromListGenerator(ListData.Instance.FemaleNames)); 27 | } 28 | 29 | _numberGenerator = new RandomThingsGenerator(0, _genderSetGenerators.Count, options.Seed); 30 | } 31 | 32 | public string? Generate() 33 | { 34 | if (IsNull()) 35 | { 36 | return null; 37 | } 38 | 39 | int maleOrFemale = _numberGenerator.Generate(); 40 | 41 | var firstNamesSet = _genderSetGenerators[maleOrFemale]; 42 | string firstName = firstNamesSet.Generate()!; 43 | string lastname = _lastNamesGenerator.Generate()!; 44 | 45 | return $"{firstName} {lastname}"; 46 | } 47 | 48 | public string? Generate(bool upperCase) 49 | { 50 | return Generate().ToCasedInvariant(upperCase); 51 | } 52 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerGuid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | 5 | namespace RandomDataGenerator.Randomizers; 6 | 7 | public class RandomizerGuid : RandomizerAbstract, IRandomizerGuid 8 | { 9 | public RandomizerGuid(FieldOptionsGuid options) : base(options) 10 | { 11 | } 12 | 13 | public Guid? Generate() 14 | { 15 | if (IsNull()) 16 | { 17 | return null; 18 | } 19 | 20 | return Guid.NewGuid(); 21 | } 22 | 23 | public string? GenerateAsString() 24 | { 25 | return IsNull() ? null : Guid.NewGuid().ToString(Options.Format).ToCasedInvariant(Options.Uppercase); 26 | } 27 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerIBAN.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using RandomDataGenerator.Data; 4 | using RandomDataGenerator.Data.Models; 5 | using RandomDataGenerator.Extensions; 6 | using RandomDataGenerator.FieldOptions; 7 | using RandomDataGenerator.Generators; 8 | 9 | namespace RandomDataGenerator.Randomizers; 10 | 11 | public class RandomizerIBAN : RandomizerAbstract, IRandomizerString 12 | { 13 | private readonly RandomItemFromListGenerator _itemGenerator; 14 | 15 | public RandomizerIBAN(FieldOptionsIBAN options) : base(options) 16 | { 17 | Func? predicate = null; 18 | 19 | if (!string.IsNullOrEmpty(options.CountryCode)) 20 | { 21 | predicate = iban => iban.CountryCode == options.CountryCode; 22 | } 23 | 24 | // Set the list to IBAN as default 25 | var list = ListData.Instance.IBANs; 26 | switch (options.Type) 27 | { 28 | case "BBAN": 29 | list = ListData.Instance.BBANs; 30 | break; 31 | 32 | case "BOTH": 33 | list = list.Union(ListData.Instance.BBANs); 34 | break; 35 | } 36 | 37 | _itemGenerator = new RandomItemFromListGenerator(options.Seed, list, predicate); 38 | } 39 | 40 | public string? Generate() 41 | { 42 | if (IsNull()) 43 | { 44 | return null; 45 | } 46 | 47 | var iban = _itemGenerator.Generate(); 48 | return iban.Generator.Generate(); 49 | } 50 | 51 | public string? Generate(bool upperCase) 52 | { 53 | return Generate().ToCasedInvariant(upperCase); 54 | } 55 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerIPv4Address.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerIPv4Address : RandomizerAbstract, IRandomizerString 9 | { 10 | private readonly RandomThingsGenerator[] _octetsGenerator = new RandomThingsGenerator[4]; 11 | 12 | public RandomizerIPv4Address(FieldOptionsIPv4Address options) : base(options) 13 | { 14 | byte[] octetsMin = string.IsNullOrEmpty(Options.Min) ? new byte[] { 0, 0, 0, 0 } : Options.Min!.Split('.').Select(byte.Parse).ToArray(); 15 | byte[] octetsMax = string.IsNullOrEmpty(Options.Max) ? new byte[] { 0xff, 0xff, 0xff, 0xff } : Options.Max!.Split('.').Select(byte.Parse).ToArray(); 16 | 17 | for (int i = 0; i < 4; i++) 18 | { 19 | _octetsGenerator[i] = new RandomThingsGenerator(octetsMin[i], octetsMax[i], options.Seed); 20 | } 21 | } 22 | 23 | public string? Generate() 24 | { 25 | return IsNull() ? null : string.Join(".", _octetsGenerator.Select(gen => $"{gen.Generate()}").ToArray()); 26 | } 27 | 28 | public string? Generate(bool upperCase) 29 | { 30 | return Generate().ToCasedInvariant(upperCase); 31 | } 32 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerIPv6Address.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Linq; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Generators; 6 | 7 | namespace RandomDataGenerator.Randomizers; 8 | 9 | public class RandomizerIPv6Address : RandomizerAbstract, IRandomizerString 10 | { 11 | private readonly int[] _defaultMin = { 0, 0, 0, 0, 0, 0, 0, 0 }; 12 | private readonly int[] _defaultMax = { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff }; 13 | 14 | private readonly RandomThingsGenerator[] _hextets = new RandomThingsGenerator[8]; 15 | 16 | public RandomizerIPv6Address(FieldOptionsIPv6Address options) : base(options) 17 | { 18 | int[] hextetsMin = string.IsNullOrEmpty(Options.Min) ? _defaultMin : Options.Min!.Split(':').Select(x => int.Parse(x, NumberStyles.HexNumber)).ToArray(); 19 | int[] hextetsMax = string.IsNullOrEmpty(Options.Max) ? _defaultMax : Options.Max!.Split(':').Select(x => int.Parse(x, NumberStyles.HexNumber)).ToArray(); 20 | 21 | for (int i = 0; i < 8; i++) 22 | { 23 | _hextets[i] = new RandomThingsGenerator(hextetsMin[i], hextetsMax[i], options.Seed); 24 | } 25 | } 26 | 27 | public string? Generate() 28 | { 29 | return IsNull() ? null : string.Join(":", _hextets.Select(gen => $"{gen.Generate():X4}").ToArray()); 30 | } 31 | 32 | public string? Generate(bool upperCase) 33 | { 34 | return Generate().ToCasedInvariant(upperCase); 35 | } 36 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerLastName.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Data; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerLastName : RandomizerAbstract, IRandomizerString 9 | { 10 | private readonly RandomStringFromListGenerator _lastNamesGenerator; 11 | 12 | public RandomizerLastName(FieldOptionsLastName options) : base(options) 13 | { 14 | _lastNamesGenerator = new RandomStringFromListGenerator(ListData.Instance.LastNames); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() ? null : _lastNamesGenerator.Generate(); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerMACAddress.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Linq; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Generators; 6 | 7 | namespace RandomDataGenerator.Randomizers; 8 | 9 | public class RandomizerMACAddress : RandomizerAbstract, IRandomizerString 10 | { 11 | private readonly byte[] _defaultMin = { 0, 0, 0, 0, 0, 0 }; 12 | private readonly byte[] _defaultMax = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 13 | private readonly RandomThingsGenerator[] _octets = new RandomThingsGenerator[6]; 14 | 15 | public RandomizerMACAddress(FieldOptionsMACAddress options) : base(options) 16 | { 17 | byte[] octetsMin = string.IsNullOrEmpty(Options.Min) ? _defaultMin : Options.Min!.Split(Options.Separator.First()).Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray(); 18 | byte[] octetsMax = string.IsNullOrEmpty(Options.Max) ? _defaultMax : Options.Max!.Split(Options.Separator.First()).Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray(); 19 | 20 | for (int i = 0; i < 6; i++) 21 | { 22 | _octets[i] = new RandomThingsGenerator(octetsMin[i], octetsMax[i], options.Seed); 23 | } 24 | } 25 | 26 | public string? Generate() 27 | { 28 | return IsNull() ? null : GenerateInternal(); 29 | } 30 | 31 | public string? Generate(bool upperCase) 32 | { 33 | return Generate().ToCasedInvariant(upperCase); 34 | } 35 | 36 | private string GenerateInternal() 37 | { 38 | var value = string.Join(Options.Separator, _octets.Select(gen => $"{gen.Generate():X2}").ToArray()); 39 | 40 | return value.ToCasedInvariant(Options.Uppercase)!; 41 | } 42 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerNumber.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.FieldOptions; 2 | using RandomDataGenerator.Generators; 3 | 4 | namespace RandomDataGenerator.Randomizers; 5 | 6 | public class RandomizerNumber : RandomizerAbstract>, IRandomizerNumber where T : struct 7 | { 8 | private readonly RandomThingsGenerator _generator; 9 | 10 | public RandomizerNumber(FieldOptionsNumber options) : base(options) 11 | { 12 | _generator = new RandomThingsGenerator(options.Min, options.Max, options.Seed); 13 | } 14 | 15 | public T? Generate() 16 | { 17 | return IsNull() ? null : (T?)_generator.Generate(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerStringList.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Extensions; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Generators; 4 | 5 | namespace RandomDataGenerator.Randomizers; 6 | 7 | public class RandomizerStringList : RandomizerAbstract, IRandomizerString 8 | { 9 | private readonly RandomStringFromListGenerator _generator; 10 | 11 | public RandomizerStringList(FieldOptionsStringList options) 12 | : base(options) 13 | { 14 | _generator = new RandomStringFromListGenerator(options.Values); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() ? null : _generator.Generate(); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return IsNull() ? null : _generator.Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerText.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Extensions; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Generators; 4 | 5 | namespace RandomDataGenerator.Randomizers; 6 | 7 | public class RandomizerText : RandomizerAbstract, IRandomizerString 8 | { 9 | private readonly RandomStringGenerator _generator; 10 | 11 | public RandomizerText(FieldOptionsText options) 12 | : base(options) 13 | { 14 | _generator = new RandomStringGenerator(options.Seed, options.UseUppercase, options.UseLowercase, options.UseNumber, options.UseSpecial, options.UseSpace); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() ? null : _generator.Generate(Options.Min, Options.Max); 20 | } 21 | public string? Generate(bool upperCase) 22 | { 23 | return Generate().ToCasedInvariant(upperCase); 24 | } 25 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTextLipsum.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Data; 2 | using RandomDataGenerator.Extensions; 3 | using RandomDataGenerator.FieldOptions; 4 | using RandomDataGenerator.Generators; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerTextLipsum : RandomizerAbstract, IRandomizerString 9 | { 10 | private const string Newline = "\r\n"; 11 | private readonly RandomStringsFromListGenerator _generator; 12 | 13 | public RandomizerTextLipsum(FieldOptionsTextLipsum options) : base(options) 14 | { 15 | _generator = new RandomStringsFromListGenerator(ListData.Instance.LoremIpsum); 16 | } 17 | 18 | public string? Generate() 19 | { 20 | return IsNull() ? null : string.Join(Newline, _generator.Generate(Options.Paragraphs).ToArray()); 21 | } 22 | 23 | public string? Generate(bool upperCase) 24 | { 25 | return Generate().ToCasedInvariant(upperCase); 26 | } 27 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTextNaughtyStrings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using RandomDataGenerator.Data; 6 | using RandomDataGenerator.Extensions; 7 | using RandomDataGenerator.FieldOptions; 8 | using RandomDataGenerator.Generators; 9 | 10 | namespace RandomDataGenerator.Randomizers; 11 | 12 | public class RandomizerTextNaughtyStrings : RandomizerAbstract, IRandomizerString 13 | { 14 | private readonly RandomStringFromListGenerator _naughtyStringCategoryGenerator; 15 | 16 | public RandomizerTextNaughtyStrings(FieldOptionsTextNaughtyStrings options) : base(options) 17 | { 18 | Type type = typeof(TheNaughtyStrings); 19 | 20 | var allStrings = new List(TheNaughtyStrings.All); 21 | 22 | var categories = options.Categories 23 | .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) 24 | .Select(s => s.Trim()) 25 | .Where(s => s != FieldOptionsTextNaughtyStrings.All); 26 | foreach (string category in categories) 27 | { 28 | if (type.GetField(category).GetValue(null) is IList strings) 29 | { 30 | allStrings.AddRange(strings); 31 | } 32 | } 33 | 34 | _naughtyStringCategoryGenerator = new RandomStringFromListGenerator(allStrings); 35 | } 36 | 37 | public string? Generate() 38 | { 39 | return IsNull() ? null : _naughtyStringCategoryGenerator.Generate(); 40 | } 41 | 42 | public string? Generate(bool upperCase) 43 | { 44 | return Generate().ToCasedInvariant(upperCase); 45 | } 46 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTextPattern.cs: -------------------------------------------------------------------------------- 1 | using RandomDataGenerator.Extensions; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Generators; 4 | 5 | namespace RandomDataGenerator.Randomizers; 6 | 7 | public class RandomizerTextPattern : RandomizerAbstract, IRandomizerString 8 | { 9 | private readonly RandomStringGenerator _generator; 10 | 11 | public RandomizerTextPattern(FieldOptionsTextPattern options) 12 | : base(options) 13 | { 14 | _generator = new RandomStringGenerator(); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() || string.IsNullOrEmpty(Options.Pattern) ? null : _generator.Generate(Options.Pattern); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTextRegex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Fare; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | 6 | namespace RandomDataGenerator.Randomizers; 7 | 8 | public class RandomizerTextRegex : RandomizerAbstract, IRandomizerString 9 | { 10 | private readonly Xeger _generator; 11 | 12 | public RandomizerTextRegex(FieldOptionsTextRegex options) : base(options) 13 | { 14 | _generator = options.Seed.HasValue ? new Xeger(options.Pattern, new Random(options.Seed.Value)) : new Xeger(options.Pattern); 15 | } 16 | 17 | public string? Generate() 18 | { 19 | return IsNull() || string.IsNullOrEmpty(Options.Pattern) ? null : _generator.Generate(); 20 | } 21 | 22 | public string? Generate(bool upperCase) 23 | { 24 | return Generate().ToCasedInvariant(upperCase); 25 | } 26 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTextWords.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using RandomDataGenerator.Data; 3 | using RandomDataGenerator.Extensions; 4 | using RandomDataGenerator.FieldOptions; 5 | using RandomDataGenerator.Generators; 6 | 7 | namespace RandomDataGenerator.Randomizers; 8 | 9 | public class RandomizerTextWords : RandomizerAbstract, IRandomizerString 10 | { 11 | private readonly RandomStringFromListGenerator _generator; 12 | private readonly RandomValueGenerator _randomValueGenerator; 13 | 14 | public RandomizerTextWords(FieldOptionsTextWords options) : base(options) 15 | { 16 | _randomValueGenerator = RandomValueGeneratorFactory.Create(options.Seed); 17 | _generator = new RandomStringFromListGenerator(ListData.Instance.LoremIpsumWords, options.Seed); 18 | } 19 | 20 | public string? Generate() 21 | { 22 | if (IsNull()) 23 | { 24 | return null; 25 | } 26 | 27 | int max = _randomValueGenerator.Next(Options.Min, Options.Max); 28 | var list = new List(max); 29 | for (int i = 0; i < max; i++) 30 | { 31 | list.Add(_generator.Generate()!); 32 | } 33 | 34 | return string.Join(" ", list.ToArray()); 35 | } 36 | 37 | public string? Generate(bool upperCase) 38 | { 39 | return Generate().ToCasedInvariant(upperCase); 40 | } 41 | } -------------------------------------------------------------------------------- /src/RandomDataGenerator/Randomizers/RandomizerTimeSpan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Generators; 4 | 5 | namespace RandomDataGenerator.Randomizers; 6 | 7 | public class RandomizerTimeSpan : RandomizerAbstract, IRandomizerTimeSpan 8 | { 9 | private readonly RandomThingsGenerator _generator; 10 | 11 | public RandomizerTimeSpan(FieldOptionsTimeSpan options) : base(options) 12 | { 13 | _generator = new RandomThingsGenerator(options.From, options.To, options.Seed); 14 | } 15 | 16 | public TimeSpan? Generate() 17 | { 18 | if (IsNull()) 19 | { 20 | return null; 21 | } 22 | 23 | var ts = _generator.Generate(); 24 | 25 | return Options.IncludeMilliseconds ? ts : new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); 26 | } 27 | 28 | public string? GenerateAsString() 29 | { 30 | TimeSpan? ts = Generate(); 31 | 32 | string format = !string.IsNullOrEmpty(Options.Format) ? Options.Format : FieldOptionsTimeSpan.DefaultFormat; 33 | return ts != null ? string.Format($"{{0:{format}}}", ts) : null; 34 | } 35 | } -------------------------------------------------------------------------------- /tests/RandomDataGenerator.Tests/CityRandomizerTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using RandomDataGenerator.FieldOptions; 3 | using RandomDataGenerator.Randomizers; 4 | using Xunit.Abstractions; 5 | 6 | namespace RandomDataGenerator.Tests; 7 | 8 | public class CityRandomizerTests 9 | { 10 | private readonly ITestOutputHelper _output; 11 | private static readonly Random Random = new(420); 12 | private static readonly object RandLock = new(); 13 | 14 | public CityRandomizerTests(ITestOutputHelper output) 15 | { 16 | _output = output; 17 | } 18 | 19 | [Theory] 20 | [InlineData(1)] 21 | [InlineData(2)] 22 | [InlineData(4)] 23 | [InlineData(8)] 24 | public void CityDistributionMustBeUniform(int degree) 25 | { 26 | var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false }); 27 | var concurrentDictionary = new ConcurrentDictionary(); 28 | var options = new ParallelOptions { MaxDegreeOfParallelism = degree }; 29 | Parallel.For(0, 1000, options, i => 30 | { 31 | Parallel.For(0, 1000, options, j => 32 | { 33 | var location = locationGenerator.Generate() ?? string.Empty; 34 | concurrentDictionary.AddOrUpdate(location, _ => 1, (k, v) => v + 1); 35 | }); 36 | }); 37 | var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First(); 38 | var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First(); 39 | 40 | _output.WriteLine($"{topCount}"); 41 | _output.WriteLine($"{bottomCount}"); 42 | 43 | Assert.True(topCount.Value / bottomCount.Value < 2); 44 | Assert.NotEqual(topCount.Key, bottomCount.Key); 45 | } 46 | 47 | [Fact] 48 | public void TwoRandomCitiesMustNotBeTheSame() 49 | { 50 | var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false }); 51 | var locationOne = locationGenerator.Generate(); 52 | var locationTwo = locationGenerator.Generate(); 53 | 54 | Assert.NotEqual(locationOne, locationTwo); 55 | } 56 | 57 | [Fact] 58 | public void SystemRandomDistributionMustBeUniform() 59 | { 60 | var concurrentDictionary = new ConcurrentDictionary(); 61 | Parallel.For(0, 1000, i => 62 | { 63 | Parallel.For(0, 1000, j => 64 | { 65 | int index; 66 | lock (RandLock) 67 | { 68 | index = Random.Next(0, 2000); 69 | } 70 | 71 | concurrentDictionary.AddOrUpdate(index, _ => 1, (k, v) => v + 1); 72 | }); 73 | }); 74 | 75 | var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First(); 76 | var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First(); 77 | 78 | _output.WriteLine($"{topCount}"); 79 | _output.WriteLine($"{bottomCount}"); 80 | 81 | Assert.True(topCount.Value / bottomCount.Value < 2); 82 | Assert.NotEqual(topCount.Key, bottomCount.Key); 83 | } 84 | } -------------------------------------------------------------------------------- /tests/RandomDataGenerator.Tests/RandomDataGenerator.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | all 16 | 17 | 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | all 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/RandomDataGenerator.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; --------------------------------------------------------------------------------