BF2Statistics.Web.Bf2Stats.Controller.SendTemplateResponse C# (CSharp) Метод

SendTemplateResponse() защищенный Метод

Runs the specified Template through the RazorEngine and sends the contents back to the client in the Response
protected SendTemplateResponse ( string TemplateName, Type ModelType, object Model, string CacheFileName = "" ) : void
TemplateName string The name of the cshtml template file we are parsing
ModelType System.Type The Model type used in the template file
Model object The Model used in the template file
CacheFileName string The name of the Cached file if we are using one. Leave blank for no caching.
Результат void
        protected void SendTemplateResponse(string TemplateName, Type ModelType, object Model, string CacheFileName = "")
        {
            // Send Response
            HttpResponse Response = Client.Response;
            Response.ContentType = "text/html";
            Response.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            Response.Response.AddHeader("Expires", "0");
            Response.ResponseBody.Append(Engine.Razor.Run(TemplateName + ".cshtml", ModelType, Model));
            Response.Send();

            // Process cache
            if (Program.Config.BF2S_CacheEnabled && !String.IsNullOrWhiteSpace(CacheFileName))
            {
                try
                {
                    // Make sure we have loaded this file
                    if (CacheFile == null)
                        CacheFile = new FileInfo(Path.Combine(Program.RootPath, "Web", "Bf2Stats", "Cache", CacheFileName + ".html"));

                    using (FileStream Stream = CacheFile.Open(FileMode.OpenOrCreate, FileAccess.Write))
                    using (StreamWriter Writer = new StreamWriter(Stream))
                    {
                        Writer.BaseStream.SetLength(0);
                        Writer.Write(Response.ResponseBody.ToString());
                        Writer.Flush();
                    }

                    // Manually set write time!!!
                    CacheFile.LastWriteTime = DateTime.Now;
                }
                catch (Exception e)
                {
                    Program.ErrorLog.Write("WARNING: [Controller.CreateCacheFile] " + e.Message);
                }
            }
        }