示例#1
0
        private static string GetPathInfo()
        {
            string result = C1PageRoute.GetPathInfo() ?? string.Empty;

            if (result != string.Empty)
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(result);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            int  segment     = (int)parameters.GetParameter("Segment");
            bool autoApprove = (bool)parameters.GetParameter("AutoApprove");

            string result = GetPathInfoSegment(segment);

            if (autoApprove && !result.IsNullOrEmpty())
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(result ?? parameters.GetParameter <string>("FallbackValue"));
        }
示例#3
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var httpContext = new HttpContextWrapper(HttpContext.Current);
            var pathInfo    = C1PageRoute.GetPathInfo();
            var path        = "/" + Namespace + "." + Name + pathInfo;

            var response = new NancyC1FunctionHost().ProcessRequest(httpContext, path, parameters);

            try
            {
                var document = ParseContent(response.Content);

                if (response.StatusCode != HttpStatusCode.NotFound)
                {
                    C1PageRoute.RegisterPathInfoUsage();
                }

                return(document);
            }
            catch (Exception)
            {
                if (response.Content.Contains("<title>404</title>"))
                {
                    return(null);
                }

                if (response.StatusCode == HttpStatusCode.InternalServerError)
                {
                    const string startTag = "<pre id=\"errorContents\">";
                    const string endTag   = "</pre>";

                    var start = response.Content.IndexOf(startTag, StringComparison.OrdinalIgnoreCase) + startTag.Length;
                    var end   = response.Content.IndexOf(endTag, start, StringComparison.OrdinalIgnoreCase);

                    var error = response.Content.Substring(start, end - start);

                    C1PageRoute.RegisterPathInfoUsage();

                    throw new HttpException(error);
                }

                httpContext.Response.Clear();
                httpContext.Response.Write(response.Content);
                httpContext.Response.End();

                return(null);
            }
        }
示例#4
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var route = GetMvcRoute(parameters);

            var routeData = GetRouteData(route, parameters);

            if (routeData == null)
            {
                return(null);
            }

            bool routeResolved = false;

            XhtmlDocument result;

            try
            {
                result = ExecuteRoute(routeData, parameters, out routeResolved);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException ||
                    ex is HttpException ||
                    ex is ThreadInterruptedException ||
                    ex is StackOverflowException ||
                    ex is OutOfMemoryException)
                {
                    throw;
                }

                throw new InvalidOperationException($"Error executing route '{route}'", ex);
            }
            finally
            {
                if (routeResolved && HandlesPathInfo && C1PageRoute.GetPathInfo() != null)
                {
                    C1PageRoute.RegisterPathInfoUsage();
                }
            }

            if (result != null)
            {
                ProcessDocument(result, parameters);
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Creates an instace of <see cref="PathInfoRoutedData{T}"/>
        /// </summary>
        protected PathInfoRoutedData()
        {
            var urlMapper = GetUrlMapper();

            Verify.IsNotNull(urlMapper, "UrlMapper is null");

            DataUrls.RegisterDynamicDataUrlMapper(PageRenderer.CurrentPageId, typeof(T), new RoutedData.RoutedDataUrlMapperAdapter(urlMapper));

            var pageUrlData = C1PageRoute.PageUrlData;

            RoutedDataModel model;

            try
            {
                model = urlMapper.GetRouteDataModel(pageUrlData) ?? new RoutedDataModel();
            }
            catch (DataUrlCollisionException)
            {
                C1PageRoute.RegisterPathInfoUsage();
                throw;
            }

            SetModel(model);

            if (!string.IsNullOrEmpty(pageUrlData.PathInfo) && model.IsRouteResolved)
            {
                if (model.IsItem)
                {
                    var canonicalUrlData = urlMapper.BuildItemUrl(model.Item);
                    if (canonicalUrlData.PathInfo != pageUrlData.PathInfo)
                    {
                        string newUrl = PageUrls.BuildUrl(canonicalUrlData);
                        if (newUrl != null)
                        {
                            PermanentRedirect(newUrl);
                        }
                    }
                }

                C1PageRoute.RegisterPathInfoUsage();
            }
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            int  segment     = (int)parameters.GetParameter("Segment");
            bool autoApprove = (bool)parameters.GetParameter("AutoApprove");

            string value = PathInfoFunction.GetPathInfoSegment(segment);

            int intValue;

            if (string.IsNullOrEmpty(value) || !int.TryParse(value, out intValue))
            {
                return(parameters.GetParameter <int>("FallbackValue"));
            }

            if (autoApprove)
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(intValue);
        }
示例#7
0
        public async Task <object> ExecuteAsync(ParameterList parameters, FunctionContextContainer context)
        {
            string virtualRoute = GetMvcRoute(parameters);
            var    routeData    = GetRouteData(virtualRoute, parameters);

            if (routeData == null)
            {
                return(null);
            }

            CultureInfo culture          = C1PageRoute.PageUrlData.LocalizationScope;
            var         publicationScope = C1PageRoute.PageUrlData.PublicationScope;

            var httpContext = HttpContext.Current;
            var result      = await ExecuteRouteAsync(routeData, httpContext, culture, publicationScope);

            if (result != null && C1PageRoute.GetPathInfo() != null)
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(result);
        }
示例#8
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            C1PageRoute.RegisterPathInfoUsage();

            return(null);
        }