예제 #1
0
        public StaticModule(StaticProvider provider)
            : base("/static")
        {
            Get["/get-js"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetJs(fileName);

                    string campaignId = Request.Query.campaignid;
                    string sid        = Request.Query.sid;
                    string qaMode     = Request.Query.qamode;

                    result = result.Replace("$campaignId$", campaignId);
                    result = result.Replace("$sid$", sid);
                    result = result.Replace("$qaMode$", qaMode);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;
                }

                return(Response.AsText((string)result, "application/javascript")
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
            Get["/get-image"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetImage(fileName);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;

                    return(Response.AsText((string)result, "text/html")
                           .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
                }

                return(Response.FromByteArray((byte[])result.content, (string)result.content_type)
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
            Get["/get-css"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetCss(fileName);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;
                }

                return(Response.AsText((string)result, "text/css")
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
        }
예제 #2
0
        public StaticModule(StaticProvider provider)
            : base("/static")
        {
            Get["/get-js"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];
                    string extentionId          = Request.Query.ext == null ? "1000" : Request.Query.ext;

                    if (extentionId == "trijiconx")
                    {
                        extentionId = "2000";
                    }

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetJs(fileName);
                    result = (string)result.Replace("$extId$", extentionId);
                    result = (string)result.Replace("$gaId$", extentionId == "1000" ? "UA-39885571-1" : "UA-39885571-3");
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;
                }

                return(Response.AsText((string)result, "application/javascript")
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
            Get["/get-image"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetImage(fileName);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;

                    return(Response.AsText((string)result, "text/html")
                           .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
                }

                return(Response.FromByteArray((byte[])result.content, (string)result.content_type)
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
            Get["/get-css"] = p =>
            {
                dynamic result = null;

                try
                {
                    string staticCacheKey       = ConfigurationManager.AppSettings["StaticCacheKey"];
                    string requestSaticCacheKey = Request.Headers.IfNoneMatch.Count() == 0 ? null : Request.Headers.IfNoneMatch.ToList()[0];

                    if (requestSaticCacheKey == staticCacheKey)
                    {
                        return(new Response().WithStatusCode(HttpStatusCode.NotModified));
                    }

                    string fileName = Request.Query.name;

                    result = provider.GetCss(fileName);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex.Message;
                }

                return(Response.AsText((string)result, "text/css")
                       .WithHeader("Etag", ConfigurationManager.AppSettings["StaticCacheKey"]));
            };
        }