11using System ;
2- using CodeHub . Core . ViewModels ;
32using System . Threading . Tasks ;
43using GitHubSharp . Models ;
54using CodeHub . Core . ViewModels ;
@@ -11,7 +10,18 @@ public class GistFileViewModel : FileSourceViewModel
1110 {
1211 private string _id ;
1312 private string _filename ;
14- private GistFileModel _fileModel ;
13+
14+ public string FileName { get ; private set ; }
15+
16+ private GistFileModel _gist ;
17+ public GistFileModel Gist
18+ {
19+ get { return _gist ; }
20+ private set {
21+ _gist = value ;
22+ RaisePropertyChanged ( ) ;
23+ }
24+ }
1525
1626 public void Init ( NavObject navObject )
1727 {
@@ -22,33 +32,33 @@ public void Init(NavObject navObject)
2232
2333 //Create the temp file path
2434 Title = fileName ;
35+ FileName = fileName ;
2536
2637 _id = navObject . GistId ;
2738 _filename = navObject . Filename ;
2839
2940 //Grab the data
30- _fileModel = GetService < IViewModelTxService > ( ) . Get ( ) as GistFileModel ;
41+ Gist = GetService < IViewModelTxService > ( ) . Get ( ) as GistFileModel ;
3142 }
3243
3344 protected override async Task Load ( bool forceCacheInvalidation )
3445 {
35- if ( _fileModel == null )
46+
47+ if ( Gist == null )
3648 {
3749 var data = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Gists [ _id ] . Get ( ) ) ;
38- _fileModel = data . Data . Files [ _filename ] ;
50+ Gist = data . Data . Files [ _filename ] ;
3951 }
4052
41- //Check to make sure...
42- if ( _fileModel == null || _fileModel . Content == null )
43- {
53+ if ( Gist == null || Gist . Content == null )
4454 throw new Exception ( "Unable to retreive gist!" ) ;
45- }
4655
47- var content = _fileModel . Content ;
48- var filePath = System . IO . Path . Combine ( System . IO . Path . GetTempPath ( ) , System . IO . Path . GetFileName ( _fileModel . Filename ) ) ;
49- System . IO . File . WriteAllText ( filePath , content , System . Text . Encoding . UTF8 ) ;
50- FilePath = filePath ;
51- ContentPath = CreateContentFile ( ) ;
56+ IsMarkdown = string . Equals ( Gist ? . Language , "Markdown" ) ;
57+ Gist = Gist ;
58+
59+ var filepath = System . IO . Path . Combine ( System . IO . Path . GetTempPath ( ) , FileName ) ;
60+ System . IO . File . WriteAllText ( filepath , Gist . Content , System . Text . Encoding . UTF8 ) ;
61+ ContentPath = FilePath = filepath ;
5262 }
5363
5464 public class NavObject
0 commit comments