Beispiel #1
0
        /// <summary>
        /// Publishes the scheduled transaction event.
        /// </summary>
        /// <param name="scheduledTransactionId">The scheduled transaction identifier.</param>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="gatewaySupportedCardTypesDefinedValueGuid">[Optional] The <see cref="Guid"/> of the <see cref="DefinedValue"/> that indicates the credit card types supported by the <see cref="FinancialGateway"/> for a specified currency.</param>
        /// <param name="gatewayCurrencyUnitMultiple">[Optional] The <see cref="Guid"/> of the <see cref="DefinedValue"/> that indicates the "unit multiple" (e.g., 100 for dollars) of the currency specified by the gatway.</param>
        public static void PublishScheduledTransactionEvent(int scheduledTransactionId, string eventType, Guid?gatewaySupportedCardTypesDefinedValueGuid = null, Guid?gatewayCurrencyUnitMultiple = null)
        {
            using (var rockContext = new RockContext())
            {
                var scheduleService = new FinancialScheduledTransactionService(rockContext);
                var gateway         = scheduleService.Queryable()
                                      .AsNoTracking()
                                      .Include(s => s.FinancialGateway)
                                      .Where(s => s.Id == scheduledTransactionId)
                                      .Select(s => s.FinancialGateway)
                                      .FirstOrDefault();

                var gatewayComponent     = gateway?.GetGatewayComponent();
                var searchKeyTiedGateway = gatewayComponent as ISearchKeyTiedGateway;
                var searchKeyTypeGuid    = searchKeyTiedGateway?.GetPersonSearchKeyTypeGuid(gateway);
                var data = GetScheduledGiftWasModifiedMessageData(rockContext, scheduledTransactionId, searchKeyTypeGuid, gatewaySupportedCardTypesDefinedValueGuid, gatewayCurrencyUnitMultiple);

                if (data != null)
                {
                    var statusGateway = gatewayComponent as IStatusProvidingGateway;

                    var message = new ScheduledGiftWasModifiedMessage
                    {
                        EventType = eventType,
                        Address   = data.Address,
                        FinancialScheduledTransaction = data.FinancialScheduledTransaction,
                        Person = data.Person,
                        Time   = RockDateTime.Now
                    };

                    _ = RockMessageBus.PublishAsync <GivingEventQueue, ScheduledGiftWasModifiedMessage>(message);
                }
            }
        }
        /// <summary>
        /// Publishes this instance.
        /// </summary>
        public static void Publish()
        {
            if (!RockMessageBus.IsRockStarted)
            {
                // Don't publish events until Rock is all the way started
                var logMessage = $"'Page Route Was Updated' message was not published because Rock is not fully started.";

                var elapsedSinceProcessStarted = RockDateTime.Now - RockInstanceConfig.ApplicationStartedDateTime;

                if (elapsedSinceProcessStarted.TotalSeconds > RockMessageBus.MAX_SECONDS_SINCE_STARTTIME_LOG_ERROR)
                {
                    RockLogger.Log.Error(RockLogDomains.Bus, logMessage);
                    ExceptionLogService.LogException(new BusException(logMessage));
                }
                else
                {
                    RockLogger.Log.Debug(RockLogDomains.Bus, logMessage);
                }

                return;
            }

            var message = new PageRouteWasUpdatedMessage();

            _ = RockMessageBus.PublishAsync <PageRouteEventQueue, PageRouteWasUpdatedMessage>(message);

            RockLogger.Log.Debug(RockLogDomains.Bus, $"Published 'Page Route Was Updated' message.");
        }
        /// <summary>
        /// Publishes the specified entity.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">The key.</param>
        /// <param name="region">The region.</param>
        public static void Publish <T>(string key = null, string region = null)
        {
            var message = new CacheWasUpdatedMessage
            {
                Key            = key,
                Region         = region,
                CacheTypeName  = typeof(T)?.AssemblyQualifiedName,
                SenderNodeName = RockMessageBus.NodeName
            };

            if (!RockMessageBus.IsRockStarted)
            {
                // Don't publish cache events until Rock is all the way started
                var logMessage = $"Cache Update message was not published because Rock is not fully started yet. {message.ToDebugString()}.";

                var elapsedSinceProcessStarted = RockDateTime.Now - RockInstanceConfig.ApplicationStartedDateTime;
                if (elapsedSinceProcessStarted.TotalSeconds > RockMessageBus.MAX_SECONDS_SINCE_STARTTIME_LOG_ERROR)
                {
                    RockLogger.Log.Error(RockLogDomains.Bus, logMessage);
                    ExceptionLogService.LogException(new BusException(logMessage));
                }
                else
                {
                    RockLogger.Log.Debug(RockLogDomains.Bus, logMessage);
                }

                return;
            }

            _ = RockMessageBus.PublishAsync <CacheEventQueue, CacheWasUpdatedMessage>(message);

            RockLogger.Log.Debug(RockLogDomains.Bus, $"Published Cache Update message. {message.ToDebugString()}.");
        }
