// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System.IO;
using System.Text;
using Rauchy.Regionerate.Shared.Components;
namespace Rauchy.Regionerate.ServiceLayer.Components
{
public sealed class FileDocument : Document
{
#region Fields (1)
private readonly string _path;
#endregion Fields
#region Constructors (1)
///
/// Initializes a new instance of the class.
///
/// The path.
public FileDocument( string path )
: base( Path.GetFileName( path ), File.ReadAllText( path, Encoding.Default ) )
{
_path = path;
}
#endregion Constructors
#region Properties (1)
///
/// Gets or sets the text.
///
/// The text.
protected override string Text
{
set
{
// In order to save on IO, any attempt to set a value which
// is identical to the source text will be blocked.
if ( value == Text.DecodeBrackets() )
{
Output.Inform( "\"{0}\" has not changed", Title );
}
else
{
string decodedValue = value.DecodeBrackets();
File.WriteAllText( _path, decodedValue, Encoding.Default );
base.Text = decodedValue;
}
}
}
#endregion Properties
}
}