Ejemplo n.º 1
0
 public static void ExecuteWebRequest(string Method, string URL, AuthCredentials Auth, IEnumerable <string> Headers, string ContentType, string Body, Dictionary <string, string> Variables, Action <int?, string, string> SetResultCallback)
 {
     if (URL != null)
     {
         // These headers are handled specially by HttpWebRequest and
         // can not be set via the generic Headers property.
         var restrictedHeaders = new Dictionary <string, Action <HttpWebRequest, string> >
         {
             { "Accept", (request, value) => { request.Accept = value; } },
Ejemplo n.º 2
0
        public void ExecuteImpl()
        {
            if (Trigger.HasValue && Trigger.Value == true && Trigger.WasSet)
            {
                string TranslateContentType(string contentTypeRaw)
                {
                    if (contentTypeRaw == "ContentType.Empty")
                    {
                        return(null);
                    }
                    else
                    {
                        return(contentTypeRaw);
                    }
                }

                string body        = Body != null ? (Body.HasValue ? Body.Value : null) : null;
                string contentType = ContentType != null ? (ContentType.HasValue ? TranslateContentType(ContentType.Value) : null) : null;
                Dictionary <string, string> variables = BuildDictionaryFromVariables(this.Variables);

                var thread = new Thread(() =>
                {
                    _BeforeExecute?.Invoke();
                    ExecuteWebRequest(
                        Method.HasValue ? Method.Value : null,
                        URL.HasValue ? URL.Value : null,
                        AuthCredentials.FromNodeParameters(AuthType, AuthToken, AuthUserName, AuthPassword),
                        Headers.Select(e => e.HasValue ? e.Value : throw new Exception("Did not expect a NULL header")),
                        contentType,
                        body,
                        variables,
                        (errorCode, errorMessage, response) =>
                    {
                        if (errorCode != null)
                        {
                            ErrorCode.Value = errorCode.Value;
                        }
                        if (errorMessage != null)
                        {
                            ErrorMessage.Value = errorMessage;
                        }
                        if (response != null)
                        {
                            Response.Value = response;
                        }
                        _AfterExecute?.Invoke();
                    });
                });
                thread.Start();
            }
        }