public void PrivateMethodFromExistingPmWorks() { var currentModel = new PmChannelModel(new CharacterModel { Name = Character }) { TypingStatus = TypingStatus.Typing }; characterManager.Setup( x => x.IsOnList(Character, ListKind.Ignored, true)).Returns(false); channelManager.Setup( x => x.AddMessage(Message, Character, Character, MessageType.Normal)); chatModel.SetupGet(x => x.CurrentPms) .Returns(new ObservableCollection <PmChannelModel> { currentModel }); MockCommand( WithArgument(Constants.Arguments.Command, Commands.UserMessage), WithArgument(Constants.Arguments.Character, Character), WithArgument(Constants.Arguments.Message, Message)); characterManager.VerifyAll(); channelManager.VerifyAll(); chatModel.VerifyGet(x => x.CurrentPms); Assert.IsTrue(currentModel.TypingStatus == TypingStatus.Clear); }
public void AddChannel(ChannelType type, string id, string name) { Log((id != name && !string.IsNullOrEmpty(name)) ? $"Making {type} Channel {id} \"{name}\"" : $"Making {type} Channel {id}"); if (type == ChannelType.PrivateMessage) { var character = characters.Find(id); character.GetAvatar(); // make sure we have their picture // model doesn't have a reference to PrivateMessage channels, build it manually var temp = new PmChannelModel(character); container.RegisterInstance(temp.Id, temp); container.Resolve <PmChannelViewModel>(new ParameterOverride("name", temp.Id)); Dispatcher.Invoke(() => cm.CurrentPms.Add(temp)); // then add it to the model's data ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name); } else { GeneralChannelModel temp; if (type == ChannelType.Utility) { // our model won't have a reference to home, so we build it manually temp = new GeneralChannelModel(id, ChannelType.Utility); container.RegisterInstance(id, temp); container.Resolve <HomeChannelViewModel>(new ParameterOverride("name", id)); } else { // our model should have a reference to other channels though temp = cm.AllChannels.FirstOrDefault(param => param.Id == id); if (temp == null) { temp = new GeneralChannelModel(id, name, id == name ? ChannelType.Public : ChannelType.Private); Dispatcher.Invoke(() => cm.AllChannels.Add(temp)); } Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp)); container.Resolve <GeneralChannelViewModel>(new ParameterOverride("name", id)); ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name); } if (!cm.CurrentChannels.Contains(temp)) { Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp)); } } }
public void AddChannel(ChannelType type, string id, string name) { if (type == ChannelType.PrivateMessage) { var character = characterManager.Find(id); character.GetAvatar(); // make sure we have their picture // model doesn't have a reference to PrivateMessage channels, build it manually var temp = new PmChannelModel(character); container.RegisterInstance(temp.Id, temp); container.Resolve<PmChannelViewModel>(new ParameterOverride("name", temp.Id)); Dispatcher.Invoke((Action) (() => model.CurrentPms.Add(temp))); // then add it to the model's data ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(model.CurrentCharacter.Name); } else { GeneralChannelModel temp; if (type == ChannelType.Utility) { // our model won't have a reference to home, so we build it manually temp = new GeneralChannelModel(id, ChannelType.Utility); container.RegisterInstance(id, temp); container.Resolve<UtilityChannelViewModel>(new ParameterOverride("name", id)); } else { // our model should have a reference to other channels though temp = model.AllChannels.FirstOrDefault(param => param.Id == id) ?? new GeneralChannelModel(id, ChannelType.InviteOnly) {Title = name}; Dispatcher.Invoke((Action) (() => model.CurrentChannels.Add(temp))); container.Resolve<GeneralChannelViewModel>(new ParameterOverride("name", id)); ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(model.CurrentCharacter.Name); } if (!model.CurrentChannels.Contains(temp)) Dispatcher.Invoke((Action) (() => model.CurrentChannels.Add(temp))); } }
private void GetProfileDataAsyncHandler(object s, DoWorkEventArgs e) { var characterName = (string)e.Argument; PmChannelModel model = null; try { model = state.Resolve <PmChannelModel>(characterName); } catch (ResolutionFailedException) { } if (!invalidCacheList.Contains(characterName)) { ProfileData cache; profileCache.TryGetValue(characterName, out cache); cache = cache ?? SettingsService.RetrieveProfile(characterName); if (cache != null) { if (!profileCache.ContainsKey(characterName)) { cache.Kinks = cache.Kinks.Select(GetFullKink).ToList(); } if (cm.CurrentCharacter.NameEquals(characterName)) { cm.CurrentCharacterData = cache; } if (model != null) { model.ProfileData = cache; } profileCache[characterName] = cache; return; } } else { invalidCacheList.Remove(characterName); } var resp = browser.GetResponse(Constants.UrlConstants.CharacterPage + characterName, true); var htmlDoc = new HtmlDocument { OptionCheckSyntax = false }; HtmlNode.ElementsFlags.Remove("option"); htmlDoc.LoadHtml(resp); if (htmlDoc.DocumentNode == null) { return; } try { var profileBody = string.Empty; var profileText = htmlDoc.DocumentNode.SelectNodes(ProfileBodySelector); if (profileText != null) { profileBody = WebUtility.HtmlDecode(profileText[0].InnerHtml); profileBody = profileBody.Replace("<br>", "\n"); } IEnumerable <ProfileTag> profileTags = new List <ProfileTag>(); var statboxTags = htmlDoc.DocumentNode.SelectNodes(ProfileStatBoxSelector); if (statboxTags != null && statboxTags.Count != 0) { profileTags = statboxTags[0].ChildNodes .Where(x => x.Name == "span" || x.Name == "#text") .Select(x => x.InnerText.Trim().DoubleDecode()) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList() .Chunk(2) .Select(x => x.ToList()) .Select(x => new ProfileTag { Label = x[0], Value = x[1].Substring(1).Trim() }); } var otherTags = htmlDoc.DocumentNode.SelectNodes(ProfileTagsSelector); if (otherTags != null) { profileTags = profileTags.Union(otherTags.SelectMany(selection => selection.ChildNodes .Where(x => x.Name == "span" || x.Name == "#text") .Select(x => x.InnerText.Trim().DoubleDecode()) .ToList() .Chunk(2) .Select(x => x.ToList()) .Select(x => new ProfileTag { Label = x[0].Replace(":", "").Trim(), Value = x[1] }))); } IEnumerable <string> allAlts = new List <string>(); var profileAlts = htmlDoc.DocumentNode.SelectNodes(ProfileAltsSelector); if (profileAlts != null) { allAlts = profileAlts[0].ChildNodes .Where(x => x.Name == "a") .Select(x => x.InnerText.Trim().DoubleDecode()) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList(); } var allKinks = new List <ProfileKink>(); var profileKinks = htmlDoc.DocumentNode.SelectNodes(ProfileKinksSelector); if (profileKinks != null) { allKinks = profileKinks.SelectMany(selection => { var kind = (KinkListKind) Enum.Parse(typeof(KinkListKind), selection.Id.Substring("Character_Fetishlist".Length)); return(selection.Descendants() .Where(x => x.Name == "a") .Select(x => { var tagId = int.Parse(x.Id.Substring("Character_Listedfetish".Length)); var isCustomKink = x.Attributes.First(y => y.Name.Equals("class")).Value.Contains("FetishGroupCustom"); var tooltip = x.Attributes.FirstOrDefault(y => y.Name.Equals("rel")); var name = x.InnerText.Trim(); return new ProfileKink { Id = tagId, IsCustomKink = isCustomKink, Name = isCustomKink ? name.DoubleDecode() : string.Empty, KinkListKind = kind, Tooltip = tooltip != null && isCustomKink ? tooltip.Value.DoubleDecode() : string.Empty }; })); }).ToList(); } var id = htmlDoc.DocumentNode.SelectSingleNode(ProfileIdSelector).Attributes["value"].Value; ApiProfileImagesResponse images; try { var imageResp = browser.GetResponse(Constants.UrlConstants.ProfileImages, new Dictionary <string, object> { { "character_id", id } }, true); images = JsonConvert.DeserializeObject <ApiProfileImagesResponse>(imageResp); images.Images = images.Images.OrderBy(x => x.SortOrder).ToList(); } catch { images = new ApiProfileImagesResponse { Images = new List <ApiProfileImage>() }; } var profileData = CreateModel(profileBody, profileTags, images, allKinks, allAlts); SettingsService.SaveProfile(characterName, profileData); profileCache[characterName] = profileData; if (model != null) { model.ProfileData = profileData; } if (cm.CurrentCharacter.NameEquals(characterName)) { cm.CurrentCharacterData = profileData; } } catch { } }
public void AddChannel(ChannelType type, string id, string name) { Log((id != name && !string.IsNullOrEmpty(name)) ? $"Making {type} Channel {id} \"{name}\"" : $"Making {type} Channel {id}"); if (type == ChannelType.PrivateMessage) { var character = characters.Find(id); character.GetAvatar(); // make sure we have their picture // model doesn't have a reference to PrivateMessage channels, build it manually var temp = new PmChannelModel(character); container.RegisterInstance(temp.Id, temp); container.Resolve<PmChannelViewModel>(new ParameterOverride("name", temp.Id)); Dispatcher.Invoke(() => cm.CurrentPms.Add(temp)); // then add it to the model's data ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name); } else { GeneralChannelModel temp; if (type == ChannelType.Utility) { // our model won't have a reference to home, so we build it manually temp = new GeneralChannelModel(id, ChannelType.Utility); container.RegisterInstance(id, temp); container.Resolve<HomeChannelViewModel>(new ParameterOverride("name", id)); } else { // our model should have a reference to other channels though temp = cm.AllChannels.FirstOrDefault(param => param.Id == id); if (temp == null) { temp = new GeneralChannelModel(id, name, id == name ? ChannelType.Public : ChannelType.Private); Dispatcher.Invoke(() => cm.AllChannels.Add(temp)); } Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp)); container.Resolve<GeneralChannelViewModel>(new ParameterOverride("name", id)); ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs); SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name); } if (!cm.CurrentChannels.Contains(temp)) Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp)); } }