public async Task <string> UpdateChannelAsync(string channelId, string type, long chatId, TimeSpan interval, string metainfo) { var settings = new ReportChannelSettings(Guid.NewGuid().ToString(), type, chatId, interval, metainfo); var item = CreateReportChannel(settings); if (item == null) { _log.Error($"Incorrect channel Type = {settings.Type}.", context: $"Data: {settings.ToJson()}"); throw new Exception($"Incorrect channel Type = {settings.Type}."); } var old = _channelList.FirstOrDefault(e => e.ChannelId == channelId); if (old == null) { _log.Error($"Not found channel with Id = {channelId}.", context: $"Data: {settings.ToJson()}"); throw new Exception($"Not found channel with Id = {channelId}."); } await _channelRepository.AddOrUpdateChannelAsync(item); _channelList.Remove(old); _channelList.Add(item); old.Stop(); item.Start(); _log.Info( $"Channel started, Id={item.ChannelId}, Type={item.GetType().FullName}, Metainfo: {item.Metainfo}"); return(item.ChannelId); }
public async Task <string> AddChannelAsync(string type, long chatId, TimeSpan interval, string metainfo) { var settings = new ReportChannelSettings(Guid.NewGuid().ToString(), type, chatId, interval, metainfo); var item = CreateReportChannel(settings); if (item == null) { _log.Error($"Incorrect channel Type = {settings.Type}.", context: $"Data: {settings.ToJson()}"); throw new Exception($"Incorrect channel Type = {settings.Type}."); } await _channelRepository.AddOrUpdateChannelAsync(item); _channelList.Add(item); item.Start(); return(item.ChannelId); }