I haven’t seen a massive amount of documentation on MSDN or other posts about this, so I thought I would write a small note.
This details a way of extracting the info you see in the news feed on your ‘My Site’
First of all you need to get the the format used by the ActivityEvent
, this done using ActivityType
and ActivityTemplate
.
1 | ActivityType type = activityMan.ActivityTypes[activity.ActivityEventId]; |
The format variable will now contain something along the lines of “{Pubisher} has posted a note {Link} on {PublishDate}”
Now you could at this point take the corresponding Properties in the ActivityEvent
, but there is a whole load of formatting that needs to be done. The Publisher Tag needs to be turned into a link to the users profile page and display their name, etc, etc.
There is an easier way, you can use the static methods of the ActivityTemplateVariable
.
1 | ActivityTemplateVariable.DateOnlyToString(tag, variable, ContentType.Html, CultureInfo.CurrentCulture); |
The problem here is that you have to pass in an ActivityTemplateVariable
as one of the parameter and there is no obvious way of doing this.
There are no properties or methods in the ActivityEvent
that give you an ActivityTemplateVariable
or is there?
After further investigation of the TemplateVariable
string property, you can see that this actually returns an XML string. This XML string is a de-serialised ActivityTemplateVariable
object.
1 | var variable = (ActivityTemplateVariable)FromXml(item.TemplateVariable, typeof(ActivityTemplateVariable)); |
You can now use this object to pass to the static method of ActivityTemplateVariable
to return the full HTML representation of the tag.
If you then combine that with SimpleTemplateFormat
you can then loop round all the tags and replace them.
1 | var items = SimpleTemplateFormat.SimpleParse(formatToUse); |