Beispiel #1
0
        /// <summary>
        /// Test WCF service by sending info to it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendItem_Click(object sender, EventArgs e)
        {
            if (AreSendErrorsDetected())
            {
                MessageBox.Show("Cannot send item until all errors fixed.");
                return;
            }

            Score item = new Score();

            item.Name   = txtName.Text;
            item.Points = int.Parse(txtScore.Text);

            if (picImage.Image != null)
            {
                using (MemoryStream memory = new MemoryStream())
                {
                    picImage.Image.Save(memory, ImageFormat.Jpeg);
                    item.Picture = memory.ToArray();
                }
            }

            try
            {
                using (ScoreServiceClient client = new ScoreServiceClient())
                {
                    client.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Utilities.GetAllExceptions(ex), "Exception attempting to send info to server.");
            }
        }
Beispiel #2
0
        public static void Send(string character, string name, int points)
        {
            byte[] picture = GetGamerAvatar(character);

            using (var client = new ScoreServiceClient())
            {
                client.Add(new Score()
                {
                    Name    = name,
                    Points  = points,
                    Picture = picture,
                });
            }
        }
Beispiel #3
0
        /// <summary>
        /// Send all info to scoring server.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="score"></param>
        /// <param name="name"></param>
        private void SendToServer(Image image, int score, string name)
        {
            Score item = new Score();

            item.Name   = txtName.Text;
            item.Points = _mainForm.Score;

            if (image != null)
            {
                // Scale image to desired send size.
                Image scaledForServer = new Bitmap(image, _mainForm._settings.Size_HeadImageToScoringServer);

                using (MemoryStream memory = new MemoryStream())
                {
                    scaledForServer.Save(memory, ImageFormat.Jpeg);
                    item.Picture = memory.ToArray();
                }
            }

            try
            {
                if (_mainForm._settings.WriteToServerDuringSubmit)
                {
                    using (ScoreServiceClient client = new ScoreServiceClient())
                    {
                        client.Add(item);

                        // Wait brief time then exit application.
                        Thread.Sleep(500);
                    }
                }

                // Exit app.
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Utilities.GetAllExceptions(ex), "Exception attempting to send info to server.");
            }
        }