/// <summary>
        /// Set the asset id of the device. If an asset id is in the Globals, it will prefill that in the text box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setAssetIdButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string assetId    = !String.IsNullOrEmpty(Globals.AssetId) ? Globals.AssetId : "Enter an Asset ID...";
            string newAssetId = GetInput.getInput("What would you like to set the asset ID to?", assetId, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Enter/Change Device Asset ID: " + Globals.SerialNumber : "Enter/Change Device Asset ID: " + Globals.DeviceId, new Button {
                IsEnabled = true, Text = "Clear Asset ID"
            });

            if (newAssetId == null)
            {
                outputField.Text = "You didn't enter anything or you pressed cancel, silly goose!";
                return;
            }
            else if (newAssetId == "ExtraButtonClicked")
            {
                newAssetId = "";
            }
            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros ", "assetid \"" + newAssetId + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " assetid \"" + newAssetId + "\"");
            }
            Globals.AssetId  = newAssetId;
            outputField.Text = gamResult + "\nAs long as you don't see an error, this query completed successfully.";
        }
        private void setUserButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string user    = !String.IsNullOrEmpty(Globals.User) ? Globals.User : "******";
            string newUser = GetInput.getInput("What would you like to set the user to?", user, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Modify Device User: "******"Modify Device User: "******"You didn't enter anything or you pressed cancel, silly goose!";
                return;
            }
            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "user " + newUser));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " user " + newUser);
            }
            Globals.User     = newUser;
            outputField.Text = gamResult + "\nAs long as you don't see an error, this query completed successfully.";
        }
        /// <summary>
        /// Set the location of the device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setLocationButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string location    = !String.IsNullOrEmpty(Globals.Location) ? Globals.Location : "Enter a location...";
            string newLocation = GetInput.getInput("What would you like to set the location to?", location, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Add/Change Device Location: " + Globals.SerialNumber : "Add/Change Device Location: " + Globals.DeviceId, new Button {
                IsEnabled = true, Text = "Clear Location"
            });

            if (newLocation == null | newLocation == location)
            {
                outputField.Text = "You didn't enter anything or pressed cancel.";
                return;
            }
            else if (newLocation == "ExtraButtonClicked")
            {
                newLocation = "";
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "location \"" + newLocation + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " location \"" + newLocation + "\"");
            }
            Globals.Location = newLocation;
            outputField.Text = gamResult + "\nAs long as you don't see an error, the location has been updated.";
        }
        private async void changeOuButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            outputField.Text = "You should see the org selector in a second...";
            //return;
            IsLoading = true;
            string orgPath = OrgUnit.HandleAwaitableGetOrgUnitFromSelector(await Task.Run(() => OrgUnit.AwaitableGetOrgUnitFromSelector()));

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "ou \"" + orgPath + "\"")));
            }
            else
            {
                gamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " ou \"" + orgPath + "\""));
            }
            IsLoading        = false;
            outputField.Text = "Done! Your OU has been changed.";
        }
        private async void enableButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "action reenable")));

                IsLoading = false;
            }
            else
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " action reenable"));

                IsLoading = false;
            }
            outputField.Text = gamResult += "\nAs long as you don't see an error, this query completed successfully.";
        }
        private async void deprovisionButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            int    depChoice = GetInput.GetDeprovisionReason();
            string depAction = null;

            switch (depChoice)
            {
            case 0:
                outputField.Text = "Either you cancelled or selected nothing.";
                return;

            case 1:
                // same model replacement
                depAction = "deprovision_same_model_replace";
                break;

            case 2:
                // different model replacement
                depAction = "deprovision_different_model_replace";
                break;

            case 3:
                // retiring device
                depAction = "deprovision_retiring_device";
                break;

            default:
                depAction = "thisbetterfailbecausesomethingiswrong";
                return;
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "action " + depAction + " acknowledge_device_touch_requirement")));

                IsLoading = false;
            }
            else
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " action " + depAction + " acknowledge_device_touch_requirement"));

                IsLoading = false;
            }
            outputField.Text = gamResult += "\nAs long as you don't see an error, this query completed successfully.";
        }
        private async void noteButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
            }
            string note = null;

            IsLoading = true;
            if (String.IsNullOrEmpty(Globals.Note) && Globals.DeviceId != "csv")
            {
                List <string> gamResult = await Task.Run(() => GAM.RunGAM("info cros " + Globals.DeviceId + " fields notes"));

                if (gamResult.Count < 2)
                {
                    note = "No note found. Enter a new one here...";
                }
                else
                {
                    note = gamResult[1].Substring(9);
                }
            }
            else if (!String.IsNullOrEmpty(Globals.Note))
            {
                note = Globals.Note;
            }
            else if (Globals.DeviceId == "csv")
            {
                note = "Set a note for all devices from this CSV...";
            }

            string newNote = GetInput.getInput("Edit/modify note:", note, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Add/Change Device Note: " + Globals.SerialNumber : "Add/Change Device Note: " + Globals.DeviceId);

            if (newNote == null | newNote == note)
            {
                outputField.Text = "You didn't change the note so I'm leaving it as it is.";
                return;
            }

            string finalGamResult;

            if (Globals.DeviceId == "csv")
            {
                finalGamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "notes \"" + newNote + "\"")));
            }
            else
            {
                finalGamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " notes \"" + newNote + "\""));
            }
            IsLoading        = false;
            Globals.Note     = newNote;
            outputField.Text = "As long as there's no error, the note was updated.";
        }
        private void changeOuButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            outputField.Text = "You should see the org selector in a second...";
            //return;

            List <string>         allOrgs   = GAM.RunGAM("print orgs allfields");
            List <List <string> > fixedOrgs = FixCSVCommas.FixCommas(allOrgs);

            List <OrgUnit> orgUnits = new List <OrgUnit>();

            foreach (List <string> org in fixedOrgs)
            {
                if (org[0] == "orgUnitPath")
                {
                    continue;
                }

                orgUnits.Add(new OrgUnit()
                {
                    OrgUnitPath        = !String.IsNullOrEmpty(org[0]) ? org[0] : null,
                    OrgUnitName        = !String.IsNullOrEmpty(org[2]) ? (org[2].StartsWith("id:") ? "(no description provided)" : org[2]) : null,
                    OrgUnitDescription = !String.IsNullOrEmpty(org[3]) ? (org[3].StartsWith("id:") ? "(no description provided)" : org[3]) : null
                });
            }
            if (orgUnits.Count < 2)
            {
                outputField.Text = "There was an error getting your org units. You don't seem to have any.";
                return;
            }
            List <string> orgSelection = GetInput.GetDataGridSelection("Pick an org!", "Click on an row to select it, or paste the full path here and press submit...", "Organizational Unit Selector", orgUnits);
            string        orgPath      = null;

            foreach (string item in orgSelection)
            {
                if (item.Contains("/"))
                {
                    orgPath = item;
                }
            }
            if (orgPath == null | orgSelection.Contains("Click on an row to select it, or paste the full path here and press submit..."))
            {
                outputField.Text = "Either you didn't enter anything or there was an error. Nothing has been changed.";
                return;
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "ou \"" + orgPath + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " ou \"" + orgPath + "\"");
            }
            outputField.Text = "Done! Your OU has been changed.";
        }