Ejemplo n.º 1
0
        CopyItemEngine ITemplateEngine.GetCopyItemEngine(TemplateContentItem contentItem)
        {
            Initialise();

            // Try to find a master.

            var state = _state;
            MasterTemplateContentItem masterContentItem = null;

            if (contentItem.VerticalId != null)
            {
                masterContentItem = (from m in state.MasterContentItems
                                     where m.Name == contentItem.Master &&
                                     m.VerticalId == contentItem.VerticalId
                                     select m).SingleOrDefault();
            }

            if (masterContentItem == null)
            {
                // Try to use the default.

                masterContentItem = (from m in state.MasterContentItems
                                     where m.Name == contentItem.Master &&
                                     m.VerticalId == null
                                     select m).SingleOrDefault();
            }

            // Create an engine specifically for this template.

            var mergedContentItem = masterContentItem == null
                ? contentItem
                : CreateTemplateContentItem(contentItem, contentItem.VerticalId, masterContentItem);

            return(CreateCopyItemEngine(contentItem.VerticalId, mergedContentItem));
        }
Ejemplo n.º 2
0
        private static TemplateContentItem CreateTemplateContentItem(TemplateBaseContentItem contentItem, Guid?verticalId, TemplateBaseContentItem masterContentItem)
        {
            var newContentItem = new TemplateContentItem
            {
                Id         = contentItem.Id,
                Name       = contentItem.Name,
                VerticalId = verticalId,
                Subject    = contentItem.Subject,
            };

            newContentItem.Views = contentItem.Views.Select(viewContentItem => CreateViewContentItem(viewContentItem, masterContentItem)).ToList();
            return(newContentItem);
        }
Ejemplo n.º 3
0
        private void Add(Engines engines, TemplateContentItem contentItem)
        {
            // Look for the engine.

            var engine = engines[contentItem.Name];

            if (engine == null)
            {
                engine = new Engine();
                engines.Add(contentItem.Name, engine);
            }

            engine.CopyItemEngines.Add(contentItem.VerticalId, CreateCopyItemEngine(contentItem));
        }
Ejemplo n.º 4
0
        private CopyItemEngine CreateCopyItemEngine(Guid?verticalId, TemplateContentItem contentItem)
        {
            // Create a text engine for this copy.

            var textTemplateEngine = CreateTextTemplateEngine(verticalId, contentItem);

            // Create the engine.

            var engine = new CopyItemEngine(textTemplateEngine);

            foreach (var viewContentItem in contentItem.Views)
            {
                engine.ViewEngines.Add(viewContentItem.MimeType, CreateViewEngine(verticalId, viewContentItem));
            }
            return(engine);
        }
Ejemplo n.º 5
0
 CopyItemEngine ITemplateEngine.GetCopyItemEngine(TemplateContentItem templateContentItem)
 {
     return(_firstTemplateEngine.GetCopyItemEngine(templateContentItem));
 }
Ejemplo n.º 6
0
 protected abstract ITextTemplateEngine CreateTextTemplateEngine(Guid?verticalId, TemplateContentItem contentItem);
Ejemplo n.º 7
0
 private CopyItemEngine CreateCopyItemEngine(TemplateContentItem contentItem)
 {
     return(CreateCopyItemEngine(contentItem.VerticalId, contentItem));
 }
Ejemplo n.º 8
0
        private static void MergeDefaultContentItem(ICollection <TemplateContentItem> mergedContentItems, TemplateContentItem contentItem, IEnumerable <TemplateContentItem> contentItems, IEnumerable <MasterTemplateContentItem> masterContentItems)
        {
            var masters = from m in masterContentItems
                          where m.Name == contentItem.Master && m.VerticalId != null
                          select m;

            foreach (var masterContentItem in masters)
            {
                var verticalSpecificContentItem = from c in contentItems
                                                  where c.Name == contentItem.Name &&
                                                  c.Master == contentItem.Master &&
                                                  c.VerticalId == masterContentItem.VerticalId
                                                  select c;

                if (!verticalSpecificContentItem.Any())
                {
                    mergedContentItems.Add(CreateTemplateContentItem(contentItem, masterContentItem.VerticalId, masterContentItem));
                }
            }
        }
Ejemplo n.º 9
0
        private static void MergeTemplateContentItems(ICollection <TemplateContentItem> mergedContentItems, TemplateContentItem contentItem, IEnumerable <TemplateContentItem> contentItems, IEnumerable <MasterTemplateContentItem> masterContentItems)
        {
            // If there is no master then simply return it.

            if (string.IsNullOrEmpty(contentItem.Master))
            {
                mergedContentItems.Add(contentItem);
                return;
            }

            // Find its master.

            var masterContentItem = (from m in masterContentItems
                                     where m.Name == contentItem.Master && m.VerticalId == contentItem.VerticalId
                                     select m).SingleOrDefault()
                                    ??
                                    (from m in masterContentItems
                                     where m.Name == contentItem.Master && m.VerticalId == null
                                     select m).SingleOrDefault();

            // Merge.

            if (masterContentItem == null)
            {
                mergedContentItems.Add(contentItem);
            }
            else
            {
                mergedContentItems.Add(CreateTemplateContentItem(contentItem, contentItem.VerticalId, masterContentItem));
            }

            // If there are vertical specific masters for this content, but there is no specific content then use the default, ie this content.

            if (contentItem.VerticalId == null)
            {
                MergeDefaultContentItem(mergedContentItems, contentItem, contentItems, masterContentItems);
            }
        }