Пример #1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string server   = request.DataStore.GetJson("SqlCredentials")["Server"].ToString();
            string user     = request.DataStore.GetJson("SqlCredentials").SelectToken("User")?.ToString();
            string password = request.DataStore.GetJson("SqlCredentials").SelectToken("Password")?.ToString();
            var    auth     = request.DataStore.GetJson("SqlCredentials")["AuthType"].ToString();

            SqlCredentials credentials = new SqlCredentials()
            {
                Server         = server,
                Username       = user,
                Password       = password,
                Authentication = auth.EqualsIgnoreCase("Windows") ? SqlAuthentication.Windows : SqlAuthentication.SQL
            };

            var response = SqlUtility.GetListOfDatabases(credentials, true);

            return(response.Count == 0
                ? new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), "NoDatabasesFound")
                : new ActionResponse(ActionStatus.Success, JsonUtility.CreateJObjectWithValueFromObject(response)));
        }