Esempio n. 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Summary.Length != 0)
            {
                hash ^= Summary.GetHashCode();
            }
            hash ^= pages_.GetHashCode();
            hash ^= rules_.GetHashCode();
            if (DocumentationRootUrl.Length != 0)
            {
                hash ^= DocumentationRootUrl.GetHashCode();
            }
            if (ServiceRootUrl.Length != 0)
            {
                hash ^= ServiceRootUrl.GetHashCode();
            }
            if (Overview.Length != 0)
            {
                hash ^= Overview.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavContext"/> class.
        /// </summary>
        /// <param name="serviceProvider">The service provider used to get the <see cref="IWebDavDispatcher"/> with</param>
        /// <param name="httpContextAccessor">The <see cref="HttpContext"/> accessor</param>
        /// <param name="options">The options for the <see cref="WebDavContext"/></param>
        public WebDavContext(IServiceProvider serviceProvider, IHttpContextAccessor httpContextAccessor, IOptions <WebDavHostOptions> options)
        {
            var opt = options?.Value ?? new WebDavHostOptions();

            _httpContextAccessor       = httpContextAccessor;
            _serviceBaseUrl            = new Lazy <Uri>(() => BuildServiceBaseUrl(httpContextAccessor.HttpContext));
            _publicBaseUrl             = new Lazy <Uri>(() => BuildPublicBaseUrl(httpContextAccessor.HttpContext, opt));
            _publicRootUrl             = new Lazy <Uri>(() => new Uri(PublicBaseUrl, "/"));
            _serviceAbsoluteRequestUrl = new Lazy <Uri>(() => BuildAbsoluteServiceUrl(httpContextAccessor.HttpContext));
            _serviceRootUrl            = new Lazy <Uri>(() => new Uri(ServiceAbsoluteRequestUrl, "/"));
            _serviceRelativeRequestUrl = new Lazy <Uri>(() => ServiceRootUrl.MakeRelativeUri(ServiceAbsoluteRequestUrl));
            _publicAbsoluteRequestUrl  = new Lazy <Uri>(() => new Uri(PublicBaseUrl, ServiceBaseUrl.MakeRelativeUri(ServiceAbsoluteRequestUrl)));
            _actionUrl = new Lazy <Uri>(() => new Uri(httpContextAccessor.HttpContext.GetRouteValue("path").ToString(), UriKind.RelativeOrAbsolute));
            _publicRelativeRequestUrl = new Lazy <Uri>(() => new Uri(PublicBaseUrl, ActionUrl));
            _publicControllerUrl      = new Lazy <Uri>(() => new Uri(PublicBaseUrl, ControllerRelativeUrl));
            _controllerRelativeUrl    = new Lazy <Uri>(
                () =>
            {
                var path  = httpContextAccessor.HttpContext.GetRouteValue("path")?.ToString();
                var input = ServiceAbsoluteRequestUrl.ToString();
                string remaining;
                if (path != null)
                {
                    var pattern = string.Format("{0}$", Regex.Escape(path));
                    remaining   = Regex.Replace(input, pattern, string.Empty);
                }
                else
                {
                    remaining = input;
                }

                var serviceControllerAbsoluteUrl = new Uri(remaining);
                var result = ServiceBaseUrl.MakeRelativeUri(serviceControllerAbsoluteUrl);
                return(result);
            });
            _requestHeaders = new Lazy <WebDavRequestHeaders>(() =>
            {
                var request     = httpContextAccessor.HttpContext.Request;
                var headerItems = request.Headers.Select(x => new KeyValuePair <string, IEnumerable <string> >(x.Key, x.Value));
                return(new WebDavRequestHeaders(headerItems, this));
            });
            _detectedClient = new Lazy <IUAParserOutput>(() => DetectClient(httpContextAccessor.HttpContext));
            _principal      = new Lazy <IPrincipal>(() => httpContextAccessor.HttpContext.User);
            _dispatcher     = new Lazy <IWebDavDispatcher>(serviceProvider.GetRequiredService <IWebDavDispatcher>);
        }