public void SendMessage(
     ComponentType contactSource,
     EventTypeEnum eventType,
     ContactInfo recipient,
     List <TemplateParameterInfo> templateParameters,
     string language)
 {
     DoSendMessageWithCarbonCopies(
         contactSource,
         eventType,
         recipient,
         new List <ContactInfo>(),
         templateParameters,
         language);
 }
 public void SendMessageWithShadowCopies(
     ComponentType contactSource,
     EventTypeEnum eventType,
     ContactInfo carbonCopyRecipient,
     List <ContactInfo> blindCarbonCopyRecipients,
     List <TemplateParameterInfo> templateParameters,
     string language)
 {
     DoSendMessageWithCarbonCopies(
         contactSource,
         eventType,
         carbonCopyRecipient,
         blindCarbonCopyRecipients,
         templateParameters,
         language);
 }
Example #3
0
        public MessageTemplateInfo GetMessageTemplate(EventType eventType, string language)
        {
            var context     = GetOrAddContext();
            var eventTypeDB = GetCachedEventType(eventType);
            var eventDB     = GetNotCustomizableEvent(eventTypeDB, context);
            var languageDB  = GetOrAddCachedLanguage(language);
            var template    = GetTemplateForLanguageOrDefaultForEvent(eventDB, languageDB);

            return(new MessageTemplateInfo {
                Subject = template.Subject,
                Text = template.Text,
                Parameters =
                    eventTypeDB.Parameters.Select(p => new TemplateParameterInfo(p.Name, null, p.Description))
                    .ToList()
            });
        }
        private void DoSendMessageWithCarbonCopies(
            ComponentType contactSource,
            EventTypeEnum eventType,
            ContactInfo carbonCopyRecipient,
            List <ContactInfo> blindCarbonCopyRecipients,
            List <TemplateParameterInfo> templateParameters,
            string language)
        {
            carbonCopyRecipient.Validate();
            blindCarbonCopyRecipients.ForEach(r => r.Validate());

            var context     = GetOrAddContext();
            var eventTypeDB = GetCachedEventType(eventType);

            AssertAllTemplateParametersSpecified(eventTypeDB, templateParameters);
            var eventDB = GetNotCustomizableEvent(eventTypeDB, context);

            if (!eventDB.IsEnabled)
            {
                Loggers.MainLogger.Info(
                    "Event with id '{0}' for context with id '{1}' is disabled, message creation skipped",
                    eventDB.Id,
                    context.Id);
                return;
            }
            var languageDB = GetOrAddCachedLanguage(language);
            var template   = GetTemplateForLanguageOrDefaultForEvent(eventDB, languageDB);
            var source     = GetContactSource(contactSource);

            var contact = GetOrAddContact(source, context, carbonCopyRecipient);

            CreateMessage(eventTypeDB.Parameters, template, contact, templateParameters);

            CreateBlindCarbnCopyMessages(
                blindCarbonCopyRecipients,
                source,
                context,
                eventTypeDB.Parameters,
                template,
                templateParameters);
            DbContext.SaveChanges(DebugInfoCollector, "Save changes");
        }
 private EventType GetCachedEventType(EventTypeEnum eventType)
 {
     return(Caches.EventType.GetValue(
                eventType,
                () => {
         var eventTypeDB =
             DbContext.EventTypes.AsNoTracking()
             .Include(x => x.Parameters)
             .Single(
                 x => x.Name == eventType.ToString(),
                 DebugInfoCollector,
                 "Get event type by name",
                 () =>
                 new MessengerException(
                     "Event type '{0}' was not found in database, create it manually",
                     eventType));
         DbContext.Entry(eventTypeDB).State = EntityState.Detached;
         return eventTypeDB;
     }));
 }
Example #6
0
        public void UpdateMessageTemplate(EventType eventType, string language, MessageTemplateUpdateData updateData)
        {
            updateData.Validate();
            var context     = GetOrAddContext();
            var eventTypeDB = GetCachedEventType(eventType);
            var eventDB     = GetNotCustomizableEvent(eventTypeDB, context);
            var languageDB  = GetOrAddCachedLanguage(language);
            var template    = GetTemplateForLanguageOrDefaultForEvent(eventDB, languageDB);

            if (Context.InstanceKey == Constants.SystemContextName)
            {
                if (DbContext.Messages.Any(m => m.TemplateId == template.Id))
                {
                    var newTemplate = new Template {
                        EventId    = eventDB.Id,
                        IsActual   = true,
                        Subject    = template.Subject,
                        Text       = template.Text,
                        LanguageId = languageDB.Id,
                        IsDefault  = template.IsDefault
                    };
                    UpdateTemplate(updateData, newTemplate);
                    DbContext.Templates.Add(newTemplate);
                    template.IsActual  = false;
                    template.IsDefault = false;
                }
                else
                {
                    UpdateTemplate(updateData, template);
                }
            }
            else
            {
                //var doesContextHaveItsOwnEvent = template.is
            }
            DbContext.SaveChanges(DebugInfoCollector, "Save");
        }