-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding text version resolver - from Mario Pareja (chucknorris/roundho…
- Loading branch information
ferventcoder
committed
Feb 16, 2012
1 parent
edff1c8
commit 7f18429
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
|
||
using roundhouse.infrastructure.filesystem; | ||
using roundhouse.infrastructure.logging; | ||
|
||
namespace roundhouse.resolvers | ||
{ | ||
public class TextVersionResolver : VersionResolver | ||
{ | ||
private readonly FileSystemAccess file_system; | ||
private readonly string version_file; | ||
|
||
public TextVersionResolver(FileSystemAccess file_system, string version_file) | ||
{ | ||
this.file_system = file_system; | ||
this.version_file = version_file; | ||
} | ||
|
||
public bool meets_criteria() | ||
{ | ||
return version_file.EndsWith(".txt", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
public string resolve_version() | ||
{ | ||
Log.bound_to(this).log_an_info_event_containing( | ||
" Attempting to resolve version from text file {0}.", version_file); | ||
|
||
string version = "0"; | ||
if (file_system.file_exists(version_file)) | ||
{ | ||
try | ||
{ | ||
version = file_system.read_file_text(version_file); | ||
Log.bound_to(this).log_an_info_event_containing(" Found version {0} from {1}.", version, version_file); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.bound_to(this).log_an_error_event_containing( | ||
"Unable to get version from text file {0}:{1}{2}", version_file, Environment.NewLine, e.Message); | ||
} | ||
} | ||
else | ||
{ | ||
Log.bound_to(this).log_a_warning_event_containing( | ||
"Unable to get version from text file {0}. File doesn't exist.", version_file); | ||
} | ||
|
||
return version; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters