示例#1
0
        /// <summary>
        /// Generate the <c>InjectionRequest</c> for sending to the Injection Api
        /// </summary>
        /// <param name="message">An <c>IBasicMessage</c> object to be sent.</param>
        /// <returns>An <c>InjectionRequest</c> for sending to the Injection Api</returns>
        public InjectionRequest GenerateRequest(IBasicMessage message)
        {
            var request = new InjectionRequest(_serverId, _apiKey);

            var jsonMsg = GenerateBaseMessageJson(message);

            jsonMsg.To  = PopulateList(message.To);
            jsonMsg.Cc  = PopulateList(message.Cc);
            jsonMsg.Bcc = PopulateList(message.Bcc);

            request.Messages.Add(jsonMsg);

            if (message.ReplyTo != null)
            {
                jsonMsg.ReplyTo = new AddressJson(message.ReplyTo.Email, message.ReplyTo.FriendlyName);
            }

            return(request);
        }
示例#2
0
        /// <summary>
        /// Generate the <c>InjectionRequest</c> for sending to the Injection Api
        /// </summary>
        /// <param name="message">An <c>IBulkMessage</c> object to be sent.</param>
        /// <returns>An <c>InjectionRequest</c> for sending to the Injection Api</returns>
        public InjectionRequest GenerateRequest(IBulkMessage message)
        {
            var request = new InjectionRequest(_serverId, _apiKey);

            var jsonMsg = GenerateBaseMessageJson(message);

            // Replace the "To" recipients with links to merge field data
            jsonMsg.To = new List <AddressJson> {
                new AddressJson("%%DeliveryAddress%%", "%%RecipientName%%")
            };

            // handle merge data per recipient for message
            var mergeDataForEmail = GetBulkMergeFields(message.To);

            jsonMsg.MergeData.PerMessage = mergeDataForEmail;

            // handle global (per message) merge data
            jsonMsg.MergeData.Global = PopulateMergeData(message.GlobalMergeData);

            request.Messages.Add(jsonMsg);

            return(request);
        }
示例#3
0
        public void UpdateInjections()
        {
            List <string> NeededAddonInjections = new List <string>();

            // First remove any unwanted injections
            foreach (IAddon loadedAddon in LoadedAddons)
            {
                if (!RequestedAddons.Exists(requestedAddon => requestedAddon == loadedAddon.CoreName))
                {
                    LoadedAddons.RemoveAll(addon => addon.CoreName == loadedAddon.CoreName);

                    logger.Debug("Removing injected dependency as it is no longer required: {0}", loadedAddon.CoreName);
                }
            }

            // Then add needed injections
            foreach (string requestedAddon in RequestedAddons)
            {
                if (!LoadedAddons.Exists(loadedAddon => loadedAddon.CoreName == requestedAddon))
                {
                    NeededAddonInjections.Add(requestedAddon);
                }
            }

            // Finally raise event and hope someone listens
            if (InjectionRequest != null)
            {
                //logger.Debug("Raising injection request for following addons: {0}", String.Join(Environment.NewLine, NeededAddonInjections));

                InjectionRequest.Invoke(this, NeededAddonInjections);
            }
            else
            {
                logger.Warn("Unmonitored injection request for {0} new dependencies", NeededAddonInjections.Count);
            }
        }