ClearStartPageCache() public static méthode

public static ClearStartPageCache ( ) : void
Résultat void
Exemple #1
0
    public void ProcessRequest(HttpContext context)
    {
        //Site.ValidateToken(context); Already logged in...

        if (!context.User.Identity.IsAuthenticated)
        {
            throw new HttpException(403, "No access");
        }

        string mode = context.Request.QueryString["mode"];
        string slug = context.Request.Form["id"];

        if (mode == "file")
        {
            if (context.Request.Files.Count > 0)
            {
                try
                {
                    var  file     = context.Request.Files[0];
                    var  fileName = file.FileName;
                    var  location = "~/files";
                    bool isMedia  = !fileName.ToLower().EndsWith(".md");
                    if (isMedia)
                    {
                        location += "/media";
                    }
                    var path     = context.Server.MapPath(location);
                    var fullPath = Path.Combine(path, fileName);
                    file.SaveAs(fullPath);
                    if (!isMedia)
                    {
                        Site.ClearStartPageCache();
                        HttpRuntime.Cache.Remove("items");
                    }
                }
                catch
                {
                    throw new HttpException(400, "File failed to save.");
                }
            }
            else
            {
                throw new HttpException(400, "No file to upload.");
            }
        }
        else if (mode == "media")
        {
            if (context.Request.Files.Count > 0)
            {
                try
                {
                    var file     = context.Request.Files[0];
                    var fileName = file.FileName;
                    var path     = context.Server.MapPath("~/files/media");
                    var fullPath = Path.Combine(path, fileName);
                    file.SaveAs(fullPath);
                    Site.ClearStartPageCache();
                    HttpRuntime.Cache.Remove("items");
                }
                catch
                {
                    throw new HttpException(400, "File failed to save.");
                }
            }
            else
            {
                throw new HttpException(400, "No file to upload.");
            }
        }
        else if (mode == "delete")
        {
            var fileName = context.Request.Form["fileName"];
            var path     = context.Server.MapPath("~/files");
            var fullPath = Path.Combine(path, fileName);

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
                Site.ClearStartPageCache();
                HttpRuntime.Cache.Remove("items");
            }
            else
            {
                throw new HttpException(400, "Nothing to delete.");
            }
        }
        else if (mode == "save")
        {
            try
            {
                var fileName = context.Request.Form["fileName"];
                var data     = context.Request.Form["lines"];
                var lines    = data.Split('\n').ToList();
                PostManager.Save(fileName, lines);
                Site.ClearStartPageCache();
                HttpRuntime.Cache.Remove("items");
            }
            catch
            {
                throw new HttpException(400, "File failed to save.");
            }
        }
        else if (mode == "create")
        {
            var fileName = context.Request.Form["fileName"];
            if (!fileName.ToLower().EndsWith(".md"))
            {
                fileName += ".md";
            }
            var path     = context.Server.MapPath("~/files");
            var fullPath = Path.Combine(path, fileName);

            if (File.Exists(fullPath))
            {
                throw new HttpException(409, "File already exists.");
            }
            else
            {
                var lines = new List <string>();
                lines.Add("Title:\t\t\tNew Title");
                lines.Add("Type:\t\t\tPost");
                lines.Add("Author:\t\tAuthor");
                lines.Add("PubDate:\t\t" + DateTime.Now.ToString("yyyy-MM-dd hh:mm tt"));
                lines.Add("Categories:\t\t");
                lines.Add("Tags:\t\t\t");
                lines.Add("Image:\t\t\t");
                lines.Add("Link:\t\t\tnone");
                lines.Add("Slug:\t\t\tnew-item-" + DateTime.Now.ToString("yyyyMMddhhmmtt").ToLower());
                lines.Add("Status:\t\t\tDraft");
                lines.Add("Excerpt:\t\t");
                lines.Add("");
                lines.Add("Contents of post goes here.");
                PostManager.Save(fileName, lines);
                Site.ClearStartPageCache();
                HttpRuntime.Cache.Remove("items");
            }
        }
    }
Exemple #2
0
 public static void Delete(Post post)
 {
     Site.ClearStartPageCache();
 }