public void DoCreateUser_Bulk()
        {
            List<string[]> newUsers = ParseCSV(@"c:\newUsers.csv");

            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            foreach (var user in newUsers)
            {
                string NewUserName = (string)user.GetValue(0);
                string NewPassword = (string)user.GetValue(1);

                string strCreateUserJSON = "{Name:'" + UserName + "', Mail:'" + UserName + "', Password:'******'}";
                Centrify_API_Interface centCreateUser = new Centrify_API_Interface().MakeRestCall(CentCreateUserURL, strCreateUserJSON, centLogin.returnedCookie);
                var jssAdvanceAuthPoll = new JavaScriptSerializer();
                Dictionary<string, dynamic> centCreateUser_Dict = jssAdvanceAuthPoll.Deserialize<Dictionary<string, dynamic>>(centCreateUser.returnedResponse);

                if (centCreateUser_Dict["Message"].ToString() != null)
                {
                    Console.WriteLine("Error: " + centCreateUser_Dict["Message"].ToString());
                }
                else
                {
                    Console.WriteLine("Create User Successful.");
                }
            }
        }
        public void RunQuery(string strUserName, string strPassword)
        {
            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            string strQueryJSON = @"{""Script"":""select * from dsusers where SystemName = '" + strUserName + @"';"",""Args"":{""PageNumber"":1,""PageSize"":10000,""Limit"":10000,""SortBy"":"""",""direction"":""False"",""Caching"":-1}}";

            Centrify_API_Interface centQueryUser = new Centrify_API_Interface().MakeRestCall(CentQueryURL, strQueryJSON, centLogin.returnedCookie);
            var jssFindUser = new JavaScriptSerializer();
            Dictionary<string, dynamic> centQueryUser_Dict = jssFindUser.Deserialize<Dictionary<string, dynamic>>(centQueryUser.returnedResponse);

            if (centQueryUser_Dict["success"].ToString() == "True")
            {
                Console.WriteLine("User Found:");

                ArrayList centFindUser_Results = centQueryUser_Dict["Result"]["Results"];
                dynamic centFindUser_Results_Column = centFindUser_Results[0];
                Dictionary<string, dynamic> centFindUser_Results_Row = centFindUser_Results_Column["Row"];

                bool bEnabled = centFindUser_Results_Row["Enabled"];
                bool bLocked = centFindUser_Results_Row["Locked"];

                Console.WriteLine("Account Enabled is: " + bEnabled.ToString() + ", Account Locked is: " + bLocked.ToString());
            }
            else
            {
                Console.WriteLine("Error Running Query: " + centQueryUser_Dict["Message"].ToString());
            }
        }
        public AdvanceAuth DoAdvanceAuth(string strSessionId, string strTenantId, bool bRememberMe, string strMechId, string strAction, string strSecondMechId = null, string strSecondAction = null)
        {
            string strAdvanceAuthJSON;

            //Multiple operations can be made at once
            if (strSecondMechId != null)
            {
                strAdvanceAuthJSON = @"{""TenantId"":""" + strTenantId + @""",""SessionId"":""" + strSessionId + @""",""PersistentLogin"":" + bRememberMe.ToString().ToLower() + @",""MultipleOperations"":[{""MechanismId"":""" + strSecondMechId + @""",""Action"":""" + strSecondAction + @"""},{""MechanismId"":""" + strMechId + @""",""Action"":""" + strAction + @"""}]}";
            }
            //Or Single Operations can be made
            else
            {
                strAdvanceAuthJSON = @"{""TenantId"":""" + strTenantId + @""",""SessionId"":""" + strSessionId + @""",""PersistentLogin"":" + bRememberMe.ToString().ToLower() + @",""MechanismId"":""" + strMechId + @""",""Action"":""" + strAction + @"""}";
            }

            Centrify_API_Interface centAdvanceAuth = new Centrify_API_Interface().MakeRestCall(CentAdvanceAuthURL, strAdvanceAuthJSON);
            var jssAdvanceAuth = new JavaScriptSerializer();
            Dictionary<string, dynamic> centAdvanceAuth_Dict = jssAdvanceAuth.Deserialize<Dictionary<string, dynamic>>(centAdvanceAuth.returnedResponse);

            ResultSummery = centAdvanceAuth_Dict["Result"]["Summary"].ToString();
            AdvanceAuth_Dict = centAdvanceAuth_Dict;

            return this;

        }
        public void GetApps()
        {
            var jss = new JavaScriptSerializer();

            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);
            Dictionary<string, dynamic> loginData = jss.Deserialize<Dictionary<string, dynamic>>(centLogin.returnedResponse);

            //To pass a specific user name if you log in as an admin.
            //string appsJSON = "{username:'******'}";
            string appsJSON = @"{""force"":""True""}";
            Centrify_API_Interface centGetApps = new Centrify_API_Interface().MakeRestCall(CentGetAppsURL, appsJSON, centLogin.returnedCookie);           
            Dictionary<string, dynamic> getAppsData = jss.Deserialize<Dictionary<string, dynamic>>(centGetApps.returnedResponse);

            var dApps = getAppsData["Result"]["Apps"];
            string strAuth = loginData["Result"]["Auth"];

            int iCount = 0;

            foreach (var app in dApps)
            {
                string strDisplayName = app["DisplayName"];
                string strAppKey = app["AppKey"];
                string strIcon = app["Icon"];

                AddUrls(strAppKey, strDisplayName, strIcon, iCount, strAuth);

                iCount++;
            }
        }
        public void UpdateApp(string strNewUserName, string strNewPass, string strAppKey)
        {
            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            string UpdateAppJson = @"{""UserNameStrategy"":""Fixed"",""Password"":""" + strNewPass + @""",""UserNameArg"":""" + strNewUserName + @"""}";
            Centrify_API_Interface centUpdateApp = new Centrify_API_Interface().MakeRestCall(CentUpdateAppURL + strAppKey, UpdateAppJson, centLogin.returnedCookie);
        }
        public void DoModifyUser()
        {
            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            //A User GUID is needed to modify a user so the user will first need to be queried unless the GUID is hardcoded
            string strQueryJSON = @"{""Script"":""select * from dsusers where SystemName = '" + UserName + @"';"",""Args"":{""PageNumber"":1,""PageSize"":10000,""Limit"":10000,""SortBy"":"""",""direction"":""False"",""Caching"":-1}}";

            Centrify_API_Interface centQueryUser = new Centrify_API_Interface().MakeRestCall(CentQueryURL, strQueryJSON, centLogin.returnedCookie);
            var jssFindUser = new JavaScriptSerializer();
            Dictionary<string, dynamic> centQueryUser_Dict = jssFindUser.Deserialize<Dictionary<string, dynamic>>(centQueryUser.returnedResponse);

            if (centQueryUser_Dict["success"].ToString() == "True")
            {
                Console.WriteLine("User Found:");

                ArrayList centFindUser_Results = centQueryUser_Dict["Result"]["Results"];
                dynamic centFindUser_Results_Column = centFindUser_Results[0];
                Dictionary<string, dynamic> centFindUser_Results_Row = centFindUser_Results_Column["Row"];

                strUuid = centFindUser_Results_Row["InternalName"];
            }
            else
            {
                Console.WriteLine("Error Running Query: " + centQueryUser_Dict["Message"].ToString());
            }

            if (strUuid != "")
            {
                string strModifyUserJSON = @"{""ID"":""" + strUuid + @""", ""enableState"":" + bDisableAccount + @",""state"":""" + strState + @"""}";
                Centrify_API_Interface centSetUser = new Centrify_API_Interface().MakeRestCall(CentSetUserURL, strModifyUserJSON);
                var jss = new JavaScriptSerializer();
                Dictionary<string, dynamic> centSetUser_Dict = jss.Deserialize<Dictionary<string, dynamic>>(centSetUser.returnedResponse);

                if (centSetUser_Dict["success"].ToString() == "True")
                {
                    if (strNewPass != null)
                    {
                        string strSetPassJSON = @"{""ID"":""" + strUuid + @""",""ConfrimPassword"":""" + strConfirmNewPass + @""",""newPassword"":""" + strNewPass + @"""}";
                        Centrify_API_Interface centSetPass = new Centrify_API_Interface().MakeRestCall(CentSetPassURL, strSetPassJSON);
                        Dictionary<string, dynamic> centSetPass_Dict = jss.Deserialize<Dictionary<string, dynamic>>(centSetPass.returnedResponse);

                        if (centSetPass_Dict["success"].ToString() == "True")
                        {
                            Console.WriteLine("User Updated.");
                        }
                        else
                        {
                            Console.WriteLine("Failed to Set Password: "******"Failed to Modify user: " + centSetUser.returnedResponse);
                }
            }
        }
        public StartAuth DoStartAuth()
        {
            string strStartAuthJSON = @"{""User"":""" + UserName + @""", ""Version"":""1.0""}";
            Centrify_API_Interface centStartAuth = new Centrify_API_Interface().MakeRestCall(CentStartAuthURL, strStartAuthJSON);
            var jss = new JavaScriptSerializer();
            Dictionary<string, dynamic> centStartAuth_Dict = jss.Deserialize<Dictionary<string, dynamic>>(centStartAuth.returnedResponse);

            TenantId = centStartAuth_Dict["Result"]["TenantId"];
            SessionId = centStartAuth_Dict["Result"]["SessionId"];
            Challenges = centStartAuth_Dict["Result"]["Challenges"];

            return this;
        }
        public List<string> GetAppKey(string strRole)
        {
            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            string UpdateAppJson = "";
            Centrify_API_Interface centGetAppKey = new Centrify_API_Interface().MakeRestCall(CentGetRoleAppsURL + strRole, UpdateAppJson, centLogin.returnedCookie);
            var jssFindUser = new JavaScriptSerializer();
            Dictionary<string, dynamic> centGetAppKey_Dict = jssFindUser.Deserialize<Dictionary<string, dynamic>>(centGetAppKey.returnedResponse);

            ArrayList aApps = centGetAppKey_Dict["Result"];

            List<string> appKeys = new List<string>();
            int iCount = 0;

            foreach (Dictionary<string, dynamic> row in aApps)
            {
                appKeys[iCount] = row["ID"];
            }

            return appKeys;
        }
        public void DoModifyUser_Bulk()
        {
            List<string[]> modifyUsers = ParseCSV(@"c:\newUsers.csv");

            string loginJSON = "{user:'******', password:'******'}";
            Centrify_API_Interface centLogin = new Centrify_API_Interface().MakeRestCall(CentLoginURL, loginJSON);

            foreach (var user in modifyUsers)
            {
                string strModUserName = (string)user.GetValue(0);
                //A User GUID is needed to modify a user so the user will first need to be queried unless the GUID is hardcoded
                string strQueryJSON = @"{""Script"":""select * from dsusers where SystemName = '" + strModUserName + @"'""}";

                Centrify_API_Interface centQueryUser = new Centrify_API_Interface().MakeRestCall(CentQueryURL, strQueryJSON, centLogin.returnedCookie);
                var jssFindUser = new JavaScriptSerializer();
                Dictionary<string, dynamic> centQueryUser_Dict = jssFindUser.Deserialize<Dictionary<string, dynamic>>(centQueryUser.returnedResponse);

                if (centQueryUser_Dict["success"].ToString() == "True")
                {
                    Console.WriteLine("User Found:");

                    ArrayList centFindUser_Results = centQueryUser_Dict["Result"]["Results"];
                    dynamic centFindUser_Results_Column = centFindUser_Results[0];
                    Dictionary<string, dynamic> centFindUser_Results_Row = centFindUser_Results_Column["Row"];

                    strUuid = centFindUser_Results_Row["InternalName"];
                }
                else
                {
                    Console.WriteLine("Error Running Query: " + centQueryUser_Dict["Message"].ToString());
                }

                if (strUuid != "")
                {
                    bool bDisableAccount = (bool)user.GetValue(1);
                    string strState = (string)user.GetValue(2);
                    string strNewPass = (string)user.GetValue(3);
                    string strConfirmNewPass = (string)user.GetValue(4);

                    string strModifyUserJSON = @"{""ID"":""" + strUuid + @""", ""enableState"":" + bDisableAccount + @",""state"":""" + strState + @"""}";
                    Centrify_API_Interface centSetUser = new Centrify_API_Interface().MakeRestCall(CentSetUserURL, strModifyUserJSON);
                    var jss = new JavaScriptSerializer();
                    Dictionary<string, dynamic> centSetUser_Dict = jss.Deserialize<Dictionary<string, dynamic>>(centSetUser.returnedResponse);

                    if (centSetUser_Dict["success"].ToString() == "True" && centSetUser_Dict["success"].ToString() == "True")
                    {
                        if (strNewPass != null)
                        {
                            string strSetPassJSON = @"{""ID"":""" + strUuid + @""",""ConfrimPassword"":""" + strConfirmNewPass + @""",""newPassword"":""" + strNewPass + @"""}";
                            Centrify_API_Interface centSetPass = new Centrify_API_Interface().MakeRestCall(CentSetPassURL, strSetPassJSON);
                            Dictionary<string, dynamic> centSetPass_Dict = jss.Deserialize<Dictionary<string, dynamic>>(centSetPass.returnedResponse);

                            if (centSetPass_Dict["success"].ToString() == "True")
                            {
                                Console.WriteLine("User Updated.");
                            }
                            else
                            {
                                Console.WriteLine("Failed to Set Password: "******"Failed to Modify user: " + centSetUser.returnedResponse);
                    }
                }
            }
        }