Beispiel #1
0
        public static void SaveOne(BlogEntry e)
        {
            var path = Path.Combine(BlogPath, e.Id + ".txt");

            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                sw.WriteLine(e.Caption);
                sw.Write(e.Text);
            }
        }
Beispiel #2
0
        public static BlogEntry ReadOne(string id, int maxRows = 0)
        {
            var path = Path.Combine(BlogPath, id + ".txt");
            var res  = new BlogEntry();

            res.Id           = id;
            res.DateCreated  = File.GetCreationTime(path);
            res.DateModified = File.GetLastWriteTime(path);

            //each file contains caption (first line) and text
            using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
            {
                res.Caption = sr.ReadLine();

                List <string> text = new List <string>();
                string        s;
                int           lines = 0;
                for (int i = 0; (s = sr.ReadLine()) != null; i++)
                {
                    if (maxRows > 0 && string.IsNullOrWhiteSpace(s)) //trim on main page, not trim when edit
                    {
                        continue;
                    }
                    lines++;
                    if (maxRows != 0 && lines > maxRows)
                    {
                        res.More = true;
                        break;
                    }
                    text.Add(s);
                }
                if (res.More)
                {
                    while (text.Count >= maxRows)
                    {
                        text.RemoveAt(text.Count - 1);
                    }
                }

                res.Text = string.Join('\n', text);
            }

            return(res);
        }
Beispiel #3
0
        public static void DeleteOne(BlogEntry e)
        {
            var path = Path.Combine(BlogPath, e.Id + ".txt");

            File.Delete(path);
        }