root / trunk / Pithos.Client.WPF / Proxy.cs @ 34bdb91d
History | View | Annotate | Download (2.3 kB)
1 |
// ----------------------------------------------------------------------- |
---|---|
2 |
// <copyright file="Proxy.cs" company="Microsoft"> |
3 |
// TODO: Update copyright text. |
4 |
// </copyright> |
5 |
// ----------------------------------------------------------------------- |
6 |
|
7 |
using System.Net; |
8 |
using Pithos.Interfaces; |
9 |
|
10 |
namespace Pithos.Client.WPF |
11 |
{ |
12 |
using System; |
13 |
using System.Collections.Generic; |
14 |
using System.Linq; |
15 |
using System.Text; |
16 |
|
17 |
/// <summary> |
18 |
/// TODO: Update summary. |
19 |
/// </summary> |
20 |
public class Proxy |
21 |
{ |
22 |
//or the proxy changes, not when the monitor starts |
23 |
public static void SetFromSettings(IPithosSettings pithosSettings) |
24 |
{ |
25 |
IWebProxy proxy; |
26 |
if (pithosSettings.UseNoProxy) |
27 |
{ |
28 |
proxy = null; |
29 |
} |
30 |
else if (pithosSettings.UseManualProxy) |
31 |
{ |
32 |
proxy = new WebProxy(pithosSettings.ProxyServer, pithosSettings.ProxyPort); |
33 |
//If the proxy requires specific authentication settings, use them |
34 |
if (pithosSettings.ProxyAuthentication) |
35 |
{ |
36 |
proxy.Credentials = new NetworkCredential(pithosSettings.ProxyUsername, pithosSettings.ProxyPassword, pithosSettings.ProxyDomain); |
37 |
} |
38 |
//Otherwise, if there are generic authentication settings, use them |
39 |
if (!String.IsNullOrWhiteSpace(CredentialCache.DefaultNetworkCredentials.UserName)) |
40 |
{ |
41 |
proxy.Credentials = CredentialCache.DefaultNetworkCredentials; |
42 |
} |
43 |
} |
44 |
//In all other cases, use the default proxy |
45 |
else |
46 |
{ |
47 |
proxy = WebRequest.GetSystemWebProxy(); |
48 |
} |
49 |
WebRequest.DefaultWebProxy = proxy; |
50 |
} |
51 |
|
52 |
|
53 |
public static void SetCredentials(string proxyUsername, string proxyPassword, string proxyDomain) |
54 |
{ |
55 |
CredentialCache.DefaultNetworkCredentials.Password = proxyPassword; |
56 |
CredentialCache.DefaultNetworkCredentials.UserName = proxyUsername; |
57 |
CredentialCache.DefaultNetworkCredentials.Domain = proxyDomain; |
58 |
if (WebRequest.DefaultWebProxy!=null) |
59 |
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials; |
60 |
} |
61 |
} |
62 |
} |