-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLoader.cs
43 lines (41 loc) · 1.25 KB
/
Loader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Net;
using System.Xml.Linq;
namespace FuryTech.OdataTypescriptServiceGenerator
{
public class Loader
{
public static XDocument Load(string source)
{
Logger.Log("Loading Metadata...");
XDocument xml;
try
{
xml = XDocument.Load(source);
return xml;
}
catch (WebException wex)
{
if (wex.Message == "The remote server returned an error: (401) Unauthorized.")
{
Logger.Warning("Authorization error, trying NTLM...");
var req = WebRequest.Create(source);
req.Credentials = CredentialCache.DefaultCredentials;
var stream = req.GetResponse().GetResponseStream();
if (stream != null)
{
xml = XDocument.Load(stream);
return xml;
}
}
Logger.Error("Failed to read metadata.");
throw;
}
catch (Exception)
{
Logger.Error("Error reading metadata.");
throw;
}
}
}
}