protected void SetPicture_Click(object sender, EventArgs e) { if (PhotoUpload.HasFile && (PhotoUpload.FileName.ToLower().EndsWith(".jpg") || PhotoUpload.FileName.ToLower().EndsWith(".jpeg"))) { string virtualFolder = "~/Patient/Photo/"; string physicalFolder = Server.MapPath(virtualFolder); string filename = Guid.NewGuid().ToString(); string extension = System.IO.Path.GetExtension(PhotoUpload.FileName); if (!String.IsNullOrEmpty(photoUrl)) { System.IO.File.Delete(photoUrl); photoUrl = null; } photoUrl = System.IO.Path.Combine(physicalFolder, filename + extension); PhotoUpload.SaveAs(photoUrl); Photo.ImageUrl = virtualFolder + filename + extension; DeletePicture.Visible = true; ImageError.Visible = false; } else { ImageError.Visible = true; } }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage) { bool rt = false; string ret = ""; string str = "Message posted"; if (message.Length > 140) { message = message.Substring(0, 135); } Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; // oAuthTwitter OAuthTwt = new oAuthTwitter("MbOQl85ZcvRGvp3kkOOJBlbFS", "GF0UIXnTAX28hFhN1ISNf3tURHARZdKWlZrsY4PlHm9A4llYjZ", "http://serv1.socioboard.com/TwitterManager/Twitter"); oAuthTwitter OAuthTwt = new oAuthTwitter("h4FT0oJ46KBBMwbcifqZMw", "yfowGI2g21E2mQHjtHjUvGqkfbI7x26WDCvjiSZOjas", "https://www.socioboard.com/TwitterManager/Twitter"); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); } else { str = "Message not posted"; } return(str); }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage) { bool rt = false; string ret = ""; string str = "Message posted"; if (message.Length > 140) { message = message.Substring(0, 135); } Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; oAuthTwitter OAuthTwt = new oAuthTwitter(Helper.AppSettings.twitterConsumerKey, Helper.AppSettings.twitterConsumerScreatKey, Helper.AppSettings.twitterRedirectionUrl); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); } else { str = "Message not posted"; } return(str); }
public ActionResult Upload(PhotoUpload photo, AppDevBusiness appbusiness, string studentnumber) { if (photo.FileUpload != null && photo.FileUpload.ContentLength > 0) { appbusiness.UploadPhoto("images", photo.FileUpload, studentnumber); } return(RedirectToAction("Index")); }
public ActionResult Upload(PhotoUpload photo) { if (photo.FileUpload != null && photo.FileUpload.ContentLength > 0) { var blobbusiness = new BlobBusiness.BlobBusiness(); blobbusiness.UploadPhoto("images", photo.FileUpload); } return(RedirectToAction("Index")); }
/// <summary> /// 添加任务 /// </summary> /// <param name="photoUpload"></param> /// <returns></returns> public bool AddUpload(PhotoUpload photoUpload) { bool result = uploadController.AddUpload(photoUpload); if (result) { EventBus.OnProgressBarMax(null, new ProgressBarMaxEventArgs(1)); } return(result); }
/// <summary> /// 添加任务 /// </summary> /// <param name="upload"></param> /// <returns></returns> public bool AddUpload(PhotoUpload upload) { if (upload == null) { return(false); } mUploadingList.Enqueue(upload); return(true); }
/// <summary> /// 获取下一个获取上传信息 /// </summary> /// <returns></returns> public PhotoUpload GetNextUpload() { if (mUploadingList.IsEmpty) { return(null); } PhotoUpload value = null; mUploadingList.TryDequeue(out value); return(value); }
protected void btnAdd_Click1(object sender, EventArgs e) { int i = blp.AddPhone(Convert.ToInt32(ddlManufacturer.SelectedValue.ToString()), txtPhone.Text, Convert.ToDecimal(txtPrice.Text), PhotoUpload.FileName); if (i > 0) { PhotoUpload.SaveAs(Server.MapPath("~/Phoneimages" + PhotoUpload.FileName)); lblMessage.Text = "Phone Added"; txtPhone.Text = ""; txtPrice.Text = ""; } }
protected void Confirm_Click(object sender, EventArgs e) { if (!Request.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); return; } Repository repository = null; if (Application["repository"] != null) { repository = (Repository)Application["repository"]; } string nickname = User.Identity.Name; var id = repository.GetAccountId(nickname); Account account = repository.GetAccount(id); if (!AuthorizationManager.PasswordMatch(nickname, InputActualPassword.Text)) { return; } string fName = string.IsNullOrEmpty(InputFName.Text) ? account.FirstName : InputFName.Text; string lName = string.IsNullOrEmpty(InputLName.Text) ? account.LastName : InputLName.Text; string info = string.IsNullOrEmpty(InputInformation.Text) ? account.Information : InputInformation.Text; string email = string.IsNullOrEmpty(InputEmail.Text) ? account.RegistrationInfo.Email : InputEmail.Text; DateTime?birthDate = string.IsNullOrEmpty(InputBirthDate.Text) ? account.BirthDate : DateTime.Parse(InputBirthDate.Text); if (!string.IsNullOrEmpty(InputPassword.Text) && string.Equals(InputPassword.Text, InputPassword2.Text)) { AuthorizationManager.ChangePassword(nickname, InputPassword.Text); } if (PhotoUpload.HasFile && PhotoUpload.FileName.EndsWith(".jpg")) { PhotoUpload.SaveAs(Server.MapPath("~/Photos/photo_" + id + ".jpg")); } account.ChangeInformation(fName, lName, info, email, birthDate); Application["repository"] = repository; Response.Redirect("Page.aspx?id=" + id); }
public async Task <IActionResult> DeleteConfirmed(int id) { var ad = await _context.Ads.FindAsync(id); _context.Ads.Remove(ad); await _context.SaveChangesAsync(); string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Admin", "Uploads", "Ads", ad.PhotoPath); PhotoUpload.DeletePhoto(path); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> UploadAsync(PhotoUpload photo) { if (ModelState.IsValid) { if (photo.FileUpload != null && photo.FileUpload.ContentLength > 0) { var blobbusiness = new BlobBusiness.BlobBusiness(); await blobbusiness.UploadPhotoAsync("images", photo.FileUpload); } } return(RedirectToAction("Index")); }
public ActionResult Upload(PhotoUpload photo) { if (ModelState.IsValid) { if (photo.FileUpload != null && photo.FileUpload.ContentLength > 0) { JazMax.Core.Blob.BlobStorageService.UploadToBlob("testimage", "test", photo.FileUpload); //ViewBag.Message = url.ToString(); } } return(RedirectToAction("Index")); }
protected void btn_update_Click(object sender, EventArgs e) { PhotoGalleryObject photogalleryObj = new PhotoGalleryObject(); photogalleryObj.PhotoId = int.Parse(Session["PhotoGallery_id"].ToString()); DataTable dt = dal.SelectInformationById(photogalleryObj.PhotoId); photogalleryObj.PhotoBrief = tbxPhotoBrief.Text; photogalleryObj.PhotoDetail = tbxPhotoDetail.Text; photogalleryObj.UserId = Int32.Parse(Session["user_id"].ToString()); if (ddlPhotoStatus.SelectedValue == "1") { photogalleryObj.Status = true; } else if (ddlPhotoStatus.SelectedValue == "0") { photogalleryObj.Status = false; } if (PhotoUpload.HasFile) { string extension = Path.GetExtension(PhotoUpload.FileName); string photopath = Guid.NewGuid().ToString() + extension; string uploadFolder = "~/Photo_gallery/"; PhotoUpload.SaveAs(Server.MapPath(uploadFolder + photopath)); photogalleryObj.PhotoPath = photopath; } else { photogalleryObj.PhotoPath = dt.Rows[0]["PhotoPath"].ToString(); } try { int result = dal.UpdateInformation(photogalleryObj); if (result == 1) { getPhotoGalleryById(); SuccessPanel.Visible = true; } else { DangerPanel.Visible = true; } } catch { throw; } }
protected void choosePhoto_Click(object sender, EventArgs e) { Session["ImageBytes"] = PhotoUpload.FileBytes; ImagePreview.ImageUrl = "~/ImageHandler.ashx"; if (PhotoUpload.HasFile) { // Get the file extension string fileExtension = System.IO.Path.GetExtension(PhotoUpload.FileName); if (fileExtension.ToLower() != ".png" && fileExtension.ToLower() != ".jpg" && fileExtension.ToLower() != ".gif") { choosePhotolbl.ForeColor = System.Drawing.Color.Red; choosePhotolbl.Text = "Only files with .png and .jpg extension are allowed"; } else { // Get the file size int fileSize = PhotoUpload.PostedFile.ContentLength; // If file size is greater than 2 MB if (fileSize > 2097152) { choosePhotolbl.ForeColor = System.Drawing.Color.Red; choosePhotolbl.Text = "File size cannot be greater than 2 MB"; } else { // Upload the file PhotoUpload.SaveAs(Server.MapPath("~/userImages/" + getFirstName() + PhotoUpload.FileName)); choosePhotolbl.ForeColor = System.Drawing.Color.Green; choosePhotolbl.Text = "File uploaded successfully"; string connStr = WebConfigurationManager.ConnectionStrings["ProjectDB"].ConnectionString; SqlConnection dbConnection = new SqlConnection(connStr); dbConnection.Open(); int uid = Convert.ToInt32(HttpContext.Current.Session["userID"]); string path = "userImages/" + getFirstName() + PhotoUpload.FileName; string strQuery = "insert into userImageTable (userID, ImageFileName, ImageFilePath) values (@userID, @FileName, @FilePath)"; SqlCommand cmd = new SqlCommand(strQuery, dbConnection); cmd.Parameters.AddWithValue("@userID", uid); cmd.Parameters.AddWithValue("@FileName", getFirstName() + PhotoUpload.FileName); cmd.Parameters.AddWithValue("@FilePath", path); cmd.ExecuteNonQuery(); } } } else { choosePhotolbl.ForeColor = System.Drawing.Color.Red; choosePhotolbl.Text = "Please select a file"; } }
protected void btn_update_Click(object sender, EventArgs e) { BannerObject bannerObj = new BannerObject(); bannerObj.BannerId = int.Parse(Session["Banner_id"].ToString()); DataTable dt = dal.SelectInformationById(bannerObj.BannerId); bannerObj.BannerInformation = tbxBannerInfo.Text; bannerObj.UserId = Int32.Parse(Session["user_id"].ToString()); if (ddlBannerStatus.SelectedValue == "1") { bannerObj.Status = true; } else if (ddlBannerStatus.SelectedValue == "0") { bannerObj.Status = false; } if (PhotoUpload.HasFile) { string extension = Path.GetExtension(PhotoUpload.FileName); string photopath = Guid.NewGuid().ToString() + extension; string uploadFolder = "~/Banner_Photos/"; PhotoUpload.SaveAs(Server.MapPath(uploadFolder + photopath)); bannerObj.PhotoPath = photopath; } else { bannerObj.PhotoPath = dt.Rows[0]["PhotoPath"].ToString(); } try { int result = dal.UpdateInformation(bannerObj); if (result == 1) { getBannerById(); SuccessPanel.Visible = true; } else { DangerPanel.Visible = true; } } catch { throw; } }
private void UpdataPhoto(int id) { PhotoUpload photo = new PhotoUpload(); if (FileUpload1.HasFile) { FileModel fileModel = photo.Upload(FileUpload1.FileName); FileUpload1.SaveAs(fileModel.AbsoluteFileName); if (photo.SavePhotoPath(fileModel.RelativeFileName, id)) { Image1.ImageUrl = fileModel.RelativeFileName; } } }
protected void Button4_Click(object sender, EventArgs e) { string imagefile4 = ""; if (PhotoUpload.HasFile) { imagefile4 = "~/upload/" + PhotoUpload.FileName; PhotoUpload.SaveAs(Server.MapPath(imagefile4)); con.Open(); SqlCommand cmd = new SqlCommand("update [dbo].[tblMemberMaster] set photoupdatedate=getdate(),UploadPhoto='" + imagefile4 + "' where usercode='" + TextBox1.Text + "'", con); cmd.ExecuteNonQuery(); con.Close(); MsgBox("Uploaded Successfully"); } }
public JsonResult AddPhoto(string path) { List <IFormFile> Photos = Request.Form.Files.ToList(); var photo_info = new List <object>(); if (Checker.CheckList(Photos) && path != null) { for (int i = 0; i < Photos.Count; i++) { if (PhotoUpload.IsValid(Photos[i])) { string filename = (DateTime.Now.ToShortDateString() + Photos[i].FileName).Replace(" ", "").Replace("/", ""); string _path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Admin", "Uploads", path, filename); if (PhotoUpload.HasPhoto(_path)) { Guid guid = new Guid(); _path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Admin", "Uploads", path, guid + filename); } PhotoUpload.UploadTo(Photos[i], _path); var obj = new { Filename = filename, Url = $"/Admin/Uploads/{path}/" + filename }; photo_info.Add(obj); } else { return(Json(new { response = 400 })); } } return(Json(new { status = 200, data = photo_info })); } else { return(Json(new { error = "something went wrong" })); } }
public async Task <IActionResult> AddDataset(PhotoUpload FileUpload) { using (var memoryStream = new MemoryStream()) { await FileUpload.FormFile.CopyToAsync(memoryStream); if (memoryStream != null) { await s3upload.UploadFileAsync(memoryStream, "fagelgamousuploads", "Photos/" + FileUpload.FormFile.FileName); } else { ModelState.AddModelError("File", "Please Select a File"); } } return(View()); }
public void BlobUpload_Test() { //Arrange var controller = new BlobController(); PhotoUpload ImageToInsert = new PhotoUpload { //not sure of data to enter for image //FileUpload = , StudentNumber = "21638797" }; //Act var result = controller.Upload(ImageToInsert, appDevBusiness, ImageToInsert.StudentNumber); //Assert Assert.IsNotNull(result); }
protected void upload(object sender, EventArgs e) { if (PhotoUpload.HasFile) { try { string filename = Path.GetFileName(PhotoUpload.FileName); PhotoUpload.SaveAs(path + @"\" + albums.SelectedItem.Text + @"\" + filename); statusLabel.Visible = true; statusLabel.Text = "Picture was uploaded"; updatePicturesList(); } catch (Exception ex) { statusLabel.Text = "error" + ex.Message; } } }
protected void btnRegister_Click(object sender, EventArgs e) { try { String path; studentID = txtStudentID.Text; EmailConfirmation obj = new EmailConfirmation(); DatabaseRegistration objdb = new DatabaseRegistration(); if (objdb.isStudentIDAvailable(studentID) && objdb.isEmailIDAvailable(txtEmailID.Text)) { if (PhotoUpload.HasFile) { PhotoUpload.SaveAs(MapPath("~/Files/Images/Students/" + PhotoUpload.FileName)); path = PhotoUpload.FileName;; } else { path = " "; } objdb.insert_Student_Info(txtStudentID.Text, txtFName.Text, txtLName.Text, ddlProgram.SelectedValue, txtCurrentSemester.Text, path); objdb.insert_Student_Login_Info(txtEmailID.Text, txtPassword.Text, txtStudentID.Text); String Subject = "Registration Confirmation Email"; String body = "You are Successfully registered with Advisor Booking Service."; body = body + "\n Now You can make an appointment with the advisor"; body = body + "\n Your User Name is =" + txtEmailID.Text; body = body + "\n Your Password is =" + txtPassword.Text; obj.sendEmail("*****@*****.**", "Passwordisimportant", txtEmailID.Text, Subject, body); lblMessage.Text = "Successfully Registered"; /// clear_Fields(); Response.Redirect("UserLogin.aspx"); } else { lblMessage.Text = "StudentID or Email ID is already registered"; clear_Fields(); } } catch (Exception obj) { lblMessage.Text = "Error in Registeration. Please try again"; } }
protected void ButtonConfirm_Click(object sender, EventArgs e) { try { string nickname = InputNickname.Text; string email = InputEmail.Text; string password = InputPassword.Text; string firstName = InputFName.Text; string lastName = InputLName.Text; string info = InputInformation.Text; DateTime?birthDate = DateTime.Parse(InputBirthDate.Text); Account account = new Account(email, nickname, firstName, lastName, info, birthDate); Repository repository; if (Application["repository"] == null) { repository = new Repository(); } else { repository = (Repository)Application["repository"]; } repository.AddAccount(account); Application["repository"] = repository; AuthorizationManager.RegisterUser(nickname, password); if (PhotoUpload.HasFile && PhotoUpload.FileName.EndsWith(".jpg")) { PhotoUpload.SaveAs(Server.MapPath("~/Photos/photo_" + account.RegistrationInfo.AccountId + ".jpg")); } Response.Redirect("Default.aspx", true); } catch (Exception exception) { } }
// TODO: mapping logic should not be in ctor private static PhotoModel GetPhotoModel(PhotoUpload model) { if (model?.File == null) { return(new PhotoModel { DisplayProperties = model?.DisplayProperties }); } using (var ms = new MemoryStream()) { model.File.CopyTo(ms); return(new PhotoModel { DisplayProperties = model.DisplayProperties, Data = new PhotoDataModel { Data = ms.ToArray(), MimeType = model.File.ContentType } }); } }
public ActionResult Upload() { List <Photo> pList = PhotoUpload.getUploadFiles(); if (pList == null || pList.Count() < 1) { return(View("Index")); } foreach (Photo p in pList) { try { _repo.AddPhoto(p); } catch { return(View("Index")); } } return(View("NewFileList", pList)); }
protected void btnPhtoUpload_Click(object sender, EventArgs e) { string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //連接資料庫 SqlConnection Conn = new SqlConnection(ConnectionString); Conn.Open(); //Cmd命令,選取所有AdminID SqlCommand checkCmd = new SqlCommand("SELECT AdminID FROM UploadPhoto", Conn); SqlDataReader Reader = checkCmd.ExecuteReader(); //設定檔案名稱 string fileName = PhotoUpload.FileName; //判斷資料夾是否存在,若無則建立資料夾 if (!Directory.Exists("Img/")) { Directory.CreateDirectory(Server.MapPath("Img")); } // 設定檔案路徑 string savePath = Server.MapPath("Img/"); //設定完整存檔路徑 string saveResults = System.IO.Path.Combine(savePath, fileName); //確認使用者是否已經有上傳過檔案了,若有的話使用Update if (Reader.Read()) { if (Reader["AdminID"].ToString() == Session["Login"].ToString()) { Reader.Close(); //判斷檔案否存在 if (PhotoUpload.HasFile) { //判斷是否為指定類型檔案,using System.IO; string saveExt = Path.GetExtension(PhotoUpload.FileName); if (saveExt == ".jpg" || saveExt == ".png") { PhotoUpload.SaveAs(saveResults); //Cmd命令,更新檔名與日期 SqlCommand updateCmd = new SqlCommand("UPDATE UploadPhoto SET PhotoFileName =@PhotoFileName, UploadTime =@UploadTime WHERE (AdminID = @AdminID)", Conn); updateCmd.Parameters.AddWithValue("@PhotoFileName", fileName); updateCmd.Parameters.AddWithValue("@AdminID", Session["Login"].ToString()); updateCmd.Parameters.AddWithValue("@UploadTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm")); //執行命令 updateCmd.ExecuteNonQuery(); updateCmd.Cancel(); Conn.Close(); Conn.Dispose(); Response.Redirect(this.Request.Url.ToString()); //頁面跳轉更新 } else { lblMessage.Text = "請使用指定檔案類型:jpg、png"; } } else { lblMessage.Text = "請選擇檔案上傳!"; } } } else //若沒有的話使用INSERT INTO { Reader.Close(); //判斷檔案否存在 if (PhotoUpload.HasFile) { //判斷是否為指定類型檔案,using System.IO; string saveExt = Path.GetExtension(PhotoUpload.FileName); if (saveExt == ".jpg" || saveExt == ".png") { PhotoUpload.SaveAs(saveResults); //Cmd命令,新增Photo資料 SqlCommand insertCmd = new SqlCommand("INSERT INTO UploadPhoto (AdminID, PhotoFileName, UploadTime) VALUES (@AdminID,@PhotoFileName,@UploadTime)", Conn); insertCmd.Parameters.AddWithValue("@AdminID", Session["Login"].ToString()); insertCmd.Parameters.AddWithValue("@PhotoFileName", fileName); insertCmd.Parameters.AddWithValue("@UploadTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm")); //執行命令 insertCmd.ExecuteNonQuery(); insertCmd.Cancel(); Conn.Close(); Conn.Dispose(); Response.Redirect(this.Request.Url.ToString());//頁面跳轉更新 } else { lblMessage.Text = "請使用指定檔案類型:jpg、png"; } } else { lblMessage.Text = "請選擇檔案上傳!"; } } }
public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user) { bool rt = false; string ret = ""; string str = "Message posted"; if (message.Length > 140) { message = message.Substring(0, 135); } Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount; oAuthTwitter OAuthTwt = new oAuthTwitter(AppSettings.twitterConsumerKey, AppSettings.twitterConsumerScreatKey, AppSettings.twitterRedirectionUrl); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(picurl)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(picurl, message, OAuthTwt, ref res); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } if (!string.IsNullOrEmpty(ret) || rt == true) { schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; //schmessage.url = ret; dbr.Update <ScheduledMessage>(schmessage); Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Scheduled"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Successfully"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleSuccessUpdates) { string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { //if (_user.scheduleSuccessUpdates) //{ // string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword); //} } } else { str = "Message not posted"; Domain.Socioboard.Models.Notifications notify = new Notifications(); Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id); if (lstnotifications == null) { notify.MsgId = schmessage.id; notify.MsgStatus = "Failed"; notify.notificationtime = schmessage.localscheduletime; notify.NotificationType = "Schedule Failed"; notify.ReadOrUnread = "Unread"; notify.UserId = userid; dbr.Add <Notifications>(notify); if (_user.scheduleFailureUpdates) { string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); } } else { //if (_user.scheduleFailureUpdates) //{ // string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword); //} } } return(str); }
public static string PostTwitterMessage(AppSettings _AppSettings, Cache _redisCache, string message, string profileid, long userid, string url, bool isScheduled, DatabaseRepository dbr, ILogger _logger, string sscheduledmsgguid = "") { bool rt = false; string ret = ""; string str = ""; int Twtsc = 0; Domain.Socioboard.Models.TwitterAccount objTwitterAccount = Api.Socioboard.Repositories.TwitterRepository.getTwitterAccount(profileid, _redisCache, dbr); oAuthTwitter OAuthTwt = new oAuthTwitter(_AppSettings.twitterConsumerKey, _AppSettings.twitterConsumerScreatKey, _AppSettings.twitterRedirectionUrl); OAuthTwt.AccessToken = objTwitterAccount.oAuthToken; OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret; OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName; OAuthTwt.TwitterUserId = objTwitterAccount.twitterUserId; Tweet twt = new Tweet(); if (!string.IsNullOrEmpty(url)) { try { PhotoUpload ph = new PhotoUpload(); string res = string.Empty; rt = ph.NewTweet(url, message, OAuthTwt, ref res); } catch (Exception ex) { _logger.LogError("PostTwitterMessageWithImage" + ex.StackTrace); _logger.LogError("PostTwitterMessageWithImage" + ex.Message); } } else { try { JArray post = twt.Post_Statuses_Update(OAuthTwt, message); ret = post[0]["id_str"].ToString(); } catch (Exception ex) { _logger.LogError("PostTwitterMessage" + ex.StackTrace); _logger.LogError("PostTwitterMessage" + ex.Message); } } if (!string.IsNullOrEmpty(ret) || rt == true) { ScheduledMessage scheduledMessage = new ScheduledMessage(); scheduledMessage.createTime = DateTime.UtcNow; scheduledMessage.picUrl = objTwitterAccount.profileImageUrl; scheduledMessage.profileId = profileid; scheduledMessage.profileType = Domain.Socioboard.Enum.SocialProfileType.Twitter; scheduledMessage.scheduleTime = DateTime.UtcNow; scheduledMessage.shareMessage = message; scheduledMessage.socialprofileName = objTwitterAccount.twitterScreenName; scheduledMessage.userId = userid; scheduledMessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated; scheduledMessage.url = url; dbr.Add <ScheduledMessage>(scheduledMessage); } else { str = "Message not posted"; } return(str); }
/// <summary> /// 上传图片执行方法 /// </summary> /// <param name="photoUpload">图片信息</param> /// <param name="eventBus">事件</param> public abstract void Execute(PhotoUpload photoUpload, EventBus eventBus);