Beispiel #1
0
        public ICollection <KeyValuePair <string, string> > AsKeyValueCollection()
        {
            //check for required properties, and throw if they are missing
            ThrowIf.IsPropertyNull(() => To);
            ThrowIf.IsPropertyNull(() => From);

            //create kv store
            var kvp = new Collection <KeyValuePair <string, string> >();

            //add the to values
            var toSb = new StringBuilder();

            foreach (var to in To)
            {
                toSb.Append(to.ToFormattedString() + ",");
            }
            kvp.Add("to", toSb.ToString());

            //add the from field
            if (From != null)
            {
                kvp.AddIfNotNullOrEmpty("from", From.ToFormattedString());
            }
            //add the subject, test, html and campaign ID
            kvp.AddIfNotNullOrEmpty("subject", Subject);
            kvp.AddIfNotNullOrEmpty("text", Text);
            kvp.AddIfNotNullOrEmpty("html", Html);
            kvp.AddIfNotNullOrEmpty("o:campaign", CampaignId);

            //add date time values
            if (DeliveryTime != null)
            {
                kvp.Add("o:deliverytime", DeliveryTime.Value.ToUnixTime().ToString());
            }


            //add boolean values
            kvp.Add("o:dkim", Dkim.AsYesNo());
            kvp.Add("o:testmode", TestMode.AsYesNo());
            kvp.Add("o:tracking", Tracking.AsYesNo());
            kvp.Add("o:tracking-clicks", TrackingClicks.AsYesNo());
            kvp.Add("o:tracking-opens", TrackingOpen.AsYesNo());


            //tags
            if (Tags != null)
            {
                foreach (var t in Tags)
                {
                    kvp.AddIfNotNullOrEmpty("o:tag", t);
                }
            }

            //add recipient variables
            if (RecipientVariables != null)
            {
                kvp.AddIfNotNullOrEmpty("recipient-variables", RecipientVariables.ToString(Formatting.None));
            }

            //add custom headers
            if (CustomHeaders != null)
            {
                foreach (var h in CustomHeaders)
                {
                    kvp.AddIfNotNullOrEmpty(string.Format("h:{0}", h.Key), h.Value);
                }
            }

            //add custom data
            if (CustomData != null)
            {
                foreach (var cd in CustomData)
                {
                    kvp.Add(string.Format("v:{0}", cd.Key), cd.Value.ToString(Formatting.None));
                }
            }

            if (CustomParameters != null)
            {
                //add custom params
                foreach (var p in CustomParameters)
                {
                    kvp.AddIfNotNullOrEmpty(p.Key, p.Value);
                }
            }

            //TODO attachments and inline
            return(kvp);
        }