Beispiel #4
0
        /// <summary>
        /// Publishes the expiring card and cardholder details
        /// </summary>
        /// <param name="person"></param>
        /// <param name="financialPaymentDetail"></param>
        /// <param name="financialScheduledTransactions"></param>
        public static void Publish(Person person, FinancialPaymentDetail financialPaymentDetail, List <int> financialScheduledTransactions)
        {
            if (!RockMessageBus.IsRockStarted)
            {
                // Don't publish events until Rock is all the way started
                const string logMessage = "'Credit Card Is Expiring Message' message was not published because Rock is not fully started yet.";

                var elapsedSinceProcessStarted = RockDateTime.Now - RockInstanceConfig.ApplicationStartedDateTime;

                if (elapsedSinceProcessStarted.TotalSeconds > RockMessageBus.MAX_SECONDS_SINCE_STARTTIME_LOG_ERROR)
                {
                    RockLogger.Log.Error(RockLogDomains.Bus, logMessage);
                    ExceptionLogService.LogException(new BusException(logMessage));
                }
                else
                {
                    RockLogger.Log.Debug(RockLogDomains.Bus, logMessage);
                }

                return;
            }

            var cardHolder = new CardHolder()
            {
                CommunicationPreference = (int)person.CommunicationPreference,
                Email      = person.Email,
                FirstName  = person.FirstName,
                Id         = person.Id,
                LastName   = person.LastName,
                MiddleName = person.MiddleName,
                NickName   = person.NickName
            };

            var message = new CreditCardIsExpiringMessage
            {
                AccountNumberMasked             = financialPaymentDetail.AccountNumberMasked,
                BillingLocation                 = financialPaymentDetail.BillingLocation?.GetFullStreetAddress(),
                CardExpirationDate              = financialPaymentDetail.CardExpirationDate,
                CreatedDateTime                 = financialPaymentDetail.CreatedDateTime,
                CreditCardTypeValue             = financialPaymentDetail.CreditCardTypeValue?.Value,
                ExpirationDate                  = financialPaymentDetail.ExpirationDate,
                ExpirationMonth                 = financialPaymentDetail.ExpirationMonth,
                ExpirationYear                  = financialPaymentDetail.ExpirationYear,
                FinancialPersonSavedAccountName = financialPaymentDetail.FinancialPersonSavedAccount?.Name,
                Id         = financialPaymentDetail.Id,
                NameOnCard = financialPaymentDetail.NameOnCard,
                Person     = cardHolder,
                FinancialScheduledTransactions = financialScheduledTransactions
            };

            _ = RockMessageBus.PublishAsync <ExpiringCardEventQueue, CreditCardIsExpiringMessage>(message);

            RockLogger.Log.Debug(RockLogDomains.Bus, "Published 'Credit Card Is Expiring Message' message.");
        }
        /// <summary>
        /// Publishes the specified entity.
        /// </summary>
        /// <param name="senderNodeName">Name of the sender node.</param>
        /// <param name="messageType">The message.</param>
        /// <param name="recipientNodeName">Name of the recipient node.</param>
        /// <param name="payload">The payload.</param>
        public static void Publish(string senderNodeName, string messageType, string recipientNodeName = "", string payload = "")
        {
            var webFarmWasUpdatedMessage = new WebFarmWasUpdatedMessage
            {
                SenderNodeName    = senderNodeName,
                MessageType       = messageType,
                RecipientNodeName = recipientNodeName,
                Payload           = payload
            };

            _ = RockMessageBus.PublishAsync <WebFarmQueue, WebFarmWasUpdatedMessage>(webFarmWasUpdatedMessage);
        }
        /// <summary>
        /// Publishes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityState">State of the entity.</param>
        public static void Publish(IEntity entity, EntityState entityState)
        {
            var entityTypeId = entity.TypeId;
            var entityType   = EntityTypeCache.Get(entityTypeId);

            var messageType = typeof(EntityWasUpdatedMessage <>).MakeGenericType(entityType.GetEntityType());
            var message     = Activator.CreateInstance(messageType) as IEntityWasUpdatedMessage;

            message.EntityId     = entity.Id;
            message.EntityTypeId = entity.TypeId;
            message.EntityState  = entityState.ToString();

            _ = RockMessageBus.PublishAsync(message, messageType);
        }
