| | 1 | | @using System.Text; |
| | 2 | | @inject IJSRuntime JSRuntime |
| | 3 | |
|
| | 4 | | @*@inject ClipboardService ClipboardService*@ |
| | 5 | |
|
| | 6 | | <div class="container"> |
| | 7 | |
|
| | 8 | | <div class="row"> |
| | 9 | | <div class="class"> |
| | 10 | | <h2>Guid</h2> |
| | 11 | | </div> |
| | 12 | | </div> |
| | 13 | |
|
| | 14 | | <div class="row"> |
| | 15 | | <label class="label-control">Zero:</label> |
| | 16 | | <div class="input-group"> |
| | 17 | | <input type="text" id="guidZero" name="guidZero" class="form-control" @bind="@zeroGuid" placeholder="0000000 |
| | 18 | | <span class="input-group-btn"> |
| | 19 | | <button class="btn btn-info" type="button" id="btnGuidZeroCopy" name="btnGuidZeroCopy" @onclick="CopyZer |
| | 20 | | </span> |
| | 21 | | </div> |
| | 22 | | </div> |
| | 23 | | <div class="row"> |
| | 24 | | <div class="form-check form-check-inline"> |
| | 25 | | <input class="form-check-input" type="checkbox" value="@removeDashes" id="chkRemoveDashesZero" |
| 4 | 26 | | @onchange="@(eventArgs => { removeDashes = (bool)eventArgs.Value; Update(); })"/> |
| | 27 | | <label class="form-check-label" for="chkRemoveDashesZero"> |
| | 28 | | Remove Dashes |
| | 29 | | </label> |
| | 30 | | </div> |
| | 31 | | | |
| | 32 | | <div class="form-check form-check-inline"> |
| | 33 | | <input class="form-check-input" type="checkbox" value="@addBraces" id="chkAddBracesZero" |
| 4 | 34 | | @onchange="@(eventArgs => { addBraces = (bool)eventArgs.Value; Update(); })"/> |
| | 35 | | <label class="form-check-label" for="chkAddBracesZero"> |
| | 36 | | Add Braces |
| | 37 | | </label> |
| | 38 | | </div> |
| | 39 | | </div> |
| | 40 | | <div class="row"> |
| | 41 | | <label class="label-control">New:</label> |
| | 42 | | <div class="input-group"> |
| | 43 | | <span class="input-group-btn"> |
| | 44 | | <button class="btn btn-info" type="button" id="btnGuidNewCreate" name="btnGuidNewCreate" @onclick="Gener |
| | 45 | | </span> |
| | 46 | | <input type="text" id="newGuid" name="newGuid" class="form-control" value="@newGuid" placeholder="00000000-0 |
| | 47 | | <input type="hidden" id="newGuidHidden" name="newGuidHidden" class="form-control" value="@newGuidHidden" pla |
| | 48 | | <span class="input-group-btn"> |
| | 49 | | <button class="btn btn-info" type="button" id="btnNewGuidCopy" name="btnNewGuidCopy" @onclick="CopyNewGu |
| | 50 | | </span> |
| | 51 | | </div> |
| | 52 | | </div> |
| | 53 | | <div class="row"> |
| | 54 | | <div class="form-check"> |
| | 55 | | <input class="form-check-input" type="checkbox" value="@removeDashesNew" id="chkRemoveDashes" |
| 0 | 56 | | @onchange="@(eventArgs => { removeDashesNew = (bool)eventArgs.Value; RemoveDashesFromNewGuid(); })"> |
| | 57 | | <label class="form-check-label" for="chkRemoveDashes"> |
| | 58 | | Remove Dashes |
| | 59 | | </label> |
| | 60 | | </div> |
| | 61 | | </div> |
| | 62 | | <hr/> |
| | 63 | | <div class="row"> |
| | 64 | | <label class="label-control">How many Guids do you wish to generate:</label> |
| | 65 | | <div class="input-group"> |
| | 66 | | <div class="form-check"> |
| | 67 | | <input class="form-check-input" type="checkbox" value="" id="chkRemoveDashesMultiple"> |
| | 68 | | <label class="form-check-label" for="chkRemoveDashesMultiple"> |
| | 69 | | Remove Dashes |
| | 70 | | </label> |
| | 71 | | </div> |
| | 72 | | </div> |
| | 73 | | <div class="input-group"> |
| | 74 | | <input type="number" class="form-control" id="guidCount" name="guidCount" @bind="@guidCount"> |
| | 75 | | <span class="input-group-btn"> |
| | 76 | | <button class="btn btn-success" type="button" id="btnGuidNewCreateMultiple" name="btnGuidNewCreateMultip |
| | 77 | | @onclick="GenerateMultipleGuids">Go!</button> |
| | 78 | | <button class="btn btn-info" type="button" id="btnGuidMultipleCopy" name="btnGuidMultipleCopy" |
| | 79 | | @onclick="CopyMultipleGuids"> |
| | 80 | | <i class="far fa-copy"></i> |
| | 81 | | </button> |
| | 82 | | <button class="btn btn-danger" type="button" id="btnGuidMultipleClear" name="btnGuidMultipleClear" |
| | 83 | | @onclick="DeleteMultipleGuids"> |
| | 84 | | <i class="far fa-trash-alt"></i> |
| | 85 | | </button> |
| | 86 | | </span> |
| | 87 | | </div> |
| | 88 | | </div> |
| | 89 | | <div class="row"> |
| | 90 | | <textarea id="guids" class="form-control" @bind="NewGuids"></textarea> |
| | 91 | | </div> |
| | 92 | | </div> |
| | 93 | |
|
| | 94 | | @code { |
| | 95 | |
|
| | 96 | | private string newGuid; |
| | 97 | | private Guid newGuidHidden; |
| | 98 | | private int guidCount; |
| | 99 | |
|
| | 100 | | protected override async Task OnInitializedAsync() |
| 5 | 101 | | { |
| 5 | 102 | | var guid = Guid.NewGuid(); |
| 5 | 103 | | newGuid = guid.ToString(); |
| 5 | 104 | | newGuidHidden = guid; |
| | 105 | |
|
| 5 | 106 | | guidCount = 5; |
| 5 | 107 | | } |
| | 108 | |
|
| | 109 | | #region Zero |
| | 110 | |
|
| 5 | 111 | | private Guid defaultZeroGuid = new Guid(); //"00000000000000000000000000000000" //"00000000-0000-0000-0000-000000000 |
| 5 | 112 | | private string zeroGuid = new Guid().ToString(); |
| | 113 | |
|
| | 114 | | async Task CopyZeroGuid() |
| 0 | 115 | | { |
| 0 | 116 | | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", zeroGuid); |
| 0 | 117 | | } |
| | 118 | |
|
| 5 | 119 | | private bool removeDashes = false; |
| | 120 | | void RemoveDashesFromZeroGuid() |
| 2 | 121 | | { |
| 2 | 122 | | zeroGuid = (removeDashes) ? defaultZeroGuid.ToString().Replace("-", "") : defaultZeroGuid.ToString(); |
| 2 | 123 | | } |
| | 124 | |
|
| 5 | 125 | | private bool addBraces = false; |
| | 126 | | void AddBracesToZeroGuid() |
| 2 | 127 | | { |
| 2 | 128 | | zeroGuid = (addBraces) ? $"{{{zeroGuid}}}" : zeroGuid.Replace("{", "").Replace("}", ""); |
| 2 | 129 | | } |
| | 130 | |
|
| | 131 | | void Update() |
| 2 | 132 | | { |
| 2 | 133 | | RemoveDashesFromZeroGuid(); |
| 2 | 134 | | AddBracesToZeroGuid(); |
| 2 | 135 | | } |
| | 136 | |
|
| | 137 | | #endregion Zero |
| | 138 | |
|
| | 139 | | #region New |
| | 140 | |
|
| | 141 | | void GenerateNewGuid() |
| 0 | 142 | | { |
| 0 | 143 | | var guid = Guid.NewGuid(); |
| 0 | 144 | | newGuid = guid.ToString(); |
| 0 | 145 | | newGuidHidden = guid; |
| 0 | 146 | | RemoveDashesFromNewGuid(); |
| 0 | 147 | | } |
| | 148 | |
|
| 5 | 149 | | private bool removeDashesNew = false; |
| | 150 | | void RemoveDashesFromNewGuid() |
| 0 | 151 | | { |
| 0 | 152 | | newGuid = (removeDashesNew) ? newGuidHidden.ToString().Replace("-", "") : newGuidHidden.ToString(); |
| | 153 | | //removeDashes = !removeDashes; |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | async Task CopyNewGuid() |
| 0 | 157 | | { |
| 0 | 158 | | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", newGuid); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | #endregion New |
| | 162 | |
|
| | 163 | | #region Multiple |
| | 164 | |
|
| | 165 | | string NewGuids; |
| | 166 | |
|
| | 167 | | async Task GenerateMultipleGuids() |
| 0 | 168 | | { |
| 0 | 169 | | NewGuids = string.Empty; //Checkbox to append? |
| | 170 | |
|
| 0 | 171 | | StringBuilder builder = new StringBuilder(); |
| 0 | 172 | | for (int i = 0; i < guidCount; i++) |
| 0 | 173 | | { |
| 0 | 174 | | var guid = System.Guid.NewGuid().ToString() + System.Environment.NewLine; |
| | 175 | |
|
| | 176 | | //if (RemoveDashesMultiple) |
| | 177 | | ///{ |
| | 178 | | // guid = Regex.Replace(guid, @"\-", ""); |
| | 179 | | //} |
| | 180 | |
|
| 0 | 181 | | builder.Append(guid); |
| 0 | 182 | | } |
| | 183 | |
|
| 0 | 184 | | NewGuids = builder.ToString(); |
| 0 | 185 | | } |
| | 186 | |
|
| | 187 | | async Task CopyMultipleGuids() |
| 0 | 188 | | { |
| 0 | 189 | | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", NewGuids); |
| 0 | 190 | | } |
| | 191 | |
|
| | 192 | | async Task DeleteMultipleGuids() |
| 1 | 193 | | { |
| 1 | 194 | | NewGuids = string.Empty; |
| 1 | 195 | | } |
| | 196 | |
|
| | 197 | | #endregion Multiple |
| | 198 | |
|
| | 199 | | } |