Example #1
0
        private ProfileData CreateModel(string profileText, IEnumerable <ProfileTag> tags,
                                        ApiProfileImagesResponse imageResponse, IEnumerable <ProfileKink> kinks, IEnumerable <string> alts)
        {
            var allKinks = kinks.Select(GetFullKink);

            var toReturn = new ProfileData
            {
                ProfileText = profileText,
                Kinks       = allKinks.ToList(),
                Alts        = alts.ToList()
            };

            var tagActions = new Dictionary <string, Action <string> >(StringComparer.OrdinalIgnoreCase)
            {
                { "age", s => toReturn.Age = s },
                { "species", s => toReturn.Species = s },
                { "orientation", s => toReturn.Orientation = s },
                { "build", s => toReturn.Build = s },
                { "height/length", s => toReturn.Height = s },
                { "body type", s => toReturn.BodyType = s },
                { "position", s => toReturn.Position = s },
                { "dom/sub role", s => toReturn.DomSubRole = s }
            };

            var profileTags = tags.ToList();

            profileTags.Each(x =>
            {
                Action <string> action;
                if (tagActions.TryGetValue(x.Label, out action))
                {
                    action(x.Value.DoubleDecode());
                }
            });

            toReturn.AdditionalTags = profileTags
                                      .Where(x => !tagActions.ContainsKey(x.Label))
                                      .Select(x =>
            {
                x.Value = x.Value.DoubleDecode();
                return(x);
            }).ToList();

            toReturn.Images = imageResponse.Images.Select(x => new ProfileImage(x)).ToList();

            toReturn.LastRetrieved = DateTime.Now;
            return(toReturn);
        }
Example #2
0
        private ProfileData CreateModel(string profileText, IEnumerable<ProfileTag> tags,
            ApiProfileImagesResponse imageResponse, IEnumerable<ProfileKink> kinks, IEnumerable<string> alts)
        {
            var allKinks = kinks.Select(GetFullKink);

            var toReturn = new ProfileData
            {
                ProfileText = profileText,
                Kinks = allKinks.ToList(),
                Alts = alts.ToList()
            };

            var tagActions = new Dictionary<string, Action<string>>(StringComparer.OrdinalIgnoreCase)
            {
                {"age", s => toReturn.Age = s},
                {"species", s => toReturn.Species = s},
                {"orientation", s => toReturn.Orientation = s},
                {"build", s => toReturn.Build = s},
                {"height/length", s => toReturn.Height = s},
                {"body type", s => toReturn.BodyType = s},
                {"position", s => toReturn.Position = s},
                {"dom/sub role", s => toReturn.DomSubRole = s}
            };

            var profileTags = tags.ToList();
            profileTags.Each(x =>
            {
                Action<string> action;
                if (tagActions.TryGetValue(x.Label, out action))
                    action(x.Value.DoubleDecode());
            });

            toReturn.AdditionalTags = profileTags
                .Where(x => !tagActions.ContainsKey(x.Label))
                .Select(x =>
                {
                    x.Value = x.Value.DoubleDecode();
                    return x;
                }).ToList();

            toReturn.Images = imageResponse.Images.Select(x => new ProfileImage(x)).ToList();

            toReturn.LastRetrieved = DateTime.Now;
            return toReturn;
        }
Example #3
0
        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
            {
            }
        }
Example #4
0
        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
            {
            }
        }