/// <summary> /// Attemps to report data to the central server. /// </summary> /// <param name="newData">The data to be reported.</param> /// <param name="peerStateGuid">The peer's state GUID.</param> private void ReportData(DataSet newData, Guid peerStateGuid) { // If we're using the config file for discovery, don't do any reporting if (GameConfig.UseConfigForDiscovery) { return; } if (_pendingAsyncResult != null) { return; } var allData = new DataSet { Locale = CultureInfo.InvariantCulture }; allData.Merge(newData); for (var i = (allData.Tables["History"].Rows.Count - 1); i >= 0; i--) { if (((int)allData.Tables["History"].Rows[i]["OrganismBlacklistedCount"]) > 0) { allData.Tables["History"].Rows.RemoveAt(i); } } InitWebService(); if (_led != null) { _led.LedState = LedStates.Waiting; } _pendingAsyncResult = (WebClientAsyncResult)_reportingService.BeginReportPopulation(allData, peerStateGuid, _currentTick, ReportServiceCallback, allData); // This is needed because if it completes synchronously, pendingAsyncResult is cleared in the // callback, and then it gets set *afterward* which we don't want since it's already done. if (_pendingAsyncResult.CompletedSynchronously) { _pendingAsyncResult = null; } }
private void AllSpeciesCallback(IAsyncResult asyncResult) { try { _pendingAsyncResult = null; _speciesDataSet = _service.EndGetAllSpecies(asyncResult); _cacheDate = DateTime.Now; _retrievingData.Visible = false; } catch { if (!_connectionCancelled) { _retrievingData.Text = "There was a problem getting species list from server."; } return; } this.Invalidate(); }
void ExtinctSpeciesCallback(IAsyncResult asyncResult) { try { pendingAsyncResult = null; dataSet = service.EndGetExtinctSpecies(asyncResult); cacheDate = DateTime.Now; retrievingData.Visible = false; } catch { if (!connectionCancelled) { retrievingData.Text = "There was a problem getting species list from server."; } return; } this.Invalidate(); }
private void ServerList_Click(object sender, EventArgs e) { _retrievingData.Visible = true; try { String assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); if (_reintroduce) { _pendingAsyncResult = (WebClientAsyncResult)_service.BeginGetExtinctSpecies(assemblyVersion, "", new AsyncCallback(ExtinctSpeciesCallback), null); } else { _pendingAsyncResult = (WebClientAsyncResult)_service.BeginGetAllSpecies(assemblyVersion, "", new AsyncCallback(AllSpeciesCallback), null); } } catch (WebException) { MessageBox.Show(this, "The connection to the server timed out. Please try again later."); } }
private void ServerList_Click(object sender, EventArgs e) { this.retrievingData.Visible = true; service = new SpeciesService(); service.Timeout = 10000; service.Url = GameConfig.WebRoot + "/Species/AddSpecies.asmx"; try { if (reintroduce) { pendingAsyncResult = (WebClientAsyncResult)service.BeginGetExtinctSpecies(Assembly.GetExecutingAssembly().GetName().Version.ToString(), "", new AsyncCallback(ExtinctSpeciesCallback), null); } else { pendingAsyncResult = (WebClientAsyncResult)service.BeginGetAllSpecies(Assembly.GetExecutingAssembly().GetName().Version.ToString(), "", new AsyncCallback(AllSpeciesCallback), null); } } catch (WebException) { MessageBox.Show(this, "The connection to the server timed out. Please try again later."); } }
private void OK_Click(object sender, System.EventArgs e) { if (_pendingAsyncResult != null) { _connectionCancelled = true; _pendingAsyncResult.Abort(); _pendingAsyncResult = null; } if (GameEngine.Current == null || _speciesDataGrid.DataSource == null || this.BindingContext[_speciesDataGrid.DataSource, "Table"] == null || this.BindingContext[_speciesDataGrid.DataSource, "Table"].Count == 0) { this.Hide(); return; } DataRowView drv = this.BindingContext[_speciesDataGrid.DataSource, "Table"].Current as DataRowView; byte[] speciesAssemblyBytes = null; try { string versionString = Assembly.GetExecutingAssembly().GetName().Version.ToString(); string dataRowName = (string)drv["Name"]; if (_reintroduce) { speciesAssemblyBytes = _service.ReintroduceSpecies(dataRowName, versionString, GameEngine.Current.CurrentVector.State.StateGuid); } else { speciesAssemblyBytes = _service.GetSpeciesAssembly(dataRowName, versionString); } } catch (WebException) { MessageBox.Show(this, "The connection to the server timed out. Please try again later."); } if (speciesAssemblyBytes == null) { MessageBox.Show("Error retrieving species from server."); } else { // Save it to a temp file string tempFile = PrivateAssemblyCache.GetSafeTempFileName(); try { _speciesDataSet.Tables["Table"].Rows.Remove(drv.Row); using (Stream fileStream = File.OpenWrite(tempFile)) { fileStream.Write(speciesAssemblyBytes, 0, (int)speciesAssemblyBytes.Length); } GameEngine.Current.AddNewOrganism(tempFile, Point.Empty, _reintroduce); } catch (TargetInvocationException exception) { Exception innerException = exception; while (innerException.InnerException != null) { innerException = innerException.InnerException; } MessageBox.Show(innerException.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (GameEngineException exception) { MessageBox.Show(exception.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (Exception exception) { MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } finally { if (File.Exists(tempFile)) { File.Delete(tempFile); } } this.Hide(); } }
private void OK_Click(object sender, System.EventArgs e) { if (pendingAsyncResult != null) { connectionCancelled = true; pendingAsyncResult.Abort(); pendingAsyncResult = null; } if (GameEngine.Current == null || dataGrid1.DataSource == null || this.BindingContext[dataGrid1.DataSource, "Table"] == null || this.BindingContext[dataGrid1.DataSource, "Table"].Count == 0) { this.Hide(); return; } DataRowView drv = (DataRowView)(this.BindingContext[dataGrid1.DataSource, "Table"].Current); SpeciesService service = new SpeciesService(); service.Url = GameConfig.WebRoot + "/Species/AddSpecies.asmx"; service.Timeout = 60000; byte [] speciesAssemblyBytes = null; try { if (reintroduce) { speciesAssemblyBytes = service.ReintroduceSpecies((string)drv["Name"], Assembly.GetExecutingAssembly().GetName().Version.ToString(), GameEngine.Current.CurrentVector.State.StateGuid); } else { speciesAssemblyBytes = service.GetSpeciesAssembly((string)drv["Name"], Assembly.GetExecutingAssembly().GetName().Version.ToString()); } } catch (WebException) { MessageBox.Show(this, "The connection to the server timed out. Please try again later."); } if (speciesAssemblyBytes == null) { MessageBox.Show("Error retrieving species from server."); } else { dataSet.Tables["Table"].Rows.Remove(drv.Row); // Save it to a temp file string tempFile = PrivateAssemblyCache.GetSafeTempFileName(); using (Stream fileStream = File.OpenWrite(tempFile)) { fileStream.Write(speciesAssemblyBytes, 0, (int)speciesAssemblyBytes.Length); fileStream.Close(); } try { GameEngine.Current.AddNewOrganism(tempFile, Point.Empty, reintroduce); File.Delete(tempFile); } catch (TargetInvocationException exception) { Exception innerException = exception; while (innerException.InnerException != null) { innerException = innerException.InnerException; } MessageBox.Show(innerException.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (GameEngineException exception) { MessageBox.Show(exception.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } this.Hide(); } }