Exemple #1
0
        public void ReceiveCallback(IAsyncResult args)
        {
            UdpClient u = ((State)(args.AsyncState)).udpClient;
            IPEndPoint e = ((State)(args.AsyncState)).Endpoint;

            Byte[] receiveBytes = u.EndReceive(args, ref e);
            string s = Encoding.ASCII.GetString(receiveBytes);
            if(ChorusHubInfo.IsChorusHubInfo(s))
            {
                _foundHub = ChorusHubInfo.Parse(s);
            }
        }
Exemple #2
0
 public ChorusHubInfo Find()
 {
     _foundHub = null;
     Start();
     for (int i = 0; i < 20; i++)
     {
         if (_foundHub != null)
             break;
         Thread.Sleep(200);
     }
     Stop();
     return _foundHub;//will be null if none found
 }
Exemple #3
0
 public ChorusHubInfo FindServer()
 {
     _foundHubInfo = null;
     StartFinding();
     for (int i = 0; i < 20; i++)
     {
         if (_foundHubInfo != null)
             break;
         Thread.Sleep(200);
     }
     StopFinding();
     return _foundHubInfo; //will be null if none found
 }
Exemple #4
0
 /// <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();
         ChorusHubInfo info = new ChorusHubInfo(_currentIpAddress, ChorusHubParameters.kMercurialPort.ToString(),
                                                System.Environment.MachineName, ChorusHubInfo.kVersionOfThisCode);
         _sendBytes = Encoding.ASCII.GetBytes(info.ToString());
         Progress.WriteMessage("Serving at http://" + _currentIpAddress + ":" + ChorusHubParameters.kMercurialPort);
     }
 }
Exemple #5
0
        private void ReceiveFindingCallback(IAsyncResult args)
        {
            Byte[] receiveBytes;
            try
            {
                if (_udpClient.Client == null)
                    return;
                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
            {
                string s = Encoding.ASCII.GetString(receiveBytes);
                if (ChorusHubInfo.IsChorusHubInfo(s))
                {
                    _foundHubInfo = ChorusHubInfo.Parse(s);
                }
            }
            catch (Exception)
            {
            #if DEBUG
                throw;
            #endif
                //else, not worth doing any more than, well, not finding the hub.
            }
        }
Exemple #6
0
        /// <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)
                    {
                        _chorusHubClient = new ChorusHub.ChorusHubClient();
                    }
                    _chorusHubInfo = _chorusHubClient.FindServer();
                }
                catch (Exception)
                {
                    //not worth complaining about
            #if DEBUG
                    throw;
            #endif
                }
            }
            if(_chorusHubInfo==null)
            {
                message = "No Chorus Hub found on local network.";
            }
            else if (!_chorusHubInfo.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}", _chorusHubInfo.HostName);
                tooltip = _chorusHubInfo.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);
                this.Invoke(callback, new object[] { isReady, message, tooltip, diagnostics });
            }
            Monitor.Exit(this);
        }