一、定义接口
using System; namespace VCShop.Advertisement { public interface IAdvertisement { string Author(); void CreateAdvertisement(string width, string height, string path, string guid, string queryarray); string Description(); string GetQuery(); string Name(); string Url(); string Version(); } }
二、实现调用模块方法
namespace VCShop.Advertisement { using System; using VCShop.Common; public class AdvertisementFactory { public static IAdvertisement GetInstance(string AdvertisementName) { try { return (IAdvertisement) Activator.CreateInstance(Type.GetType(string.Format("VCShop.Advertisement.{0}.Advertisement, VCShop.Advertisement.{0}", AdvertisementName), false, true)); } catch { utils.ShowErrorPage("请检查BIN文件夹下是否有VCShop.Advertisement." + AdvertisementName + ".dll这个文件"); return null; } } } }
三、广告位实体
1.普通 图片+链接广告位
namespace VCShop.Advertisement.Simple { using System; using System.IO; using System.Text; using VCShop.Advertisement; public class Advertisement : IAdvertisement { public string Author() { return "Terry"; } public void CreateAdvertisement(string width, string height, string path, string guid, string queryArray) { if (queryArray.IndexOf(",") == -1) { queryArray = queryArray + ","; } StringBuilder builder = new StringBuilder(); string[] strArray = queryArray.Split(new char[] { ',' }); if (strArray[1] != "") { builder.Append("document.write('<a href=\"" + strArray[1] + "\" title=\"" + strArray[2] + "\" target=\"_blank\"><img src=\"" + strArray[0] + "\" width=\"" + width + "\" height=\"" + height + "\" border=\"0\"></a>');"); } else { builder.Append("document.write('<img src=\"" + strArray[0] + "\" width=\"" + width + "\" height=\"" + height + "\" border=\"0\">');"); } File.WriteAllText(path + "/" + guid + ".js", builder.ToString()); } public string Description() { return "正常的广告"; } public string GetQuery() { return "1|"; } public string Name() { return "普通广告"; } public string Url() { return "http://www.***.com.cn"; } public string Version() { return "V1.0"; } } }
2. FALSH动态变换广告位
namespace VCShop.Advertisement.Flash { using System; using System.IO; using System.Text; using VCShop.Advertisement; public class Advertisement : IAdvertisement { public string Author() { return "Terry"; } public void CreateAdvertisement(string width, string height, string path, string guid, string queryArray) { if (queryArray == "") { File.WriteAllText(path + "/" + guid + ".js", ""); } else { if (queryArray.IndexOf(",") == -1) { queryArray = queryArray + ",,,,,,,,,,,,,,,,,"; } StringBuilder builder = new StringBuilder(); builder.Append("var swf_width=" + width + ";"); builder.Append("var swf_height=" + height + ";"); builder.Append("var swf_config=\"|4|||0xFFFFFF|0xFF6600||4|3|1|_blank\";"); builder.Append("document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"'+ swf_width +'\" height=\"'+ swf_height +'\">');"); builder.Append("document.write('<param name=\"movie\" value=\"Lib/flash/bcastr.swf?bcastr_xml_url=show/" + guid + ".xml \">');"); builder.Append("document.write('<param name=\"quality\" value=\"high\">');"); builder.Append("document.write('<param name=\"menu\" value=\"false\">');"); builder.Append("document.write('<param name=\"wmode\" value=\"opaque\">');"); builder.Append("document.write('<param name=\"FlashVars\" value=\"bcastr_config='+swf_config+'\">');"); builder.Append("document.write('<embed src=\"Lib/flash/bcastr.swf?bcastr_xml_url=show/" + guid + ".xml\" FlashVars=\"bcastr_config='+swf_config+'\" wmode=\"opaque\" FlashVars=\"bcastr_config='+swf_config+'\" menu=\"false\" quality=\"high\" width=\"'+ swf_width +'\" height=\"'+ swf_height +'\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');"); builder.Append("document.write('</object>');"); File.WriteAllText(path + "/" + guid + ".js", builder.ToString()); string[] strArray = queryArray.Split(new char[] { ',' }); builder = new StringBuilder(); builder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); builder.Append("<bcaster>"); for (int i = 0; i < 6; i++) { if (strArray[i * 3].ToString() != "") { builder.Append("<item item_url=\"" + strArray[i * 3] + "\" link=\"" + strArray[(i * 3) + 1] + "\" />"); } } builder.Append("</bcaster>"); File.WriteAllText(path + "/" + guid + ".xml", builder.ToString()); } } public string Description() { return "FLASH轮换广告"; } public string GetQuery() { return "6|"; } public string Name() { return "FLASH轮换广告"; } public string Url() { return "http://www.021web.com.cn"; } public string Version() { return "V1.0"; } } }
三、调用广告位模块
AdvertisementFactory.GetInstance(str2).CreateAdvertisement(this.txtWidth.Text, this.txtHeight.Text, base.Server.MapPath("../template/" + this.path + "/Show"), mark, info);