using System;
using System.Linq;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
[Extension("Embeds a silverlight object.", "1.0", "Createdbyx.com")]
public class SilverlightExt
{
public SilverlightExt()
{
Post.Serving += this.Serving;
Page.Serving += this.Serving;
}
private void Serving(object sender, ServingEventArgs e)
{
var tagPattern = " ", startPos + tagPattern.Length);
if (startPos != -1 && endPos != -1 && endPos >= startPos)
{
string argsString = e.Body.Substring(startPos + tagPattern.Length, endPos - (startPos + tagPattern.Length));
string[] parts = argsString.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
try
{
var xapFile = (from p in parts
where p.ToLower().Trim().StartsWith("xap:")
select new string(p.Substring(4).ToCharArray())).FirstOrDefault();
var width = (from p in parts
where p.ToLower().Trim().StartsWith("width:")
select int.Parse(p.Substring(6))).FirstOrDefault();
var height = (from p in parts
where p.ToLower().Trim().StartsWith("height:")
select int.Parse(p.Substring(7))).FirstOrDefault();
var htmlData = GetHTML(xapFile, width, height);
e.Body = e.Body.Remove(startPos, (endPos + 1) - startPos);
e.Body = e.Body.Insert(startPos, htmlData);
}
catch (Exception)
{
return;
}
}
}
}
public string GetHTML(string xapFile, int pWidth, int pHeight)
{
var data =
"<object data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"{0}\" height=\"{1}\">" +
" <param name=\"source\" value=\"ClientBin/{2}.xap\"/>" +
" <param name=\"onError\" value=\"onSilverlightError\" />" +
" <param name=\"background\" value=\"white\" />" +
" <param name=\"minRuntimeVersion\" value=\"3.0.40624.0\" />" +
" <param name=\"autoUpgrade\" value=\"true\" />" +
" <a href=\"http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0\" style=\"text-decoration:none\">" +
" <img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\" style=\"border-style:none\"/>" +
" </a>" +
"</object> <iframe id=\"_sl_historyFrame\" style=\"visibility:hidden;height:0px;width:0px;border:0px\"></iframe>";
data = string.Format(data, pWidth, pHeight, xapFile);
return data;
}
}