コード例 #1
0
        //
        // GET: /Home/
        public string AjaxSaveToDB()
        {
            if (Session["LoggedASP"] != null)
            {
                TimelineOptions options = new TimelineOptions();

                options.Count = 200;
                options.IncludeRetweets = true;

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                TwitterResponse<TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);

                TweetEntity tweetEntity = new TweetEntity();

                tweetEntity.RemoveTweetFromOwner(((User)Session["LoggedUser"]).ID);

                foreach (var item in truc.ResponseObject)
                {
                    //int lol = ;

                    tweetEntity.AddTweet(item.Id, item.Text, item.User.ScreenName, item.User.ProfileImageLocation, ((User)Session["LoggedUser"]).ID, ((int)((TimeSpan)(item.CreatedDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));
                }
                return "Success";
            }
            else
                return "Fail";
        }
コード例 #2
0
 public string EditGet(string id)
 {
     if (Session["LoggedASP"] != null && Session["LoggedTwitter"] != null)
     {
         Tweet tweet = new TweetEntity().GetTweet(Decimal.Parse(id));
         return tweet.Text;
     }
     else
         return "Fail";
 }
コード例 #3
0
        public string EditPost(string id, string text)
        {
            if (Session["LoggedASP"] != null && Session["LoggedTwitter"] != null)
            {
                Tweet tweet = new TweetEntity().GetTweet(Decimal.Parse(id));
                new TweetEntity().EditTweet(int.Parse(id),text);
                new TweetEntity().EditTweet(int.Parse(id), ((int)((TimeSpan)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                if (TwitterStatus.Delete(token, Decimal.Parse(tweet.IDTwitter.ToString())).ErrorMessage == null)
                {
                    TwitterResponse<TwitterStatus> status = TwitterStatus.Update(token, text);
                    if (status.ErrorMessage == null)
                    {
                        new TweetEntity().EditTweet(int.Parse(id), status.ResponseObject.Id, ((int)((TimeSpan)(status.ResponseObject.CreatedDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));

                        return "Success";
                    }
                    else
                        return "Fail";
                }
                else
                {
                    return "Fail1";
                }

            }
            else
            {
                return "Fail2";
            }
        }
コード例 #4
0
 public string GetTweetCode(string id)
 {
     Tweet item = new TweetEntity().GetTweet(Decimal.Parse(id));
     return "<div class='editTweet'><a class='editTweetA' rel='" + item.ID.ToString() + "' href='/Tweet/EditGet/" + item.ID.ToString() + "'>Edit</a> <a class='deleteLink' href='/Tweet/Delete/" + item.IDTwitter.ToString() + "'>Delete</a></div><div class='tweetP'><img class='inTweetImg' src='" + item.Avatar + "' /><a href=\"/User/" + item.Username + "\">" + item.Username + "</a> ---- " + item.Text + "</div>";
 }
コード例 #5
0
        public ActionResult Index()
        {
            if (Session["LoggedASP"] != null && Session["DatabaseMode"] != null)
            {
                User myUser = (User)Session["LoggedUser"];
                ViewData["Username"] = myUser.Username;

                TweetEntity entity = new TweetEntity();
                List<Tweet> list = entity.GetTweetsForOwner(((User)Session["LoggedUser"]).ID);

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                //string loggedUserName = TwitterUser.Show(token, Decimal.Parse(((User)Session["LoggedUser"]).TwitterID)).ResponseObject.ScreenName.ToLower();

                if (list.Count != 0)
                {
                    foreach (var item in list)
                    {
                        ViewData["message"] += "<div class='message'><div class='editTweet'><a class='editTweetA' rel='" + item.ID.ToString() + "' href='/Tweet/EditGet/" + item.ID.ToString() + "'>Edit</a> <a class='deleteLink' href='/Tweet/Delete/" + item.IDTwitter.ToString() + "'>Delete</a></div><div class='tweetP'><img class='inTweetImg' src='" + item.Avatar + "' /><a href=\"/User/" + item.Username + "\">" + item.Username + "</a> ---- " + item.Text + "</div></div>";
                    }
                }
                else
                {
                    ViewData["message"] = "<p style='text-align: center;'>Aucun rang dans la base de donnée. :(</p>";
                }
                return View();

            }
            else
            {

                if (Session["LoggedASP"] != null)
                {
                    User myUser = (User)Session["LoggedUser"];
                    ViewData["Username"] = myUser.Username;
                }

                if (Session["LoggedTwitter"] != null)
                {
                    TimelineOptions options = new TimelineOptions();

                    options.Count = 200;
                    options.IncludeRetweets = true;

                    OAuthTokens token = new OAuthTokens();
                    token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
                    token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
                    token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken;
                    token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                    try
                    {
                        TwitterResponse<TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);

                        foreach (var item in truc.ResponseObject)
                        {
                            ViewData["message"] += "<p class='tweetP'><img class='inTweetImg' src='" + item.User.ProfileImageLocation + "' /><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text + "</p>";
                        }
                    }
                    catch (WebException exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }
                    catch (Exception exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }
                }
                else
                {
                    if (Session["LoggedASP"] != null)
                        ViewData["message"] = "<p style='text-align:center;'>Bonjour " + ((User)Session["LoggedUser"]).Username + ", ton compte existe mais il n'est pas associé a un compte Twitter pour le moment, si tu veux associer ton compte Twitter avec ton Compte Tweetasse, rends toi sur la page Manage via le menu en haut.</p><hr />";

                    try
                    {
                        TwitterResponse<TwitterStatusCollection> publicTimeline = TwitterTimeline.PublicTimeline();
                        if (String.IsNullOrEmpty(publicTimeline.ErrorMessage))
                        {
                            foreach (var item in publicTimeline.ResponseObject)
                            {
                                ViewData["message"] += "<p class='tweetP'><img class='inTweetImg' src='" + item.User.ProfileImageLocation + "' /><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text + "</p>";
                            }
                        }
                        else
                            ViewData["message"] = "<p style='text-align:center;'>Bonjour shagasse, l'application a excedé le nombre de demandes maximum sur l'API Twitter Publique sans Login oAuth pour cette heure. Démerdes-toi, merssi!</p>";
                    }
                    catch (WebException exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : "+exception.Message+"</p>";
                        return View();
                    }
                    catch (Exception exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }

                }
                return View();
            }
        }