private async Task <ServerStatusUpdate> GenerateServerStatusUpdateAsync(ServerStatusUpdateRegistration registration) { var registrationKey = registration.SteamEndpoint.ToString(); // // First check the process status // Process process; var processStatus = GetServerProcessStatus(registration, out process); switch (processStatus) { case ServerProcessStatus.NotInstalled: return(new ServerStatusUpdate { Status = ServerStatus.NotInstalled }); case ServerProcessStatus.Stopped: return(new ServerStatusUpdate { Status = ServerStatus.Stopped }); case ServerProcessStatus.Unknown: return(new ServerStatusUpdate { Status = ServerStatus.Unknown }); case ServerProcessStatus.Running: break; default: Debugger.Break(); break; } var currentStatus = ServerStatus.Initializing; // // If the process was running do we then perform network checks. // Logger.Debug("Checking server local status at {0}", registration.LocalEndpoint); // get the server information direct from the server using local connection. ReadOnlyCollection <Player> players; var localInfo = GetLocalNetworkStatus(registration.LocalEndpoint, out players); if (localInfo != null) { currentStatus = ServerStatus.RunningLocalCheck; // // Now that it's running, we can check the publication status. // Logger.Debug("Checking server public status at {0}", registration.SteamEndpoint); // get the server information direct from the server using public connection. var serverStatus = NetworkUtils.CheckServerStatusDirect(registration.SteamEndpoint); // check if the server returned the information. if (!serverStatus) { // server did not return any information var lastExternalStatusQuery = _lastExternalStatusQuery.ContainsKey(registrationKey) ? _lastExternalStatusQuery[registrationKey] : DateTime.MinValue; if (DateTime.Now >= lastExternalStatusQuery.AddMilliseconds(REMOTE_STATUS_QUERY_DELAY)) { currentStatus = ServerStatus.RunningExternalCheck; // get the server information direct from the server using external connection. serverStatus = await NetworkUtils.CheckServerStatusViaAPI(registration.SteamEndpoint); _lastExternalStatusQuery[registrationKey] = DateTime.Now; } } var lastExternalCallQuery = _lastExternalCallQuery.ContainsKey(registrationKey) ? _lastExternalCallQuery[registrationKey] : DateTime.MinValue; //if (DateTime.Now >= lastExternalCallQuery.AddMilliseconds(REMOTE_CALL_QUERY_DELAY)) if (lastExternalCallQuery == DateTime.MinValue) { // perform a server call to the web api. await NetworkUtils.PerformServerCallToAPI(registration.SteamEndpoint); _lastExternalCallQuery[registrationKey] = DateTime.Now; } // check if the server returned the information. if (serverStatus) { currentStatus = ServerStatus.Published; } else { Logger.Debug("No public status returned for {0}", registration.SteamEndpoint); } } var statusUpdate = new ServerStatusUpdate { Process = process, Status = currentStatus, ServerInfo = localInfo, Players = players }; return(await Task.FromResult(statusUpdate)); }
public async Task CheckForUpdatesAsync() { var result = await NetworkUtils.GetLatestAvailableVersion(); await TaskUtils.RunOnUIThreadAsync(() => this.AvailableVersion = result.Current); }
private static async Task <ServerStatusUpdate> GenerateServerStatusUpdateAsync(ServerStatusUpdateRegistration registration) { // // First check the process status // Process process; var processStatus = GetServerProcessStatus(registration, out process); switch (processStatus) { case ServerProcessStatus.NotInstalled: return(new ServerStatusUpdate { Status = ServerStatus.NotInstalled }); case ServerProcessStatus.Stopped: return(new ServerStatusUpdate { Status = ServerStatus.Stopped }); case ServerProcessStatus.Running: break; default: Debugger.Break(); break; } ServerStatus currentStatus = ServerStatus.Initializing; // // If the process was running do we then perform network checks. // ServerInfo localInfo; ReadOnlyCollection <Player> players; localInfo = GetLocalNetworkStatus(registration.LocalEndpoint, out players); if (localInfo != null) { currentStatus = ServerStatus.Running; // // Now that it's running, we can check the publication status. // logger.Debug("Checking server public status at {0}", registration.SteamEndpoint); var serverInfo = await NetworkUtils.GetServerNetworkInfo(registration.SteamEndpoint); if (serverInfo != null) { currentStatus = ServerStatus.Published; } else { logger.Debug("No public status returned for {0}", registration.SteamEndpoint); } } var statusUpdate = new ServerStatusUpdate { Process = process, Status = currentStatus, ServerInfo = localInfo, Players = players }; return(await Task.FromResult(statusUpdate)); }