public void AddCharacterInChannel(string channel, string character) { if (!ChannelsInfo.ContainsKey(channel)) { ChannelsInfo.TryAdd(channel, new ChannelState() { Channel = channel }); } if (!CharactersInfos.ContainsKey(character)) { CharactersInfos.TryAdd(character, new CharacterState() { Character = character }); } var chanInfo = ChannelsInfo.GetValueOrDefault(channel); var charInfo = chanInfo.CharactersInfo.Find(x => x.Character.ToLower() == character.ToLower()); if (charInfo == null) { chanInfo.CharactersInfo.Add(CharactersInfos.GetValueOrDefault(character)); } }
public ResultOperationInfo Update(ChannelsInfo itemInfo) { var item = MapperInstance.Map <ChannelsInfo, Channels>(itemInfo); var updatedItem = UnitOfWork.GetRepository <Channels>().Update(item, item.Id); return(updatedItem == null ? new ResultOperationInfo(false, Localization.Error_OperationComplited) : new ResultOperationInfo(true, Localization.Success_OperationComplited)); }
public void RemoveCharacterInChannel(string channel, string character) { var chanInfo = ChannelsInfo.GetValueOrDefault(channel); if (chanInfo != null && chanInfo.CharactersInfo.Any(x => x.Character.ToLower() == character.ToLower())) { chanInfo.CharactersInfo.RemoveAll(x => x.Character.ToLower() == character.ToLower()); } }
public async Task <IHttpActionResult> Join(JoinChannelBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ChannelDataRepository repository = new ChannelDataRepository(); var channelModel = await repository.FindAsync(model.ChannelName); if (channelModel == null) { return(GetErrorResult(new IdentityResult("Channel not exists"))); } var channel = ChannelsInfo.GetChannelInfo(channelModel.Name); if (channel != null) { channel.Members.Add(model.User); return(Ok(Convert.ToInt32(channel.Port))); } int initPort = 5000; VoiceServer newVoiceServer = new VoiceServer(); while (initPort < 65000) { try { newVoiceServer.Start(initPort); ChannelsInfo.ListOfSockets.Add(initPort.ToString(), newVoiceServer); ChannelsInfo.AddChannel(channelModel, initPort.ToString()); ChannelsInfo.AddMember(channelModel.Name, model.User); break; } catch (Exception e) { ChannelsInfo.ListOfSockets.Remove(initPort.ToString()); initPort++; } } using (UserDataRepository db = new UserDataRepository()) { var user = db.FindByName(model.User); if (!user.RecenltyVisitedRooms.Split(',').Contains(model.ChannelName)) { db.UpdateVisitedChannels(model.User, model.ChannelName); } } return(Ok(initPort)); }
public ResultOperationInfo <ChannelsInfo> Create(ChannelsInfo itemInfo) { var item = MapperInstance.Map <ChannelsInfo, Channels>(itemInfo); var addedItem = UnitOfWork.GetRepository <Channels>().Add(item); var addedItemInfo = MapperInstance.Map <Channels, ChannelsInfo>(addedItem); return(addedItem == null ? new ResultOperationInfo <ChannelsInfo>(null, false, Localization.Error_OperationComplited) : new ResultOperationInfo <ChannelsInfo>(addedItemInfo, true, Localization.Success_OperationComplited)); }
public void Updete(ChannelsInfo itemInfo) { var result = _channelService.Update(itemInfo); if (result.IsSuccess) { return; } throw new Exception(result.Message); }
public ChannelsInfo Create(ChannelsInfo itemInfo) { var result = _channelService.Create(itemInfo); if (result.IsSuccess) { return(result.Value); } throw new Exception(result.Message); }
private async void OnUpdateChannale(object obj) { _tLChannelFull = await _telegramLogic.GetFullInfoCannelsAsync(); _tLChannels = await _telegramLogic.GetInfoChannelsAsync(); List <ChannelsInfo> cannelsTelegram = new List <ChannelsInfo>(); foreach (var item in _tLChannelFull) { var channelsInfo = new ChannelsInfo(); foreach (var item1 in _tLChannels) { if (item.Id == item1.Id) { channelsInfo.NameChannel = item1.Title; channelsInfo.UriChannel = item1.Username; channelsInfo.IdChannel = item1.Id; channelsInfo.AccessHashChannel = (long)item1.AccessHash; break; } } if (item.ChatPhoto is TLPhoto tLPhoto) { channelsInfo.AvatarChannel = DateTimeOffset.FromUnixTimeSeconds(tLPhoto.Date).DateTime; } else { channelsInfo.AvatarChannel = new DateTime(2000, 1, 1); } channelsInfo.SubscribersChannel = (int)item.ParticipantsCount; cannelsTelegram.Add(channelsInfo); } List <ChannelsInfo> tmpList = new List <ChannelsInfo>(); foreach (var tLChannelItem in cannelsTelegram) { foreach (var infoChannelsItem in InfoChannels) { if (infoChannelsItem.IdChannel == tLChannelItem.IdChannel) { tmpList.Add(tLChannelItem); } } } foreach (var item in tmpList) { cannelsTelegram.Remove(item); } foreach (var item in cannelsTelegram) { InfoChannels.Add(_channelsService.Create(item)); } }
public async Task <IHttpActionResult> Leave(LeaveChannelBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ChannelsInfo.RemoveMember(model.ChannelName, model.User); return(Ok()); }
public List <CharacterState> GetAllCharactersInChannel(string channel) { var chanInfo = ChannelsInfo.GetValueOrDefault(channel); if (chanInfo != null) { return(chanInfo.CharactersInfo); } else { return(new List <CharacterState>()); } }
private async void OnAddChannel(object obj) { await Task.Run(async() => { string res = ""; try { res = InputUriChannel.Split('/').Last().Split('@').Last(); } catch (Exception) { } try { var id = await _telegramLogic.JoinCannel(res); _tLChannelFull = await _telegramLogic.GetFullInfoCannelsAsync(); _tLChannels = await _telegramLogic.GetInfoChannelsAsync(); var tLChannelFullinfo = _tLChannelFull.Where(p => p.Id == id).FirstOrDefault(); var tLChannels = _tLChannels.Where(p => p.Id == id).FirstOrDefault(); var channelsInfo = new ChannelsInfo() { SubscribersChannel = (int)tLChannelFullinfo.ParticipantsCount, UriChannel = tLChannels.Username, NameChannel = tLChannels.Title, IdChannel = tLChannels.Id, AccessHashChannel = (long)tLChannels.AccessHash, FullUriCannel = InputUriChannel }; channelsInfo.AvatarChannel = tLChannelFullinfo.ChatPhoto is TLPhoto tLPhoto ? DateTimeOffset.FromUnixTimeSeconds(tLPhoto.Date).DateTime : new DateTime(2000, 1, 1); InfoChannels.Add(_channelsService.Create(channelsInfo)); AddChannels addChannels = new AddChannels { UriChannel = InputUriChannel }; UriList.Add(addChannels); } catch (Exception) { } }); }
private async void OnCheckAll(object obj) { NoLinks = 0; UpdatedAvatar = 0; ChangeTitles = 0; SubscribersChannel = 0; _tLChannelFull = await _telegramLogic.GetFullInfoCannelsAsync(); _tLChannels = await _telegramLogic.GetInfoChannelsAsync(); List <ChannelsInfo> cannelsTelegram = new List <ChannelsInfo>(); foreach (var item in _tLChannelFull) { var channelsInfoTelegram = new ChannelsInfo(); foreach (var item1 in _tLChannels) { if (item.Id == item1.Id) { channelsInfoTelegram.NameChannel = item1.Title; channelsInfoTelegram.UriChannel = item1.Username; channelsInfoTelegram.IdChannel = item1.Id; channelsInfoTelegram.AccessHashChannel = (long)item1.AccessHash; break; } } if (item.ChatPhoto is TLPhoto tLPhoto) { channelsInfoTelegram.AvatarChannel = DateTimeOffset.FromUnixTimeSeconds(tLPhoto.Date).DateTime; } else { channelsInfoTelegram.AvatarChannel = new DateTime(2000, 1, 1); } channelsInfoTelegram.SubscribersChannel = (int)item.ParticipantsCount; cannelsTelegram.Add(channelsInfoTelegram); } string resultStatus = String.Empty; foreach (var itemInfoChannels in InfoChannels) { var isCheck = await _telegramLogic.CheckUriChannel(itemInfoChannels.AccessHashChannel, itemInfoChannels.IdChannel); if (!isCheck) { resultStatus += $"Ссылка не действительна. "; NoLinks++; var tmpChannel = itemInfoChannels; tmpChannel.Status = resultStatus; _updateChannelsBD.Add(tmpChannel); resultStatus = String.Empty; continue; } foreach (var itemCannelsTelegram in cannelsTelegram) { if (itemInfoChannels.IdChannel == itemCannelsTelegram.IdChannel) { if (DateTime.Compare(itemInfoChannels.AvatarChannel, itemCannelsTelegram.AvatarChannel) != 0) { resultStatus += $"Изменили аватар. "; itemInfoChannels.AvatarChannel = itemCannelsTelegram.AvatarChannel; UpdatedAvatar++; } if (!itemInfoChannels.NameChannel.Equals(itemCannelsTelegram.NameChannel)) { resultStatus += $"Изменили имя группы. "; itemInfoChannels.NameChannel = itemCannelsTelegram.NameChannel; ChangeTitles++; } if (itemInfoChannels.SubscribersChannel != itemCannelsTelegram.SubscribersChannel) { resultStatus += $"Изменилось количество подписчиков группы. "; itemInfoChannels.SubscribersChannel = itemCannelsTelegram.SubscribersChannel; SubscribersChannel++; } var tmp = itemInfoChannels; tmp.Status = resultStatus; _updateChannelsBD.Add(tmp); resultStatus = String.Empty; } } } foreach (var item in _updateChannelsBD) { InfoChannels.Remove(item); InfoChannels.Add(item); } CheckStatusInfo checkStatusInfo = new CheckStatusInfo() { CheckDate = DateTime.Now, ChangeAvatar = UpdatedAvatar, ChangeName = ChangeTitles, ChannelsCount = SubscribersChannel, NoUri = NoLinks }; StatChannels.Add(_checkStatusService.Create(checkStatusInfo)); }