Beispiel #7
0
        /// <summary>
        /// Publishes the gift event.
        /// </summary>
        /// <param name="transactionId">The transaction identifier.</param>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="gatewaySupportedCardTypesDefinedValueGuid">[Optional] The <see cref="Guid"/> of the <see cref="DefinedValue"/> that indicates the credit card types supported by the <see cref="FinancialGateway"/> for a specified currency.</param>
        /// <param name="gatewayCurrencyUnitMultiple">[Optional] The <see cref="Guid"/> of the <see cref="DefinedValue"/> that indicates the "unit multiple" (e.g., 100 for dollars) of the currency specified by the gatway.</param>
        public static void PublishTransactionEvent(int transactionId, string eventType = null, Guid?gatewaySupportedCardTypesDefinedValueGuid = null, Guid?gatewayCurrencyUnitMultiple = null)
        {
            using (var rockContext = new RockContext())
            {
                var transactionService = new FinancialTransactionService(rockContext);
                var gateway            = transactionService.Queryable()
                                         .AsNoTracking()
                                         .Include(t => t.FinancialGateway)
                                         .Where(t => t.Id == transactionId)
                                         .Select(t => t.FinancialGateway)
                                         .FirstOrDefault();

                var gatewayComponent     = gateway?.GetGatewayComponent();
                var searchKeyTiedGateway = gatewayComponent as ISearchKeyTiedGateway;
                var searchKeyTypeGuid    = searchKeyTiedGateway?.GetPersonSearchKeyTypeGuid(gateway);
                var data = GetGiftWasGivenMessageData(rockContext, transactionId, searchKeyTypeGuid, gatewaySupportedCardTypesDefinedValueGuid, gatewayCurrencyUnitMultiple);

                if (data != null)
                {
                    var statusGateway = gatewayComponent as IStatusProvidingGateway;

                    if (eventType.IsNullOrWhiteSpace())
                    {
                        eventType =
                            statusGateway.IsPendingStatus(data.FinancialTransaction.Status) ? GiftEventTypes.GiftPending :
                            statusGateway.IsSuccessStatus(data.FinancialTransaction.Status) ? GiftEventTypes.GiftSuccess :
                            statusGateway.IsFailureStatus(data.FinancialTransaction.Status) ? GiftEventTypes.GiftFailure :
                            null;
                    }

                    if (!eventType.IsNullOrWhiteSpace())
                    {
                        var message = new GiftWasGivenMessage
                        {
                            EventType            = eventType,
                            Address              = data.Address,
                            FinancialTransaction = data.FinancialTransaction,
                            Person = data.Person,
                            Time   = RockDateTime.Now
                        };

                        _ = RockMessageBus.PublishAsync <GivingEventQueue, GiftWasGivenMessage>(message);
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Publishes the specified entity.
        /// </summary>
        /// <param name="personIds">The person ids.</param>
        public static void Publish(IEnumerable <int> personIds)
        {
            var list = personIds?.ToList();

            if (list?.Any() != true)
            {
                // Don't publish if there are no person IDs
                return;
            }

            if (!RockMessageBus.IsRockStarted)
            {
                // Don't publish events until Rock is all the way started
                var logMessage = $"'Giving Unit Was Classified' message was not published because Rock is not fully started yet.";

                var elapsedSinceProcessStarted = RockDateTime.Now - RockInstanceConfig.ApplicationStartedDateTime;

                if (elapsedSinceProcessStarted.TotalSeconds > RockMessageBus.MAX_SECONDS_SINCE_STARTTIME_LOG_ERROR)
                {
                    RockLogger.Log.Error(RockLogDomains.Bus, logMessage);
                    ExceptionLogService.LogException(new BusException(logMessage));
                }
                else
                {
                    RockLogger.Log.Debug(RockLogDomains.Bus, logMessage);
                }

                return;
            }

            var message = new GivingUnitWasClassifiedMessage
            {
                PersonIds = list
            };

            _ = RockMessageBus.PublishAsync <GivingEventQueue, GivingUnitWasClassifiedMessage>(message);

            RockLogger.Log.Debug(RockLogDomains.Bus, $"Published 'Giving Unit Was Classified' message.");
        }
 /// <summary>
 /// Sends the messages to the bus.
 /// </summary>
 public static void Publish(this ITransactionWasAlertedMessage message)
 {
     _ = RockMessageBus.PublishAsync(message, message.GetType());
 }