예제 #1
0
        /// <summary>
        /// Called by followers through FollowTag->Communicate()
        /// </summary>
        private static void ClientUpdate()
        {
            if (Enabled)
            {
                _updateRunning = true;
                try
                {
                    if (Host != null && Host.State == CommunicationState.Opened)
                    {
                        Logr.Log("Shutting down Server Service");
                        Host.Close();
                        Host = null;
                    }
                }
                catch (Exception ex)
                {
                    Logr.Error("Error shutting down server service: " + ex);
                }

                StartClient();

                try
                {
                    if (Initialized && Leader.GetMillisecondsSinceLastUpdate() >= 250)
                    {
                        // Get the leader message and store it
                        Leader = HttpProxy.GetUpdate();

                        // Send our follower message to the leader
                        HttpProxy.SendUpdate(_lastMessage);


                        if (LastLeaderUpdateMessage == null || LastLeaderUpdateMessage != Leader)
                        {
                            LastLeaderUpdateMessage = Leader;

                            SetQuestToolsOptionsFromLeader();

                            if (Settings.Instance.DebugLogging)
                            {
                                Logr.Debug("Leader {0}", Leader.ToString());
                            }
                        }
                    }
                }
                catch (EndpointNotFoundException ex)
                {
                    Logr.Error("Error 201: Could not get an update from the leader using {0}. Is the leader running? ({1})", HttpFactory.Endpoint.Address.Uri.AbsoluteUri, ex.Message);
                    Initialized = false;
                }
                catch (CommunicationException ex)
                {
                    Logr.Error("Error 202: Could not get an update from the leader using {0}. Is the leader running? ({1})", HttpFactory.Endpoint.Address.Uri.AbsoluteUri, ex.Message);
                    Initialized = false;
                }
                catch (Exception ex)
                {
                    Logr.Error("Error 203: Could not get an update from the leader using {0}. Is the leader running?", HttpFactory.Endpoint.Address.Uri.AbsoluteUri);
                    Initialized = false;
                    Logr.Log(ex.ToString());
                }
                _updateRunning = false;
            }
        }