Esempio n. 1
0
        Account IAccountHelper.CreateBy(Type connectionType, string connectionAccountName, string token)
        {
            //创建随机账号
            var account = new Account("a"
                + DateTime.Now.ToString("yyyyMMddHHmmss")
                + _rd.Next(10, 100));//TODO:随机数方式修改或改为guid
            this._accountService.Create(account);

            //创建连接
            AccountConnection connection = null;
            if (connectionType == typeof(GoogleConnection))
                connection = new GoogleConnection(connectionAccountName, token, account);
            else if (connectionType == typeof(GitHubConnection))
                connection = new GitHubConnection(connectionAccountName, token, account);
            else
                connection = this.GenerateConnection(account, connectionType, connectionAccountName, token);
            //指定令牌
            connection.SetToken(token);
            this._connectionService.Create(connection);

            if (this._log.IsInfoEnabled)
                this._log.InfoFormat("根据连接{0}|{1}创建账号#{2}"
                    , connectionType
                    , connectionAccountName
                    , account.ID);

            return account;
        }
Esempio n. 2
0
        public void CreateGoole()
        {
            var u = this.RandomString();
            var c = new GoogleConnection(u, _token, this.CreateAccount());
            this._accountConnectionService.Create(c);
            Assert.Greater(c.ID, 0);

            var c2 = this._accountConnectionService.GetConnection<GoogleConnection>(u);
            Assert.IsNotNull(c2);
            Assert.AreEqual(c2.ID, c.ID);
            Assert.AreEqual(c2.Name, c.Name);
        }
        /// <summary>
        /// 刷新GoogleToken信息
        /// </summary>
        private void RefreshConnectionToken(GoogleConnection connection)
        {
            _token = _googleTokenService.DeserializeToken(connection.Token);
            _googleTokenService.RefreshToken(_token);

            connection.SetToken(_googleTokenService.SerializeToken(_token));
            _accountConnectionService.Update(connection);
        }