示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }