Example #1
0
        public void Create_Success_UsernameShouldBeReflected()
        {
            var credentialResult = Credential.Create(_username, _password);

            Assert.True(credentialResult.IsSuccess);
            Assert.Equal(_username, credentialResult.Value.Username);
        }
        public List <Credential> GetCredentials(int limit, int offset)
        {
            List <Credential> credentials = new List <Credential>();

            MySql.Data.MySqlClient.MySqlConnection connection = (MySqlConnection)MySql.Data.MySqlClient.MySqlClientFactory.Instance.CreateConnection();
            connection.ConnectionString = _connectionString;
            connection.Open();

            string SQL = @"SELECT credential_id, current_flag, is_latest, b.name as program_type, a.name as credential_name, a.ds as description, a.lst_mod_dt, active_flag, c.name as org_name, transferability_id, program_mode, _external_credential_id, top_code
FROM  credential a left join credential_type b on a.credential_type_id = b.credential_type_id 
left join org_entity c on a.org_entity_id = c.org_entity_id
LIMIT {0}, {1}";

            using (MySqlCommand cmd = new MySqlCommand(string.Format(SQL, offset, limit), connection))
            {
                using (MySqlDataReader dr = (MySqlDataReader)cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Credential nextCred = Credential.Create(dr);
                        credentials.Add(nextCred);
                    }
                }
            }

            return(credentials);
        }
Example #3
0
        public void QrCreateTest()
        {
            if (Credential.CachedAccessToken == null)
            {
                var t = Credential.Create().AccessToken;
            }
            try
            {
                //生成带参数的二维码
                var ret = QrCodeManager.Default.Create(new QrCode
                {
                    action_name = QrCode.Temporary,
                    action_info = new QrCodeActionInfo()
                    {
                        scene = new QrCodeScene()
                        {
                            scene_id = 200
                        }
                    },
                    expire_seconds = 1800
                });

                Debug.WriteLine(ret.expire_seconds);
                Debug.WriteLine(ret.ticket);
            }
            catch (WxException ex)
            {
                Assert.Fail(ex.ErrMsg);
            }
        }
Example #4
0
        public void Create_Success_IsActiveIsAlwaysTrue()
        {
            var credentialResult = Credential.Create(_username, _password);

            Assert.True(credentialResult.IsSuccess);
            Assert.True(credentialResult.Value.IsActive);
        }
Example #5
0
        public void Authenticate_Fail_SuppliedPasswordIsNull()
        {
            var credential   = Credential.Create(_username, _password).Value;
            var authenticate = credential.Authenticate(null);

            Assert.False(authenticate);
        }
Example #6
0
        public void Authenticate_Fail_SuppliedPasswordIsEmptyString()
        {
            var credential   = Credential.Create(_username, _password).Value;
            var authenticate = credential.Authenticate(string.Empty);

            Assert.False(authenticate);
        }
Example #7
0
        public void Create_Success_PasswordShouldBeEncrypted()
        {
            var credentialResult = Credential.Create(_username, _password);

            Assert.True(credentialResult.IsSuccess);
            Assert.NotEqual(credentialResult.Value.Password, _password);
        }
Example #8
0
        public void Authenticate_Success()
        {
            var credential   = Credential.Create(_username, _password).Value;
            var authenticate = credential.Authenticate(_password);

            Assert.True(authenticate);
        }
Example #9
0
        private void PasswordOkButton_Click(object sender, RoutedEventArgs e)
        {
            credential = Credential.Create(new PasswordEnrollmentData(OldPasswordTextBox.Password, NewPasswordTextBox.Password));

            DialogResult = true;
            Close();
        }
Example #10
0
 public void Create_Fail_UsernameHasOtherSpecialCharacters()
 {
     Assert.True(Credential.Create("u`sername", _password).IsFailure);
     Assert.True(Credential.Create("u~sername", _password).IsFailure);
     Assert.True(Credential.Create("u!sername", _password).IsFailure);
     Assert.True(Credential.Create("u@sername", _password).IsFailure);
     Assert.True(Credential.Create("u#sername", _password).IsFailure);
     Assert.True(Credential.Create("u$sername", _password).IsFailure);
     Assert.True(Credential.Create("u%sername", _password).IsFailure);
     Assert.True(Credential.Create("u^sername", _password).IsFailure);
     Assert.True(Credential.Create("u&sername", _password).IsFailure);
     Assert.True(Credential.Create("u*sername", _password).IsFailure);
     Assert.True(Credential.Create("u(sername", _password).IsFailure);
     Assert.True(Credential.Create("u)sername", _password).IsFailure);
     Assert.True(Credential.Create("u-sername", _password).IsFailure);
     Assert.True(Credential.Create("u=sername", _password).IsFailure);
     Assert.True(Credential.Create("u+sername", _password).IsFailure);
     Assert.True(Credential.Create("u[sername", _password).IsFailure);
     Assert.True(Credential.Create("u{sername", _password).IsFailure);
     Assert.True(Credential.Create("u]sername", _password).IsFailure);
     Assert.True(Credential.Create("u}sername", _password).IsFailure);
     Assert.True(Credential.Create("u\\sername", _password).IsFailure);
     Assert.True(Credential.Create("u|sername", _password).IsFailure);
     Assert.True(Credential.Create("u;sername", _password).IsFailure);
     Assert.True(Credential.Create("u:sername", _password).IsFailure);
     Assert.True(Credential.Create("u'sername", _password).IsFailure);
     Assert.True(Credential.Create("u\"sername", _password).IsFailure);
     Assert.True(Credential.Create("u,sername", _password).IsFailure);
     Assert.True(Credential.Create("u<sername", _password).IsFailure);
     Assert.True(Credential.Create("u.sername", _password).IsFailure);
     Assert.True(Credential.Create("u>sername", _password).IsFailure);
     Assert.True(Credential.Create("u/sername", _password).IsFailure);
     Assert.True(Credential.Create("u?sername", _password).IsFailure);
 }
        public Credential GetCredential(string credentialId)
        {
            Credential nextCred = null;

            MySql.Data.MySqlClient.MySqlConnection connection = (MySqlConnection)MySql.Data.MySqlClient.MySqlClientFactory.Instance.CreateConnection();
            connection.ConnectionString = _connectionString;
            connection.Open();

            string SQL = string.Format(@"SELECT credential_id, current_flag, is_latest, b.name as program_type, a.name as credential_name, a.ds as description, a.lst_mod_dt, active_flag, c.name as org_name, transferability_id, program_mode, _external_credential_id, top_code
FROM  credential a left join credential_type b on a.credential_type_id = b.credential_type_id 
left join org_entity c on a.org_entity_id = c.org_entity_id where credential_id = '{0}'", credentialId);

            using (MySqlCommand cmd = new MySqlCommand(SQL, connection))
            {
                using (MySqlDataReader dr = (MySqlDataReader)cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        nextCred       = Credential.Create(dr);
                        nextCred.sloes = (new OutcomeData(_connectionString)).GetCredentialOutcomes(credentialId);
                    }
                }
            }

            return(nextCred);
        }
Example #12
0
        public void UserPagedListTest()
        {
            if (Credential.CachedAccessToken == null)
            {
                var t = Credential.Create().AccessToken;
            }
            try
            {
                //回调函数
                var callback = new Action <WxUserListResult, int>((ret, currentPage) =>
                {
                    Debug.WriteLine("总数:" + ret.total + ",当前页:" + currentPage);
                    foreach (var s in ret.data.openid)
                    {
                        Debug.WriteLine(s);
                    }
                });

                //分页获取,每页10000
                UserManager.Default.GetUserList(callback);
            }
            catch (WxException ex)
            {
                Assert.Fail(ex.ErrMsg);
            }
        }
Example #13
0
        public void QueryGroupTest()
        {
            try
            {
                if (string.IsNullOrEmpty(Credential.CachedAccessToken))
                {
                    var t = Credential.Create().AccessToken;
                }

                //获得所有分组
                var r = GroupManager.Default.Query();

                Debug.WriteLine("分组数:" + r.Groups.Count);
                foreach (var g in r.Groups)
                {
                    Debug.WriteLine(g.ID);
                    Debug.WriteLine(g.Name);
                }
            }
            catch (WxException ex)
            {
                Debug.WriteLine(ex.ErrMsg);

                Assert.Fail(ex.Message);
            }
        }
        public void CreateCredential(DatabaseServer server, CredentialsSpec credentials)
        {
            var serverConn = CreateServerConnection(server);

            var newCredential = new Credential(serverConn, credentials.CredentialName);

            newCredential.Create(credentials.Identity, credentials.Secret.Value);
        }
        public async Task HandleAsync(AddCredentialCommand message,
                                      CancellationToken token = default(CancellationToken))
        {
            var user = await this.GetUserAsync(message.UserId, token);

            user.AddCredential(Credential.Create(message.CredentialTypeId,
                                                 message.Identifier, message.Secret));
            await _users.SaveChangesAsync(token);
        }
Example #16
0
        public void Authenticate_Fail_DeactivatedCredential()
        {
            var credential = Credential.Create(_username, _password).Value;

            credential.Deactivate();
            var authenticate = credential.Authenticate(_password);

            Assert.False(authenticate);
        }
Example #17
0
        public void QueryMenu()
        {
            var h = MenuHelper.Create();

            h.AccessToken = Credential.Create().AccessToken;
            var menu = h.QueryMenu();

            Debug.WriteLine(menu);
            Assert.IsNotNull(menu);
        }
Example #18
0
        public void DeleteMenu()
        {
            var h = MenuHelper.Create();

            h.AccessToken = Credential.Create().AccessToken;
            var r = h.DeleteMenu();

            Debug.WriteLine(r.ErrMsg);
            Assert.IsTrue(r.IsSuccess);
        }
Example #19
0
        public Credential AuthenticateUser(string username, string password)
        {
            InternalCredential userData = _users.FirstOrDefault(u => u.Username.Equals(username) && u.Hashed.Equals(CalculateHash(password, u.Username)));

            if (userData == null)
            {
                throw new UnauthorizedAccessException(Resources.AuthenticationService_UnauthorizedAccess);
            }
            return(Credential.Create(userData.Username, userData.Password, userData.Description));
        }
Example #20
0
        private void OtpOkButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(OneTimePasswordTextBox.Text))
            {
                return;
            }

            credential   = Credential.Create(new OtpEnrollmentData(OneTimePasswordTextBox.Text, otpEnrollmentKey));
            DialogResult = true;
        }
Example #21
0
        private void CardOkButton_Click(object sender, RoutedEventArgs e)
        {
            var card = CardsListBox.SelectedItem as Tuple <string, Card>;

            if (card == null)
            {
                return;
            }

            credential   = Credential.Create(new CardEnrollmentData(card.Item2.Id));
            DialogResult = true;
        }
        public void MultiTokenCacheTest()
        {
            //从配置文件读取appid和appsecret
            var c = Credential.Create();

            var s = c.AccessToken;

            var s2 = c.AccessToken;

            Debug.WriteLine(s);

            Assert.AreEqual(s, s2);
        }
Example #23
0
        public void UpdateGroupTest()
        {
            if (string.IsNullOrEmpty(Credential.CachedAccessToken))
            {
                var t = Credential.Create().AccessToken;
            }
            var r = GroupManager.Default.Update(new WxGroup {
                ID = 100, Name = "test-modified"
            });

            Debug.WriteLine(r.ErrMsg);

            Assert.IsTrue(r.IsSuccess);
        }
Example #24
0
        private void LiveQuestionButton_Click(object sender, RoutedEventArgs e)
        {
            if (LiveAnswers.Any(string.IsNullOrWhiteSpace) || SelectedQuestions.Any(p => p == null))
            {
                return;
            }

            var answerData = new List <LiveQuestionAnswer>();

            for (int i = 0; i < 3; i++)
            {
                answerData.Add(new LiveQuestionAnswer(SelectedQuestions[i], LiveAnswers[i]));
            }

            credential   = Credential.Create(new LiveQuestionEnrollmentData(answerData));
            DialogResult = true;
        }
Example #25
0
 public void QrDownTest()
 {
     if (Credential.CachedAccessToken == null)
     {
         var t = Credential.Create().AccessToken;
     }
     try
     {
         QrCodeManager.Default.Exchange(
             "gQE48DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xLzUwekp5OG5sbk56bGFPSEtSR0tzAAIE81y1UgMECAcAAA==", //ticket
             @"F:\移动硬盘\图片\qrcode.jpg");                                                                          //保存路径
     }
     catch (WxException ex)
     {
         Assert.Fail(ex.ErrMsg);
     }
 }
        public void PushNewsTest()
        {
            if (Credential.CachedAccessToken == null)
            {
                var t = Credential.Create().AccessToken;
            }

            //图片图文
            var news = new NewsMsgDataForPush();//定义图片内容

            news.Articles.AddRange(new List <NewsMsgDataItemForPush>
            {
                new NewsMsgDataItemForPush()
                {
                    Description = "这是描述",
                    PicUrl      = "http://blog.tecd.pw/wp-content/uploads/http://bcs.duapp.com/td-bucket//blog/201309//QQ%E5%9B%BE%E7%89%8720130914160223.jpg",
                    Title       = "这是标题",
                    Url         = "http://blog.tecd.pw"
                },
                new NewsMsgDataItemForPush()
                {
                    Description = "这是描述",
                    PicUrl      = "http://blog.tecd.pw/wp-content/uploads/http://bcs.duapp.com/td-bucket//blog/201309//QQ%E5%9B%BE%E7%89%8720130914160223.jpg",
                    Title       = "这是标题",
                    Url         = "http://blog.tecd.pw"
                },
                new NewsMsgDataItemForPush()
                {
                    Description = "这是描述",
                    PicUrl      = "http://blog.tecd.pw/wp-content/uploads/http://bcs.duapp.com/td-bucket//blog/201309//QQ%E5%9B%BE%E7%89%8720130914160223.jpg",
                    Title       = "这是标题",
                    Url         = "http://blog.tecd.pw"
                },
            });
            var msg = new NewsMessageForPush()
            {
                ToUser = "******",
                News   = news
            };
            var ret = MessagePusher.Default.Push(msg);

            Debug.WriteLine(ret.ErrMsg);

            Assert.IsTrue(ret.IsSuccess);
        }
Example #27
0
        public void UserInfoTest()
        {
            if (Credential.CachedAccessToken == null)
            {
                var t = Credential.Create().AccessToken;
            }
            try
            {
                //获取用户基本信息
                var ret = UserManager.Default.GetUserInfo(_openid);

                Debug.WriteLine(ret.openid + ret.nickname);
            }
            catch (WxException ex)
            {
                Assert.Fail(ex.ErrMsg);
            }
        }
Example #28
0
        private void FingerprintOkButton_Click(object sender, RoutedEventArgs e)
        {
            if (fingerprintImage == null)
            {
                return;
            }

            FingerPosition position = FingerPosition.Unknown;

            if (FingerprintPosition.SelectedIndex >= 0)
            {
                position = (FingerPosition)(FingerprintPosition.SelectedIndex + 1);
            }
            credential = Credential.Create(new FingerprintEnrollmentData(position, fingerprintEnrollmentData));

            DialogResult = true;
            Close();
        }
Example #29
0
        public void DownloadMediaTest()
        {
            //mLtXk9ttRQaWBC0Cjzg24ZXtx0mcSInMcssLCWi2qbpUSuWbkeCYumwMkmZPtFz-
            if (Credential.CachedAccessToken == null)
            {
                var t = Credential.Create().AccessToken;
            }

            //下载
            //文件的保存路径。如果不确定以什么文件名保存,希望以默认文件名(媒体id为文件名)保存,可指定以反斜杠"\"结尾的文件名
            var directory = @"F:\移动硬盘\图片\images\f.jpg";

            var ret = MediaManager.Default.Download("mLtXk9ttRQaWBC0Cjzg24ZXtx0mcSInMcssLCWi2qbpUSuWbkeCYumwMkmZPtFz-", directory);

            Debug.WriteLine(ret.ErrMsg, ret.ErrCode);

            Assert.IsTrue(ret.IsSuccess);
        }
Example #30
0
        public void CreateGroupTest()
        {
            try
            {
                if (string.IsNullOrEmpty(Credential.CachedAccessToken))
                {
                    var t = Credential.Create().AccessToken;
                }
                var r = GroupManager.Default.Create("我的分组");

                Debug.WriteLine(r.Group.ID);
                Debug.WriteLine(r.Group.Name);
            }
            catch (WxException ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public static void CopyDatabase(MyArgs parms)
        {
            //remove trailing slash on the path if provided by user
            if (parms.PathToLocalMdf.EndsWith("\\"))
                parms.PathToLocalMdf = parms.PathToLocalMdf.Substring(0, parms.PathToLocalMdf.Length - 1);

            //Set Source SQL Server (SQL Azure)
            Server sourceServer = new Server(new ServerConnection(parms.SourceServer, parms.SourceUser, parms.SourcePassword));
            Database sourceDatabase = sourceServer.Databases[parms.SourceDatabase];

            //Set Destination SQL Server (SQL IaaS)
            Server destServer = new Server(new ServerConnection(parms.DestinationServer, parms.DestinationUser, parms.DestinationPassword));
            Database destDatabase = null;

            //Drop the detination database if it exits
            if (destServer.Databases.Contains(parms.DestinationDatabase))
            {
                Console.Write($"Destintation DB {parms.DestinationDatabase} on {destServer.Name} Exists. Dropping.");
                destServer.KillDatabase(parms.DestinationDatabase);
                Console.WriteLine(" . . . Done!");
            }

            //create the temp database on SQL IaaS
            Console.Write($"Creating Destintation DB {parms.DestinationDatabase} on {destServer.Name}.");
            destDatabase = new Database(destServer, parms.DestinationDatabase);

            var fg = new FileGroup(destDatabase, "PRIMARY");
            destDatabase.FileGroups.Add(fg);

            var df = new DataFile(fg, $"{parms.DestinationDatabase}_data");
            fg.Files.Add(df);
            df.FileName = $"{parms.PathToLocalMdf}\\{parms.DestinationDatabase}.mdf";
            df.IsPrimaryFile = true;
            df.Growth = 10;
            df.GrowthType = FileGrowthType.Percent;

            destDatabase.Create();
            Console.WriteLine(" . . . Done!");

            //Transfer the schema and data from SQL Azure to SQL IaaS
            Console.WriteLine("Starting Transfer...");
            Transfer transfer = new Transfer(sourceDatabase);
            transfer.DataTransferEvent += (object sender, DataTransferEventArgs e) =>
            {
                Console.WriteLine($"{e.DataTransferEventType}: {e.Message}");
            };

            transfer.CopyAllObjects = true;
            transfer.Options.WithDependencies = true;
            transfer.Options.Triggers = true;
            transfer.Options.Indexes = true;
            transfer.Options.ClusteredIndexes = true;
            transfer.Options.Default = true;
            transfer.Options.DriAll = true;
            transfer.CopyData = true;

            transfer.DestinationServer = parms.DestinationServer;
            transfer.DestinationDatabase = parms.DestinationDatabase;

            transfer.TransferData();

            Console.WriteLine("Transfer Complete!");

            //Create a backup credential in the SQL IaaS instance to perform the backup to Azure Blob
            Console.Write("Creating Backup Credential...");
            if (destServer.Credentials.Contains("BackupCred"))
            {
                Console.Write(" Dropping ");
                destServer.Credentials["BackupCred"].Drop();
            }

            Credential credential = new Credential(destServer, "BackupCred");
            credential.Create(parms.StorageAccountName, parms.StorageKey);
            Console.WriteLine(" Complete!");

            string storageEndpoint = $"https://{parms.StorageAccountName}.{parms.StorageEndpointBase}/{parms.StorageContainer}/{parms.StorageFileBase}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm}.bak";

            //Perform the backup from SQL IaaS to Azure Blob
            //https://msdn.microsoft.com/en-us/library/dn435916.aspx
            Console.WriteLine("Starting Backup...");
            Backup backup = new Backup();
            backup.Action = BackupActionType.Database;
            backup.Database = parms.DestinationDatabase;
            backup.Devices.Add(new BackupDeviceItem(storageEndpoint, DeviceType.Url, "BackupCred"));
            backup.CredentialName = "BackupCred";
            backup.Incremental = false;
            backup.SqlBackup(destServer);
            Console.WriteLine("Backup Complete!");
        }