Skip to content

Commit 119e108

Browse files
Update readme
1 parent e9b2cfc commit 119e108

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ShortCode.GenerateSequentialShortCode();
5252

5353
// To generate sequential short code of the given length
5454
ShortCode.GenerateSequentialShortCode(int length);
55+
56+
// To generate a patterned short code
57+
// by default in the format XXX-XXX-XXX
58+
ShortCode.GeneratePatternedShortCode();
5559
```
5660

5761
There are some configuration methods you can call during your app's startup:
@@ -63,6 +67,15 @@ There are some configuration methods you can call during your app's startup:
6367
- `GuidCodeGenerator`: The code is a hashed form of a GUID
6468
- `RandomCodeGenerator`: The code is generated from the `Random` class.
6569
- `CrytographicallyRandomCodeGenerator`: The code is generated using a cryptographic strength random number generator.
70+
* `ShortCode.SetPattern(IEnumerable<PatternPart> parts)`: Sets the pattern using the given parts. (See below)
71+
72+
## Pattern Parts
73+
74+
If you are using patterned short codes then you can define the pattern with a collection of `PatternPart`. There are two types of pattern part, a `Fixed` part, which consists of a fixed string; and, a `EncodeIntoCharacterSpace` type, which is part of the encoded short code.
75+
76+
To create the encoding part: `new PatternPart(string characterSpace, int length)`. The character space is a string containing the valid characters that a code can contain. It must be made up of unique characters. The `length` is the length of the encoded sequence.
77+
78+
To create the fixed part: `new PatternPart(string fixedChars)`. Where `fixedChars` is the fixed string that is used to separate parts of the code.
6679

6780
## Setting up Short Codes with Microsoft's Dependency Injection
6881

@@ -143,9 +156,37 @@ In the appsettings.json file:
143156
}
144157
```
145158

159+
If you prefer to use a patterned short code generator the appsettings.json will look something like this:
160+
161+
```json
162+
{
163+
"Stravaig": {
164+
"ShortCode": {
165+
"Pattern":[{
166+
"Type": "EncodeIntoCharacterSpace",
167+
"CharacterSpace": "0123456789QWERTYPLKJHGFDSAZXCVBNM",
168+
"Length": 4
169+
},{
170+
"Type": "Fixed",
171+
"FixedString": "-"
172+
},{
173+
"Type": "EncodeIntoCharacterSpace",
174+
"CharacterSpace": "0123456789QWERTYPLKJHGFDSAZXCVBNM",
175+
"Length": 4
176+
}],
177+
"Generator": {
178+
"Seed": 12345
179+
}
180+
}
181+
}
182+
}
183+
```
184+
185+
Note, that when the configuration contains a pattern it overrides any general specification.
186+
146187
## Using the IShortCodeFactory
147188

148189
To get a short code, the `IShortCodeFactory` interface exposes two methods for to create short codes.
149190

150191
* `GetNextCode()` will simply get the next code.
151-
* `GetCodes(int)` will return the number of codes specified as an `IEnumerable<string>`
192+
* `GetCodes(int number)` will return the `number` of codes specified as an `IEnumerable<string>`

0 commit comments

Comments
 (0)