DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
FileConfigSource.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.IO;
19 
20 namespace Deveel.Data.Configuration {
25  public sealed class FileConfigSource : IConfigSource {
32  public FileConfigSource(string filePath) {
33  if (filePath == null)
34  throw new ArgumentNullException("filePath");
35 
36  FilePath = filePath;
37  }
38 
42  public string FilePath { get; private set; }
43 
45  public Stream InputStream {
46  get {
47  try {
48  return new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 1024);
49  } catch (Exception ex) {
50  throw new DatabaseConfigurationException(String.Format("Cannot open a read stream from file '{0}'", FilePath), ex);
51  }
52  }
53  }
54 
56  public Stream OutputStream {
57  get {
58  try {
59  return new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read, 1024);
60  } catch (Exception ex) {
61  throw new DatabaseConfigurationException(String.Format("Cannot open a write stream to file '{0}'", FilePath), ex);
62  }
63  }
64  }
65  }
66 }
A source for stored configurations or destination to configurations to store.
FileConfigSource(string filePath)
Constructs the source over the file located at the given path within the underlying file-system...
A channel used to read from and write to a given file in the underlying file-system.