Ejemplo n.º 1
0
        public static RequestValidationResult ResolveQueueRequestByLocalConfig(
            string targetUrl, string queueitToken, QueueEventConfig queueConfig,
            string customerId, string secretKey)
        {
            var debugEntries         = new Dictionary <string, string>();
            var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);

            if (connectorDiagnostics.HasError)
            {
                return(connectorDiagnostics.ValidationResult);
            }

            try
            {
                targetUrl = GenerateTargetUrl(targetUrl);
                return(ResolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, connectorDiagnostics.IsEnabled));
            }
            catch (Exception e)
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["Exception"] = e.Message;
                }
                throw;
            }
            finally
            {
                SetDebugCookie(debugEntries);
            }
        }
Ejemplo n.º 2
0
        public static RequestValidationResult ValidateRequestByIntegrationConfig(
            string currentUrlWithoutQueueITToken, string queueitToken,
            CustomerIntegration customerIntegrationInfo, string customerId, string secretKey)
        {
            var debugEntries         = new Dictionary <string, string>();
            var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);

            if (connectorDiagnostics.HasError)
            {
                return(connectorDiagnostics.ValidationResult);
            }
            try
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["SdkVersion"]    = UserInQueueService.SDK_VERSION;
                    debugEntries["Runtime"]       = GetRuntime();
                    debugEntries["ConfigVersion"] = customerIntegrationInfo != null?customerIntegrationInfo.Version.ToString() : "NULL";

                    debugEntries["PureUrl"]      = currentUrlWithoutQueueITToken;
                    debugEntries["QueueitToken"] = queueitToken;
                    debugEntries["OriginalUrl"]  = GetHttpContextProvider().HttpRequest.Url.AbsoluteUri;

                    LogExtraRequestDetails(debugEntries);
                }
                if (string.IsNullOrEmpty(currentUrlWithoutQueueITToken))
                {
                    throw new ArgumentException("currentUrlWithoutQueueITToken can not be null or empty.");
                }
                if (customerIntegrationInfo == null)
                {
                    throw new ArgumentException("customerIntegrationInfo can not be null.");
                }

                var configEvaluater = new IntegrationEvaluator();

                var matchedConfig = configEvaluater.GetMatchedIntegrationConfig(
                    customerIntegrationInfo,
                    currentUrlWithoutQueueITToken,
                    GetHttpContextProvider().HttpRequest);

                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["MatchedConfig"] = matchedConfig != null ? matchedConfig.Name : "NULL";
                }
                if (matchedConfig == null)
                {
                    return(new RequestValidationResult(null));
                }

                switch (matchedConfig.ActionType ?? string.Empty)
                {
                case "":    //backward compatibility
                case ActionType.QueueAction:
                {
                    return(HandleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
                                             customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled));
                }

                case ActionType.CancelAction:
                {
                    return(HandleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
                                              customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled));
                }

                default:
                {
                    return(HandleIgnoreAction(matchedConfig.Name));
                }
                }
            }
            catch (Exception e)
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["Exception"] = e.Message;
                }
                throw;
            }
            finally
            {
                SetDebugCookie(debugEntries);
            }
        }