|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | + |
| 5 | +namespace blazor_wasm |
| 6 | +{ |
| 7 | + public partial class App |
| 8 | + { |
| 9 | + List<Data> data = new List<Data>(); |
| 10 | + int selected; |
| 11 | + int id = 1; |
| 12 | + Random random = new Random(0); |
| 13 | + |
| 14 | + string[] adjectives = new string[] |
| 15 | + { |
| 16 | + "pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy" |
| 17 | + }; |
| 18 | + |
| 19 | + string[] colours = new string[] |
| 20 | + { |
| 21 | + "red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange" |
| 22 | + }; |
| 23 | + |
| 24 | + string[] nouns = new string[] |
| 25 | + { |
| 26 | + "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard" |
| 27 | + }; |
| 28 | + |
| 29 | + List<Data> BuildData(int count = 1000) |
| 30 | + { |
| 31 | + var result = new List<Data>(); |
| 32 | + for (int i = 0; i < count; i++) |
| 33 | + { |
| 34 | + result.Add(new Data |
| 35 | + { |
| 36 | + Id = this.id++, |
| 37 | + Label = adjectives[this.random.Next(adjectives.Length)] + " " + colours[this.random.Next(colours.Length)] + " " + nouns[this.random.Next(nouns.Length)] |
| 38 | + }); |
| 39 | + } |
| 40 | + |
| 41 | + return result; |
| 42 | + } |
| 43 | + |
| 44 | + public void Select(Data item) |
| 45 | + { |
| 46 | + this.selected = item.Id; |
| 47 | + } |
| 48 | + |
| 49 | + void Delete(Data item) |
| 50 | + { |
| 51 | + this.data.Remove(item); |
| 52 | + } |
| 53 | + |
| 54 | + void Run() |
| 55 | + { |
| 56 | + this.data = this.BuildData(); |
| 57 | + } |
| 58 | + void Runlots() |
| 59 | + { |
| 60 | + this.data = this.BuildData(10000); |
| 61 | + } |
| 62 | + void Add() |
| 63 | + { |
| 64 | + this.data.AddRange(this.BuildData(1000)); |
| 65 | + } |
| 66 | + void Update() |
| 67 | + { |
| 68 | + for (var i = 0; i < this.data.Count; i += 10) |
| 69 | + { |
| 70 | + this.data[i].Label += " !!!"; |
| 71 | + } |
| 72 | + } |
| 73 | + void Clear() |
| 74 | + { |
| 75 | + this.data = new List<Data>(); |
| 76 | + this.selected = 0; |
| 77 | + } |
| 78 | + void SwapRows() |
| 79 | + { |
| 80 | + if (this.data.Count > 998) |
| 81 | + { |
| 82 | + var a = this.data[1]; |
| 83 | + this.data[1] = this.data[998]; |
| 84 | + this.data[998] = a; |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments