示例#1
0
        public void Builder_Should_Build_New_Poster_Instance()
        {
            var poster = new PosterBuilder()
                         .Build();

            Assert.NotNull(poster);
        }
示例#2
0
        public static void SendPosterToBrowser( PosterBuilder.Builder pb, HttpResponse resp, string posterFilename, PosterBuilder.ImgFormat.SupportedTypes outputFormat)
        {
            string filename = BuildFilename(posterFilename, outputFormat);

            resp.Clear();
            // Ensure caching is off naturally
            resp.CacheControl = "no-cache";

            resp.ContentType = PosterBuilder.ImgFormat.ToMimeType(outputFormat);
            resp.AddHeader("Content-Disposition", "attachment;filename=" + filename);

            // Call our image with our amendments and have it save to the response so we can send it back
            Bitmap bmp = pb.Render();

            // Have the Poster build our new image and save the result to the outgoing response
            // ... have to do all this with MemoryStreams as PNG doesn't like being saved directly to HttpResponse.OutputStream
            // ... may as well do the same for all image types and be consistent
            using (Bitmap bitmap = pb.Render()) {

                using (MemoryStream ms = new MemoryStream()) {
                    ImageFormat outFmt = PosterBuilder.ImgFormat.ToImageFormat(outputFormat);

                    bmp.Save(ms, outFmt);

                    ms.WriteTo(resp.OutputStream);
                } // using ms

            } // using pb

            // And of course, clear up after ourselves
            pb.Dispose();
            resp.End();
        }
示例#3
0
        public static string BuildFilename(string filenamePrefix, PosterBuilder.ImgFormat.SupportedTypes imgFormat)
        {
            string newFilename = ""; string extension = "";

            extension = PosterBuilder.ImgFormat.ToFileExtension(imgFormat);
            newFilename = System.IO.Path.ChangeExtension(filenamePrefix, extension);

            return newFilename;
        }
示例#4
0
        public PosterTests()
        {
            _httpClientMock = new Mock <IHttpClient>();

            var poster = new PosterBuilder()
                         .AddHttpClient(_httpClientMock.Object)
                         .Build();

            _testGenericOrderService = poster.BuildService <IGenericOrderService>();
        }
示例#5
0
        /// <summary>
        /// Adds <see cref="Poster"/> object to <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="serviceCollection">The application service collection.</param>
        /// <param name="posterBuilderFactory">Factory of <see cref="PosterBuilder"/>.</param>
        /// <returns><see cref="IDiPosterBuilder"/>.</returns>
        public static IDiPosterBuilder AddPoster(this IServiceCollection serviceCollection, Func <PosterBuilder, Poster> posterBuilderFactory)
        {
            var posterBuilder = new PosterBuilder();

            serviceCollection.AddSingleton <IPoster, Poster>(provider =>
            {
                var httpClientFactory = provider.GetService <IHttpClientFactory>();
                var contentSerializer = provider.GetService <IContentSerializer>();

                if (httpClientFactory != null)
                {
                    posterBuilder.AddHttpClientFactory(httpClientFactory);
                }

                if (contentSerializer != null)
                {
                    posterBuilder.AddContentSerializer(contentSerializer);
                }

                return(posterBuilderFactory(posterBuilder));
            });

            return(new DefaultDiPosterBuilder(serviceCollection));
        }