Пример #1
0
        private static bool RequestProcessorDuplicates(RequestProcessor <TAccount> first,
                                                       RequestProcessor <TAccount> second)
        {
            if (first == null || second == null)
            {
                return(false);
            }

            return(first.SubUri == second.SubUri && first.Method == second.Method);
        }
Пример #2
0
        public static bool AddRequestProcessor(RequestProcessor <TAccount> requestProcessor)
        {
            if (CheckRequestProcessor(requestProcessor) != true)
            {
                return(false);
            }

            requestProcessor.SubUri = requestProcessor.SubUri.Trim('/');
            var duplicate = InnerRequestProcessors.FirstOrDefault(rp => RequestProcessorDuplicates(rp, requestProcessor));

            if (duplicate != null)
            {
                InnerRequestProcessors.Remove(duplicate);
            }

            InnerRequestProcessors.Add(requestProcessor);
            return(true);
        }
Пример #3
0
        private static bool CheckRequestProcessor(RequestProcessor <TAccount> requestProcessor)
        {
            if (requestProcessor.SubUri == null)
            {
                return(false);
            }

            if (requestProcessor.Method == HttpMethod.Options || requestProcessor.Method == HttpMethod.Head)
            {
                LogMessage(LogLevel.Warning, $"Cannot explicitely register {requestProcessor.Method.Method.ToUpperInvariant()} processor");
                return(false);
            }

            var serviceDuplicate = ServiceUris.FirstOrDefault(su => requestProcessor.SubUri.Trim('/').StartsWith(su));

            if (serviceDuplicate != null)
            {
                LogMessage(LogLevel.Warning, $"Failed to register uri '{requestProcessor.SubUri}'. Section '{serviceDuplicate}' is reserved.");
                return(false);
            }

            return(true);
        }