Beispiel #1
0
        public string UrlFor(Type modelType, RouteParameters parameters, string categoryOrHttpMethod = null)
        {
            var    chain = resolver.FindUniqueByType(modelType, categoryOrHttpMethod);
            string url   = chain.Route.Input.CreateUrlFromParameters(parameters);

            return(_httpRequest.ToFullUrl(url));
        }
Beispiel #2
0
        public string UrlFor(Type modelType, RouteParameters parameters)
        {
            var    chain = resolver.FindUniqueByInputType(modelType);
            string url   = chain.Route.Input.CreateUrlFromParameters(parameters);

            return(_httpRequest.ToFullUrl(url));
        }
Beispiel #3
0
        //[AsymmetricJson]
        public ResourceDiscovery Execute()
        {
            var baseUrl         = _urlRegistry.UrlFor <ResourceDiscoveryAction>(m => m.Execute());
            var absoluteBaseUrl = _currentHttpRequest.ToFullUrl(baseUrl);

            var apis = _connegActionFinder
                       .ActionsByGroup()
                       .Where(a => a.Any(b => b.HasOutput && b.OutputType() == typeof(ResourceDiscovery)) == false) //HACK filter out this action
                       .Select(s =>
            {
                var description = "APIs for {0}".ToFormat(s.Key);

                //UGH we need to make api urls relative for swagger to be happy.
                var resourceAPIRequestUrl = _urlRegistry.UrlFor(new ResourceRequest {
                    GroupKey = s.Key
                });
                var resourceUrl = baseUrl.UrlRelativeTo(resourceAPIRequestUrl);

                return(new ResourceDiscoveryAPI
                {
                    path = resourceUrl,
                    description = description
                });
            });


            return(new ResourceDiscovery
            {
                basePath = absoluteBaseUrl,
                apiVersion = Assembly.GetExecutingAssembly().GetVersion(),
                swaggerVersion = "1.0",
                apis = apis.ToArray()
            });
        }
        //[AsymmetricJson]
        public Resource Execute(ResourceRequest request)
        {
            var baseUrl         = _urlRegistry.UrlFor(request);
            var absoluteBaseUrl = _currentHttpRequest.ToFullUrl(baseUrl);

            var apis = createSwaggerAPIs(request, baseUrl);

            //models support should go onto another branch.
            //var typeSet = new HashSet<Type>();
            //actions.Each(a =>
            //                {
            //                    if(a.HasInput) typeSet.Add(a.InputType());
            //                    if (a.HasOutput) typeSet.Add(a.OutputType());
            //                });

            return(new Resource
            {
                basePath = absoluteBaseUrl,
                resourcePath = "/" + request.GroupKey,            //SWAGGER HACK - this assumes that the resource path will always be relative to the basePath.
                apiVersion = Assembly.GetExecutingAssembly().GetVersion(),
                swaggerVersion = "1.0",
                apis = apis,
                //models = typeSet.ToArray()
            });
        }
Beispiel #5
0
        private string buildUrlTemplate(object model, string categoryOrHttpMethod, Func <object, object>[] hash)
        {
            var chain = resolver.FindUnique(model, categoryOrHttpMethod);

            string url = _templateFunc(chain.Route.CreateTemplate(model, hash));

            return(_httpRequest.ToFullUrl(url));
        }
Beispiel #6
0
        public ExampleHtmlWriter(IServiceLocator serviceLocator, IUrlRegistry urlRegistry, BehaviorGraph behaviorGraph, ICurrentHttpRequest httpRequest)
        {
            _serviceLocator = serviceLocator;
            _urlRegistry = urlRegistry;
            _behaviorGraph = behaviorGraph;
            _httpRequest = httpRequest;

            _examplePageUrl = httpRequest.ToFullUrl("_fubu/html/example");
        }
Beispiel #7
0
        public ExampleHtmlWriter(IServiceLocator serviceLocator, IUrlRegistry urlRegistry, BehaviorGraph behaviorGraph, ICurrentHttpRequest httpRequest)
        {
            _serviceLocator = serviceLocator;
            _urlRegistry    = urlRegistry;
            _behaviorGraph  = behaviorGraph;
            _httpRequest    = httpRequest;

            _examplePageUrl = httpRequest.ToFullUrl("_fubu/html/example");
        }
 public UrlContextModel Get(UrlRequest request)
 {
     return(new UrlContextModel()
     {
         RelativeUrl = _currentHttpRequest.RelativeUrl(),
         RawUrl = _currentHttpRequest.RawUrl(),
         FullUrl = _currentHttpRequest.ToFullUrl(request.FullUrl ?? "/")
     });
 }
