1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Views
20 /// Represents a view template source on the file system.
22 public class FileViewSource
: IViewSource
24 private readonly FileInfo fileInfo
;
25 private readonly bool enableCache
;
26 private long lastUpdated
;
29 /// Initializes a new instance of the <see cref="FileViewSource"/> class.
31 /// <param name="fileInfo">The file info.</param>
32 /// <param name="enableCache">if set to <c>true</c> [enable cache].</param>
33 public FileViewSource(FileInfo fileInfo
, bool enableCache
)
35 this.fileInfo
= fileInfo
;
36 this.enableCache
= enableCache
;
38 lastUpdated
= LastModified
;
42 /// Opens the view stream.
44 /// <returns></returns>
45 public Stream
OpenViewStream()
47 lastUpdated
= LastModified
;
49 return fileInfo
.OpenRead();
53 /// Gets a value indicating whether cache is enabled for it.
55 /// <value><c>true</c> if cache is enabled for it; otherwise, <c>false</c>.</value>
56 public bool EnableCache
58 get { return enableCache; }
62 /// Gets or sets the last updated.
64 /// <value>The last updated.</value>
65 public long LastUpdated
67 get { return lastUpdated; }
68 set { lastUpdated = value; }
72 /// Gets the last modified.
74 /// <value>The last modified.</value>
75 public long LastModified
77 get { return File.GetLastWriteTime(fileInfo.FullName).Ticks; }