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 async void ImportFromGoogleAdminQueryStringBulk_Click(object sender, RoutedEventArgs e) { currentView.IsLoading = true; string inputBoxPrefill = "example: user:jsmith\nThat imports all devices with the user:jsmith.\nClick the link on the bottom left for more information."; string queryString = GetInput.getInput( "Enter an Admin Console query string.", inputBoxPrefill, "Import from Google Admin query string", new Button() { IsEnabled = true, Text = "Open Help Page" } ); if (queryString == "ExtraButtonClicked") { Process.Start("https://support.google.com/chrome/a/answer/1698333#search"); ImportFromGoogleAdminQueryStringBulk_Click(sender, e); return; } else if (queryString == inputBoxPrefill || queryString == null) { GetInput.ShowInfoDialog("ChromebookGUI: No input", "No Input", "No query string entered, silly goose!"); currentView.IsLoading = false; return; } List <string> gamResult = await Task.Run(() => GAM.RunGAM("print cros query \"" + queryString + "\"")); if (gamResult.Count == 0) { GetInput.ShowInfoDialog("ChromebookGUI: Invalid Query String", "Invalid Query String", "That's an invalid query string. If you don't think it is, try running this in cmd:\n\ngam print cros query \"" + queryString + "\""); currentView.IsLoading = false; return; } else if (gamResult.Count < 2) { GetInput.ShowInfoDialog("ChromebookGUI: No Results", "No Results from Query String", "No results from that query (" + queryString + ")"); currentView.IsLoading = false; return; } File.WriteAllLines(System.IO.Path.GetTempPath() + "ChromebookGUI.csv", gamResult.ToArray()); Globals.ClearGlobals(); Globals.CsvLocation = System.IO.Path.GetTempPath() + "ChromebookGUI.csv"; Globals.DeviceId = "csv"; currentView.IsLoading = false; GetInput.ShowInfoDialog("ChromebookGUI: Success", "Successful Query", "Found " + (gamResult.Count - 1) + " devices using query " + queryString + "."); // subtract 1 because the first is "deviceId" }
/// <summary> /// Runs GAM and FixCSVCommas.FixCommas /// </summary> /// <param name="gamCommand"></param> /// <returns></returns> public static List <List <string> > RunGAMCommasFixed(String gamCommand) { return(FixCSVCommas.FixCommas(GAM.RunGAM(gamCommand))); }
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."; }
private async void ApplyChangesButton_Click(object sender, RoutedEventArgs e) { try { IsLoading = true; // check to see which fields have been changed (ones that aren't the global or "<no value present>", should make this an independent function) ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Updating Device", 50, "Updating device info..."); progressBar.UpdateBarAndText(50, "Updating device info..."); string gamCommand = "update cros " + Globals.DeviceId + " "; string outputText = ""; if (LocationField.Text != Globals.Location) { if (ShouldEmptyField(LocationField.Text, Globals.Location)) { switch (GetInput.GetYesOrNo("Empty Location?", "Clear the field?", "Click yes if you want to empty the Location field. Click no to cancel.")) { case "yes": break; case "no": outputField.Text = "Cancelling because you didn't want to empty a field."; progressBar.Close(); IsLoading = false; return; default: progressBar.Close(); return; } } gamCommand += "location \"" + LocationField.Text + "\" "; Globals.Location = LocationField.Text; outputText += "Location, "; } if (AssetIdField.Text != Globals.AssetId) { if (ShouldEmptyField(AssetIdField.Text, Globals.AssetId)) { switch (GetInput.GetYesOrNo("Empty Asset ID?", "Clear the field?", "Click yes if you want to empty the Asset ID field. Click no to cancel.")) { case "yes": break; case "no": outputField.Text = "Cancelling because you didn't want to empty a field."; progressBar.Close(); IsLoading = false; return; default: progressBar.Close(); return; } } gamCommand += "asset_id \"" + AssetIdField.Text + "\" "; Globals.AssetId = LocationField.Text; outputText += "Asset ID, "; } if (UserField.Text != Globals.User) { if (ShouldEmptyField(UserField.Text, Globals.User)) { switch (GetInput.GetYesOrNo("Empty User?", "Clear the field?", "Click yes if you want to empty the User field. Click no to cancel.")) { case "yes": break; case "no": outputField.Text = "Cancelling because you didn't want to empty a field."; progressBar.Close(); return; default: progressBar.Close(); return; } } gamCommand += "user \"" + UserField.Text + "\" "; Globals.User = UserField.Text; outputText += "User, "; } if (NoteField.Text != Globals.Note) { if (ShouldEmptyField(NoteField.Text, Globals.Note)) { switch (GetInput.GetYesOrNo("Empty Note?", "Clear the field?", "Click yes if you want to empty the Note field. Click no to cancel.")) { case "yes": break; case "no": outputField.Text = "Cancelling because you didn't want to empty a field."; progressBar.Close(); IsLoading = false; return; default: progressBar.Close(); return; } } gamCommand += "notes \"" + NoteField.Text.Replace("\"", "\\\"") + "\" "; // will output a note like this: "He told me \"Hello!\" yesterday." Globals.Note = NoteField.Text; outputText += "Note, "; } if (StatusDisabledRadio.IsChecked == true && Globals.Status != "DISABLED") { progressBar.UpdateBarAndText(55, "Disabling..."); await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action disable")); Globals.Status = "DISABLED"; outputText += "Status, "; } if (StatusActiveRadio.IsChecked == true && Globals.Status != "ACTIVE") { progressBar.UpdateBarAndText(55, "Enabling..."); await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action reenable")); Globals.Status = "ACTIVE"; outputText += "Status, "; } if (StatusDeprovisionedRadio.IsChecked == true && Globals.Status != "DEPROVISIONED") { //deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device [acknowledge_device_touch_requirement] int depReason = GetInput.GetDeprovisionReason(); switch (depReason) { case 1: progressBar.UpdateBarAndText(55, "Deprovisioning..."); await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_same_model_replace acknowledge_device_touch_requirement")); break; case 2: progressBar.UpdateBarAndText(55, "Deprovisioning..."); await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_different_model_replace acknowledge_device_touch_requirement")); break; // different case 3: // retire progressBar.UpdateBarAndText(55, "Deprovisioning..."); await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_retiring_device acknowledge_device_touch_requirement")); break; default: outputField.Text = "No deprovision reason was selected so that choice was not saved.\n"; break; // do nothing: they selected nothing. } if (depReason != 0) { Globals.Status = "DEPROVISIONED"; outputText += "Status, "; StatusActiveRadio.IsEnabled = false; StatusDeprovisionedRadio.IsEnabled = false; StatusDisabledRadio.IsEnabled = false; } } if (OrganizationalUnitField.Text != Globals.OrgUnitPath) { if (ShouldEmptyField(OrganizationalUnitField.Text, Globals.OrgUnitPath)) { GetInput.ShowInfoDialog("Empty org unit path.", "Your org unit path can't be blank.", "You can't have a blank org unit path."); return; } gamCommand += "ou \"" + OrganizationalUnitField.Text + "\" "; Globals.OrgUnitPath = OrganizationalUnitField.Text; outputText += "Organizational Unit "; } progressBar.UpdateBarAndText(75, "Updating info..."); if (gamCommand != "update cros " + Globals.DeviceId + " ") // if something was changed { string decision = GetInput.GetYesOrNo("GAM Confirmation", "Do you want to send this GAM command?", "gam " + gamCommand.Replace("\\", "\\\\")); if (decision != "yes") { IsLoading = false; progressBar.Close(); return; } string gamOutput = await Task.Run(() => GAM.RunGAMFormatted(gamCommand)); Console.WriteLine(gamOutput); } progressBar.UpdateBarAndText(99, "Finishing up..."); IsLoading = false; if (outputText.Length > 1) { outputField.Text = outputText += "was updated."; } progressBar.Close(); // build a GAM command from that information // run it // update globals // show success in output field } catch (Exception err) { Debug.CaptureRichException(err, CollectFieldsForRichException()); Debug.ShowErrorMessage(); } }