/// <summary> /// Sends the notification. /// </summary> /// <param name="context">The context.</param> public void SendNotification(INotificationContext context) { try { System.Web.Security.MembershipUser user = ITUser.GetUser(context.Username); //check if this user had this notifiction type enabled in their profile. if (user != null && ITUser.IsNotificationTypeEnabled(context.Username, this.Name)) { string From = HostSetting.GetHostSetting("HostEmailAddress"); string SMTPServer = HostSetting.GetHostSetting("SMTPServer"); int SMTPPort = HostSetting.GetHostSetting("SMTPPort", 25); bool SMTPAuthentictation = HostSetting.GetHostSetting("SMTPAuthentication", false); bool SMTPUseSSL = HostSetting.GetHostSetting("SMTPUseSSL", false); string SMTPDomain = HostSetting.GetHostSetting("SMTPDomain", string.Empty); // Only fetch the password if you need it string SMTPUsername = ""; string SMTPPassword = ""; if (SMTPAuthentictation) { SMTPUsername = HostSetting.GetHostSetting("SMTPUsername"); SMTPPassword = HostSetting.GetHostSetting("SMTPPassword"); } SmtpClient smtp = new SmtpClient() { Host = SMTPServer, Port = SMTPPort, EnableSsl = SMTPUseSSL, }; if (SMTPAuthentictation) smtp.Credentials = new NetworkCredential(SMTPUsername, SMTPPassword, SMTPDomain); MailMessage message = new MailMessage(); message.Body = context.BodyText; message.From = new MailAddress(From); message.Subject = context.Subject.Trim(); message.To.Add(new MailAddress(user.Email, context.UserDisplayName)); message.IsBodyHtml = (context.EmailFormatType == EmailFormatTypes.HTML); smtp.Send(message); // try to clean up the credentials if (smtp.Credentials != null) smtp.Credentials = null; SMTPPassword = "******"; SMTPUsername = "******"; } } catch (Exception ex) { ProcessException(ex); } }
public async Task <ICommandResult <ReportSubmission <Comment> > > SendAsync(INotificationContext <ReportSubmission <Comment> > context) { // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(EmailNotifications.CommentReport.Name, StringComparison.Ordinal)) { return(null); } // Create result var result = new CommandResult <ReportSubmission <Comment> >(); // Get email template const string templateId = "NewCommentReport"; // Tasks run in a background thread and don't have access to HttpContext // Create a dummy principal to represent the user so we can still obtain // the current culture for the email var principal = await _claimsPrincipalFactory.CreateAsync((User)context.Notification.To); var culture = await _contextFacade.GetCurrentCultureAsync(principal.Identity); var email = await _localeStore.GetFirstOrDefaultByKeyAsync <LocaleEmail>(culture, templateId); if (email == null) { return(result.Failed( $"No email template with the Id '{templateId}' exists within the 'locales/{culture}/emails.json' file!")); } // Get entity for reply var entity = await _articleStore.GetByIdAsync(context.Model.What.EntityId); // We need an entity for the reply if (entity == null) { return(result.Failed( $"No entity with id '{context.Model.What.EntityId}' exists. Failed to send reply spam email notification.")); } // Build entity url var baseUri = await _capturedRouterUrlHelper.GetBaseUrlAsync(); var url = _capturedRouterUrlHelper.GetRouteUrl(baseUri, new RouteValueDictionary() { ["area"] = "Plato.Articles", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = context.Model.What.Id }); // Reason given text var reasonText = S["None Provided"]; if (ReportReasons.Reasons.ContainsKey(context.Model.Why)) { reasonText = S[ReportReasons.Reasons[context.Model.Why]]; } // Build message from template var message = email.BuildMailMessage(); message.Body = string.Format( email.Message, context.Notification.To.DisplayName, entity.Title, reasonText.Value, context.Model.Who.DisplayName, context.Model.Who.UserName, baseUri + url); message.IsBodyHtml = true; message.To.Add(new MailAddress(context.Notification.To.Email)); // Send message var emailResult = await _emailManager.SaveAsync(message); if (emailResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(emailResult.Errors?.ToArray())); }
/// <summary> /// Finalizes the notification in preparation to it being sent. /// </summary> /// <param name="context">The context of this notification.</param> /// <param name="player">The player which this notification is being prepared for.</param> /// <returns>A collection of <see cref="IOutboundPacket"/>s, the ones to be sent.</returns> protected override IEnumerable <IOutboundPacket> Prepare(INotificationContext context, IPlayer player) { return(new WorldLightPacket(this.LightLevel, this.LightColor).YieldSingleItem()); }
public async Task <ICommandResult <DocComment> > SendAsync(INotificationContext <DocComment> context) { // Validate if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Notification == null) { throw new ArgumentNullException(nameof(context.Notification)); } if (context.Notification.Type == null) { throw new ArgumentNullException(nameof(context.Notification.Type)); } if (context.Notification.To == null) { throw new ArgumentNullException(nameof(context.Notification.To)); } // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(WebNotifications.CommentSpam.Name, StringComparison.Ordinal)) { return(null); } // Create result var result = new CommandResult <DocComment>(); // Get entity for reply var entity = await _entityStore.GetByIdAsync(context.Model.EntityId); // Ensure we found the entity if (entity == null) { return(result.Failed( $"No entity with id '{context.Model.EntityId}' exists. Failed to send reply spam web notification.")); } var baseUri = await _urlHelper.GetBaseUrlAsync(); var url = _urlHelper.GetRouteUrl(baseUri, new RouteValueDictionary() { ["area"] = "Plato.Docs", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = context.Model.Id }); //// Build notification var userNotification = new UserNotification() { NotificationName = context.Notification.Type.Name, UserId = context.Notification.To.Id, Title = S["Possible SPAM"].Value, Message = S["A doc comment has been detected as SPAM!"], Url = url, CreatedUserId = context.Notification.From?.Id ?? 0, CreatedDate = DateTimeOffset.UtcNow }; // Create notification var userNotificationResult = await _userNotificationManager.CreateAsync(userNotification); if (userNotificationResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(userNotificationResult.Errors?.ToArray())); }
public ProductService(IProductRepository repository, IUnitOfWork unitOfWork, INotificationContext notificationContext, IMapper mapper) : base(repository, unitOfWork, notificationContext, mapper) { }
public FriendsController(ILogger <FriendsController> logger, IMediator mediator, INotificationContext notificationContext) : base(logger, mediator, notificationContext) { }
/// <summary> /// Finalizes the notification in preparation to it being sent. /// </summary> /// <param name="context">The context of this notification.</param> /// <param name="player">The player which this notification is being prepared for.</param> /// <returns>A collection of <see cref="IOutboundPacket"/>s, the ones to be sent.</returns> protected override IEnumerable<IOutboundPacket> Prepare(INotificationContext context, IPlayer player) { return new AnimatedTextPacket(this.Location, this.Color, this.Text).YieldSingleItem(); }
public async Task <ICommandResult <Comment> > SendAsync(INotificationContext <Comment> context) { // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(WebNotifications.NewMention.Name, StringComparison.Ordinal)) { return(null); } // We always need a model if (context.Model == null) { return(null); } // The reply should be visible if (context.Model.IsHidden()) { return(null); } // Get entity for reply var entity = await _entityStore.GetByIdAsync(context.Model.EntityId); // We need an entity if (entity == null) { return(null); } // The entity should be visible if (entity.IsHidden()) { return(null); } // Create result var result = new CommandResult <Comment>(); // Build user notification var userNotification = new UserNotification() { NotificationName = context.Notification.Type.Name, UserId = context.Notification.To.Id, Title = S["New Mention"].Value, Message = S["You've been mentioned by "].Value + context.Model.CreatedBy.DisplayName, CreatedUserId = context.Model.CreatedUserId, Url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Issues", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = context.Model.Id }) }; var userNotificationResult = await _userNotificationManager.CreateAsync(userNotification); if (userNotificationResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(userNotificationResult.Errors?.ToArray())); }
public UpdateSegmentExchangeRateUseCase(IMediator mediator, INotificationContext notificationContext, IUnitOfWork unitOfWork) : base(unitOfWork, notificationContext) { _mediator = mediator; _notificationContext = notificationContext; }
public PartialOrderShippedMonitor(INotificationContext notificationContext) : base(notificationContext) { }
public EventController(IMediator mediator, INotificationContext notificationContext) { _mediator = mediator; _notificationContext = notificationContext; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public NotificationGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _notificationContext = ((GatewayContext)MerchelloContext.Gateways).Notification; }
public NotificationService(INotificationContext notificationContext, INotificationQueries notificationQueries) { _notificationContext = notificationContext; _notificationQueries = notificationQueries; }
public ClienteService(IUnitOfWork unitOfWork, IRepository <Cliente, int> repository, IMapper mapper, INotificationContext notificationContext) : base(unitOfWork, repository, mapper, notificationContext) { }
public ValidationRequestBehavior(IEnumerable <IValidator <TRequest> > validators, INotificationContext notificationContext) { _validators = validators; _notificationContext = notificationContext; }
public async Task <ICommandResult <Doc> > SendAsync(INotificationContext <Doc> context) { // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(EmailNotifications.NewMention.Name, StringComparison.Ordinal)) { return(null); } // We always need a model if (context.Model == null) { return(null); } // The entity should be visible if (context.Model.IsHidden()) { return(null); } // Create result var result = new CommandResult <Doc>(); // Get email template const string templateId = "NewDocMention"; // Tasks run in a background thread and don't have access to HttpContext // Create a dummy principal to represent the user so we can still obtain // the current culture for the email var principal = await _claimsPrincipalFactory.CreateAsync((User)context.Notification.To); var culture = await _contextFacade.GetCurrentCultureAsync(principal.Identity); var email = await _localeStore.GetFirstOrDefaultByKeyAsync <LocaleEmail>(culture, templateId); if (email != null) { // Build topic url var baseUri = await _contextFacade.GetBaseUrlAsync(); var url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Docs", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = context.Model.Id, ["opts.alias"] = context.Model.Alias }); // Build message from template var message = email.BuildMailMessage(); message.Body = string.Format( email.Message, context.Notification.To.DisplayName, context.Model.Title, baseUri + url); message.IsBodyHtml = true; message.To.Add(new MailAddress(context.Notification.To.Email)); // Send message var emailResult = await _emailManager.SaveAsync(message); if (emailResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(emailResult.Errors?.ToArray())); } return(result.Failed($"No email template with the Id '{templateId}' exists within the 'locales/{culture}/emails.json' file!")); }
public ProductAddMonitor(INotificationContext notificationContext) : base(notificationContext) { }
public ExceptionFilter(ILogger <ExceptionFilter> logger, INotificationContext notificationContext) { _notificationContext = notificationContext; _logger = logger; }
/// <summary> /// Finalizes the notification in preparation to it being sent. /// </summary> /// <param name="context">The context of this notification.</param> /// <param name="player">The player which this notification is being prepared for.</param> /// <returns>A collection of <see cref="IOutboundPacket"/>s, the ones to be sent.</returns> protected override IEnumerable <IOutboundPacket> Prepare(INotificationContext context, IPlayer player) { return(new MagicEffectPacket(this.Location, this.Effect).YieldSingleItem()); }
/// <summary> /// Finalizes the notification in preparation to it being sent. /// </summary> /// <param name="context">The context of this notification.</param> /// <param name="player">The player which this notification is being prepared for.</param> /// <returns>A collection of <see cref="IOutboundPacket"/>s, the ones to be sent.</returns> protected override IEnumerable <IOutboundPacket> Prepare(INotificationContext context, IPlayer player) { var packets = new List <IOutboundPacket>(); var creature = context.CreatureFinder.FindCreatureById(this.CreatureId); var allCreatureIdsToLearn = new List <uint>(); var allCreatureIdsToForget = new List <uint>(); if (this.CreatureId == player.Id) { if (this.WasTeleport) { if (this.OldStackPosition <= MapConstants.MaximumNumberOfThingsToDescribePerTile) { // Since this was described to the client before, we send a packet that lets them know the thing must be removed from that Tile's stack. packets.Add(new RemoveAtLocationPacket(this.OldLocation, this.OldStackPosition)); } // Then send the entire description at the new location. var(descriptionMetadata, descriptionBytes) = context.MapDescriptor.DescribeAt(player, this.NewLocation); packets.Add(new MapDescriptionPacket(this.NewLocation, descriptionBytes)); return(packets); } if (this.OldLocation.Z == 7 && this.NewLocation.Z > 7) { if (this.OldStackPosition <= MapConstants.MaximumNumberOfThingsToDescribePerTile) { packets.Add(new RemoveAtLocationPacket(this.OldLocation, this.OldStackPosition)); } } else { packets.Add(new CreatureMovedPacket(this.OldLocation, this.OldStackPosition, this.NewLocation)); } // floor change down if (this.NewLocation.Z > this.OldLocation.Z) { var windowStartLocation = new Location() { X = this.OldLocation.X - ((MapConstants.DefaultWindowSizeX / 2) - 1), // -8 Y = this.OldLocation.Y - ((MapConstants.DefaultWindowSizeY / 2) - 1), // -6 Z = this.NewLocation.Z, }; (IDictionary <string, object> Metadata, ReadOnlySequence <byte> Data)description; // going from surface to underground if (this.NewLocation.Z == 8) { // Client already has the two floors above (6 and 7), so it needs 8 (new current), and 2 below. description = context.MapDescriptor.DescribeWindow( player, (ushort)windowStartLocation.X, (ushort)windowStartLocation.Y, this.NewLocation.Z, (sbyte)(this.NewLocation.Z + 2), MapConstants.DefaultWindowSizeX, MapConstants.DefaultWindowSizeY, -1); } // going further down underground; watch for world's deepest floor (hardcoded for now). else if (this.NewLocation.Z > 8 && this.NewLocation.Z < 14) { // Client already has all floors needed except the new deepest floor, so it needs the 2th floor below the current. description = context.MapDescriptor.DescribeWindow( player, (ushort)windowStartLocation.X, (ushort)windowStartLocation.Y, (sbyte)(this.NewLocation.Z + 2), (sbyte)(this.NewLocation.Z + 2), MapConstants.DefaultWindowSizeX, MapConstants.DefaultWindowSizeY, -3); } // going down but still above surface, so client has all floors. else { description = (new Dictionary <string, object>(), ReadOnlySequence <byte> .Empty); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.FloorChangeDown, description.Data)); // moving down a floor makes us out of sync, include east and south var(eastDescriptionMetadata, eastDescriptionBytes) = this.EastSliceDescription( context, player, this.OldLocation.X - this.NewLocation.X, this.OldLocation.Y - this.NewLocation.Y + this.OldLocation.Z - this.NewLocation.Z); if (eastDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object eastCreatureIdsToLearnBoxed) && eastDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object eastCreatureIdsToForgetBoxed) && eastCreatureIdsToLearnBoxed is IEnumerable <uint> eastCreatureIdsToLearn && eastCreatureIdsToForgetBoxed is IEnumerable <uint> eastCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(eastCreatureIdsToLearn); allCreatureIdsToForget.AddRange(eastCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceEast, eastDescriptionBytes)); var(southDescriptionMetadata, southDescriptionBytes) = this.SouthSliceDescription(context, player, this.OldLocation.Y - this.NewLocation.Y); if (southDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object southCreatureIdsToLearnBoxed) && southDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object southCreatureIdsToForgetBoxed) && southCreatureIdsToLearnBoxed is IEnumerable <uint> southCreatureIdsToLearn && southCreatureIdsToForgetBoxed is IEnumerable <uint> southCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(southCreatureIdsToLearn); allCreatureIdsToForget.AddRange(southCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceSouth, southDescriptionBytes)); } // floor change up else if (this.NewLocation.Z < this.OldLocation.Z) { var windowStartLocation = new Location() { X = this.OldLocation.X - ((MapConstants.DefaultWindowSizeX / 2) - 1), // -8 Y = this.OldLocation.Y - ((MapConstants.DefaultWindowSizeY / 2) - 1), // -6 Z = this.NewLocation.Z, }; (IDictionary <string, object> Metadata, ReadOnlySequence <byte> Data)description; // going to surface if (this.NewLocation.Z == 7) { // Client already has the first two above-the-ground floors (6 and 7), so it needs 0-5 above. description = context.MapDescriptor.DescribeWindow( player, (ushort)windowStartLocation.X, (ushort)windowStartLocation.Y, 5, 0, MapConstants.DefaultWindowSizeX, MapConstants.DefaultWindowSizeY, 3); } // going up but still underground else if (this.NewLocation.Z > 7) { // Client already has all floors needed except the new highest floor, so it needs the 2th floor above the current. description = context.MapDescriptor.DescribeWindow( player, (ushort)windowStartLocation.X, (ushort)windowStartLocation.Y, (sbyte)(this.NewLocation.Z - 2), (sbyte)(this.NewLocation.Z - 2), MapConstants.DefaultWindowSizeX, MapConstants.DefaultWindowSizeY, 3); } // already above surface, so client has all floors. else { description = (new Dictionary <string, object>(), ReadOnlySequence <byte> .Empty); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.FloorChangeUp, description.Data)); // moving up a floor up makes us out of sync, include west and north var(westDescriptionMetadata, westDescriptionBytes) = this.WestSliceDescription( context, player, this.OldLocation.X - this.NewLocation.X, this.OldLocation.Y - this.NewLocation.Y + this.OldLocation.Z - this.NewLocation.Z); if (westDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object westCreatureIdsToLearnBoxed) && westDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object westCreatureIdsToForgetBoxed) && westCreatureIdsToLearnBoxed is IEnumerable <uint> westCreatureIdsToLearn && westCreatureIdsToForgetBoxed is IEnumerable <uint> westCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(westCreatureIdsToLearn); allCreatureIdsToForget.AddRange(westCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceWest, westDescriptionBytes)); var(northDescriptionMetadata, northDescriptionBytes) = this.NorthSliceDescription(context, player, this.OldLocation.Y - this.NewLocation.Y); if (northDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object northCreatureIdsToLearnBoxed) && northDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object northCreatureIdsToForgetBoxed) && northCreatureIdsToLearnBoxed is IEnumerable <uint> northCreatureIdsToLearn && northCreatureIdsToForgetBoxed is IEnumerable <uint> northCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(northCreatureIdsToLearn); allCreatureIdsToForget.AddRange(northCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceNorth, northDescriptionBytes)); } if (this.OldLocation.Y > this.NewLocation.Y) { // Creature is moving north, so we need to send the additional north bytes. var(northDescriptionMetadata, northDescriptionBytes) = this.NorthSliceDescription(context, player); if (northDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object northCreatureIdsToLearnBoxed) && northDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object northCreatureIdsToForgetBoxed) && northCreatureIdsToLearnBoxed is IEnumerable <uint> northCreatureIdsToLearn && northCreatureIdsToForgetBoxed is IEnumerable <uint> northCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(northCreatureIdsToLearn); allCreatureIdsToForget.AddRange(northCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceNorth, northDescriptionBytes)); } else if (this.OldLocation.Y < this.NewLocation.Y) { // Creature is moving south, so we need to send the additional south bytes. var(southDescriptionMetadata, southDescriptionBytes) = this.SouthSliceDescription(context, player); if (southDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object southCreatureIdsToLearnBoxed) && southDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object southCreatureIdsToForgetBoxed) && southCreatureIdsToLearnBoxed is IEnumerable <uint> southCreatureIdsToLearn && southCreatureIdsToForgetBoxed is IEnumerable <uint> southCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(southCreatureIdsToLearn); allCreatureIdsToForget.AddRange(southCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceSouth, southDescriptionBytes)); } if (this.OldLocation.X < this.NewLocation.X) { // Creature is moving east, so we need to send the additional east bytes. var(eastDescriptionMetadata, eastDescriptionBytes) = this.EastSliceDescription(context, player); if (eastDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object eastCreatureIdsToLearnBoxed) && eastDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object eastCreatureIdsToForgetBoxed) && eastCreatureIdsToLearnBoxed is IEnumerable <uint> eastCreatureIdsToLearn && eastCreatureIdsToForgetBoxed is IEnumerable <uint> eastCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(eastCreatureIdsToLearn); allCreatureIdsToForget.AddRange(eastCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceEast, eastDescriptionBytes)); } else if (this.OldLocation.X > this.NewLocation.X) { // Creature is moving west, so we need to send the additional west bytes. var(westDescriptionMetadata, westDescriptionBytes) = this.WestSliceDescription(context, player); if (westDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object westCreatureIdsToLearnBoxed) && westDescriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object westCreatureIdsToForgetBoxed) && westCreatureIdsToLearnBoxed is IEnumerable <uint> westCreatureIdsToLearn && westCreatureIdsToForgetBoxed is IEnumerable <uint> westCreatureIdsToForget) { allCreatureIdsToLearn.AddRange(westCreatureIdsToLearn); allCreatureIdsToForget.AddRange(westCreatureIdsToForget); } packets.Add(new MapPartialDescriptionPacket(OutgoingPacketType.MapSliceWest, westDescriptionBytes)); } } else if (player.CanSee(this.OldLocation) && player.CanSee(this.NewLocation)) { if (player.CanSee(creature)) { if (this.WasTeleport || (this.OldLocation.Z == 7 && this.NewLocation.Z > 7) || this.OldStackPosition > 9) { if (this.OldStackPosition <= MapConstants.MaximumNumberOfThingsToDescribePerTile) { packets.Add(new RemoveAtLocationPacket(this.OldLocation, this.OldStackPosition)); } var creatureIsKnown = player.Client.KnowsCreatureWithId(this.CreatureId); var creatureIdToForget = player.Client.ChooseCreatureToRemoveFromKnownSet(); if (!creatureIsKnown) { allCreatureIdsToLearn.Add(this.CreatureId); } if (creatureIdToForget > uint.MinValue) { allCreatureIdsToForget.Add(creatureIdToForget); } packets.Add(new AddCreaturePacket(creature, creatureIsKnown, creatureIdToForget)); } else { packets.Add(new CreatureMovedPacket(this.OldLocation, this.OldStackPosition, this.NewLocation)); } } } else if (player.CanSee(this.OldLocation) && !player.CanSee(creature)) { if (this.OldStackPosition <= MapConstants.MaximumNumberOfThingsToDescribePerTile) { packets.Add(new RemoveAtLocationPacket(this.OldLocation, this.OldStackPosition)); } } else if (player.CanSee(this.NewLocation) && player.CanSee(creature)) { if (this.NewStackPosition <= MapConstants.MaximumNumberOfThingsToDescribePerTile) { var creatureIsKnown = player.Client.KnowsCreatureWithId(this.CreatureId); var creatureIdToForget = player.Client.ChooseCreatureToRemoveFromKnownSet(); if (!creatureIsKnown) { allCreatureIdsToLearn.Add(this.CreatureId); } if (creatureIdToForget > uint.MinValue) { allCreatureIdsToForget.Add(creatureIdToForget); } packets.Add(new AddCreaturePacket(creature, creatureIsKnown, creatureIdToForget)); } } if (this.WasTeleport) { packets.Add(new MagicEffectPacket(this.NewLocation, AnimatedEffect.BubbleBlue)); } this.Sent += (client) => { foreach (var creatureId in allCreatureIdsToLearn) { client.AddKnownCreature(creatureId); } foreach (var creatureId in allCreatureIdsToForget) { client.RemoveKnownCreature(creatureId); } }; return(packets); }
protected BaseController(ILogger <T> logger, IMediator mediator, INotificationContext notificationContext) { _mediator = mediator; _logger = logger; _notificationContext = notificationContext; }
private (IDictionary <string, object> descriptionMetadata, ReadOnlySequence <byte> descriptionData) WestSliceDescription(INotificationContext notificationContext, IPlayer player, int floorChangeOffsetX = 0, int floorChangeOffsetY = 0) { // A = old location, B = new location // // |------ MapConstants.DefaultWindowSizeX = 18 ------| // as seen by A // x . . . . . . . . . . . . . . . . . . --- // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . B A . . . . . . . . . | MapConstants.DefaultWindowSizeY = 14 // ~ . . . . . . . . . . . . . . . . . . | as seen by A // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . | // ~ . . . . . . . . . . . . . . . . . . --- // // x = target start of window (~) to refresh. var windowStartLocation = new Location() { // -8 X = this.NewLocation.X - ((MapConstants.DefaultWindowSizeX / 2) - 1) + floorChangeOffsetX, // -6 Y = this.NewLocation.Y - ((MapConstants.DefaultWindowSizeY / 2) - 1) + floorChangeOffsetY, Z = this.NewLocation.Z, }; return(notificationContext.MapDescriptor.DescribeWindow( player, (ushort)windowStartLocation.X, (ushort)windowStartLocation.Y, (sbyte)(this.NewLocation.IsUnderground ? Math.Max(0, this.NewLocation.Z - 2) : 7), (sbyte)(this.NewLocation.IsUnderground ? Math.Min(15, this.NewLocation.Z + 2) : 0), 1, MapConstants.DefaultWindowSizeY)); }
public EscolaCommandHandlerQuery(INotificationContext notificationContext, IUnitOfWork uow, IMapper mapper, IEscolaRepository repo) : base(notificationContext, uow, mapper) { _repo = repo; }
public GravarEmpresaService(IRepository <Empresa> empreaRepository, INotificationContext notification) { _empreaRepository = empreaRepository; notificationContext = notification; _validador = new EmpresaValidador(notificationContext, _empresa, _empreaRepository); }
public async Task <ICommandResult <ReportSubmission <IdeaComment> > > SendAsync(INotificationContext <ReportSubmission <IdeaComment> > context) { // Validate if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Notification == null) { throw new ArgumentNullException(nameof(context.Notification)); } if (context.Notification.Type == null) { throw new ArgumentNullException(nameof(context.Notification.Type)); } if (context.Notification.To == null) { throw new ArgumentNullException(nameof(context.Notification.To)); } // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(WebNotifications.IdeaCommentReport.Name, StringComparison.Ordinal)) { return(null); } // Get entity for reply var entity = await _entityStore.GetByIdAsync(context.Model.What.EntityId); // Ensure entity exists if (entity == null) { return(null); } // Create result var result = new CommandResult <ReportSubmission <IdeaComment> >(); var baseUri = await _urlHelper.GetBaseUrlAsync(); var url = _urlHelper.GetRouteUrl(baseUri, new RouteValueDictionary() { ["area"] = "Plato.Ideas", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = context.Model.What.Id }); // Get reason given text var reasonText = S["Idea Comment Reported"]; if (ReportReasons.Reasons.ContainsKey(context.Model.Why)) { reasonText = S[ReportReasons.Reasons[context.Model.Why]]; } // Build notification var userNotification = new UserNotification() { NotificationName = context.Notification.Type.Name, UserId = context.Notification.To.Id, Title = reasonText.Value, Message = S["A comment has been reported!"], Url = url, CreatedUserId = context.Notification.From?.Id ?? 0, CreatedDate = DateTimeOffset.UtcNow }; // Create notification var userNotificationResult = await _userNotificationManager.CreateAsync(userNotification); if (userNotificationResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(userNotificationResult.Errors?.ToArray())); }
public ContatoTests(INotificationContext notificationContext) { NotificationContext = notificationContext; }
/// <summary> /// Initializes a new instance of the <see cref="OrderConfirmationMonitor"/> class. /// </summary> /// <param name="notificationContext"> /// The notification context. /// </param> public OrderConfirmationMonitor(INotificationContext notificationContext) : base(notificationContext) { }
/// <summary> /// Finalizes the notification in preparation to it being sent. /// </summary> /// <param name="context">The context of this notification.</param> /// <param name="player">The player which this notification is being prepared for.</param> /// <returns>A collection of <see cref="IOutboundPacket"/>s, the ones to be sent.</returns> protected abstract IEnumerable <IOutboundPacket> Prepare(INotificationContext context, IPlayer player);
public AddUserCommandHandler(IMediator mediator, IConfiguration configuration, INotificationContext notificationContext, IUserRepository userRepository, IUnitOfWork uow) : base(mediator, notificationContext) { _userRepository = userRepository; _configuration = configuration; _notificationContext = notificationContext; _uow = uow; }
/// <summary> /// Constructor /// </summary> /// <param name="notificationContext"></param> public NotificationFilterSetup(INotificationContext notificationContext) { _notificationContext = notificationContext; }
public ResponseValidationFilter(INotificationContext notificationContext) { _notificationContext = notificationContext; }
public async Task <ICommandResult <Idea> > SendAsync(INotificationContext <Idea> context) { // Validate if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Notification == null) { throw new ArgumentNullException(nameof(context.Notification)); } if (context.Notification.Type == null) { throw new ArgumentNullException(nameof(context.Notification.Type)); } if (context.Notification.To == null) { throw new ArgumentNullException(nameof(context.Notification.To)); } // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(WebNotifications.IdeaSpam.Name, StringComparison.Ordinal)) { return(null); } // Create result var result = new CommandResult <Idea>(); var baseUri = await _urlHelper.GetBaseUrlAsync(); var url = _urlHelper.GetRouteUrl(baseUri, new RouteValueDictionary() { ["area"] = "Plato.Ideas", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = context.Model.Id, ["opts.alias"] = context.Model.Alias }); //// Build notification var userNotification = new UserNotification() { NotificationName = context.Notification.Type.Name, UserId = context.Notification.To.Id, Title = S["Possible SPAM"].Value, Message = S["An idea has been detected as SPAM!"], Url = url, CreatedUserId = context.Notification.From?.Id ?? 0, CreatedDate = DateTimeOffset.UtcNow }; // Create notification var userNotificationResult = await _userNotificationManager.CreateAsync(userNotification); if (userNotificationResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(userNotificationResult.Errors?.ToArray())); }
/// <summary> /// Initializes a new instance of the <see cref="NotificationGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public NotificationGatewayApiController(IMerchelloContext merchelloContext) : base(merchelloContext) { _notificationContext = ((GatewayContext)MerchelloContext.Gateways).Notification; _notificationMessageService = ((ServiceContext)MerchelloContext.Services).NotificationMessageService; }
/// <summary> /// Sends the notification. /// </summary> /// <param name="context">The context.</param> public void SendNotification(INotificationContext context) { try { var user = UserManager.GetUser(context.Username); //check if this user had this notifiction type enabled in their profile. if (user != null && UserManager.IsNotificationTypeEnabled(context.Username, Name)) { var from = HostSettingManager.HostEmailAddress; var smtpServer = HostSettingManager.SmtpServer; var smtpPort = int.Parse(HostSettingManager.Get(HostSettingNames.SMTPPort)); var smtpAuthentictation = Convert.ToBoolean(HostSettingManager.Get(HostSettingNames.SMTPAuthentication)); var smtpUseSSL = Boolean.Parse(HostSettingManager.Get(HostSettingNames.SMTPUseSSL)); // Security Bugfix by SMOSS // Only fetch the password if you need it var smtpUsername = string.Empty; var smtpPassword = string.Empty; var smtpDomain = string.Empty; if (smtpAuthentictation) { smtpUsername = HostSettingManager.Get(HostSettingNames.SMTPUsername, string.Empty); smtpPassword = HostSettingManager.Get(HostSettingNames.SMTPPassword, string.Empty); smtpDomain = HostSettingManager.Get(HostSettingNames.SMTPDomain, string.Empty); } using (var smtp = new SmtpClient()) { smtp.Host = smtpServer; smtp.Port = smtpPort; smtp.EnableSsl = smtpUseSSL; if (smtpAuthentictation) smtp.Credentials = new NetworkCredential(smtpUsername, smtpPassword, smtpDomain); using (var message = new MailMessage( from, user.Email, context.Subject, context.BodyText) { IsBodyHtml = true }) { smtp.Send(message); } } } } catch (Exception ex) { ProcessException(ex); } }