⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adbarimp.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc
{
    using Imps.Client;
    using Imps.Client.Core;
    using Imps.Client.Pc.BizControls;
    using Imps.Client.Pc.BizControls.NotifyWindows;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class AdBarImp : Panel, IAdBar
    {
        private IFrameworkWindow _framework;
        private BWebBrowser innerBrowser;
        private bool innerNavigate;
        private PictureBox innerPicBox;

        public AdBarImp(IFrameworkWindow framework)
        {
            this._framework = framework;
            this._framework.AccountManager.CurrentUser.AdManager.AdBarUrlChanged += new EventHandler(this.AdBarUrl_Changed);
            this._framework.AccountManager.CurrentUser.AdManager.AdNotifyUrlChanged += new EventHandler(this.AdNotifyUrl_Changed);
            base.SetStyle(ControlStyles.ResizeRedraw, false);
            this.InitializeComponent();
            this.innerPicBox.Image = ImpsResources.GetImage("Images.ad.gif");
            this.innerPicBox.Cursor = Cursors.Hand;
            this.innerPicBox.Click += new EventHandler(this.innerPicBox_Click);
        }

        private void AdBarUrl_Changed(object sender, EventArgs e)
        {
            try
            {
                ClientLogger.WriteBizOperation("设置TargetUrl", this.InnerAdManager.AdBarUrl);
                this.TargetUrl = this.InnerAdManager.AdBarUrl;
            }
            catch
            {
            }
        }

        private void AdNotifyUrl_Changed(object sender, EventArgs e)
        {
            try
            {
                SystemInfoNotify notifyWindow = new SystemInfoNotify(AppDictionary.CurrentClientName, this.InnerAdManager.AdNotifyUrl);
                notifyWindow.Click += new EventHandler(this.notifyWnd_Click);
                NotifyWindowManager.Add(notifyWindow);
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            this.innerBrowser = new BWebBrowser();
            this.innerPicBox = new PictureBox();
            ((ISupportInitialize) this.innerPicBox).BeginInit();
            base.SuspendLayout();
            this.innerBrowser.AllowWebBrowserDrop = false;
            this.innerBrowser.IsWebBrowserContextMenuEnabled = false;
            this.innerBrowser.Location = new Point(0x20, 5);
            this.innerBrowser.MinimumSize = new Size(20, 20);
            this.innerBrowser.Name = "innerBrowser";
            this.innerBrowser.ScriptErrorsSuppressed = true;
            this.innerBrowser.ScrollBarsEnabled = false;
            this.innerBrowser.Size = new Size(0x102, 0x44);
            this.innerBrowser.TabIndex = 0;
            this.innerBrowser.WebBrowserShortcutsEnabled = false;
            this.innerBrowser.NavigateError += new EventHandler<BWebBrowserNavigatingEventArgs>(this.innerBrowser_NavigateError);
            this.innerBrowser.Navigated += new WebBrowserNavigatedEventHandler(this.innerBrowser_Navigated);
            this.innerBrowser.Visible = false;
            this.innerPicBox.Location = new Point(0x20, 5);
            this.innerPicBox.Name = "innerPicBox";
            this.innerPicBox.Size = new Size(100, 50);
            this.innerPicBox.TabIndex = 0;
            this.innerPicBox.TabStop = false;
            this.innerPicBox.Size = new Size(0x102, 0x44);
            this.innerPicBox.BorderStyle = BorderStyle.None;
            this.innerPicBox.Visible = true;
            this.BackColor = Color.Transparent;
            base.Controls.Add(this.innerBrowser);
            base.Controls.Add(this.innerPicBox);
            base.Padding = new Padding(5);
            base.Size = new Size(0x142, 0x4e);
            ((ISupportInitialize) this.innerPicBox).EndInit();
            base.ResumeLayout(false);
        }

        private void innerBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            this.innerNavigate = false;
        }

        private void innerBrowser_NavigateError(object sender, BWebBrowserNavigatingEventArgs e)
        {
            ClientLogger.WriteBizOperation("ywq", "触发Browser NavigateError事件");
            this.NavigateToUrl(string.Empty);
        }

        private void innerBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (!this.innerNavigate)
            {
                try
                {
                    if (e.Url.Scheme == Uri.UriSchemeHttp)
                    {
                        e.Cancel = true;
                        ShellHelper.StartUri(e.Url);
                    }
                }
                catch (Exception exception)
                {
                    UiErrorHelper.HandExceptionSafely(this._framework, exception);
                }
            }
        }

        private void innerBrowser_NewWindow(object sender, CancelEventArgs e)
        {
            try
            {
                string statusText = this.innerBrowser.StatusText;
                if (IsValidUrl(statusText))
                {
                    e.Cancel = true;
                    ShellHelper.StartUrl(statusText);
                }
            }
            catch (Exception exception)
            {
                UiErrorHelper.HandExceptionSafely(this._framework, exception);
            }
        }

        private void innerPicBox_Click(object sender, EventArgs e)
        {
            try
            {
                string uriPortal = this._framework.AccountManager.CurrentUser.Configuration.SystemSetting.ServerUriSetting.UriPortal;
                if (IsValidUrl(uriPortal))
                {
                    ShellHelper.StartUrl(uriPortal);
                }
            }
            catch (Exception exception)
            {
                UiErrorHelper.HandExceptionSafely(this._framework, exception);
            }
        }

        private static bool IsValidUrl(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return false;
            }
            int index = url.IndexOf(Uri.SchemeDelimiter);
            if (index <= 0)
            {
                return false;
            }
            return Uri.CheckSchemeName(url.Substring(0, index));
        }

        private void NavigateToUrl(string url)
        {
            if (IsValidUrl(url))
            {
                if (this.innerPicBox.Visible)
                {
                    base.SuspendLayout();
                    this.innerPicBox.Visible = false;
                    Image image = this.innerPicBox.Image;
                    this.innerPicBox.Image = null;
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    ClientLogger.WriteBizOperation("ywq", "置NavigateToUrl:innerBrower可见");
                    this.innerBrowser.Visible = true;
                    base.ResumeLayout(true);
                }
                ClientLogger.WriteBizOperation("ywq--NavigateToUrl:Navigate", url);
                this.innerBrowser.Navigate(url);
            }
            else
            {
                ClientLogger.WriteBizOperation("ywq--非法url", url);
                base.SuspendLayout();
                ClientLogger.WriteBizOperation("ywq", "置NavigateToUrl:innerBrower不可见,Navigate(balnk)");
                this.innerBrowser.Visible = false;
                this.innerPicBox.Image = ImpsResources.GetImage("Images.ad.gif");
                this.innerPicBox.Visible = true;
                this.innerBrowser.Navigate("about:blank");
                base.ResumeLayout(true);
            }
        }

        private void notifyWnd_Click(object sender, EventArgs e)
        {
            try
            {
                ((SystemInfoNotify) sender).Close();
            }
            catch
            {
            }
        }

        public Control Bar
        {
            get
            {
                return this;
            }
        }

        private AdManager InnerAdManager
        {
            get
            {
                return this._framework.AccountManager.CurrentUser.AdManager;
            }
        }

        public string TargetUrl
        {
            get
            {
                return this.innerBrowser.Url.AbsoluteUri;
            }
            set
            {
                this.innerNavigate = true;
                this.NavigateToUrl(value);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -