Advertisement
Guest User

Untitled

a guest
Oct 1st, 2013
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.61 KB | None | 0 0
  1.        public ObservableCollection<InboxFeedViewModel> ParseInboxFeed(string HTMLCode)
  2.        {
  3.            ObservableCollection<InboxFeedViewModel> observableCollection = new ObservableCollection<InboxFeedViewModel>();
  4.            string text = "<ul class=\"activity\">";
  5.            string value = "</ul>";
  6.            int num = 0;
  7.            int num2;
  8.            while ((num2 = HTMLCode.IndexOf(text, num)) != -1)
  9.            {
  10.                num = num2 + text.Length;
  11.                int num3 = HTMLCode.IndexOf(value, num);
  12.                string text2 = HTMLCode.Substring(num, num3 - num).Trim();
  13.                int num4 = 0;
  14.                int count = new Regex("<li").Matches(text2).Count;
  15.                for (int i = 1; i <= count; i++)
  16.                {
  17.                    num4 = text2.IndexOf("<li", num4);
  18.                    int num5 = text2.IndexOf("</li>", num4);
  19.                    string input = text2.Substring(num4, num5 - num4).Trim();
  20.                    Match match = Regex.Match(input, "<li class=\\\"(?<GroupName>[a-zA-Z0-9\\w\\s\\-]+?)\"\\>");
  21.                    if (match.Success)
  22.                    {
  23.                        string value2 = match.Groups["GroupName"].Value;
  24.                        InboxFeedViewModel inboxFeedViewModel = new InboxFeedViewModel();
  25.                        Match match2 = Regex.Match(input, "<p class=\\\"timestamp\\\" data-timestamp=\\\"(?<TimeStamp>[0-9]+?)\\\">(?<RelativeTime>[a-zA-Z0-9\\w\\s\\-]+?)</p>\\n");
  26.                        Match match3 = Regex.Match(input, "<a class=\\\"single-image profile-pic thumbnail\\\" href=\\\"instagram://user\\?username=(?<UserName>[a-zA-Z0-9_]+?)\\\"><img aria-label=\\\"(?<UserNameDesc>[a-zA-Z0-9_ ]+?)\\\" src=\\\"(?<URL>[a-zA-Z0-9:/._]+?)\\\" onerror=");
  27.                        Match match4 = Regex.Match(input, "/profiles/profile_(?<UserId>[0-9]+?)_");
  28.                        Match match5 = Regex.Match(input, "<a class=\\\"thumbnail gutter single-image\\\" href=\\\"instagram://media\\?id=(?<MediaId>[a-zA-Z0-9_]+?)\\\"><img src=\\\"(?<URL>[a-zA-Z0-9:/._]+?)\\\"/></a>");
  29.                        if (value2 == "fb-contact-joined-activity group gutter")
  30.                        {
  31.                            if (match2.Success && match3.Success)
  32.                            {
  33.                                inboxFeedViewModel.timestamp = long.Parse(match2.Groups["TimeStamp"].Value);
  34.                                inboxFeedViewModel.TimeStampRelative = match2.Groups["RelativeTime"].Value;
  35.                                inboxFeedViewModel.ImageFromURL = match3.Groups["URL"].Value;
  36.                                inboxFeedViewModel.Username = match3.Groups["UserName"].Value;
  37.                                inboxFeedViewModel.UsernameDesc = match3.Groups["UserNameDesc"].Value;
  38.                                if (match5.Success)
  39.                                {
  40.                                    inboxFeedViewModel.OptionalMediaId = match5.Groups["MediaId"].Value;
  41.                                    inboxFeedViewModel.ImageToURL = match5.Groups["URL"].Value;
  42.                                }
  43.                                inboxFeedViewModel.ProfileId = match4.Groups["UserId"].Value;
  44.                                string a;
  45.                                if ((a = value2) != null)
  46.                                {
  47.                                    if (!(a == "group no-media follow-activity"))
  48.                                    {
  49.                                        if (!(a == "group no-media follow-activity hidden"))
  50.                                        {
  51.                                            if (!(a == "like-activity group"))
  52.                                            {
  53.                                                if (!(a == "mention-activity group gutter"))
  54.                                                {
  55.                                                    if (!(a == "comment-activity group"))
  56.                                                    {
  57.                                                        if (a == "fb-contact-joined-activity group gutter")
  58.                                                        {
  59.                                                            inboxFeedViewModel.EnumType = InboxFeedTypeEnum.None;
  60.                                                            inboxFeedViewModel.PostDesc = " joined Instagram";
  61.                                                        }
  62.                                                    }
  63.                                                    else
  64.                                                    {
  65.                                                        inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Comment;
  66.                                                        inboxFeedViewModel.PostDesc = " left a comment on your photo.";
  67.                                                    }
  68.                                                }
  69.                                                else
  70.                                                {
  71.                                                    inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Mention;
  72.                                                    inboxFeedViewModel.PostDesc = " mentioned you in a comment.";
  73.                                                }
  74.                                            }
  75.                                            else
  76.                                            {
  77.                                                inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Like;
  78.                                                inboxFeedViewModel.PostDesc = " liked your photo.";
  79.                                            }
  80.                                        }
  81.                                        else
  82.                                        {
  83.                                            inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Follow;
  84.                                            inboxFeedViewModel.PostDesc = " started following you.";
  85.                                        }
  86.                                    }
  87.                                    else
  88.                                    {
  89.                                        inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Follow;
  90.                                        inboxFeedViewModel.PostDesc = " started following you.";
  91.                                    }
  92.                                }
  93.                                observableCollection.Add(inboxFeedViewModel);
  94.                            }
  95.                        }
  96.                        else
  97.                        {
  98.                            if (match2.Success && match3.Success && match4.Success)
  99.                            {
  100.                                inboxFeedViewModel.timestamp = long.Parse(match2.Groups["TimeStamp"].Value);
  101.                                inboxFeedViewModel.TimeStampRelative = match2.Groups["RelativeTime"].Value;
  102.                                inboxFeedViewModel.ImageFromURL = match3.Groups["URL"].Value;
  103.                                inboxFeedViewModel.Username = match3.Groups["UserName"].Value;
  104.                                inboxFeedViewModel.UsernameDesc = match3.Groups["UserNameDesc"].Value;
  105.                                if (match5.Success)
  106.                                {
  107.                                    inboxFeedViewModel.OptionalMediaId = match5.Groups["MediaId"].Value;
  108.                                    inboxFeedViewModel.ImageToURL = match5.Groups["URL"].Value;
  109.                                }
  110.                                inboxFeedViewModel.ProfileId = match4.Groups["UserId"].Value;
  111.                                string a2;
  112.                                if ((a2 = value2) != null)
  113.                                {
  114.                                    if (!(a2 == "group no-media follow-activity"))
  115.                                    {
  116.                                        if (!(a2 == "group no-media follow-activity hidden"))
  117.                                        {
  118.                                            if (!(a2 == "like-activity group"))
  119.                                            {
  120.                                                if (!(a2 == "mention-activity group gutter"))
  121.                                                {
  122.                                                    if (!(a2 == "comment-activity group"))
  123.                                                    {
  124.                                                        if (a2 == "fb-contact-joined-activity group gutter")
  125.                                                        {
  126.                                                            inboxFeedViewModel.EnumType = InboxFeedTypeEnum.None;
  127.                                                            inboxFeedViewModel.PostDesc = " joined Instagram";
  128.                                                        }
  129.                                                    }
  130.                                                    else
  131.                                                    {
  132.                                                        inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Comment;
  133.                                                        inboxFeedViewModel.PostDesc = " left a comment on your photo.";
  134.                                                    }
  135.                                                }
  136.                                                else
  137.                                                {
  138.                                                    inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Mention;
  139.                                                    inboxFeedViewModel.PostDesc = " mentioned you in a comment.";
  140.                                                }
  141.                                            }
  142.                                            else
  143.                                            {
  144.                                                inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Like;
  145.                                                inboxFeedViewModel.PostDesc = " liked your photo.";
  146.                                            }
  147.                                        }
  148.                                        else
  149.                                        {
  150.                                            inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Follow;
  151.                                            inboxFeedViewModel.PostDesc = " started following you.";
  152.                                        }
  153.                                    }
  154.                                    else
  155.                                    {
  156.                                        inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Follow;
  157.                                        inboxFeedViewModel.PostDesc = " started following you.";
  158.                                    }
  159.                                }
  160.                                observableCollection.Add(inboxFeedViewModel);
  161.                            }
  162.                        }
  163.                    }
  164.                    if (num4 <= 0)
  165.                    {
  166.                        num4 += num5;
  167.                    }
  168.                    else
  169.                    {
  170.                        num4 = num5;
  171.                    }
  172.                }
  173.            }
  174.            return observableCollection;
  175.        }
  176.        public ObservableCollection<InboxFeedViewModel> ParseRequestFeed(string HTMLCode)
  177.        {
  178.            ObservableCollection<InboxFeedViewModel> observableCollection = new ObservableCollection<InboxFeedViewModel>();
  179.            string text = "<ul class=\"activity friend-requests\">";
  180.            string value = "</ul>";
  181.            int num = 0;
  182.            int num2;
  183.            while ((num2 = HTMLCode.IndexOf(text, num)) != -1)
  184.            {
  185.                num = num2 + text.Length;
  186.                int num3 = HTMLCode.IndexOf(value, num);
  187.                string text2 = HTMLCode.Substring(num, num3 - num).Trim();
  188.                int num4 = 0;
  189.                int count = new Regex("<li").Matches(text2).Count;
  190.                for (int i = 1; i <= count; i++)
  191.                {
  192.                    num4 = text2.IndexOf("<li", num4);
  193.                    int num5 = text2.IndexOf("</li>", num4);
  194.                    string input = text2.Substring(num4, num5 - num4).Trim();
  195.                    Match match = Regex.Match(input, "<li class=\\\"(?<GroupName>[a-zA-Z0-9\\w\\s\\-]+?)\"\\>");
  196.                    if (match.Success)
  197.                    {
  198.                        string value2 = match.Groups["GroupName"].Value;
  199.                        InboxFeedViewModel inboxFeedViewModel = new InboxFeedViewModel();
  200.                        Match match2 = Regex.Match(input, "<a class=\\\"single-image profile-pic thumbnail\\\" href=\\\"instagram://user\\?username=(?<UserName>[a-zA-Z0-9_]+?)\\\"><img aria-label=\\\"(?<UserNameDesc>[a-zA-Z0-9_ ]+?)\\\" src=\\\"(?<URL>[a-zA-Z0-9:/._]+?)\\\" onerror=");
  201.                        Match match3 = Regex.Match(input, "/profiles/profile_(?<UserId>[0-9]+?)_");
  202.                        Match match4 = Regex.Match(input, "<a class=\\\"thumbnail gutter single-image\\\" href=\\\"instagram://media\\?id=(?<MediaId>[a-zA-Z0-9_]+?)\\\"><img src=\\\"(?<URL>[a-zA-Z0-9:/._]+?)\\\"/></a>");
  203.                        if (match2.Success && match3.Success)
  204.                        {
  205.                            inboxFeedViewModel.ImageFromURL = match2.Groups["URL"].Value;
  206.                            inboxFeedViewModel.Username = match2.Groups["UserName"].Value;
  207.                            inboxFeedViewModel.UsernameDesc = match2.Groups["UserNameDesc"].Value;
  208.                            if (match4.Success)
  209.                            {
  210.                                inboxFeedViewModel.OptionalMediaId = match4.Groups["MediaId"].Value;
  211.                                inboxFeedViewModel.ImageToURL = match4.Groups["URL"].Value;
  212.                            }
  213.                            inboxFeedViewModel.ProfileId = match3.Groups["UserId"].Value;
  214.                            string a;
  215.                            if ((a = value2) != null && a == "group")
  216.                            {
  217.                                inboxFeedViewModel.EnumType = InboxFeedTypeEnum.Follow;
  218.                                inboxFeedViewModel.PostDesc = inboxFeedViewModel.Username + " requests to follow you.";
  219.                            }
  220.                            observableCollection.Add(inboxFeedViewModel);
  221.                        }
  222.                    }
  223.                    if (num4 <= 0)
  224.                    {
  225.                        num4 += num5;
  226.                    }
  227.                    else
  228.                    {
  229.                        num4 = num5;
  230.                    }
  231.                }
  232.            }
  233.            return observableCollection;
  234.        }
  235.    }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement