BExISMigration.UserMigration.GetFromBExIS C# (CSharp) Method

GetFromBExIS() public method

public GetFromBExIS ( string DataBase ) : List
DataBase string
return List
        public List<UserProperties> GetFromBExIS(string DataBase)
        {
            List<UserProperties> transferUsers = new List<UserProperties>();

            // DB query
            string mySelectQuery = "select username, email, firstname, lastname, " +
                                   "organization, projectname, projectleader, " +
                                   "url, phone, mobile, fax, original, street, zipcode, city";
            mySelectQuery += " from provider.users;";
            DB2Connection connect = new DB2Connection(DataBase);
            DB2Command myCommand = new DB2Command(mySelectQuery, connect);
            connect.Open();
            DB2DataReader myReader = myCommand.ExecuteReader();
            // random password
            Random gen = new Random();
            while (myReader.Read())
            {
                UserProperties transferUser = new UserProperties();

                // bexis1 DB user data
                transferUser.username = myReader.GetValue(0).ToString();
                transferUser.email = myReader.GetValue(1).ToString();
                transferUser.firstname = myReader.GetValue(2).ToString();
                transferUser.lastname = myReader.GetValue(3).ToString();
                transferUser.organization = myReader.GetValue(4).ToString();
                transferUser.projectname = myReader.GetValue(5).ToString();
                transferUser.projectleader = myReader.GetValue(6).ToString();
                transferUser.url = myReader.GetValue(7).ToString();
                transferUser.phone = myReader.GetValue(8).ToString();
                transferUser.mobile = myReader.GetValue(9).ToString();
                transferUser.fax = myReader.GetValue(10).ToString();
                transferUser.original = myReader.GetValue(11).ToString();
                transferUser.street = myReader.GetValue(12).ToString();
                transferUser.zipcode = myReader.GetValue(13).ToString();
                transferUser.city = myReader.GetValue(14).ToString();
                // bexis2 required security data
                transferUser.password = randomPassword(ref gen); // random password
                transferUser.securityQuestionId = 1;
                transferUser.securityAnswer = "1";
                transferUser.authenticatorId = 1;

                // add to list; username required
                if (transferUser.username != "")
                    transferUsers.Add(transferUser);
            }
            myReader.Close();
            connect.Close();

            return transferUsers;
        }

Usage Example

Example #1
0
        public void UserMigration()
        {
            // data base of bexis1 user query
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");
            // names of the features witch set to the group "bexisUser"
            string[] featureNames = { "Search", "Data Collection", "Research Plan", "Data Dissemination" };

            UserMigration userMigration = new UserMigration();

            // create or get a group named "bexisUser"
            long groupId = userMigration.bexisUserGroup();

            // set feature permission of the group "bexisUser"
            userMigration.SetFeaturePermissions(groupId, featureNames);

            // query bexis1 user from provider.users and generate a random password
            List<UserProperties> BExISUsers = userMigration.GetFromBExIS(DataBase);

            // transfer users to bpp; not all user data are provided in bpp
            // save usernames and passwords in file "passwords.txt"
            userMigration.CreateOnBPP(BExISUsers, filePath, groupId);
        }