2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Net ;
5
6
using System . Text ;
6
7
using System . Threading . Tasks ;
7
8
using System . Xml ;
10
11
namespace MaterialDesignDemo . Helper {
11
12
public class SourceRouter {
12
13
private string _typeName ;
13
- private const bool GetFromLocalSource = true ;
14
+ private const bool GetFromLocalSource = false ;
14
15
public SourceRouter ( string typeName ) {
15
16
_typeName = typeName ;
16
17
}
@@ -29,8 +30,34 @@ public XmlDocument Local() {
29
30
}
30
31
31
32
public XmlDocument Remote ( ) {
32
- return new MaterialDesignInXamlToolkitGitHubFile ( _typeName ) . GetXmlDocument ( ) ;
33
+ string ownerName = "wongjiahau" ;
34
+ string branchName = "New-Demo-2" ;
35
+ string sourceCode = DownloadFile (
36
+ @"https://raw.githubusercontent.com/" +
37
+ $ "{ ownerName } /" +
38
+ "MaterialDesignInXamlToolkit/" +
39
+ $ "{ branchName } /"+
40
+ "MainDemo.Wpf/" +
41
+ $ "{ _typeName } .xaml"
42
+ ) ;
43
+ var xmlDoc = new XmlDocument ( ) ;
44
+ xmlDoc . LoadXml ( sourceCode ) ;
45
+ return xmlDoc ;
46
+ }
33
47
48
+ private static string DownloadFile ( string sourceUrl )
49
+ //Refered from : https://gist.github.com/nboubakr/7812375
50
+ {
51
+
52
+ long existLen = 0 ;
53
+ var httpReq = ( HttpWebRequest ) WebRequest . Create ( sourceUrl ) ;
54
+ httpReq . AddRange ( ( int ) existLen ) ;
55
+ var httpRes = ( HttpWebResponse ) httpReq . GetResponse ( ) ;
56
+ var responseStream = httpRes . GetResponseStream ( ) ;
57
+ if ( responseStream == null ) return "Fail to fetch file" ;
58
+ var streamReader = new StreamReader ( responseStream ) ;
59
+ return streamReader . ReadToEnd ( ) ;
34
60
}
61
+
35
62
}
36
63
}
0 commit comments