Ejemplo n.º 1
0
        /// <summary>
        /// 注册新的打码平台实现类
        /// </summary>
        /// <param name="vcodeProvider"></param>
        public void RegisterPlatform(VcodeProvider vcodeProvider)
        {
            if (vcodeProvider == null)
            {
                throw new ArgumentNullException("vcodeProvider");
            }

            vcodeDict[vcodeProvider.Platform] = vcodeProvider;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更改已注册的打码平台的打码账户信息
        /// </summary>
        /// <param name="platform"></param>
        /// <param name="user"></param>
        /// <param name="pwd"></param>
        /// <param name="softId"></param>
        /// <param name="softKey"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public bool InitializePlatform(VcodePlatform platform, string user, string pwd, string softId = null, string softKey = null, object tag = null, bool setAsCurrentPlatform = false)
        {
            if (platform == null)
            {
                throw new ArgumentNullException("platform");
            }

            if (!vcodeDict.ContainsKey(platform))
            {
                throw new KeyNotFoundException("the platform is not found in SupportedPlatforms, you should register it first.");
            }

            var vcode = vcodeDict[platform];
            var force = vcode.Username != user || vcode.Password != pwd ||
                        vcode.SoftId != softId || vcode.SoftKey != softKey || vcode.Tag != tag;

            if (!string.IsNullOrEmpty(user))
            {
                vcode.Username = user;
            }
            if (!string.IsNullOrEmpty(pwd))
            {
                vcode.Password = pwd;
            }
            if (!string.IsNullOrEmpty(softId))
            {
                vcode.SoftId = softId;
            }
            if (!string.IsNullOrEmpty(softKey))
            {
                vcode.SoftKey = softKey;
            }
            if (tag != null)
            {
                vcode.Tag = tag;
            }
            var result = vcode.Initialize(force);

            if (result && setAsCurrentPlatform)
            {
                currentProvider = vcode;
            }
            return(result);
        }