public async Task OnSwitchOpened(long elementGid, long?outageId) { while (!ReliableDictionariesInitialized) { await Task.Delay(1000); } using (var unitOfWork = new UnitOfWork()) { try { if (!await OpenedSwitches.ContainsKeyAsync(elementGid)) { var equipment = new EquipmentHistorical() { OutageId = outageId, EquipmentId = elementGid, OperationTime = DateTime.Now, DatabaseOperation = DatabaseOperation.INSERT, }; unitOfWork.EquipmentHistoricalRepository.Add(equipment); await OpenedSwitches.SetAsync(elementGid, 0); unitOfWork.Complete(); } } catch (Exception e) { string message = $"{baseLogString} OnSwitchOpened => Exception: {e.Message}"; Logger.LogError(message, e); } } }
public async Task UpdateClosedSwitch(long elementGid, long outageId) { while (!ReliableDictionariesInitialized) { await Task.Delay(1000); } using (var unitOfWork = new UnitOfWork()) { try { if (!(await OpenedSwitches.ContainsKeyAsync(elementGid))) { var equipment = new EquipmentHistorical() { EquipmentId = elementGid, OperationTime = DateTime.Now, DatabaseOperation = DatabaseOperation.UPDATE, OutageId = outageId }; unitOfWork.EquipmentHistoricalRepository.Add(equipment); //await OpenedSwitches.TryRemoveAsync(elementGid); unitOfWork.Complete(); } } catch (Exception e) { string message = $"{baseLogString} UpdateClosedSwitch => Exception: {e.Message}"; Logger.LogError(message, e); } } }