root/lang/csharp/soyText/soyText/Document.cs @ 31255

Revision 31255, 2.0 kB (checked in by hoge1e3, 4 years ago)

close #129

Line 
1using System;
2using System.IO;
3
4namespace SoyText
5{
6    class Document
7    {
8        /**
9         * handle: Not a permanent id of this document. Indicate files
10         */
11        public int handle;
12        String _content;
13        public String content
14        {
15            get
16            {
17                if (_content != null) return _content;
18                var st = new FileStream(fileName, FileMode.Open);
19                var tx = new StreamReader(st);
20                _content = "";
21                while (true)
22                {
23                    String rd = tx.ReadLine();
24                    if (rd == null) break;
25                    _content += rd+"\r\n";
26                }
27                tx.Close();
28                return _content;
29            }
30            set { _content = value; }
31        }
32        public void save()
33        {
34            if (isNew) handle = DocumentSet.createHandle();
35            var st = new FileStream(fileName, FileMode.Create);
36            var tx = new StreamWriter(st);
37            tx.Write(content);
38            tx.Close();
39        }
40        public Boolean isNew
41        {
42            get { return handle < 0; }
43        }
44        public Document() {
45            handle = -1;
46            _content = "id: "+TimeFormat.now()+"\r\n\r\n";
47        }
48        public Document(int handle)
49        {
50            this.handle = handle;
51           
52        }
53        public String fileName
54        {
55            get { return DocumentSet.home + handle + ".txt"; }
56        }
57        public DateTime lastUpdate
58        {
59            get
60            {
61                return File.GetLastWriteTime(fileName);
62            }
63        }
64        public bool matches(String kw)
65        {
66            return content.IndexOf(kw) >= 0;
67        }
68        public override String ToString()
69        {
70            if (content.Length < 10) return content;
71            return content.Substring(0, 10);
72        }
73    }
74}
Note: See TracBrowser for help on using the browser.