예제 #1
0
 /// <summary>
 /// Sets the default API setting event handler. It is especially needed when ASP.NET do not host API but uses <see cref="RestApiContextConsistenceAttribute"/>
 /// </summary>
 /// <param name="apiEventHandler">The API event handler.</param>
 public static void SetDefaultApiSettingEventHandler(IRestApiEventHandlers apiEventHandler)
 {
     if (apiEventHandler != null)
     {
         RestApiSettingPool.DefaultRestApiSettings.EventHandlers = apiEventHandler;
     }
 }
예제 #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;
            }
        }