protected virtual async Task OnAfterInsert(GridCreateComponent <T> component) { if (AfterInsert != null) { await AfterInsert.Invoke(component, _item); } }
/// <summary> /// Add a value /// </summary> /// <param name="value"></param> /// <returns></returns> public async Task <ExecutionResult <T> > AddAsync(T value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } var connectMessage = Connect(); if (connectMessage != "OK") { throw new ConnectionException(connectMessage); } BeforeInsert?.Invoke(value); var stop = new Stopwatch(); stop.Start(); if (_diagnosticSource.IsEnabled($"{typeof(T).Name}_Add")) { _diagnosticSource.Write($"{typeof(T).Name}_Add", value); } _logger.LogTrace("Try to add"); var key = FindKey(); var id = key.GetValue(value); var item = await _instance.SearchASingleItemAsync(x => { var val = key.GetValue(x); return(val.Equals(id)); }); if (item == null) { item = await TryAdd(value); } else { throw new DuplicateNameException(); } stop.Stop(); _logger.LogTrace($"End Add in {stop.Elapsed}"); AfterInsert?.Invoke(item); return(new ExecutionResult <T>(item != null, item)); }