Fix: Disable HTTP KeepAlive
To improve support for proxy servers which do not support this optimisation. See: http://discoict.com.au/forum/support/2013/2/connection-issues,-lwt,-updates-etc.aspx
This commit is contained in:
+211
-204
@@ -1,205 +1,212 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web
|
||||
{
|
||||
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
|
||||
// visit http://go.microsoft.com/?LinkId=9394801
|
||||
|
||||
public class DiscoApplication : System.Web.HttpApplication
|
||||
{
|
||||
public DiscoApplication()
|
||||
{
|
||||
base.AuthenticateRequest += new EventHandler(DiscoApplication_AuthenticateRequest);
|
||||
base.BeginRequest += new EventHandler(DiscoApplication_BeginRequest);
|
||||
base.Error += new EventHandler(DiscoApplication_Error);
|
||||
}
|
||||
|
||||
protected void Application_Start()
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
long timer_last;
|
||||
timer.Start();
|
||||
|
||||
|
||||
Debug.WriteLine("Application Startup Profiling Started");
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
if (AppConfig.InitializeDatabase())
|
||||
{
|
||||
Debug.WriteLine("Initialized Database: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
|
||||
Debug.WriteLine("Registered Areas: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
WebApiConfig.Register(GlobalConfiguration.Configuration);
|
||||
|
||||
Debug.WriteLine("Registered API: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
|
||||
Debug.WriteLine("Registered Global Filters: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
|
||||
Debug.WriteLine("Registered Routes: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
BundleConfig.RegisterBundles();
|
||||
|
||||
Debug.WriteLine("Registered Bundles: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
AppConfig.InitalizeEnvironment();
|
||||
|
||||
Debug.WriteLine("Initialized Environment: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Install
|
||||
InitialConfig = true;
|
||||
RouteConfig.RegisterInstallRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles();
|
||||
}
|
||||
}
|
||||
protected void Application_End()
|
||||
{
|
||||
AppConfig.DisposeEnvironment();
|
||||
}
|
||||
|
||||
void DiscoApplication_BeginRequest(object sender, EventArgs e)
|
||||
{
|
||||
// Force Disable IE Compatibility Mode
|
||||
Response.Headers.Add("X-UA-Compatible", "IE=edge");
|
||||
}
|
||||
|
||||
#region Authentication
|
||||
void DiscoApplication_AuthenticateRequest(object sender, EventArgs e)
|
||||
{
|
||||
User u = CurrentUser;
|
||||
if (u != null)
|
||||
{
|
||||
base.Context.User = new GenericPrincipal(base.Context.User.Identity, new string[] { u.Type });
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InitialConfig { get; set; }
|
||||
|
||||
public static User CurrentUser
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!InitialConfig)
|
||||
return BI.UserBI.UserCache.CurrentUser;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Cached Properties
|
||||
|
||||
private static string _OrganisationName;
|
||||
public static string OrganisationName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_OrganisationName))
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
return _OrganisationName;
|
||||
}
|
||||
set
|
||||
{
|
||||
_OrganisationName = value;
|
||||
}
|
||||
}
|
||||
public static bool MultiSiteMode { get; set; }
|
||||
|
||||
#region Version
|
||||
private static Lazy<string> _Version = new Lazy<string>(() =>
|
||||
{
|
||||
var AssemblyVersion = typeof(DiscoApplication).Assembly.GetName().Version;
|
||||
return string.Format("{0}.{1}.{2:0000}", AssemblyVersion.Major, AssemblyVersion.Minor, AssemblyVersion.Build);
|
||||
});
|
||||
public static string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Version.Value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Proxy
|
||||
private static IWebProxy _defaultProxy;
|
||||
public static void SetGlobalProxy(string Address, int Port, string Username, string Password)
|
||||
{
|
||||
if (_defaultProxy == null)
|
||||
{
|
||||
_defaultProxy = WebRequest.DefaultWebProxy;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(Address))
|
||||
{
|
||||
WebProxy p = new WebProxy(new Uri(string.Format("http://{0}:{1}", Address, Port)));
|
||||
if (!string.IsNullOrWhiteSpace(Username))
|
||||
{
|
||||
p.Credentials = new NetworkCredential(Username, Password);
|
||||
}
|
||||
WebRequest.DefaultWebProxy = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
WebRequest.DefaultWebProxy = _defaultProxy;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Scheduler Factory
|
||||
private static Lazy<Quartz.ISchedulerFactory> _SchedulerFactory = new Lazy<Quartz.ISchedulerFactory>(() =>
|
||||
{
|
||||
// Initialize Scheduler Factory
|
||||
return new Quartz.Impl.StdSchedulerFactory();
|
||||
});
|
||||
public static Quartz.ISchedulerFactory SchedulerFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
return _SchedulerFactory.Value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Dropbox Monitor
|
||||
public static BI.DocumentTemplateBI.Importer.DocumentDropBoxMonitor DocumentDropBoxMonitor { get; set; }
|
||||
#endregion
|
||||
#region Global Error Logging
|
||||
void DiscoApplication_Error(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Disco.Services.Logging.SystemLog.LogException("Global Application Exception Caught", Server.GetLastError());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore all logging errors
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web
|
||||
{
|
||||
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
|
||||
// visit http://go.microsoft.com/?LinkId=9394801
|
||||
|
||||
public class DiscoApplication : System.Web.HttpApplication
|
||||
{
|
||||
public DiscoApplication()
|
||||
{
|
||||
base.AuthenticateRequest += new EventHandler(DiscoApplication_AuthenticateRequest);
|
||||
base.BeginRequest += new EventHandler(DiscoApplication_BeginRequest);
|
||||
base.Error += new EventHandler(DiscoApplication_Error);
|
||||
}
|
||||
|
||||
protected void Application_Start()
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
long timer_last;
|
||||
timer.Start();
|
||||
|
||||
|
||||
Debug.WriteLine("Application Startup Profiling Started");
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
if (AppConfig.InitializeDatabase())
|
||||
{
|
||||
Debug.WriteLine("Initialized Database: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
|
||||
Debug.WriteLine("Registered Areas: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
WebApiConfig.Register(GlobalConfiguration.Configuration);
|
||||
|
||||
Debug.WriteLine("Registered API: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
|
||||
Debug.WriteLine("Registered Global Filters: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
|
||||
Debug.WriteLine("Registered Routes: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
BundleConfig.RegisterBundles();
|
||||
|
||||
Debug.WriteLine("Registered Bundles: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
AppConfig.InitalizeEnvironment();
|
||||
|
||||
Debug.WriteLine("Initialized Environment: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Install
|
||||
InitialConfig = true;
|
||||
RouteConfig.RegisterInstallRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles();
|
||||
}
|
||||
}
|
||||
protected void Application_End()
|
||||
{
|
||||
AppConfig.DisposeEnvironment();
|
||||
}
|
||||
|
||||
void DiscoApplication_BeginRequest(object sender, EventArgs e)
|
||||
{
|
||||
// Force Disable IE Compatibility Mode
|
||||
Response.Headers.Add("X-UA-Compatible", "IE=edge");
|
||||
}
|
||||
|
||||
#region Authentication
|
||||
void DiscoApplication_AuthenticateRequest(object sender, EventArgs e)
|
||||
{
|
||||
User u = CurrentUser;
|
||||
if (u != null)
|
||||
{
|
||||
base.Context.User = new GenericPrincipal(base.Context.User.Identity, new string[] { u.Type });
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InitialConfig { get; set; }
|
||||
|
||||
public static User CurrentUser
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!InitialConfig)
|
||||
return BI.UserBI.UserCache.CurrentUser;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Cached Properties
|
||||
|
||||
private static string _OrganisationName;
|
||||
public static string OrganisationName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_OrganisationName))
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
return _OrganisationName;
|
||||
}
|
||||
set
|
||||
{
|
||||
_OrganisationName = value;
|
||||
}
|
||||
}
|
||||
public static bool MultiSiteMode { get; set; }
|
||||
|
||||
#region Version
|
||||
private static Lazy<string> _Version = new Lazy<string>(() =>
|
||||
{
|
||||
var AssemblyVersion = typeof(DiscoApplication).Assembly.GetName().Version;
|
||||
return string.Format("{0}.{1}.{2:0000}", AssemblyVersion.Major, AssemblyVersion.Minor, AssemblyVersion.Build);
|
||||
});
|
||||
public static string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Version.Value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Proxy
|
||||
private static IWebProxy _defaultProxy;
|
||||
public static void SetGlobalProxy(string Address, int Port, string Username, string Password)
|
||||
{
|
||||
if (_defaultProxy == null)
|
||||
{
|
||||
_defaultProxy = WebRequest.DefaultWebProxy;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(Address))
|
||||
{
|
||||
WebProxy p = new WebProxy(Address, Port);
|
||||
p.BypassProxyOnLocal = true;
|
||||
if (!string.IsNullOrWhiteSpace(Username))
|
||||
{
|
||||
p.Credentials = new NetworkCredential(Username, Password);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Added 2013-02-08 G#
|
||||
// Improve support for Integrated Windows Authentication
|
||||
p.UseDefaultCredentials = true;
|
||||
}
|
||||
WebRequest.DefaultWebProxy = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
WebRequest.DefaultWebProxy = _defaultProxy;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Scheduler Factory
|
||||
private static Lazy<Quartz.ISchedulerFactory> _SchedulerFactory = new Lazy<Quartz.ISchedulerFactory>(() =>
|
||||
{
|
||||
// Initialize Scheduler Factory
|
||||
return new Quartz.Impl.StdSchedulerFactory();
|
||||
});
|
||||
public static Quartz.ISchedulerFactory SchedulerFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
return _SchedulerFactory.Value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Dropbox Monitor
|
||||
public static BI.DocumentTemplateBI.Importer.DocumentDropBoxMonitor DocumentDropBoxMonitor { get; set; }
|
||||
#endregion
|
||||
#region Global Error Logging
|
||||
void DiscoApplication_Error(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Disco.Services.Logging.SystemLog.LogException("Global Application Exception Caught", Server.GetLastError());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore all logging errors
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,88 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class CompleteModel
|
||||
{
|
||||
public Tuple<IPHostEntry, Exception> DiscoDnsTestResult { get; set; }
|
||||
public Exception RegistryDatabaseResult { get; set; }
|
||||
public Exception DiscoIctComAuWebResult { get; set; }
|
||||
|
||||
public bool LaunchAllowed
|
||||
{
|
||||
get
|
||||
{
|
||||
return (RegistryDatabaseResult == null);
|
||||
}
|
||||
}
|
||||
|
||||
public void PerformTests()
|
||||
{
|
||||
|
||||
#region DNS for 'Disco'
|
||||
try
|
||||
{
|
||||
// Try and Resolve 'disco'
|
||||
DiscoDnsTestResult = new Tuple<IPHostEntry, Exception>(Dns.GetHostEntry("disco"), null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoDnsTestResult = new Tuple<IPHostEntry, Exception>(null, ex);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Write Database to Registry
|
||||
try
|
||||
{
|
||||
// Make Connection String Persistent
|
||||
Disco.Data.Repository.DiscoDatabaseConnectionFactory.SetDiscoDataContextConnectionString(
|
||||
Disco.Data.Repository.DiscoDatabaseConnectionFactory.DiscoDataContextConnectionString, true);
|
||||
RegistryDatabaseResult = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RegistryDatabaseResult = ex;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Communicate with http://discoict.com.au/
|
||||
try
|
||||
{
|
||||
Dns.GetHostEntry("discoict.com.au");
|
||||
try
|
||||
{
|
||||
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://discoict.com.au/");
|
||||
wReq.Method = WebRequestMethods.Http.Get;
|
||||
wReq.UserAgent = string.Format("Disco/{0} (Initial Config; Org: {1})", DiscoApplication.Version, DiscoApplication.OrganisationName);
|
||||
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
|
||||
{
|
||||
if (wRes.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
DiscoIctComAuWebResult = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscoIctComAuWebResult = new Exception(string.Format("Server returned response: [{0}] {1}", wRes.StatusCode, wRes.StatusDescription));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoIctComAuWebResult = new WebException("DNS Resolved the host 'discoict.com.au' but could not establish a connection.", ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoIctComAuWebResult = new Exception("Could not resolve the name 'discoict.com.au'", ex);
|
||||
throw;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class CompleteModel
|
||||
{
|
||||
public Tuple<IPHostEntry, Exception> DiscoDnsTestResult { get; set; }
|
||||
public Exception RegistryDatabaseResult { get; set; }
|
||||
public Exception DiscoIctComAuWebResult { get; set; }
|
||||
|
||||
public bool LaunchAllowed
|
||||
{
|
||||
get
|
||||
{
|
||||
return (RegistryDatabaseResult == null);
|
||||
}
|
||||
}
|
||||
|
||||
public void PerformTests()
|
||||
{
|
||||
|
||||
#region DNS for 'Disco'
|
||||
try
|
||||
{
|
||||
// Try and Resolve 'disco'
|
||||
DiscoDnsTestResult = new Tuple<IPHostEntry, Exception>(Dns.GetHostEntry("disco"), null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoDnsTestResult = new Tuple<IPHostEntry, Exception>(null, ex);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Write Database to Registry
|
||||
try
|
||||
{
|
||||
// Make Connection String Persistent
|
||||
Disco.Data.Repository.DiscoDatabaseConnectionFactory.SetDiscoDataContextConnectionString(
|
||||
Disco.Data.Repository.DiscoDatabaseConnectionFactory.DiscoDataContextConnectionString, true);
|
||||
RegistryDatabaseResult = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RegistryDatabaseResult = ex;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Communicate with http://discoict.com.au/
|
||||
try
|
||||
{
|
||||
Dns.GetHostEntry("discoict.com.au");
|
||||
try
|
||||
{
|
||||
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://discoict.com.au/");
|
||||
// Added: 2013-02-08 G#
|
||||
// Fix for Proxy Servers which dont support KeepAlive
|
||||
wReq.KeepAlive = false;
|
||||
// End Added: 2013-02-08 G#
|
||||
wReq.Method = WebRequestMethods.Http.Get;
|
||||
wReq.UserAgent = string.Format("Disco/{0} (Initial Config; Org: {1})", DiscoApplication.Version, DiscoApplication.OrganisationName);
|
||||
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
|
||||
{
|
||||
if (wRes.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
DiscoIctComAuWebResult = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscoIctComAuWebResult = new Exception(string.Format("Server returned response: [{0}] {1}", wRes.StatusCode, wRes.StatusDescription));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoIctComAuWebResult = new WebException("DNS Resolved the host 'discoict.com.au' but could not establish a connection.", ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DiscoIctComAuWebResult = new Exception("Could not resolve the name 'discoict.com.au'", ex);
|
||||
throw;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class WelcomeModel
|
||||
{
|
||||
[Required(ErrorMessage="The Organisation Name is required.")]
|
||||
public string OrganisationName { get; set; }
|
||||
|
||||
|
||||
private static string _OrganisationNameCache;
|
||||
public bool AutodetectOrganisation()
|
||||
{
|
||||
if (_OrganisationNameCache != null)
|
||||
{
|
||||
this.OrganisationName = _OrganisationNameCache;
|
||||
return true;
|
||||
}
|
||||
|
||||
// DnsQuery for broadband.doe.wan
|
||||
IPHostEntry doeWanDnsEntry;
|
||||
try
|
||||
{
|
||||
doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan");
|
||||
}
|
||||
catch (Exception)
|
||||
{ return false; } // Fail on error
|
||||
|
||||
// Try using IPSearch feature
|
||||
XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(true);
|
||||
if (doeWanIPSearchResult == null)
|
||||
doeWanIPSearchResult = TryDownloadDoeIPSearch(false);
|
||||
|
||||
if (doeWanIPSearchResult == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var siteName = doeWanIPSearchResult.Element("resultset").Element("site").Element("name").Value.ToLower();
|
||||
this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(siteName);
|
||||
_OrganisationNameCache = this.OrganisationName;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{ return false; } // Fail on error
|
||||
}
|
||||
private XDocument TryDownloadDoeIPSearch(bool useProxy)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
|
||||
if (!useProxy)
|
||||
wReq.Proxy = new WebProxy(); // Empty Proxy Config
|
||||
wReq.Method = WebRequestMethods.Http.Post;
|
||||
wReq.ContentType = "application/x-www-form-urlencoded";
|
||||
wReq.UserAgent = string.Format("Disco/{0}", DiscoApplication.Version);
|
||||
using (var wrStream = wReq.GetRequestStream())
|
||||
{
|
||||
using (var wrStreamWriter = new StreamWriter(wrStream))
|
||||
{
|
||||
wrStreamWriter.Write("mode=whoami");
|
||||
}
|
||||
}
|
||||
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
|
||||
{
|
||||
if (wRes.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using (var wResStream = wRes.GetResponseStream())
|
||||
{
|
||||
return XDocument.Load(wResStream);
|
||||
}
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{ return null; } // Fail on error
|
||||
}
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Disco.Web.Models.InitialConfig
|
||||
{
|
||||
public class WelcomeModel
|
||||
{
|
||||
[Required(ErrorMessage="The Organisation Name is required.")]
|
||||
public string OrganisationName { get; set; }
|
||||
|
||||
|
||||
private static string _OrganisationNameCache;
|
||||
public bool AutodetectOrganisation()
|
||||
{
|
||||
if (_OrganisationNameCache != null)
|
||||
{
|
||||
this.OrganisationName = _OrganisationNameCache;
|
||||
return true;
|
||||
}
|
||||
|
||||
// DnsQuery for broadband.doe.wan
|
||||
IPHostEntry doeWanDnsEntry;
|
||||
try
|
||||
{
|
||||
doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan");
|
||||
}
|
||||
catch (Exception)
|
||||
{ return false; } // Fail on error
|
||||
|
||||
// Try using IPSearch feature
|
||||
XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(true);
|
||||
if (doeWanIPSearchResult == null)
|
||||
doeWanIPSearchResult = TryDownloadDoeIPSearch(false);
|
||||
|
||||
if (doeWanIPSearchResult == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var siteName = doeWanIPSearchResult.Element("resultset").Element("site").Element("name").Value.ToLower();
|
||||
this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(siteName);
|
||||
_OrganisationNameCache = this.OrganisationName;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{ return false; } // Fail on error
|
||||
}
|
||||
private XDocument TryDownloadDoeIPSearch(bool useProxy)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
|
||||
// Added: 2013-02-08 G#
|
||||
// Fix for Proxy Servers which dont support KeepAlive
|
||||
wReq.KeepAlive = false;
|
||||
// End Added: 2013-02-08 G#
|
||||
if (!useProxy)
|
||||
wReq.Proxy = new WebProxy(); // Empty Proxy Config
|
||||
wReq.Method = WebRequestMethods.Http.Post;
|
||||
wReq.ContentType = "application/x-www-form-urlencoded";
|
||||
wReq.UserAgent = string.Format("Disco/{0}", DiscoApplication.Version);
|
||||
using (var wrStream = wReq.GetRequestStream())
|
||||
{
|
||||
using (var wrStreamWriter = new StreamWriter(wrStream))
|
||||
{
|
||||
wrStreamWriter.Write("mode=whoami");
|
||||
}
|
||||
}
|
||||
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
|
||||
{
|
||||
if (wRes.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using (var wResStream = wRes.GetResponseStream())
|
||||
{
|
||||
return XDocument.Load(wResStream);
|
||||
}
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{ return null; } // Fail on error
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.2.0207.1727")]
|
||||
[assembly: AssemblyFileVersion("1.2.0207.1727")]
|
||||
[assembly: AssemblyVersion("1.2.0208.1156")]
|
||||
[assembly: AssemblyFileVersion("1.2.0208.1156")]
|
||||
|
||||
Reference in New Issue
Block a user