Пример #1
0
        private static string GetEmbeddedStaticContent(string virtualDirectory, string requestedFilename, string root = null)
        {
            var resource =
                string.Format("/{0}/{1}", virtualDirectory, requestedFilename);

            var context =
                new NancyContext
            {
                Request = new Request("GET", resource, "http")
            };

            var assembly =
                Assembly.GetExecutingAssembly();

            var resolver =
                EmbeddedStaticContentConventionBuilder.AddDirectory(virtualDirectory, assembly, "Resources");

            var response =
                resolver.Invoke(context, null) as EmbeddedFileResponse;

            if (response != null)
            {
                using (var stream = new MemoryStream())
                {
                    response.Contents(stream);
                    return(Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length));
                }
            }

            return(null);
        }
Пример #2
0
        protected override void ConfigureConventions(NancyConventions nancyConventions)
        {
            base.ConfigureConventions(nancyConventions);

            nancyConventions.StaticContentsConventions.Add(
                EmbeddedStaticContentConventionBuilder.AddDirectory("Content", typeof(Bootstrapper).Assembly, "content"));
        }
Пример #3
0
        private static string GetEmbeddedStaticContent(string virtualDirectory, string requestedFilename, string contentPath = null)
        {
            var resource =
                string.Format("/{0}/{1}", virtualDirectory, requestedFilename);

            var context =
                new NancyContext
            {
                Request = new Request("GET", resource, "http"),
                Trace   = new DefaultRequestTrace
                {
                    TraceLog = new DefaultTraceLog()
                }
            };

            var assembly =
                typeof(EmbeddedStaticContentConventionBuilderFixture).GetAssembly();

            var resolver =
                EmbeddedStaticContentConventionBuilder.AddDirectory(virtualDirectory, assembly, contentPath ?? "Resources");

            var response =
                resolver.Invoke(context, null) as EmbeddedFileResponse;

            if (response != null)
            {
                using (var stream = new MemoryStream())
                {
                    response.Contents(stream);
                    return(Encoding.UTF8.GetString(stream.ToArray()));
                }
            }

            return(null);
        }
Пример #4
0
        private static Response GetEmbeddedStaticContentResponse(string virtualDirectory, string requestedFilename, string root = null, IDictionary <string, IEnumerable <string> > headers = null)
        {
            var resource = string.Format("/{0}/{1}", virtualDirectory, requestedFilename);

            var context = GetContext(virtualDirectory, requestedFilename, headers);

            var assembly = Assembly.GetExecutingAssembly();

            var resolver = EmbeddedStaticContentConventionBuilder.AddDirectory(virtualDirectory, assembly, "Resources");

            return(resolver.Invoke(context, null));
        }
        public static void RegisterStaticEmbedded(NancyConventions nancyConventions)
        {
            //Need to register static content for embedded. Views work out of the box
            var staticContentsConventions = nancyConventions.StaticContentsConventions;

            staticContentsConventions.Clear();

            var assembly = GetAssembly();

            foreach (var asset in _assetLocations)
            {
                staticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory(asset, assembly));
            }
        }
Пример #6
0
        protected override void ConfigureConventions(NancyConventions conventions)
        {
            base.ConfigureConventions(conventions);
            conventions.StaticContentsConventions.AddDirectory("/Scripts");
            conventions.StaticContentsConventions.AddDirectory("/cdn");
            conventions.StaticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory("/_kola/fonts", typeof(ClientIdentifier).Assembly, "/fonts"));
            conventions.StaticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory("/_kola/scripts", typeof(ClientIdentifier).Assembly, "/scripts"));
            conventions.StaticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory("/_kola/content", typeof(ClientIdentifier).Assembly, "/content"));

            foreach (var plugin in KolaConfigurationRegistry.Plugins)
            {
                conventions.StaticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory("/_kola/plugins/" + plugin.PluginName, plugin.GetType().Assembly, "/editors"));
            }
        }
Пример #7
0
 protected override void ConfigureConventions(NancyConventions nancyConventions)
 {
     nancyConventions.StaticContentsConventions.Add(EmbeddedStaticContentConventionBuilder.AddDirectory("Content", GetType().Assembly, "Content"));
     base.ConfigureConventions(nancyConventions);
 }