| 1 |
using System; |
| 2 |
using SeedCreate.CommonLibrary; |
| 3 |
|
| 4 |
namespace Toast |
| 5 |
{ |
| 6 |
public class MessageFormatter |
| 7 |
{ |
| 8 |
private static readonly Pair<string, string> UriConvert = new Pair<string, string>("@url", "{0}"); |
| 9 |
private static readonly Pair<string, string> TitleConvert = new Pair<string, string>("@title", "{1}"); |
| 10 |
|
| 11 |
private string formatString; |
| 12 |
private string rawFormatString; |
| 13 |
|
| 14 |
|
| 15 |
public MessageFormatter(string formatString) |
| 16 |
{ |
| 17 |
if (formatString == null) |
| 18 |
{ |
| 19 |
throw new ArgumentNullException("formatString"); |
| 20 |
} |
| 21 |
|
| 22 |
FormatString = formatString; |
| 23 |
|
| 24 |
} |
| 25 |
|
| 26 |
public string FormatString |
| 27 |
{ |
| 28 |
get |
| 29 |
{ |
| 30 |
return formatString; |
| 31 |
} |
| 32 |
set |
| 33 |
{ |
| 34 |
if (value == null) |
| 35 |
{ |
| 36 |
throw new ArgumentNullException("FormatString"); |
| 37 |
} |
| 38 |
|
| 39 |
formatString = value; |
| 40 |
|
| 41 |
rawFormatString = formatString.Replace(UriConvert.ValueT, UriConvert.ValueU); |
| 42 |
rawFormatString = rawFormatString.Replace(TitleConvert.ValueT, TitleConvert.ValueU); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
public string BuildMessage(string uri, string title) |
| 48 |
{ |
| 49 |
if(uri==null) |
| 50 |
{ |
| 51 |
throw new ArgumentNullException("uri"); |
| 52 |
} |
| 53 |
|
| 54 |
if (title == null) |
| 55 |
{ |
| 56 |
throw new ArgumentNullException("title"); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
return string.Format(rawFormatString, uri, title); |
| 61 |
} |
| 62 |
|
| 63 |
public string BuildMessage(LiveProgram Source) |
| 64 |
{ |
| 65 |
try |
| 66 |
{ |
| 67 |
return BuildMessage(Source.ProgramUrl, Source.Title); |
| 68 |
} |
| 69 |
catch (NullReferenceException) |
| 70 |
{ |
| 71 |
throw new ArgumentNullException("Source"); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
} |
| 77 |
} |