コード例 #1
0
 private IEnumerable<Teaser> GetEntityItems(EntityModel entity)
 {
     List<Teaser> res = new List<Teaser>();
     //1. Check if entity is a teaser, if add it
     if (entity is Teaser)
     {
         res.Add((Teaser)entity);
     }
     else
     {
         //2. Second check if entity type is (semantically) a list, and if so, get its list items
         List<Teaser> items = GetTeaserListFromSemantics(entity);
         if (items != null)
         {
             res = items;
         }
         else
         {
             //3. Last resort, try to find some suitable properties using reflection
             Teaser teaser = new Teaser();
             foreach (PropertyInfo pi in entity.GetType().GetProperties())
             {
                 switch (pi.Name)
                 {
                     case "Headline":
                     case "Name":
                         teaser.Headline = pi.GetValue(entity) as String;
                         break;
                     case "Date":
                         DateTime? date = pi.GetValue(entity) as DateTime?;
                         if (date != null)
                             teaser.Date = date;
                         break;
                     case "Description":
                         teaser.Text = pi.GetValue(entity) as String;
                         break;
                     case "Link":
                         teaser.Link = pi.GetValue(entity) as Link;
                         break;
                     case "Url":
                         string url = pi.GetValue(entity) as String;
                         if (url != null)
                             teaser.Link = new Link { Url = url };
                         break;
                 }
             }
             if (teaser.Headline != null || teaser.Text != null || teaser.Link != null)
             {
                 res.Add(teaser);
             }
         }
     }
     return res;
 }
コード例 #2
0
 private static Teaser GetTeaserFromMeta(IComponentMeta compMeta)
 {
     Teaser result = new Teaser
         {
             Link = new Link { Url = String.Format("tcm:{0}-{1}", compMeta.PublicationId, compMeta.Id) },
             Date = GetDateFromCustomMeta(compMeta.CustomMeta, "dateCreated") ?? compMeta.LastPublicationDate,
             Headline = GetTextFromCustomMeta(compMeta.CustomMeta, "name") ?? compMeta.Title,
             Text = GetTextFromCustomMeta(compMeta.CustomMeta, "introText")
         };
     return result;
 }
コード例 #3
0
 private SyndicationItem GetSyndicationItemFromTeaser(Teaser item)
 {
     SyndicationItem si = new SyndicationItem();
     if (item.Headline != null)
     {
         si.Title = new TextSyndicationContent(item.Headline);
     }
     if (item.Text != null)
     {
         si.Summary = new TextSyndicationContent(item.Text.ToString());
     }
     if (item.Link != null && item.Link.Url!=null && item.Link.Url.StartsWith("http"))
     {
         si.Links.Add(new SyndicationLink(new Uri(item.Link.Url)));
     }
     if (item.Date != null)
     {
         si.PublishDate = (DateTime)item.Date;
     }
     return si;
 }