Exemplo n.º 1
0
        private void buttonTestToken_Click(object sender, EventArgs e)
        {
            List <VehicleDetails> vehicles;

            textBoxToken.Text = textBoxToken.Text.Trim();
            if (textBoxToken.Text.Length < 1)
            {
                MessageBox.Show("Please enter a token.", "Missing token", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try {
                SetCursorToWait();
                token             = new TeslaAccessToken(textBoxToken.Text);
                tesla.AccessToken = token;

                vehicles = tesla.LoadVehicles();

                StringBuilder details = new StringBuilder();

                details.AppendLine("Total " + vehicles.Count.ToString() + " vehicle(s) found.");
                foreach (var vehicle in vehicles)
                {
                    string s = "NAME: " + vehicle.DisplayName + ", MODEL: " + tesla.GetModel(vehicle) + ", VIN: " + vehicle.VIN + " STATE: " + vehicle.State;
                    details.AppendLine(s);

                    Debug.Write(vehicle.ToString());
                }

                if (vehicles.Count == 1)
                {
                    this.vehicleID = vehicles[0].ID;
                }

                VehicleData data = new VehicleData();
                data = tesla.GetAllVehicleData(this.vehicleID, token.AccessToken);
                Debug.WriteLine(data.ToString());

                SetCursorToDefault();
                MessageBox.Show(details.ToString(), "Vehicle details", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex) {
                SetCursorToDefault();
                Debug.WriteLine(ex.ToString());
                MessageBox.Show("Following error occured:\n" + ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void buttonTestToken_Click(object sender, EventArgs e)
        {
            List <VehicleDetails> vehicles;

            try {
                SetCursorToWait();
                vehicles = tesla.LoadVehicles();

                StringBuilder details = new StringBuilder();

                details.AppendLine("Total " + vehicles.Count.ToString() + " vehicle(s) found.");
                foreach (var vehicle in vehicles)
                {
                    string temp = "NAME: " + vehicle.DisplayName + ", MODEL: " + tesla.GetModel(vehicle) + ", VIN: " + vehicle.VIN + " STATE: " + vehicle.State;
                    details.AppendLine(temp);

                    Debug.Write(vehicle.ToString());
                }

                if (vehicles.Count == 1)
                {
                    this.vehicleID = vehicles[0].ID;
                    if (vehicles[0].State == "online")
                    {
                        this.vehicleAwake = true;
                    }
                    else
                    {
                        this.vehicleAwake = false;
                    }
                }

                SetCursorToDefault();
                MessageBox.Show(details.ToString(), "Vehicle details", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex) {
                SetCursorToDefault();
                Debug.WriteLine(ex.ToString());
                MessageBox.Show("Following error occured:\n" + ex.ToString());
            }
        }