You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// To generate sequential short code of the given length
54
54
ShortCode.GenerateSequentialShortCode(intlength);
55
+
56
+
// To generate a patterned short code
57
+
// by default in the format XXX-XXX-XXX
58
+
ShortCode.GeneratePatternedShortCode();
55
59
```
56
60
57
61
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:
63
67
-`GuidCodeGenerator`: The code is a hashed form of a GUID
64
68
-`RandomCodeGenerator`: The code is generated from the `Random` class.
65
69
-`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.
66
79
67
80
## Setting up Short Codes with Microsoft's Dependency Injection
68
81
@@ -143,9 +156,37 @@ In the appsettings.json file:
143
156
}
144
157
```
145
158
159
+
If you prefer to use a patterned short code generator the appsettings.json will look something like this:
0 commit comments