Exemplo n.º 1
0
        public void LavaDataObjectType_SerializeDeserialize_CanRoundtrip()
        {
            var dynamicObject = new LavaDataObject();

            dynamicObject["Color1"] = "red";
            dynamicObject["Color2"] = "green";
            dynamicObject["Color3"] = "blue";

            var json            = JsonConvert.SerializeObject(dynamicObject);
            var dynamicFromJson = JsonConvert.DeserializeObject <LavaDataObject>(json);

            var mergeValues = new LavaDataDictionary {
                { "Colors", dynamicFromJson }
            };

            var template = @"Color 1: {{ Colors.Color1 }}, Color 2: {{ Colors.Color2 }}, Color 3: {{ Colors.Color3 }}";

            TestHelper.AssertTemplateOutput("Color 1: red, Color 2: green, Color 3: blue", template, mergeValues);
        }
Exemplo n.º 2
0
        private static void SendNotificationMessage(JobExecutionException jobException, ServiceJob job)
        {
            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, null, new Lava.CommonMergeFieldsOptions {
                GetLegacyGlobalMergeFields = false
            });

            mergeFields.Add("Job", job);
            try
            {
                if (jobException != null)
                {
                    if (LavaService.RockLiquidIsEnabled)
                    {
                        mergeFields.Add("Exception", Hash.FromAnonymousObject(jobException));
                    }
                    else
                    {
                        mergeFields.Add("Exception", LavaDataObject.FromAnonymousObject(jobException));
                    }
                }
            }
            catch
            {
                // ignore
            }

            var notificationEmailAddresses = job.NotificationEmails.ResolveMergeFields(mergeFields).SplitDelimitedValues().ToList();
            var emailMessage = new RockEmailMessage(Rock.SystemGuid.SystemCommunication.CONFIG_JOB_NOTIFICATION.AsGuid());

            emailMessage.AdditionalMergeFields     = mergeFields;
            emailMessage.CreateCommunicationRecord = false;

            // NOTE: the EmailTemplate may also have TO: defined, so even if there are no notificationEmailAddress defined for this specific job, we still should send the mail
            foreach (var notificationEmailAddress in notificationEmailAddresses)
            {
                emailMessage.AddRecipient(RockEmailMessageRecipient.CreateAnonymous(notificationEmailAddress, null));
            }

            emailMessage.Send();
        }