Exemplo n.º 1
0
        // GET: Home
        public ActionResult Index()
        {
            if (!new SessionStateCredentialStore().HasAllCredentials())
                return RedirectToAction("Begin", "OAuth");
            var TweetVM = new LoadUserViewModel
            {
                Text = "",
                size = 300,
                Response = ""
            };

            return View(TweetVM);
        }
Exemplo n.º 2
0
        public async Task<ActionResult> TweetAsync(LoadUserViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return View(user);
            }
            //load OAuth credentials
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };
            
            var ctx = new TwitterContext(auth);

            Friendship friendship;

            long cursor = -1;

            List<string> urls = new List<string>();
            List<int> counts = new List<int>();
            // load profile picture urls and tweets count using linq2twitter
            try
            {
                if (user.size < 24 || user.size > 2000)
                    throw new Exception("Size out of bounds. Min size: 24, Max size: 2000");

                do
                {
                    friendship =
                        await
                        (from friend in ctx.Friendship
                         where friend.Type == FriendshipType.FriendsList &&
                         friend.ScreenName == user.Text.Trim() &&
                         friend.Cursor == cursor
                         select friend).SingleOrDefaultAsync();

                    if (friendship != null &&
                        friendship.Users != null &&
                        friendship.CursorMovement != null)
                    {
                        cursor = friendship.CursorMovement.Next;

                        friendship.Users.ForEach(friend =>
                        {
                            urls.Add(friend.ProfileImageUrl.Replace("normal","bigger"));
                            counts.Add(friend.StatusesCount);
                        }
                        );
                    }
                } while (cursor != 0);

                // generate image collage from urls
                ViewBag.ImageData = ImageProcessing(urls, user.size, counts, user.Resize);

                // genrate status response
                var responseTweetVM = new LoadUserViewModel
                {
                    Text = user.Text,
                    size = user.size,
                    Response = "Collage loaded"
                };

                return View(responseTweetVM);
            }
            catch (Exception ex)
            {
                ViewBag.errors = ex.Message.Replace("page", "user");
            }
            return View();
        }