//public static string TwitterAccessToken { get; set; } //public static string TwitterAccessTokenSecret { get; set; } private static void InitiateTwitterAuthentication(SessionProperties sessionProperties) { if (String.IsNullOrEmpty(Parameters.Instance.TwitterAccessToken) || String.IsNullOrEmpty(Parameters.Instance.TwitterAccessTokenSecret)) { return; } try { // Step 3 - Exchange the Request Token for an Access Token Global.TwitterService = new TwitterService(Global.TwitterConsumerKey, Global.TwitterConsumerSecret); // Step 4 - User authenticates using the Access Token Global.TwitterService.AuthenticateWith(Parameters.Instance.TwitterAccessToken, Parameters.Instance.TwitterAccessTokenSecret); TwitterUser user = Global.TwitterService.VerifyCredentials(new VerifyCredentialsOptions()); if (user == null) { TwitterService = null; } } catch (Exception exception) { WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail); Global.TwitterService = null; } }
protected void Application_Error(object sender, EventArgs e) { var exception = Server.GetLastError().InnerException ?? Server.GetLastError(); //mail error message #if !DEBUG WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail); #endif var exceptionMsg = Server.HtmlEncode(exception.Message); //exceptionMsg += "<p>" + Server.HtmlEncode(exception.StackTrace).Replace("\n", "<br>").Replace(" at ", "<br> at ") + "</p>"; Response.Redirect("/Error.aspx?errorMsg=" + Server.UrlEncode(exceptionMsg)); }
protected void btnUpload_Click(object sender, EventArgs e) { var stream = uplImage.FileContent; lblMessage.Text = ""; lblMessage.ToolTip = ""; //check file size if (stream.Length > (1024 * 512)) { lblMessage.Text = "Max storlek för bilder att ladda upp är 512 MB"; return; } try { var serverSideImage = new System.Drawing.Bitmap(stream); var rescaledImage = RescaleImage(serverSideImage, MaximumWidth, MaximumHeight); var fileName = NewImageName + uplImage.FileName.Substring(uplImage.FileName.LastIndexOf(".")); rescaledImage.Save(Server.MapPath("~/img/user/") + fileName); LoadPreviewImage(fileName); uplImage.Visible = false; btnUpload.Visible = false; btnUndo.Visible = true; btnChangeImage.Visible = true; } catch (Exception exception) { lblMessage.Text = "Kan inte läsa bilden, testa med ett annat format."; lblMessage.ToolTip = exception.Message; WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail); } }
public static void SendTweet(string tweet, string appendUrl, SessionProperties sessionProperties) { if (TwitterService == null) { InitiateTwitterAuthentication(sessionProperties); } if (TwitterService == null) { WebControlManager.SendAndLogErrorMessage(new Exception("TwitterService not initialized"), Parameters.Instance.MailSender, Parameters.Instance.SupportMail); //clear authentication, guess we need to authenticate again? Parameters.Instance.TwitterAccessToken = null; Parameters.Instance.TwitterAccessTokenSecret = null; return; } try { //format the string, replace if (tweet.Contains("&")) { tweet = HttpUtility.HtmlDecode(tweet); } string shortUrl = String.Empty; //parse url to shorturl if (!String.IsNullOrEmpty(appendUrl)) { IBitlyService s = new BitlyService("o_3cpfcndji4", "R_8e203358cb5ca0f68d809419b056b192"); string shortened = s.Shorten(appendUrl); if (shortened != null) { shortUrl = " " + shortened; } } var maxLength = 140 - shortUrl.Length; if (tweet.Length > maxLength) { tweet = tweet.Substring(0, maxLength); } tweet += shortUrl; TwitterService.SendTweet(new SendTweetOptions() { Status = tweet }); // Likely this is an error; we don't have to go fishing for it TwitterError error = TwitterService.Response.Error; TwitterResponse response = TwitterService.Response; if (error != null || response.StatusCode != HttpStatusCode.OK) { // You now know you have a real error from Twitter, and can handle it string message; if (error != null) { message = String.Format("Twitter error: {0} ({1})", error.Message, error.Code); } else { message = String.Format("Twitter response status not ok: {0} ({1})\n{2}", response.StatusDescription, response.StatusCode, response.Response); } WebControlManager.SendAndLogErrorMessage(new Exception(message), Parameters.Instance.MailSender, Parameters.Instance.SupportMail); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }