📄 admanager.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client;
using Imps.Client.Base;
using Imps.Client.Utils;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Xml;
public class AdManager : UserItemBase
{
private AdInfo _adStatusBar;
private Dictionary<string, EventHandler> _updateTickHandlers;
private string _urlAdBar;
private string _urlAdNotify;
private const string BT_AdBar = "AdBar2008";
private const string BT_Logo = "Logo";
private const string BT_NotifyWnd = "NotifyWnd";
private const string BT_StatusBar = "StatusBar";
public event EventHandler AdBarUrlChanged;
public event EventHandler AdNotifyUrlChanged;
public event EventHandler AdStatusBarChanged;
internal AdManager(User owner) : base(owner)
{
this._updateTickHandlers = new Dictionary<string, EventHandler>();
this._updateTickHandlers.Add("AdBar2008", new EventHandler(this.AdBar_UpdateTick));
this._updateTickHandlers.Add("StatusBar", new EventHandler(this.StatusBar_UpdateTick));
this._updateTickHandlers.Add("NotifyWnd", new EventHandler(this.NotifyWnd_UpdateTick));
this._updateTickHandlers.Add("Logo", new EventHandler(this.Logo_UpdateTick));
this._adStatusBar = new AdInfo();
owner.RealtimeStatusChanged += new EventHandler<UserSatusChangedEventArgs>(this, (IntPtr) this.owner_RealtimeStatusChanged);
}
private void AdAll_UpdateTick(object sender, EventArgs e)
{
GlobalTimer.Unregister(new EventHandler(this.AdAll_UpdateTick));
if (base.Owner.Status == UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerGetAdInfo));
}
}
private void AdBar_UpdateTick(object sender, EventArgs e)
{
if (base.Owner.Status == UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerGetAdInfo), "AdBar2008");
}
}
private void InnerGetAdInfo(object state)
{
try
{
XmlNode node;
string text = (state is string) ? ((string) state) : string.Empty;
if ((text.Length == 0) || (text == "AdBar2008"))
{
node = this.RequestBulletin("AdBar2008");
this.AdBarUrl = (node != null) ? node.InnerText : string.Empty;
}
if ((text.Length == 0) || (text == "StatusBar"))
{
node = this.RequestBulletin("StatusBar");
if (node != null)
{
XmlNode node2 = node.SelectSingleNode("ad");
if (node2 != null)
{
this._adStatusBar.LoadXmlNode(node2);
FuncDispatcher.InvokeEventHandlerInUiThread(this, this.AdStatusBarChanged, EventArgs.Empty);
}
}
}
if ((text.Length == 0) || (text == "NotifyWnd"))
{
node = this.RequestBulletin("NotifyWnd");
if (node != null)
{
this.AdNotifyUrl = node.InnerText;
}
}
}
catch (Exception exception)
{
ClientLogger.WriteBizOperation("获取广告信息", exception.ToString(), 20);
}
}
private void Logo_UpdateTick(object sender, EventArgs e)
{
if (base.Owner.Status == UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerGetAdInfo), "Logo");
}
}
private void NotifyWnd_UpdateTick(object sender, EventArgs e)
{
if (base.Owner.Status == UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerGetAdInfo), "NotifyWnd");
}
}
private void owner_RealtimeStatusChanged(object sender, UserSatusChangedEventArgs e)
{
if (e.NewStatus == UserAccountStatus.Logon)
{
GlobalTimer.Register(new EventHandler(this.AdAll_UpdateTick), 0x708, TimerHandlerPriority.Lowest);
}
}
private XmlNode RequestBulletin(string bulletinType)
{
string detail = this.GetAdUrl + "?BulletinType=" + bulletinType;
ClientLogger.WriteBizOperation("获取广告信息", detail);
using (HttpWebResponse response = ((HttpWebResponse) ConnectionFactory.CreateHttpWebRequest(detail, base.Owner, false, true).GetResponse()))
{
if (response.ContentLength <= 0)
{
ClientLogger.WriteBizOperation("广告信息为空");
return null;
}
XmlDocument document = new XmlDocument();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), true))
{
string text2 = reader.ReadToEnd();
ClientLogger.WriteBizOperation("广告信息", text2);
document.LoadXml(text2);
}
XmlNode node = document.DocumentElement.SelectSingleNode("bulletin");
if (node != null)
{
int num = XmlHelper.ReadXmlAttributeInt32(node, "update-hours", 0);
EventHandler handler = this._updateTickHandlers.get_Item(bulletinType);
if (num > 0)
{
GlobalTimer.Register(handler, (int) (num * 0x8ca0));
}
else
{
GlobalTimer.Unregister(handler);
}
}
response.Close();
return node;
}
}
private void StatusBar_UpdateTick(object sender, EventArgs e)
{
if (base.Owner.Status == UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerGetAdInfo), "StatusBar");
}
}
public string AdBarUrl
{
get
{
return this._urlAdBar;
}
set
{
if ((this._urlAdBar != value) && (this.AdBarUrlChanged != null))
{
this._urlAdBar = value;
FuncDispatcher.InvokeEventHandlerInUiThread(this, this.AdBarUrlChanged, EventArgs.Empty);
}
}
}
public string AdNotifyUrl
{
get
{
return this._urlAdNotify;
}
set
{
if ((this._urlAdNotify != value) && (this.AdNotifyUrlChanged != null))
{
this._urlAdNotify = value;
FuncDispatcher.InvokeEventHandlerInUiThread(this, this.AdNotifyUrlChanged, EventArgs.Empty);
}
}
}
public AdInfo AdStatusBar
{
get
{
return this._adStatusBar;
}
}
private string GetAdUrl
{
get
{
return base.Owner.Configuration.SystemSetting.ServerUriSetting.UriGetAD;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -