Esempio n. 1
0
 /// <summary>
 /// Translate XML to IDList
 /// </summary>
 /// <param name="idList">XML with IDs and cursor info</param>
 /// <returns>New IDList instance</returns>
 public static IDList CreateIDList(XElement idList)
 {
     return(new IDList
     {
         CursorMovement = Cursors.CreateCursors(idList),
         IDs =
             (from id in idList.Element("ids").Elements("id")
              select id.Value)
             .ToList()
     });
 }
Esempio n. 2
0
 public static List CreateList(XElement list, XElement cursorNode)
 {
     return(new List
     {
         ListID = list.Element("id").Value,
         Name = list.Element("name").Value,
         FullName = list.Element("full_name").Value,
         Slug = list.Element("slug").Value,
         Description = list.Element("description").Value,
         SubscriberCount = int.Parse(list.Element("subscriber_count").Value),
         MemberCount = int.Parse(list.Element("member_count").Value),
         Uri = list.Element("uri").Value,
         Mode = list.Element("mode").Value,
         Users = new List <User>
         {
             User.CreateUser(list.Element("user"))
         },
         CursorMovement = Cursors.CreateCursors(cursorNode)
     });
 }
Esempio n. 3
0
        /// <summary>
        /// creates a new user based on an XML user fragment
        /// </summary>
        /// <param name="user">XML user fragment</param>
        /// <returns>new User instance</returns>
        public static User CreateUser(XElement user)
        {
            if (user == null)
            {
                return(null);
            }

            var tempUserProtected     = false;
            var tempFollowersCount    = 0ul;
            var tempFriendsCount      = 0ul;
            var tempFavoritesCount    = 0ul;
            var tempStatusesCount     = 0ul;
            var tempFollowingUsers    = false;
            var tempShowInlineMedia   = false;
            var tempListedCount       = 0;
            var tempFollowRequestSent = false;

            var canParseProtected =
                user.Element("protected") == null ?
                false :
                bool.TryParse(user.Element("protected").Value, out tempUserProtected);

            var followersCount =
                user.Element("followers_count") == null ?
                false :
                ulong.TryParse(user.Element("followers_count").Value, out tempFollowersCount);

            var friendsCount =
                user.Element("friends_count") == null ?
                false :
                ulong.TryParse(user.Element("friends_count").Value, out tempFriendsCount);

            var userDate          = user.Element("created_at").Value;
            var userCreatedAtDate = String.IsNullOrEmpty(userDate) ?
                                    DateTime.MinValue :
                                    DateTime.ParseExact(
                userDate,
                "ddd MMM dd HH:mm:ss %zzzz yyyy",
                CultureInfo.InvariantCulture,
                DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);

            var favoritesCount =
                user.Element("favourites_count") == null ?
                false :
                ulong.TryParse(user.Element("favourites_count").Value, out tempFavoritesCount);

            var statusesCount =
                user.Element("statuses_count") == null ?
                false :
                ulong.TryParse(user.Element("statuses_count").Value, out tempStatusesCount);

            var notifications =
                user.Element("notifications") == null ||
                string.IsNullOrEmpty(user.Element("notifications").Value) ?
                false :
                bool.Parse(user.Element("notifications").Value);

            var geoEnabled =
                user.Element("geo_enabled") == null ||
                string.IsNullOrEmpty(user.Element("geo_enabled").Value) ?
                false :
                bool.Parse(user.Element("geo_enabled").Value);

            var verified =
                user.Element("verified") == null ||
                string.IsNullOrEmpty(user.Element("verified").Value) ?
                false :
                bool.Parse(user.Element("verified").Value);

            var contributorsEnabled =
                user.Element("contributors_enabled") == null ||
                string.IsNullOrEmpty(user.Element("contributors_enabled").Value) ?
                false :
                bool.Parse(user.Element("contributors_enabled").Value);

            var isFollowing =
                user.Element("following") == null ||
                string.IsNullOrEmpty(user.Element("following").Value) ?
                false :
                bool.TryParse(user.Element("following").Value, out tempFollowingUsers);

            var showInlineMedia =
                user.Element("show_all_inline_media") == null ?
                false :
                bool.TryParse(user.Element("show_all_inline_media").Value, out tempShowInlineMedia);

            var listedCount =
                user.Element("listed_count") == null ?
                false :
                int.TryParse(user.Element("listed_count").Value, out tempListedCount);

            var followRequestSent =
                user.Element("follow_request_sent") == null ?
                false :
                bool.TryParse(user.Element("follow_request_sent").Value, out tempFollowRequestSent);

            var status =
                user.Element("status");

            var newUser = new User
            {
                Identifier = new UserIdentifier
                {
                    ID         = user.Element("id") == null ? "0" : user.Element("id").Value,
                    UserID     = user.Element("id") == null ? "0" : user.Element("id").Value,
                    ScreenName = user.Element("screen_name") == null ? "" : user.Element("screen_name").Value
                },
                Name                   = user.Element("name") == null ? "" : user.Element("name").Value,
                Location               = user.Element("location") == null ? "" : user.Element("location").Value,
                Description            = user.Element("description") == null ? "" : user.Element("description").Value,
                ProfileImageUrl        = user.Element("profile_image_url") == null ? "" : user.Element("profile_image_url").Value,
                URL                    = user.Element("url") == null ? "" : user.Element("url").Value,
                Protected              = tempUserProtected,
                FollowersCount         = tempFollowersCount,
                ProfileBackgroundColor =
                    user.Element("profile_background_color") == null ?
                    string.Empty :
                    user.Element("profile_background_color").Value,
                ProfileTextColor =
                    user.Element("profile_text_color") == null ?
                    string.Empty :
                    user.Element("profile_text_color").Value,
                ProfileLinkColor =
                    user.Element("profile_link_color") == null ?
                    string.Empty :
                    user.Element("profile_link_color").Value,
                ProfileSidebarFillColor =
                    user.Element("profile_sidebar_fill_color") == null ?
                    string.Empty :
                    user.Element("profile_sidebar_fill_color").Value,
                ProfileSidebarBorderColor =
                    user.Element("profile_sidebar_border_color") == null ?
                    string.Empty :
                    user.Element("profile_sidebar_border_color").Value,
                FriendsCount   = tempFriendsCount,
                CreatedAt      = userCreatedAtDate,
                FavoritesCount = tempFavoritesCount,
                UtcOffset      =
                    user.Element("utc_offset") == null ?
                    string.Empty :
                    user.Element("utc_offset").Value,
                TimeZone =
                    user.Element("time_zone") == null ?
                    string.Empty :
                    user.Element("time_zone").Value,
                ProfileBackgroundImageUrl =
                    user.Element("profile_background_image_url") == null ?
                    string.Empty :
                    user.Element("profile_background_image_url").Value,
                ProfileBackgroundTile =
                    user.Element("profile_background_tile") == null ?
                    string.Empty :
                    user.Element("profile_background_tile").Value,
                StatusesCount       = tempStatusesCount,
                Notifications       = notifications,
                GeoEnabled          = geoEnabled,
                Verified            = verified,
                ContributorsEnabled = contributorsEnabled,
                Following           = tempFollowingUsers,
                ShowAllInlineMedia  = tempShowInlineMedia,
                ListedCount         = tempListedCount,
                FollowRequestSent   = tempFollowRequestSent,
                Status         = Status.CreateStatus(status),
                CursorMovement = Cursors.CreateCursors(GrandParentOrNull(user))
            };

            return(newUser);
        }
