private static void ReceiveFindingCallback(IAsyncResult args) { Byte[] receiveBytes; try { var udpClient = (UdpClient)((object[])args.AsyncState)[0]; if (udpClient.Client == null) { return; } var ipEndPoint = (IPEndPoint)((object[])args.AsyncState)[1]; receiveBytes = udpClient.EndReceive(args, ref ipEndPoint); } catch (ObjectDisposedException) { //this is actually the expected behavior, if there is no chorus hub out there! //http://stackoverflow.com/questions/4662553/how-to-abort-sockets-beginreceive //note the check for Client == null above seems to help some... return; } try { var s = Encoding.ASCII.GetString(receiveBytes); if (IsChorusHubInfo(s)) { _chorusHubServerInfo = Parse(s); } } catch (Exception) { #if DEBUG throw; #endif //else, not worth doing any more than, well, not finding the hub. } }
public ChorusHubClient(ChorusHubServerInfo chorusHubServerInfo) { Guard.AgainstNull(chorusHubServerInfo, "chorusHubServerInfo"); _chorusHubServerInfo = chorusHubServerInfo; }
/// <summary> /// Called by our worker thread to avoid inordinate pauses in the UI while checking the /// Shared Network Folder to determine its status. /// </summary> private void CheckNetworkStatusAndUpdateUI() { // Check network Shared Folder status string message, tooltip, diagnostics; message = tooltip = diagnostics = ""; bool isReady=false; _lanMode = LANMode.ChorusHub; if (Properties.Settings.Default.ShowChorusHubInSendReceive) { try { if (_chorusHubClient == null) { _chorusHubServerInfo = ChorusHubServerInfo.FindServerInformation(); if (_chorusHubServerInfo != null) _chorusHubClient = new ChorusHubClient(_chorusHubServerInfo); } } catch (Exception) { //not worth complaining about #if DEBUG throw; #endif } } if(_chorusHubServerInfo==null) { message = "No Chorus Hub found on local network."; } else if (!_chorusHubServerInfo.ServerIsCompatibleWithThisClient) { message = "Found Chorus Hub but it is not compatible with this version of "+Application.ProductName; } else { isReady = true; message = string.Format("Found Chorus Hub at {0}", _chorusHubServerInfo.HostName); tooltip = _chorusHubServerInfo.GetHgHttpUri(Path.GetFileName(_repository.PathToRepo)); } Monitor.Enter(this); // Using a callback and Invoke ensures that we avoid cross-threading updates. if (!_exiting) { var callback = new UpdateNetworkUICallback(UpdateNetworkUI); Invoke(callback, new object[] { isReady, message, tooltip, diagnostics }); } Monitor.Exit(this); }
/// <summary> /// Since this migt not be a real "server", its ipaddress could be assigned dynamically, /// and could change each time someone "wakes up the server laptop" each morning /// </summary> private void UpdateAdvertisementBasedOnCurrentIpAddress() { if (_currentIpAddress != GetLocalIpAddress()) { _currentIpAddress = GetLocalIpAddress(); var serverInfo = new ChorusHubServerInfo(_currentIpAddress, ChorusHubOptions.MercurialPort.ToString(CultureInfo.InvariantCulture), Environment.MachineName, ChorusHubServerInfo.VersionOfThisCode); _sendBytes = Encoding.ASCII.GetBytes(serverInfo.ToString()); //EventLog.WriteEntry("Application", "Serving at http://" + _currentIpAddress + ":" + ChorusHubOptions.MercurialPort, EventLogEntryType.Information); } }
public static void ClearServerInfoForTests() { _chorusHubServerInfo = null; }
private static void ReceiveFindingCallback(IAsyncResult args) { Byte[] receiveBytes; try { var udpClient = (UdpClient)((object[])args.AsyncState)[0]; if (udpClient.Client == null) return; var ipEndPoint = (IPEndPoint)((object[])args.AsyncState)[1]; receiveBytes = udpClient.EndReceive(args, ref ipEndPoint); } catch (ObjectDisposedException) { //this is actually the expected behavior, if there is no chorus hub out there! //http://stackoverflow.com/questions/4662553/how-to-abort-sockets-beginreceive //note the check for Client == null above seems to help some... return; } try { var s = Encoding.ASCII.GetString(receiveBytes); if (IsChorusHubInfo(s)) { _chorusHubServerInfo = Parse(s); } } catch (Exception) { #if DEBUG throw; #endif //else, not worth doing any more than, well, not finding the hub. } }