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

📄 protocolpanel.cs

📁 Gibphone is CSharp Program, it can tell you how to design p2p chat.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using GPCore.Protocols;
using GPCore.Phones;
using GPCore.Vocoders;
using GPCore.NetworkProtocols;

namespace GPCore
{
    /// <summary>
    /// Provides a way to retrieve information from the user
    /// necessary to create a new account. Extend this class
    /// if you wish to add more fields.
    /// </summary>
    public partial class ProtocolPanel : UserControl
    {
        /// <summary>
        /// Creates a new <see cref="ProtocolPanel"/> without any type.
        /// </summary>
        protected ProtocolPanel() : this("") { }
        /// <summary>
        /// The FullName of the Type of the <see cref="IProtocol"/>
        /// to create in this panel.
        /// </summary>
        protected string protocolType;

        /// <summary>
        /// Creates a new <see cref="ProtocolPanel"/>.
        /// </summary>
        /// <param name="typename">The full name of the type of <see cref="IProtocol"/> this
        /// account will use to communicate with other people.</param>
        public ProtocolPanel(string typename)
        {
            protocolType = typename;
            InitializeComponent();
            OKButton.Click += new EventHandler(OKButton_Click);
        }

        /// <summary>
        /// The button that submits information to the given <see cref="IProtocol"/> and creates a new instance.
        /// Override this to initialize any extra information needed by the <see cref="IProtocol"/>.
        /// <remarks>
        /// An event handler will automatically be added to this button when the constructor for <see cref="ProtocolPanel"/>
        /// is called. It will automatically create an instance of the <see cref="IProtocol"/> and sign on.
        /// </remarks>
        /// </summary>
        public virtual Button OKButton
        {
            get { return cmdOK; }
        }

        /// <summary>
        /// This button closes down the form without submitting any information or instantiating any objects.
        /// </summary>
        public virtual Button CancelButton
        {
            get { return cmdCancel; }
        }

        /// <summary>
        /// Gets an object array supplying any extra information necessary to sign on.
        /// Override this if your <see cref="IProtocol"/> requires any extra information. It will 
        /// automatically be passed to SignOn.
        /// </summary>
        public virtual object[] Args
        {
            get { return null; }
        }

        void OKButton_Click(object sender, EventArgs e)
        {
            Protocol prot = Core.CreateInstance(protocolType, txtUsername.Text, txtPassword.Text, chkAuto.Checked, this.Args) as Protocol;
            if (prot is IPhone)
            {
                IVocoder vox = Core.CreateInstance(Core.PluginManager.Vocoders[0]) as IVocoder;
                INetworkProtocol nox = Core.CreateInstance(Core.PluginManager.NetworkProtocols[0]) as INetworkProtocol;
                Core.SavePhone(prot as IPhone,vox,nox);
                (prot as IPhone).Initialize(vox, nox);
            }
            if (chkSignin.Checked && prot.Connected == false) 
                (prot as IAuthenticate).SignOn();
        }
    }
}

⌨️ 快捷键说明

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