Esempio n. 4
0
        /// <summary>
        /// transforms XML into IList of List
        /// </summary>
        /// <param name="responseXml">xml with Twitter response</param>
        /// <returns>IList of List</returns>
        public virtual List <T> ProcessResults(string responseXml)
        {
            XElement    twitterResponse = XElement.Parse(responseXml);
            List <List> lists           = new List <List>();

            if (twitterResponse.Name == "lists_list" || twitterResponse.Name == "lists")
            {
                IEnumerable <XElement> listElements =
                    twitterResponse.Name == "lists_list" ?
                    twitterResponse.Element("lists").Elements("list") :
                    twitterResponse.Elements("list");

                lists =
                    (from list in listElements
                     select List.CreateList(list, twitterResponse))
                    .ToList();
            }
            else if (twitterResponse.Name == "list")
            {
                lists.Add(
                    List.CreateList(twitterResponse, twitterResponse)
                    );
            }
            else if (twitterResponse.Name == "users_list")
            {
                lists.Add(
                    new List
                {
                    Users =
                        (from user in twitterResponse.Element("users").Elements("user")
                         select User.CreateUser(user))
                        .ToList(),
                    CursorMovement = Cursors.CreateCursors(twitterResponse)
                });
            }
            else if (twitterResponse.Name == "user")
            {
                lists.Add(
                    new List
                {
                    Users = new List <User>
                    {
                        User.CreateUser(twitterResponse)
                    }
                });
            }
            else if (twitterResponse.Name == "statuses")
            {
                lists.Add(
                    new List
                {
                    Statuses =
                        (from status in twitterResponse.Elements("status")
                         select Status.CreateStatus(status))
                        .ToList(),
                    CursorMovement = Cursors.CreateCursors(twitterResponse)
                });
            }

            lists.ForEach(list =>
            {
                list.Type   = Type;
                list.Cursor = Cursor;
                list.ID     = ID;

                if (String.IsNullOrEmpty(list.ListID) && !String.IsNullOrEmpty(ListID))
                {
                    list.ListID = ListID;
                }

                list.PerPage    = PerPage;
                list.Page       = Page;
                list.ScreenName = ScreenName;
                list.SinceID    = SinceID;
            });

            return(lists.AsEnumerable().OfType <T>().ToList());
        }