public override async Task <ActionResult> RunAsync(ActionProperties properties)
        {
            ActionResult actionResult = new ActionResult
            {
                Result = 0
            };

            try
            {
                SpringCMConnectorSettings settings = new SpringCMConnectorSettings(properties.Context.BusinessUnitGuid);
                bool   debug        = settings.DebugMode;
                string clientId     = string.Empty;
                string clientSecret = string.Empty;
                string authURL      = string.Empty;
                string requestURL   = string.Empty;
                string workflowName = string.Empty;
                string environment  = string.Empty;
                string xmlPayload   = string.Empty;

                var workflowDocs = new Dictionary <string, List <string> >
                {
                    { "Items", new List <string>() }
                };

                foreach (RoutingOption routingOption in properties.ActionInputs)
                {
                    ActionInput input = (ActionInput)routingOption;
                    if (input.ElementTypeId == this._workflowName)
                    {
                        workflowName = input.OutputValue;
                        if (string.IsNullOrEmpty(workflowName))
                        {
                            throw new ApplicationException("A SpringCM workflow name must be specified.  Please check your action attributes in Designer.");
                        }
                    }
                    else if (input.ElementTypeId == this._environment)
                    {
                        environment = input.OutputValue;
                        if (string.IsNullOrEmpty(environment))
                        {
                            throw new ApplicationException("A SpringCM environment must be specified.  Please check your action attributes in Designer.");
                        }
                    }
                    input = null;
                }

                if (environment == "prod")
                {
                    clientId     = settings.ClientId;
                    clientSecret = settings.ClientSecret;
                    authURL      = settings.AuthURL;
                    requestURL   = settings.RequestURL;
                }
                else
                {
                    clientId     = settings.UatClientId;
                    clientSecret = settings.UatClientSecret;
                    authURL      = settings.UatAuthURL;
                    requestURL   = settings.UatRequestURL;
                }

                bool flag = string.IsNullOrEmpty(clientId);
                if (flag)
                {
                    throw new Exception("Infiniti user name must be provided.  Please fix the connector settings in Manage.  Manage -> Settings -> Connector Settings -> SpringCM Connector");
                }
                bool flag2 = string.IsNullOrEmpty(clientSecret);
                if (flag2)
                {
                    throw new Exception("Infiniti password name must be provided.  Please fix the connector settings in Manage.  Manage -> Settings -> Connector Settings -> SpringCM Connector");
                }
                bool flag3 = string.IsNullOrEmpty(authURL);
                if (flag3)
                {
                    throw new Exception("An endpoint must be provided.  Please fix the connector settings in Manage.  Manage -> Settings -> Connector Settings -> SpringCM Connector");
                }
                bool flag4 = string.IsNullOrEmpty(requestURL);
                if (flag4)
                {
                    throw new Exception("An endpoint must be provided.  Please fix the connector settings in Manage.  Manage -> Settings -> Connector Settings -> SpringCM Connector");
                }

                for (int i = 0; i < properties.Documents.Count; i++)
                {
                    string docName = properties.Documents[i].DisplayName;
                    string text    = await this.GetDocumentTextAsync(properties, properties.Documents[i]);

                    string extension = properties.Documents[i].Extension;
                    if (extension == ".xml")
                    {
                        xmlPayload = text;
                    }
                    else
                    {
                        workflowDocs["Items"].Add(text);
                    }
                    text = null;
                }

                HttpClientHandler handler = new HttpClientHandler();
                HttpClient        client  = new HttpClient(handler);
                client.DefaultRequestHeaders.ExpectContinue = new bool?(false);
                JObject jobject = new JObject();
                jobject.Add("client_id", clientId);
                jobject.Add("client_secret", clientSecret);
                JObject login = jobject;
                if (debug)
                {
                    this.Log("JSON payload: " + login.ToString(), properties.Context.UserGuid, LogLevel.Info);
                    properties.AddMessage("JSON payload: " + login.ToString(), "SpringCM Initiate Workflow");
                }
                HttpResponseMessage httpResponseMessage = await client.PostAsync(authURL, new StringContent(login.ToString(), Encoding.UTF8, "application/json"));

                HttpResponseMessage authResponse = httpResponseMessage;
                httpResponseMessage = null;
                if (!authResponse.IsSuccessStatusCode)
                {
                    string text2 = await authResponse.Content.ReadAsStringAsync();

                    string authResponseContent = text2;
                    text2 = null;
                    this.Log(string.Concat(new object[]
                    {
                        "Could not make login web service call.  Response status code: ",
                        authResponse.StatusCode,
                        " response content",
                        authResponseContent,
                        " response reason phrase",
                        authResponse.ReasonPhrase
                    }), properties.Context.UserGuid, LogLevel.Info);
                    authResponseContent = null;
                }
                string bearerToken = string.Empty;
                string text3       = await authResponse.Content.ReadAsStringAsync();

                JObject token = JObject.Parse(text3);
                text3       = null;
                bearerToken = token["access_token"].ToString();
                JObject jobject2 = new JObject();

                jobject2.Add("Name", workflowName);
                jobject2.Add("Params", xmlPayload);
                if (workflowDocs["Items"].Count > 0)
                {
                    jobject2.Add("WorkflowDocuments", JsonConvert.SerializeObject(workflowDocs));
                }

                JObject workflow_config = jobject2;
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + bearerToken);
                HttpResponseMessage httpResponseMessage2 = await client.PostAsync(requestURL, new StringContent(workflow_config.ToString(), Encoding.UTF8, "application/json"));

                HttpResponseMessage generateResponse = httpResponseMessage2;
                httpResponseMessage2 = null;
                string text4 = await generateResponse.Content.ReadAsStringAsync();

                string generateResponseContent = text4;
                text4 = null;
                if (!generateResponse.IsSuccessStatusCode)
                {
                    this.Log(string.Concat(new object[]
                    {
                        "Could not make request web service call.  Response status code: ",
                        generateResponse.StatusCode,
                        " response content",
                        generateResponseContent,
                        " response reason phrase",
                        generateResponse.ReasonPhrase
                    }), properties.Context.UserGuid, LogLevel.Info);
                    properties.AddMessage(string.Concat(new object[]
                    {
                        "Could not make request web service call.  Response status code: ",
                        generateResponse.StatusCode,
                        " response content",
                        generateResponseContent,
                        " response reason phrase",
                        generateResponse.ReasonPhrase
                    }), "Infiniti REST Action");
                    throw new Exception("Error calling SpringCM");
                }

                actionResult.Result = Intelledox.QAWizard.Design.ActionResultType.Success;
                JObject jsonResponse = JObject.Parse(generateResponseContent);
                string  href         = jsonResponse["Href"].ToString();
                string  workflowID   = href.Substring(href.Length - 36);
                actionResult.Outputs = new List <Intelledox.Model.ActionOutput> {
                    new Intelledox.Model.ActionOutput()
                    {
                        ID    = _workflowID,
                        Name  = "Workflow ID",
                        Value = workflowID
                    }
                };
                settings         = null;
                clientId         = null;
                clientSecret     = null;
                authURL          = null;
                requestURL       = null;
                workflowName     = null;
                xmlPayload       = null;
                handler          = null;
                client           = null;
                login            = null;
                authResponse     = null;
                bearerToken      = null;
                token            = null;
                workflow_config  = null;
                generateResponse = null;
            }
            catch (ArgumentNullException ane)
            {
                properties.AddMessage("ArgumentNullException " + ane.Message, "SpringCM Initiate Workflow");
                properties.AddMessage("ArgumentNullException " + ane.InnerException.ToString(), "SpringCM Initiate Workflow");
                actionResult.Result = Intelledox.QAWizard.Design.ActionResultType.Fail;
            }
            catch (HttpRequestException hre)
            {
                properties.AddMessage("HttpRequestException " + hre.Message, "SpringCM Initiate Workflow");
                properties.AddMessage("HttpRequestException " + hre.InnerException.ToString(), "SpringCM Initiate Workflow");
                actionResult.Result = Intelledox.QAWizard.Design.ActionResultType.Fail;
            }
            catch (Exception ex)
            {
                properties.AddMessage("Exception " + ex.Message, "SpringCM Initiate Workflow");
                properties.AddMessage("Exception " + ex.Message.ToString(), "SpringCM Initiate Workflow");
                actionResult.Result = Intelledox.QAWizard.Design.ActionResultType.Fail;
            }
            return(actionResult);
        }
 public override List <GlobalSetting> GetAvailableGlobalSettings()
 {
     return(SpringCMConnectorSettings.GetAvailableGlobalSettings());
 }