Beispiel #9
0
        protected override Endpoint createResult(object model, BehaviorChain chain)
        {
            var urlFromInput = chain.Route.CreateUrlFromInput(model);

            return(new Endpoint {
                IsAuthorized = _authorizor.Authorize(chain, model) == AuthorizationRight.Allow,
                Url = _httpRequest.ToFullUrl(urlFromInput)
            });
        }
Beispiel #10
0
 // TODO -- trace here!!!
 public IEnumerable <HtmlTag> BuildTagsAndRecord(IEnumerable <MissingAssetTagSubject> subjects)
 {
     return(subjects.Select(s =>
     {
         var url = "missing/assets/" + s.Name;
         return new HtmlTag("script")
         .Attr("type", MimeType.Javascript.Value)
         .Attr("src", _httpRequest.ToFullUrl(url));
     }));
 }
        private void addLink(DiagnosticChain diagnosticChain, IDiagnosticContext context, ICurrentHttpRequest currentHttpRequest)
        {
            var url = currentHttpRequest.ToFullUrl(diagnosticChain.GetRoutePattern());
            var li = Add("li");
            li.Add("a").Attr("href", url).Text(diagnosticChain.Title).Attr("title", diagnosticChain.Description);

            if (context.CurrentChain() == diagnosticChain)
            {
                li.AddClass("active");
            }
        }
        public DiagnosticGroupsMenuTag(DiagnosticGraph groups, ICurrentHttpRequest httpRequest) : base("ul")
        {
            AddClass("dropdown-menu");
            Attr("role", "menu");
            Attr("aria-labelledby", "groups");

            groups.Groups().OrderBy(x => x.Title).Each(group => {
                var li = Add("li").Attr("role", "presentation");
                li.Add("a")
                    .Attr("role", "menuitem")
                    .Attr("tabindex", "-1")
                    .Attr("href", httpRequest.ToFullUrl(group.GetDefaultUrl()))
                    .Text(group.Title).Attr("title", group.Description);
            });
        }
Beispiel #13
0
        public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
        {
            var text = Text(chain);

            if (shouldBeClickable(chain))
            {
                cell.Append(new LinkTag(text, _request.ToFullUrl(chain.Route.Pattern)).AddClass("route-link"));
            }
            else
            {
                cell.Text(text);
            }
            if (text.StartsWith(DiagnosticUrlPolicy.DIAGNOSTICS_URL_ROOT))
            {
                row.AddClass(BehaviorGraphWriter.FUBU_INTERNAL_CLASS);
            }
        }
Beispiel #14
0
        public HtmlDocument GettingStarted()
        {
            var document = new FubuHtmlDocument(_services);

            document.Title = "Getting Started with FubuMVC";
            document.Add(x => x.Image("logo.png"));

            document.Push("div");
            document.Add("hr");

            // we're gonna cheat here since the diagnostics markers changed
            // TODO -- Share input models for the dashboard
            document.Add(new LinkTag("Diagnostics for your application", _request.ToFullUrl("_fubu")));

            document.Add("div").Encoded(false).Text(getContent());

            return(document);
        }
        public IEnumerable <NavigationMenuItem> MenuItems()
        {
            return(_actions
                   .OrderBy(a => a.Rank)
                   .ThenBy(a => a.Text())
                   .Select(a =>
            {
                var url = _httpRequest.ToFullUrl(a.Url());
                if (url.EndsWith("/"))
                {
                    url = url.TrimEnd('/');
                }

                return new NavigationMenuItem {
                    Text = a.Text(),
                    Url = a.Url(),
                    IsActive = url.Equals(_httpRequest.RawUrl())
                };
            }));
        }
Beispiel #16
0
        // TODO -- this could really use some more end to end testing
        public MenuItemToken BuildToken(MenuNode node)
        {
            var token = new MenuItemToken {
                Children = node.Children.Select(BuildToken).ToArray(),
                Key      = node.Key.Key,
                Text     = node.Key.ToString(),

                MenuItemState = _stateService.DetermineStateFor(node)
            };

            if (node.Icon().IsNotEmpty())
            {
                token.IconUrl = _urls.UrlForAsset(AssetFolder.images, node.Icon());
            }

            if (node.Type == MenuNodeType.Leaf)
            {
                token.Url = _request.ToFullUrl(node.CreateUrl());
            }

            return(token);
        }
        /// <summary>
        /// Resolve the url for a named asset
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string UrlForAsset(AssetFolder folder, string name)
        {
            var relativeUrl = DetermineRelativeAssetUrl(folder, name);

            return(_httpRequest.ToFullUrl(relativeUrl));
        }
Beispiel #18
0
        public string UrlFor(object model, BehaviorChain chain)
        {
            var url = chain.Route.CreateUrlFromInput(model);

            return(_httpRequest.ToFullUrl(url));
        }