Ejemplo n.º 1
0
 /// <summary>
 /// Consists the context.
 /// </summary>
 /// <param name="httpRequest">The HTTP request.</param>
 /// <param name="settings">The settings.</param>
 internal static void ConsistContext(HttpRequestBase httpRequest, RestApiSettings settings)
 {
     if (httpRequest != null && settings != null)
     {
         ConsistContext(
             httpRequest.Headers.Get(HttpConstants.HttpHeader.TOKEN) ?? httpRequest.Cookies.TryGetValue(HttpConstants.HttpHeader.TOKEN),
             settings,
             httpRequest.UserHostAddress,
             httpRequest.UserAgent,
             httpRequest.QueryString.Get(HttpConstants.QueryString.Language).SafeToString(httpRequest.Cookies.Get(HttpConstants.QueryString.Language)?.Value).SafeToString(httpRequest.UserLanguages.SafeFirstOrDefault()).EnsureCultureCode(),
             httpRequest.Url,
             HttpExtension.GetBasicAuthentication(httpRequest.Headers.Get(HttpConstants.HttpHeader.Authorization).DecodeBase64()),
             new ApiUniqueIdentifier
         {
             HttpMethod = httpRequest.HttpMethod,
             Path       = httpRequest.Url.AbsolutePath
         }
             );
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Consists the context.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="setting">The setting.</param>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="userAgent">The user agent.</param>
        /// <param name="cultureCode">The culture code.</param>
        /// <param name="currentUri">The current URI.</param>
        /// <param name="basicAuthentication">The basic authentication.</param>
        /// <param name="apiUniqueIdentifier">The API unique identifier.</param>
        internal static void ConsistContext(string token, RestApiSettings setting, string ipAddress, string userAgent, string cultureCode, Uri currentUri, HttpCredential basicAuthentication, ApiUniqueIdentifier apiUniqueIdentifier)
        {
            IRestApiEventHandlers restApiEventHandlers = setting?.EventHandlers;

            var apiContext = ContextHelper.ApiContext;

            apiContext.UserAgent         = userAgent;
            apiContext.IpAddress         = ipAddress;
            apiContext.CultureCode       = cultureCode;
            apiContext.CurrentUri        = currentUri;
            apiContext.HttpAuthorization = basicAuthentication;
            apiContext.UniqueIdentifier  = apiUniqueIdentifier;

            if (restApiEventHandlers != null && !string.IsNullOrWhiteSpace(token))
            {
                apiContext.CurrentCredential = restApiEventHandlers.GetCredentialByToken(token);
                apiContext.Token             = token;
            }
            else
            {
                apiContext.CurrentCredential = null;
                apiContext.Token             = null;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RestApiContextConsistenceAttribute"/> class.
 /// </summary>
 /// <param name="restApiSetting">The rest API settings.</param>
 public RestApiContextConsistenceAttribute(RestApiSettings restApiSetting) : base()
 {
     settings    = restApiSetting ?? RestApiSettingPool.DefaultRestApiSettings;
     ApiTracking = restApiSetting?.ApiTracking;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Consists the context.
 /// </summary>
 /// <typeparam name="TRequest">The type of the request.</typeparam>
 /// <typeparam name="TResponse">The type of the response.</typeparam>
 /// <param name="context">The context.</param>
 /// <param name="settings">The settings.</param>
 internal static void ConsistContext <TRequest, TResponse>(HttpContextContainer <TRequest, TResponse> context, RestApiSettings settings)
 {
     ConsistContext(
         GetValueCompatibly(context, context, HttpConstants.HttpHeader.TOKEN),
         settings,
         context.ClientIpAddress,
         context.UserAgent,
         context.QueryString.Get(HttpConstants.QueryString.Language).SafeToString(context?.GetCookieValue(HttpConstants.QueryString.Language)).SafeToString(context.UserLanguages.SafeFirstOrDefault()).EnsureCultureCode(),
         context.Url,
         HttpExtension.GetBasicAuthentication(context.TryGetRequestHeader(HttpConstants.HttpHeader.Authorization).DecodeBase64()),
         new ApiUniqueIdentifier
     {
         HttpMethod = context.HttpMethod,
         Path       = context.Url.AbsolutePath
     }
         );
 }