private void LoadProducers() { var producers = _dataLoader.GetProducers(); Producers.Clear(); foreach (var producer in producers) { Producers.Add(producer); } }
public void Dispose() { if (_isDisposed) { return; } _isDisposed = true; if (!Producers.Any()) { Logger.LogDebug($"Disposed producer pool with no producers in the pool."); return; } var poolDisposeStopwatch = Stopwatch.StartNew(); Logger.LogInformation($"Disposing producer pool ({Producers.Count} producers)."); var remainingWaitDuration = TotalDisposeWaitDuration; foreach (var producer in Producers.Values) { var poolItemDisposeStopwatch = Stopwatch.StartNew(); try { producer.Value.Dispose(); } catch { } poolItemDisposeStopwatch.Stop(); remainingWaitDuration = remainingWaitDuration > poolItemDisposeStopwatch.Elapsed ? remainingWaitDuration.Subtract(poolItemDisposeStopwatch.Elapsed) : TimeSpan.Zero; } poolDisposeStopwatch.Stop(); Logger.LogInformation( $"Disposed Kafka Producer Pool ({Producers.Count} producers in {poolDisposeStopwatch.Elapsed.TotalMilliseconds:0.00} ms)."); if (poolDisposeStopwatch.Elapsed.TotalSeconds > 5.0) { Logger.LogWarning( $"Disposing Kafka Producer Pool got time greather than expected: {poolDisposeStopwatch.Elapsed.TotalMilliseconds:0.00} ms."); } Producers.Clear(); }
private void refresh() { using (var _unitOfWork = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { Producers.Clear(); Farms.Clear(); Fields.Clear(); Lists = new ObservableCollection <PickupListGridItem>(); Producers = new ObservableCollection <ComboBoxItemViewModel>(); Producers.Add(new ComboBoxItemViewModel { ID = "", DisplayText = "All Clients" }); Farms = new ObservableCollection <FarmComboBoxItemViewModel>(); Farms.Add(new FarmComboBoxItemViewModel { ID = "", DisplayText = "All Farms" }); Fields = new ObservableCollection <FieldComboBoxItemViewModel>(); Fields.Add(new FieldComboBoxItemViewModel { ID = "", DisplayText = "All Fields" }); var clients = _unitOfWork.ClientRepository.GetAll(new string[] { "Farms.Fields" }).OrderBy(c => c.Name); foreach (var c in clients.Where(x => x.Id != GUIDS.UNASSIGNED_CLIENT_ID)) { var producer = new ComboBoxItemViewModel { ID = c.Id, DisplayText = c.Name }; Producers.Add(producer); foreach (var farm in c.Farms.OrderBy(f => f.Name)) { var item = new FarmComboBoxItemViewModel { ClientID = c.Id, ID = farm.Id, DisplayText = farm.Name }; Farms.Add(item); foreach (var field in farm.Fields.OrderBy(f => f.Name)) { var fieldItem = new FieldComboBoxItemViewModel { ClientID = farm.ClientId, FarmID = farm.Id, ID = field.Id, DisplayText = field.Name }; Fields.Add(fieldItem); } } } var truck = _unitOfWork.SettingsRepository.GetCurrentTruck(); string truckID = ""; if (truck != null) { truckID = truck.Id; } foreach (var list in _unitOfWork.PickupListRepository.FindMatching(p => p.Id != GUIDS.UNASSIGNED_LIST_ID && p.AssignedTrucks.Any(t => t.Id == truckID), new string[] { "Field.Farm.Client", "AssignedTrucks" }).OrderBy(p => p.Name)) { Lists.Add(new PickupListGridItem { Client = list.Field.Client.Name, Farm = list.Field.Farm.Name, Field = list.Field.Name, ListID = list.Id, ListName = list.Name }); } } }