Exemplo n.º 1
0
 public Uri BuildAbsoluteUri(NancyContext context, string routeName, dynamic parameters = null)
 {
   var parameterDictionary = ToDictionary(parameters as object ?? new { });
   var pathTemplate = GetRouteTemplateFromRouteName(routeName);
   if (pathTemplate == null)
     throw new UnknownRouteException(routeName, this.AllRoutes);
   var realizedPath = 
     this.segmentExtractor.Extract(pathTemplate.Path)
         .Aggregate("~", (accumulatedtPath, segment) => GetSegmentValue(segment, parameterDictionary, accumulatedtPath));
   return uriFilter.Apply(new Uri(GetBaseUri(context), context.ToFullPath(realizedPath)), context);
 }
        private void After(NancyContext nancyContext)
        {
            if (nancyContext.Response != null)
            {
                var status = (int) nancyContext.Response.StatusCode;
                var level = LogLevel.Error;

                if (status >= 400 && status <= 600)
                {
                    var req = nancyContext.Request;

                    if (status < 500)
                        level = LogLevel.Warn;

                    var logMessage = String.Format("Responding {0} for {1} to path {2}", status, req.Method,
                        nancyContext.ToFullPath(req.Path));
                    Logary.Logging.GetCurrentLogger()
                        .Log(level, logMessage, GetLogData(nancyContext), null, null, nancyContext.ToFullPath(req.Path));
                }

                nancyContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                nancyContext.Response.Headers.Add("Access-Control-Allow-Methods",
                    "GET, POST, PUT, DELETE, OPTIONS, PATCH");
                nancyContext.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
            }
        }
        private Response Error(NancyContext nancyContext, Exception ex)
        {
            var req = nancyContext.Request;
            var logMessage = string.Format("An error occurred handling {0} to {1}", nancyContext.Request.Method,
                nancyContext.ToFullPath(req.Path));

            Logary.Logging.GetCurrentLogger()
                .Log(LogLevel.Error, logMessage, GetLogData(nancyContext), null, ex, nancyContext.ToFullPath(req.Path));
            return nancyContext.Response;
        }
            private void RegisterFacebookOAuthClientPerRequest(TinyIoC.TinyIoCContainer container, NancyContext context)
            {
            var facebookOAuthClient =
                new Facebook.FacebookOAuthClient(container.Resolve<Facebook.IFacebookApplication>())
                    {
                        RedirectUri = new Uri("http://localhost:45254" + context.ToFullPath("~/facebook/login/callback"))
                    };

            container.Register(facebookOAuthClient);
            }