public virtual IEnumerable send(PXAdapter adapter) { var emailMessage = Message.Current; CheckValue(emailMessage.MailAccountID, "From"); CheckText(emailMessage.MailTo, "To"); CheckText(emailMessage.Subject, "Subject"); WikiDescriptorExt record = PXSelect <WikiDescriptorExt, Where <WikiDescriptorExt.pageID, Equal <Required <WikiDescriptorExt.pageID> > > > . Select(this, emailMessage.WikiID); var wikiSettings = WikiSettings; var newSettings = wikiSettings == null ? new PXSettings() : new PXSettings(wikiSettings); newSettings.ExternalRootUrl = record == null ? null : record.PubVirtualPath; var sender = new NotificationGenerator(this) { MailAccountId = emailMessage.MailAccountID, Subject = emailMessage.Subject, To = emailMessage.MailTo, Cc = emailMessage.MailCc, Bcc = emailMessage.MailBcc, Body = emailMessage.WikiText, //WikiSettings = newSettings, //WikiID = emailMessage.WikiID }; sender.Send(); return(adapter.Get()); }
public JsonResult SendNotification(CasualNotificationDto casualNotification) { if (ModelState.IsValid) { Image image; if (casualNotification.Avatar != null) { image = ImageHandler.CreateWebImage(casualNotification.Avatar, casualNotification.Title, WebImageType.NOTIFICATION_IMAGE); } else { image = ImageHandler.CreateDefaultImage(casualNotification.Title, WebImageType.NOTIFICATION_IMAGE); } NotificationGenerator.CasualNotification(db, casualNotification.Title, casualNotification.Message, image); return(Json(new { result = true })); } return(Json(new { result = false })); }
public JsonResult LongRunningProcess() { //THIS COULD BE SOME LIST OF DATA int itemsCount = 100; for (int i = 0; i <= itemsCount; i++) { //SIMULATING SOME TASK Thread.Sleep(500); //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT NotificationGenerator.SendProgress("Process in progress...", i, itemsCount); } return(Json("", JsonRequestBehavior.AllowGet)); }
public void NotificationGenerator_Generates_Succesfully() { var generator = new NotificationGenerator(); var args = new NotificationArgs { BaseUrl = ConfigurationManager.AppSettings["WebUrl"], DisplayName = "Matt Schwartz", Recipient = "*****@*****.**", SessionId = "2434", SessionName = "Email Session Test" }; Assert.DoesNotThrow(() => generator.Generate(EventType.ReviewSessionReleased, args)); Assert.DoesNotThrow(() => generator.Generate(EventType.ReviewerAssigned, args)); Assert.DoesNotThrow(() => generator.Generate(EventType.QuestionnaireCompleted, args)); }
private void SendNotifications(RoutingAddress from, RoutingAddress recipient, MbxTransportMailItem rmi, string threadIndex, string threadTopic, string existingDecisionMakerAddress, ApprovalStatus?existingApprovalStatus, ExDateTime?existingDecisionTime) { HeaderList headers = rmi.RootPart.Headers; Header acceptLanguageHeader = headers.FindFirst("Accept-Language"); Header contentLanguageHeader = headers.FindFirst(HeaderId.ContentLanguage); string decisionMakerDisplayName = existingDecisionMakerAddress; bool? flag = null; if (existingApprovalStatus != null) { if ((existingApprovalStatus.Value & ApprovalStatus.Approved) == ApprovalStatus.Approved) { flag = new bool?(true); } else if ((existingApprovalStatus.Value & ApprovalStatus.Rejected) == ApprovalStatus.Rejected) { flag = new bool?(false); } } if (!string.IsNullOrEmpty(existingDecisionMakerAddress)) { ADNotificationAdapter.TryRunADOperation(delegate() { IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(existingDecisionMakerAddress); ADRawEntry adrawEntry = recipientSession.FindByProxyAddress(new SmtpProxyAddress(existingDecisionMakerAddress, true), ApprovalProcessingAgent.DisplayNameProperty); if (adrawEntry != null) { string text = (string)adrawEntry[ADRecipientSchema.DisplayName]; if (!string.IsNullOrEmpty(text)) { decisionMakerDisplayName = text; } } }, 1); } ApprovalProcessingAgent.diag.TraceDebug <bool?, string>(0L, "Generating conflict notification. Decision='{0}', DecisionMaker='{1}'", flag, decisionMakerDisplayName); EmailMessage emailMessage = NotificationGenerator.GenerateDecisionNotTakenNotification(from, recipient, rmi.Subject, threadIndex, threadTopic, decisionMakerDisplayName, flag, existingDecisionTime, acceptLanguageHeader, contentLanguageHeader, rmi.TransportSettings.InternalDsnDefaultLanguage); if (emailMessage != null) { this.server.SubmitMessage(rmi, emailMessage, rmi.OrganizationId, rmi.ExternalOrganizationId, false); } }
public IHttpActionResult Send(CasualNotificationDto casualNotification) { if (ModelState.IsValid) { string imageFilePath = ""; var folderRandomIndex = RandomHelper.RandomInt(0, 10000); if (casualNotification.Avatar != null) { var fileRandomIndex = RandomHelper.RandomInt(0, 10000); var fileExtension = Path.GetExtension(casualNotification.Avatar.FileName); Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Image/Notification/" + folderRandomIndex)); var fileName = fileRandomIndex + DateTime.Now.ToString("yy-MM-dd-hh-mm-ss") + fileExtension; imageFilePath = "/Image/Notification/" + folderRandomIndex + "/" + fileName; fileName = Path.Combine(HttpContext.Current.Server.MapPath("~/Image/Notification/" + folderRandomIndex + "/"), fileName); casualNotification.Avatar.SaveAs(fileName); } else { //Default imageFilePath = "/Image/Games/Default/Default.jpg"; } Image image = new Image() { CreatedAt = DateTime.Now, Type = ImageType.NOTIFICATION_IMAGE, ImagePath = imageFilePath, Name = casualNotification.Title, UpdatedAt = DateTime.Now }; NotificationGenerator.CasualNotification(db, casualNotification.Title, casualNotification.Message, image); return(Ok()); } return(BadRequest()); }
public async Task <IHttpActionResult> Edit(AdvertisementEditDto editAd) { if (ModelState.IsValid) { var session = await db.Sessions.SingleOrDefaultAsync( QueryHelper.GetSessionObjectValidationQuery(editAd.Session)); if (session != null) { var user = session.User; var adInDb = db.Advertisements.Include(d => d.UserImage) .SingleOrDefault(a => a.Id == editAd.Id && a.User.Id == user.Id); if (adInDb != null) { var isImageEmpty = string.IsNullOrEmpty(editAd.UserImage); //we check if a user has lowered the price of an advertisement to some degree. var isHot = editAd.Price <= adInDb.Price * 3 / 4; //We want to know if a user has uploaded a new image for his/her advertisement if (!isImageEmpty) { adInDb.UserImage = ImageHandler.CreateUserImage(db, user.Id, editAd.UserImage); } else { adInDb.UserImage = null; } adInDb.MedType = editAd.MedType; adInDb.Latitude = editAd.Latitude; adInDb.Longitude = editAd.Longitude; adInDb.LocationRegionId = editAd.LocationRegionId; adInDb.LocationCityId = editAd.LocationCityId; adInDb.LocationProvinceId = editAd.LocationProvinceId; adInDb.Price = editAd.Price; adInDb.Caption = editAd.Caption; adInDb.UpdatedAt = DateTime.Now; //first we have to get rid of old exchange records in database db.Exchanges.RemoveRange(db.Exchanges.Where(x => x.AdvertisementId == adInDb.Id)); if (editAd.ExchangeGames.Count > 0) //we have some games to exchange { foreach (var game in editAd.ExchangeGames) { var newExchange = new Exchange() { AdvertisementId = adInDb.Id, GameId = game }; db.Exchanges.Add(newExchange); } } await db.SaveChangesAsync(); // we re-broadcast this advertisement NotificationGenerator.OldAdvertisementNotification(db, adInDb, isHot); return(Ok()); } return(NotFound()); } return(Unauthorized()); } return(BadRequest()); }
public async Task <IHttpActionResult> Create(AdvertisementCreateDto advertisementCreate) { if (ModelState.IsValid) { var session = await db.Sessions.SingleOrDefaultAsync( QueryHelper.GetSessionObjectValidationQuery(advertisementCreate.Session)); if (session != null) { var user = session.User; var isImageEmpty = string.IsNullOrEmpty(advertisementCreate.UserImage); Models.Image userImage = null; if (!isImageEmpty) { //we write user's uploaded image in memory userImage = ImageHandler.CreateUserImage(db, user.Id, advertisementCreate.UserImage); } var newAdvertisement = new Advertisement() { User = user, MedType = advertisementCreate.MedType, GameId = advertisementCreate.GameId, GameReg = advertisementCreate.GameReg, Latitude = advertisementCreate.Latitude, Longitude = advertisementCreate.Longitude, LocationRegionId = advertisementCreate.LocationRegionId, LocationCityId = advertisementCreate.LocationCityId, LocationProvinceId = advertisementCreate.LocationProvinceId, Price = advertisementCreate.Price, PlatformId = advertisementCreate.PlatformId, Caption = advertisementCreate.Caption, UserImage = userImage, isDeleted = false, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; db.Advertisements.Add(newAdvertisement); if (advertisementCreate.ExchangeGames.Count > 0) //we have some games to exchange { foreach (var game in advertisementCreate.ExchangeGames) { var newExchange = new Exchange() { AdvertisementId = newAdvertisement.Id, GameId = game }; db.Exchanges.Add(newExchange); } } await db.SaveChangesAsync(); // Broadcasting NotificationGenerator.NewAdvertisementNotification(db, newAdvertisement); return(Ok(newAdvertisement.Id)); } return(Unauthorized()); } return(BadRequest()); }