Esempio n. 1
0
 public HttpRequestModel(HttpOperation owner, HttpProviderAttribute httpClient, HttpPathAttribute httpPath, HttpMethodAttribute httpVerb, HttpTimeoutAttribute httpTimeout, HttpHeaderAttribute[] httpClassHeaders)
 {
     _owner = owner;
     _owner.Log("HttpRequestModel Initializing", LogSeverity.VERBOSE);
     _httpClient       = httpClient;
     _httpPath         = httpPath;
     _httpVerb         = httpVerb;
     _httpTimeout      = httpTimeout;
     _uriTemplates     = new Hashtable();
     _formFields       = new Hashtable();
     _binaryFormFields = new Dictionary <string, HttpBinaryFormField>();
     _httpHeaders      = new Dictionary <string, string>();
     _queryStrings     = new List <DictionaryEntry>();
     _stringBody       = null;
     _binaryBody       = null;
     _owner.Log("Processing class level maps.", LogSeverity.VERBOSE);
     foreach (HttpHeaderAttribute httpHeaderAttribute in httpClassHeaders)
     {
         if (httpHeaderAttribute.MapOnRequest())
         {
             _owner.Log("Processing map '" + httpHeaderAttribute.GetType().FullName + "'.", LogSeverity.VERBOSE);
             httpHeaderAttribute.Initialize();
             string text  = httpHeaderAttribute.OnRequestResolveName(_owner, null);
             object value = httpHeaderAttribute.OnRequestResolveValue(text, _owner, null);
             value = httpHeaderAttribute.OnRequestApplyConverters(value, _owner, null);
             if (!string.IsNullOrEmpty(text))
             {
                 AddHttpHeader(text, (value != null) ? value.ToString() : "");
             }
         }
     }
 }
Esempio n. 2
0
        protected virtual HttpRequest ToRequest(params string[] parameters)
        {
            InParameters  = parameters;
            TransactionId = $"{Guid.NewGuid().GetHashCode():X}";
            Log("<color=white><b>'" + GetType().FullName + "'</b> HTTP Operation Initializing</color>");
            HttpPathAttribute httpPath = GetHttpPath();

            HttpMethodAttribute[] array = (HttpMethodAttribute[])GetType().GetCustomAttributes(typeof(HttpMethodAttribute), inherit: true);
            if (array.Length == 0)
            {
                throw new Exception(GetType().Name + " class is missing [HttpMethod] attribute.");
            }
            if (array.Length > 1)
            {
                Log("Multiple [HttpMethod] attributes found.  Verb " + array[0].Verb + " will be used.", LogSeverity.ERROR);
            }
            Log("<color=green>" + array[0].Verb + "</color><color=cyan><b> " + httpPath.Uri + "</b></color>");
            HttpProviderAttribute[] array2 = (HttpProviderAttribute[])GetType().GetCustomAttributes(typeof(HttpProviderAttribute), inherit: true);
            if (array2.Length == 0)
            {
                array2 = new HttpProviderAttribute[1]
                {
                    new HttpProviderAttribute(Configuration.GetSetting <Type>("default-http-client"))
                };
                Log("Missing [HttpProvider] attribute.  Provider '" + array2[0].ProviderType.FullName + "' will be used.", LogSeverity.VERBOSE);
            }
            HttpTimeoutAttribute[] array3 = (HttpTimeoutAttribute[])GetType().GetCustomAttributes(typeof(HttpTimeoutAttribute), inherit: true);
            if (array3.Length == 0)
            {
                array3 = new HttpTimeoutAttribute[1]
                {
                    new HttpTimeoutAttribute(Configuration.GetSetting <float>("request-timeout"))
                };
            }
            Log("Request TTL : " + array3[0].Timeout + " seconds.", LogSeverity.VERBOSE);
            HttpHeaderAttribute[] httpClassHeaders = (HttpHeaderAttribute[])GetType().GetCustomAttributes(typeof(HttpHeaderAttribute), inherit: true);
            _cachedFieldInfos = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            HttpRequestModel model = new HttpRequestModel(this, array2[0], httpPath, array[0], array3[0], httpClassHeaders);

            FieldInfo[] cachedFieldInfos = _cachedFieldInfos;
            foreach (FieldInfo fieldInfo in cachedFieldInfos)
            {
                Log("Processing field '" + fieldInfo.Name + "'.", LogSeverity.VERBOSE);
                HttpMappedValueAttribute[] array4 = (HttpMappedValueAttribute[])fieldInfo.GetCustomAttributes(typeof(HttpMappedValueAttribute), inherit: true);
                HttpMappedValueAttribute[] array5 = array4;
                foreach (HttpMappedValueAttribute httpMappedValueAttribute in array5)
                {
                    if (httpMappedValueAttribute.MapOnRequest())
                    {
                        Log("Processing map '" + httpMappedValueAttribute.GetType().FullName + "'.", LogSeverity.VERBOSE);
                        httpMappedValueAttribute.Initialize();
                        string name  = httpMappedValueAttribute.OnRequestResolveName(this, fieldInfo);
                        object value = httpMappedValueAttribute.OnRequestResolveValue(name, this, fieldInfo);
                        value = httpMappedValueAttribute.OnRequestApplyConverters(value, this, fieldInfo);
                        httpMappedValueAttribute.OnRequestResolveModel(name, value, ref model, this, fieldInfo);
                    }
                }
            }
            HttpAuthorizationAttribute[] array6 = (HttpAuthorizationAttribute[])GetType().GetCustomAttributes(typeof(HttpAuthorizationAttribute), inherit: true);
            if (array6.Length > 0)
            {
                HttpAuthorizationAttribute httpAuthorizationAttribute = array6[0];
                Log("Processing map '" + httpAuthorizationAttribute.GetType().FullName + "'.", LogSeverity.VERBOSE);
                httpAuthorizationAttribute.Initialize();
                string name2  = httpAuthorizationAttribute.OnRequestResolveName(this, null);
                object value2 = httpAuthorizationAttribute.OnRequestResolveValue(name2, this, null);
                value2 = httpAuthorizationAttribute.OnRequestApplyConverters(value2, this, null);
                httpAuthorizationAttribute.OnRequestResolveModel(name2, value2, ref model, this, null);
            }
            HttpRequestModel.HttpRequestModelResult httpRequestModelResult = model.Build();
            Log(httpRequestModelResult.Summary(), LogSeverity.VERBOSE);
            Configuration.Log(httpRequestModelResult.LogSummary(), LogSeverity.DEBUG);
            return(new HttpRequest(httpRequestModelResult));
        }