public ActionResult Send(FormCollection collection) { try { string fileid = collection.GetValue("FieldId").AttemptedValue; int fileId = Convert.ToInt32(fileid); PubSubRepository psr = new PubSubRepository(); FilesRepository fr = new FilesRepository(); Models.File f = fr.GetFile(fileId); FileSendTo fst = new FileSendTo(); string email = collection.GetValue("Email").AttemptedValue; string message = collection.GetValue("Message").AttemptedValue; fst.Link = f.Link; fst.Name = f.Name; fst.OwnerFk = f.OwnerFk; fst.Message = message; fst.Email = email; psr.AddToEmailQueue(fst); psr.DownloadEmailFromQueueAndSend(); new LoggingRepository().Logging("File: " + f.Name + " Shared With: " + email + " At: " + DateTime.Now); return(RedirectToAction("Index")); } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); } return(View()); }
// GET: Cron public ActionResult RunEveryMinute() { PubSubRepository psr = new PubSubRepository(); psr.DownloadEmailFromQueueAndSend(); return(Content("Sent")); }
public ActionResult Share(string ftitle, string recepient) { try { FileRepository ff = new FileRepository(); if (TempData["filename"] != null) { ftitle = TempData["filename"].ToString(); //if email is valid if (ff.IsValidEmail(recepient)) { //Actual file retreived using the file title. File file = ff.GetFile(ftitle); //PubSub - publish topic PubSubRepository psr = new PubSubRepository(); psr.AddToEmailQueue(file, recepient); //grants Read premissions to recepient on file. psr.AddReadPermOnFile("pfc-file-bucket", ftitle, recepient); //DownloadEmailFromQueueAndSend() should be called using third party cronJobs website. //psr.DownloadEmailFromQueueAndSend(); //this will be called using cronJobs (ideal to be in another application but for this assignment was created in another controller) //ViewBag.Error = "Invalid Email address"; ViewBag.ShareSucc = "File was shared successfully."; TempData["filename"] = null; } } } catch (Exception e) { ViewBag.Error = "File was not shared. " + e.Message; TempData["filename"] = null; new LogRepository().LogError(e); } return(RedirectToAction("Index")); }
public ActionResult PubSub(int id) { //get prop PropertyRepository p = new PropertyRepository(); var prop = p.GetPropertyById(id); PubSubRepository psp = new PubSubRepository(); var msg = new PropertyNotificationMessage() { Email = User.Identity.Name, Location = prop.Location, Fullname = prop.Username, PropertyName = prop.Name }; psp.PublishMessage(JsonConvert.SerializeObject(msg), "TestTopic_2"); ViewBag.Success = "success"; return(RedirectToAction("Index", "Property")); }
// GET: Cron public ActionResult RunEveryMinute() { try { PubSubRepository psr = new PubSubRepository(); psr.DownloadEmailFromQueueAndSend(); ViewBag.Message = "Email sent"; LogsRepository lr = new LogsRepository(); lr.WriteLogEntry("CRON was added"); } catch (Exception ex) { LogsRepository lr = new LogsRepository(); lr.LogError(ex); } return(Content("Sent")); }
public ActionResult Create(Product p, HttpPostedFileBase file) { //upload image related to product on the bucket try { if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("pfcbrandonbucket", filename, null, f); link = "https://storage.cloud.google.com/pfcbrandonbucket/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfcbrandonbucket", Entity = $"user-" + User.Identity.Name, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfcbrandonbucket", Entity = $"user-" + p.Shareuser, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link List <Product> results = new List <Product>(); p.File = link; // p.Name = System.IO.Path.GetExtension(model.Shareuser); //p.OwnerFK = User.Identity.Name; //p.Shareuser = Shareuser; // results.Add(p); #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFK = User.Identity.Name; ProductsRepository pr = new ProductsRepository(); pr.AddProduct(p); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db try { CacheRepository cr = new CacheRepository(); cr.UpdateCache(pr.GetProducts(User.Identity.Name)); } catch (Exception ex) { new LogsRepository().LogError(ex); } #endregion PubSubRepository psr = new PubSubRepository(); psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. ViewBag.Message = "Product created successfully"; new LogsRepository().WriteLogEntry("Product created successfully for user: "******"Product failed to be created; " + ex.Message; } return(View()); ////upload image related to product on bucket //var storage = StorageClient.Create(); //string link = ""; //using (var f = file.InputStream) //{ // var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); // var storageObject = storage.UploadObject("pfcbrandonbucket", filename, null, f); // link = storageObject.MediaLink; // if (null == storageObject.Acl) // { // storageObject.Acl = new List<ObjectAccessControl>(); // } // storageObject.Acl.Add(new ObjectAccessControl() // { // Bucket = "pfcbrandonbucket", // Entity = $"*****@*****.**", // Role = "READER", // }); // storageObject.Acl.Add(new ObjectAccessControl() // { // Bucket = "pfcbrandonbucket", // Entity = $"*****@*****.**", // Role = "OWNER", // }); // var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() // { // // Avoid race conditions. // IfMetagenerationMatch = storageObject.Metageneration, // }); //} ////create p in db ////p.Link = link; //return View(); }
public ActionResult FileUpload(FileUpload sf, HttpPostedFileBase file) { try { if (file != null) { var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("justinportellipfc", filename, null, f); link = "https://storage.cloud.google.com/justinportellipfc/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "justinportellipfc", Entity = $"user-" + User.Identity.Name, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", //READER }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "justinportellinpfc", Entity = $"user-" + sf.receiverEmail, //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); FileRepository fr = new FileRepository(); UsersRepository ur = new UsersRepository(); CacheRepository cr = new CacheRepository(); fr.AddFile(filename.ToString(), link, sf.receiverEmail, ur.GetUserID(User.Identity.Name)); cr.UpdateCache(GetFiles(ur.GetUserID(User.Identity.Name)), ur.GetUserID(User.Identity.Name)); PubSubRepository psr = new PubSubRepository(); psr.AddToEmailQueue(sf); } ViewBag.Message = "File uploaded"; LogsRepository logr = new LogsRepository(); logr.WriteLogEntry("File was Uploaded"); } } catch (Exception ex) { LogsRepository logr = new LogsRepository(); logr.LogError(ex); ViewBag.Message = "File was not uploaded"; } return(View()); }
public ActionResult Create(Product p, HttpPostedFileBase file) { //upload image related to product on the bucket try { if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("pfct001", filename, null, f); link = "https://storage.cloud.google.com/pfct001/" + file.FileName; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfct001", Entity = $"user-" + "*****@*****.**", //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", //READER }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfct001", Entity = $"user-" + "*****@*****.**", //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFk = "*****@*****.**"; //User.Identity.Name ProductsRepository pr = new ProductsRepository(); //pr.AddProduct(p); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db CacheRepository cr = new CacheRepository(); //cr.UpdateCache(pr.GetProducts()); #endregion PubSubRepository psr = new PubSubRepository(); //psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. ViewBag.Message = "Product created successfully"; } catch (Exception ex) { ViewBag.Error = "Product failed to be created; " + ex.Message; } return(View()); }