コード例 #1
0
        public ShortenerModule(IUrlStorage urlStorage)
        {
            storage = urlStorage;

            Post["/urls"] = HandleCreate;
            Get["/urls/{shortUrl}"] = HandlerGet;
        }
コード例 #2
0
 public UrlShortenerController(IUrlKeyGenerator generator, IUrlStorage storage)
 {
     this.generator = generator;
     this.storage   = storage;
 }
コード例 #3
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/who", async context =>
                {
                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    await context.Response.WriteAsync(Quote.GetRandomWho());
                });

                endpoints.MapGet("/how", async context =>
                {
                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    await context.Response.WriteAsync(Quote.GetRandomHow());
                });

                endpoints.MapGet("/does", async context =>
                {
                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    await context.Response.WriteAsync(Quote.GetRandomDoes());
                });

                endpoints.MapGet("/what", async context =>
                {
                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    await context.Response.WriteAsync(Quote.GetRandomWhat());
                });

                endpoints.MapGet("/quote", async context =>
                {
                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    await context.Response.WriteAsync(Quote.GetQuote());
                });

                endpoints.MapGet("/incamp18-quote", async context =>
                {
                    Timer timer = new Timer();
                    timer.Start();

                    context.toUtf8();
                    context.Response.Headers.Add("InCamp-Student", Dns.GetHostName().ToString());

                    IUrlStorage urlStorage  = ConfigParams.UrlStorage;
                    string[] urls           = ConfigParams.RandomUrl.GetRandomUrls(urlStorage.Get());
                    WebResponse[] responses = await ConfigParams.RequestType.makeRequest(urls);

                    ResponseInfo[] info = responses.Select(r => r.GetInformation()).ToArray();

                    timer.End();
                    await context.Response.WriteAsync(info.BuildResponse() + "<br>" + timer.GetTime());
                });
            });
        }
コード例 #4
0
 public RedirectMiddleware(OwinMiddleware next,
                           IUrlStorage <Domain.Entities.PunyUrl> urlStorage) : base(next)
 {
     this.urlStorage = urlStorage;
 }
コード例 #5
0
 public UrlController(IUrlStorage <Domain.Entities.PunyUrl> storage,
                      IUrlShortener shortener)
 {
     this.storage   = storage;
     this.shortener = shortener;
 }