public override void EstablishConnection() { var serverType = Uri.CheckHostName(Server); if (serverType != UriHostNameType.Dns) { Trace.WriteLine("Server is not DNS - direct connection"); GetDomainInfo(); return; } Trace.WriteLine("Locating a DC"); try { Server = DomainLocator.GetDC(Server, false, false); } catch (Exception) { Trace.WriteLine("The domain location didn't worked - trying it directly"); GetDomainInfo(); return; } for (int i = 0; i < 2; i++) { try { Trace.WriteLine("Trying " + Server); GetDomainInfo(); Trace.WriteLine("The connection worked"); return; } catch (COMException ex) { // server not available - force rediscovery of DC if ((uint)ex.ErrorCode == 0x8007203a) { if (i == 0) { // if we coulnd't connect to the select DC, even after a refresh, go to exception Trace.WriteLine("Unable to connect - force rediscovery of DC"); } else { throw; } } else { throw; } } if (i > 0) { Server = DomainLocator.GetDC(Server, false, true); } } }
public override void EstablishConnection() { if (Uri.CheckHostName(Server) != UriHostNameType.Dns) { Trace.WriteLine("Server is not a DNS entry - checking it directly"); GetDomainInfo(); return; } Trace.WriteLine("Trying to locate the domain"); Trace.WriteLine("Locating a DC"); try { Server = DomainLocator.GetDC(Server, true, false); } catch (Exception) { Trace.WriteLine("The domain location didn't worked - trying it directly"); GetDomainInfo(); return; } for (int i = 0; i < 2; i++) { try { Trace.WriteLine("Trying " + Server); GetDomainInfo(); Trace.WriteLine("The connection worked"); return; } catch (EndpointNotFoundException) { Trace.WriteLine("The connection didn't worked"); CleanConnection <Resource>(_resource); _resource = null; } catch (Exception ex) { Trace.WriteLine("Exception: " + ex.Message); Trace.WriteLine("Type: " + ex.GetType().ToString()); Trace.WriteLine("The connection didn't worked"); CleanConnection <Resource>(_resource); _resource = null; } if (i > 0) { Server = DomainLocator.GetDC(Server, true, true); } } // if we coulnd't connect to the select DC, even after a refresh, go to exception throw new EndpointNotFoundException(); }