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