private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); switch (newState) { case TransportStates.Connected: this.State = ConnectionStates.Connected; if (this.OnConnected != null) { this.OnConnected(this); } break; case TransportStates.Failed: this.State = ConnectionStates.Closed; if (this.OnError != null) { this.OnError(this, this.Transport.ErrorReason); } break; case TransportStates.Closed: this.State = ConnectionStates.Closed; if (this.OnClosed != null) { this.OnClosed(this); } break; } }
public void Reconnect() { HTTPManager.Logger.Information("Transport - " + Name, "Reconnecting"); Stop(); State = TransportStates.Reconnecting; Connect(); }
/// <summary> /// Sends out the /start request to the server. /// </summary> protected void Start() { HTTPManager.Logger.Information("Transport - " + this.Name, "Sending Start Request"); this.State = TransportStates.Starting; if (this.Connection.Protocol > ProtocolVersions.Protocol_2_0) { var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Start, this), HTTPMethods.Get, true, true, OnStartRequestFinished); request.Tag = 0; request.DisableRetry = true; request.Timeout = Connection.NegotiationResult.ConnectionTimeout + TimeSpan.FromSeconds(10); Connection.PrepareRequest(request, RequestTypes.Start); request.Send(); } else { // The transport and the signalr protocol now started this.State = TransportStates.Started; Started(); Connection.TransportStarted(); } }
public TransportObject(int ID_, string Name, int Period_) : base(ID_, WorldServiceLocator._WS_Transports.GetNewGUID()) { TransportName = ""; Passengers = new List <WS_Base.BaseUnit>(); Waypoints = new List <TransportWP>(); Period = 0; PathTime = 0; FirstStop = -1; LastStop = -1; CurrentWaypoint = 0; NextWaypoint = 0; NextNodeTime = 0; TimeToNextEvent = 0; TransportState = TransportStates.TRANSPORT_DOCKED; TransportAt = 0; TransportName = Name; Period = Period_; if (GenerateWaypoints()) { positionX = Waypoints[0].X; positionY = Waypoints[0].Y; positionZ = Waypoints[0].Z; MapID = Waypoints[0].MapID; orientation = 1f; VisibleDistance = 99999f; State = GameObjectLootState.DOOR_CLOSED; TransportState = TransportStates.TRANSPORT_DOCKED; TimeToNextEvent = 60000; WorldServiceLocator._WorldServer.WORLD_TRANSPORTs_Lock.AcquireWriterLock(-1); WorldServiceLocator._WorldServer.WORLD_TRANSPORTs.Add(GUID, this); WorldServiceLocator._WorldServer.WORLD_TRANSPORTs_Lock.ReleaseWriterLock(); Update(); } }
protected void AbortFinished() { this.State = TransportStates.Closed; Connection.TransportAborted(); this.Aborted(); }
void IHeartbeat.OnHeartbeatUpdate(TimeSpan dif) { TransportStates state = base.State; if (state == TransportStates.Started && pollRequest == null && DateTime.UtcNow >= LastPoll + PollDelay + base.Connection.NegotiationResult.LongPollDelay) { Poll(); } }
private void OnStartRequestFinished(HTTPRequest req, HTTPResponse resp) { switch (req.State) { case HTTPRequestStates.Finished: if (resp.IsSuccess) { HTTPManager.Logger.Information("Transport - " + this.Name, "Start - Returned: " + resp.DataAsText); string response = Connection.ParseResponse(resp.DataAsText); if (response != "started") { Connection.Error(string.Format("Expected 'started' response, but '{0}' found!", response)); return; } // The transport and the signalr protocol now started this.State = TransportStates.Started; Started(); Connection.TransportStarted(); return; } else { HTTPManager.Logger.Warning("Transport - " + this.Name, string.Format("Start - request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2} Uri: {3}", resp.StatusCode, resp.Message, resp.DataAsText, req.CurrentUri)); } goto default; default: HTTPManager.Logger.Information("Transport - " + this.Name, "Start request state: " + req.State.ToString()); // The request may not reached the server. Try it again. int retryCount = (int)req.Tag; if (retryCount++ < MaxRetryCount) { req.Tag = retryCount; req.Send(); } else { Connection.Error("Failed to send Start request."); } break; } }
public virtual void Abort() { if (State == TransportStates.Started) { State = TransportStates.Closing; HTTPRequest hTTPRequest = new HTTPRequest(Connection.BuildUri(RequestTypes.Abort, this), HTTPMethods.Get, isKeepAlive: true, disableCache: true, OnAbortRequestFinished); hTTPRequest.Tag = 0; hTTPRequest.DisableRetry = true; Connection.PrepareRequest(hTTPRequest, RequestTypes.Abort); hTTPRequest.Send(); } }
protected void OnConnected() { if (State != TransportStates.Reconnecting) { Start(); } else { Connection.TransportReconnected(); Started(); State = TransportStates.Started; } }
/// <summary> /// Called after a succesful connect/reconnect. The transport implementations have to call this function. /// </summary> protected void OnConnected() { if (this.State != TransportStates.Reconnecting) { // Send the Start request Start(); } else { Connection.TransportReconnected(); Started(); this.State = TransportStates.Started; } }
/// <summary> /// Sends out the /start request to the server. /// </summary> protected void Start() { HTTPManager.Logger.Information("Transport - " + this.Name, "Sending Start Request"); this.State = TransportStates.Starting; var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Start, this), HTTPMethods.Get, true, true, OnStartRequestFinished); request.Tag = 0; request.DisableRetry = true; request.Timeout = Connection.NegotiationResult.ConnectionTimeout + TimeSpan.FromSeconds(10); Connection.PrepareRequest(request, RequestTypes.Start); request.Send(); }
private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); switch (newState) { case TransportStates.Connected: SetState(ConnectionStates.Connected); break; case TransportStates.Failed: SetState(ConnectionStates.Closed, this.Transport.ErrorReason); break; case TransportStates.Closed: SetState(ConnectionStates.Closed); break; } }
/// <summary> /// Will abort the transport. In SignalR 'Abort'ing is a graceful process, while 'Close'ing is a hard-abortion... /// </summary> public virtual void Abort() { if (this.State != TransportStates.Started) { return; } this.State = TransportStates.Closing; var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Abort, this), HTTPMethods.Get, true, true, OnAbortRequestFinished); // Retry counter request.Tag = 0; request.DisableRetry = true; Connection.PrepareRequest(request, RequestTypes.Abort); request.Send(); }
protected void Start() { HTTPManager.Logger.Information("Transport - " + Name, "Sending Start Request"); State = TransportStates.Starting; if ((int)Connection.Protocol > 0) { HTTPRequest hTTPRequest = new HTTPRequest(Connection.BuildUri(RequestTypes.Start, this), HTTPMethods.Get, isKeepAlive: true, disableCache: true, OnStartRequestFinished); hTTPRequest.Tag = 0; hTTPRequest.DisableRetry = true; hTTPRequest.Timeout = Connection.NegotiationResult.ConnectionTimeout + TimeSpan.FromSeconds(10.0); Connection.PrepareRequest(hTTPRequest, RequestTypes.Start); hTTPRequest.Send(); } else { State = TransportStates.Started; Started(); Connection.TransportStarted(); } }
private void OnStartRequestFinished(HTTPRequest req, HTTPResponse resp) { HTTPRequestStates state = req.State; if (state == HTTPRequestStates.Finished) { if (resp.IsSuccess) { HTTPManager.Logger.Information("Transport - " + Name, "Start - Returned: " + resp.DataAsText); string text = Connection.ParseResponse(resp.DataAsText); if (text != "started") { Connection.Error($"Expected 'started' response, but '{text}' found!"); } else { State = TransportStates.Started; Started(); Connection.TransportStarted(); } return; } HTTPManager.Logger.Warning("Transport - " + Name, $"Start - request finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText} Uri: {req.CurrentUri}"); } HTTPManager.Logger.Information("Transport - " + Name, "Start request state: " + req.State.ToString()); int num = (int)req.Tag; if (num++ < 5) { req.Tag = num; req.Send(); } else { Connection.Error("Failed to send Start request."); } }
private void OnStartRequestFinished(HTTPRequest req, HTTPResponse resp) { switch (req.State) { case HTTPRequestStates.Finished: if (resp.IsSuccess) { HTTPManager.Logger.Information("Transport - " + this.Name, "Start - Returned: " + resp.DataAsText); string response = Connection.ParseResponse(resp.DataAsText); if (response != "started") { Connection.Error(string.Format("Expected 'started' response, but '{0}' found!", response)); return; } // The transport and the signalr protocol now started this.State = TransportStates.Started; Started(); Connection.TransportStarted(); return; } else HTTPManager.Logger.Warning("Transport - " + this.Name, string.Format("Start - request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2} Uri: {3}", resp.StatusCode, resp.Message, resp.DataAsText, req.CurrentUri)); goto default; default: HTTPManager.Logger.Information("Transport - " + this.Name, "Start request state: " + req.State.ToString()); // The request may not reached the server. Try it again. int retryCount = (int)req.Tag; if (retryCount++ < MaxRetryCount) { req.Tag = retryCount; req.Send(); } else Connection.Error("Failed to send Start request."); break; } }
public TransportBase(string name, Connection connection) { Name = name; Connection = connection; State = TransportStates.Initial; }
public TransportBase(string name, Connection connection) { this.Name = name; this.Connection = connection; this.State = TransportStates.Initial; }
/// <summary> /// Start the reconnect process /// </summary> public void Reconnect() { HTTPManager.Logger.Information("Transport - " + this.Name, "Reconnecting"); Stop(); this.State = TransportStates.Reconnecting; Connect(); }
/// <summary> /// Will abort the transport. In SignalR 'Abort'ing is a graceful process, while 'Close'ing is a hard-abortion... /// </summary> public virtual void Abort() { if (this.State != TransportStates.Started) return; this.State = TransportStates.Closing; var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Abort, this), HTTPMethods.Get, true, true, OnAbortRequestFinished); // Retry counter request.Tag = 0; request.DisableRetry = true; Connection.PrepareRequest(request, RequestTypes.Abort); request.Send(); }
private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); if (this.State == ConnectionStates.Closed) { HTTPManager.Logger.Verbose("HubConnection", "Transport_OnStateChanged - already closed!"); return; } switch (newState) { case TransportStates.Connected: try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.Connected); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Connected); break; case TransportStates.Failed: if (this.State == ConnectionStates.Negotiating) { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.FailedToConnect); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } this.triedoutTransports.Add(this.Transport.TransportType); var nextTransport = GetNextTransportToTry(); if (nextTransport == null) { SetState(ConnectionStates.Closed, this.Transport.ErrorReason); } else { ConnectImpl(nextTransport.Value); } } else { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.ClosedWithError); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Closed, this.Transport.ErrorReason); } break; case TransportStates.Closed: { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.Closed); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Closed); } break; } }