Пример #1
0
        public static JsonObjectCollection ConvertToJson(UserInfo user)
        {
            JsonObjectCollection jsonUser = new JsonObjectCollection("User");
            jsonUser.Add(new JsonStringValue("Email", user.Email));
            jsonUser.Add(new JsonStringValue("AdditionalInfo", user.AdditionalInfo));

            return jsonUser;
        }
Пример #2
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            UserInfo user = new UserInfo(txtBoxEmail.Text, txtBoxAdditionalInfo.Text);

            Settings.Default.HideReportForm = checkBoxShow.Checked;
            Settings.Default.Save();

            try
            {
                Configuration.StorageDevices.RemoveAll(device => device.Model != comboBoxStorageModel.Text);

                // TODO: fix this method to return string.
                string jsonData = JsonUtils.ConvertToJson(user, Configuration, BenchmarkSessions).ToString();
                ServerConnector = new ServerConnection();

                Logger.Info("Sending data to server...");

                HttpWebResponse response = ServerConnector.SendDataAsPost(jsonData);
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string benchmarkLink = reader.ReadLine();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Logger.Info("Data sent succesfully to server...");
                    MessageBox.Show("Data sent successfully to server.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Process.Start(benchmarkLink);

                    this.Close();
                }
                else
                {
                    Logger.Info(String.Format("Send error..."));
                    Logger.Info(String.Format("Server return code: {0}", response.StatusCode));

                    MessageBox.Show(String.Format("There was an error. The server returned code: {0}", response.StatusCode.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception exc)
            {
                Logger.Error("Send error...", exc);
                MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        /// <summary>
        /// Convert the data into a JSON format.
        /// </summary>
        public static JsonObjectCollection ConvertToJson(UserInfo user, ComputerConfiguration configuration, List<BenchmarkTest> benchmarks)
        {
            List<JsonObjectCollection> jsonData = new List<JsonObjectCollection>();

            // User.
            var jsonUser = ConvertToJson(user);
            jsonData.Add(jsonUser);

            // Computer configuration.
            var jsonComputer = ConvertToJson(configuration);
            jsonData.Add(jsonComputer);

            // Benchmark test.
            foreach (var benchmark in benchmarks)
            {
                var jsonTest = ConvertToJson(benchmark, ReportType.Detailed);
                jsonData.Add(jsonTest);
            }

            return new JsonObjectCollection(jsonData);
        }