Esempio n. 1
0
        public static BasicDeviceInfo GetAllDeviceInfo(string deviceId)
        {
            List <string>   gamResult = RunGAM("info cros " + deviceId + " fields deviceId,lastSync,serialNumber,status,notes,assetId,location,user,orgUnitPath");
            BasicDeviceInfo output    = new BasicDeviceInfo
            {
                DeviceId = deviceId
            };
            Dictionary <string, string> dict = new Dictionary <string, string>();

            for (int i = 1; i < gamResult.Count; i++)                      //starting i at 1 to ignore the first line of GAM output
            {
                gamResult[i] = gamResult[i].TrimStart(new char[] { ' ' }); // remove white space from the start of the string
                int splitPoint = gamResult[i].IndexOf(": ");
                dict.Add(gamResult[i].Substring(0, splitPoint), gamResult[i].Substring(splitPoint + 2, (gamResult[i].Length - splitPoint) - 2));
            }
            // now, I need to put a switch in a for loop to put this data into a basicdeviceinfo object, but should test it first..
            foreach (KeyValuePair <string, string> kvp in dict)
            {
                switch (kvp.Key)
                {
                case "orgUnitPath":
                    output.OrgUnitPath = kvp.Value;
                    break;

                case "annotatedAssetId":
                    output.AssetId = kvp.Value;
                    break;

                case "annotatedLocation":
                    output.Location = kvp.Value;
                    break;

                case "annotatedUser":
                    output.User = kvp.Value;
                    break;

                case "lastSync":
                    output.LastSync = kvp.Value;
                    break;

                case "notes":
                    output.Notes = kvp.Value;
                    break;

                case "serialNumber":
                    output.SerialNumber = kvp.Value;
                    break;

                case "status":
                    output.Status = kvp.Value;
                    break;

                default:
                    Console.WriteLine(kvp.Key + "," + kvp.Value);
                    break;
                }
            }

            return(output);
        }
        /// <summary>
        /// Essentially, run GAM.GetDeviceId() on whatever is entered into the text field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SubmitDeviceId_Click(object sender, RoutedEventArgs e)
        {
            ToggleMainWindowButtons(false);
            if (deviceInputField.Text.Length < 1 || deviceInputField.Text.ToLower() == "enter a device id, serial number, query string or email...")
            {
                outputField.Text = "You must enter something into the field at the top.";
                return;
            }

            //outputField.Text = GAM.GetDeviceId(deviceInputField.Text);
            IsLoading = true;
            string input = deviceInputField.Text;
            List <BasicDeviceInfo> possibleDevices = await Task.Run(() => GAM.GetDeviceId(input));

            BasicDeviceInfo deviceInfo = BasicDeviceInfo.HandleGetDeviceId(possibleDevices);

            Globals.ClearGlobals(); // clear the globals before adding new ones
            Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo);
            if (deviceInfo.Error)
            {
                outputField.Text = deviceInfo.ErrorText;
                return;
            }

            outputField.Text = "Found device. ID: " + deviceInfo.DeviceId + ".";
            if (!String.IsNullOrEmpty(deviceInfo.SerialNumber))
            {
                outputField.Text += "\nSerial Number: " + deviceInfo.SerialNumber;
            }
            if (!String.IsNullOrEmpty(deviceInfo.Notes))
            {
                outputField.Text += "\nNotes: " + deviceInfo.Notes;
            }
            if (!String.IsNullOrEmpty(deviceInfo.LastSync))
            {
                outputField.Text += "\nLast Sync: " + deviceInfo.LastSync;
            }
            if (!String.IsNullOrEmpty(deviceInfo.AssetId))
            {
                outputField.Text += "\nAsset ID: " + deviceInfo.AssetId;
            }
            if (!String.IsNullOrEmpty(deviceInfo.Location))
            {
                outputField.Text += "\nLocation: " + deviceInfo.Location;
            }
            if (!String.IsNullOrEmpty(deviceInfo.User))
            {
                outputField.Text += "\nUser: "******"\nStatus: " + deviceInfo.Status;
            }
            IsLoading = false;
            //deviceInputField.Text = deviceId;
        }
Esempio n. 3
0
 /// <summary>
 /// Sets globals from a BasicDeviceInfo object. Only sets the DeviceId, Note, Status, Serial Number, Asset ID and Location. Only the DeviceId is required.
 /// </summary>
 /// <param name="info"></param>
 public static void SetGlobalsFromBasicDeviceInfo(BasicDeviceInfo info)
 {
     DeviceId     = (!String.IsNullOrEmpty(info.DeviceId)) ? info.DeviceId : null;
     Note         = (!String.IsNullOrEmpty(info.Notes)) ? info.Notes : null;
     Status       = (!String.IsNullOrEmpty(info.Status)) ? info.Status : null;
     SerialNumber = (!String.IsNullOrEmpty(info.SerialNumber)) ? info.SerialNumber : null;
     AssetId      = (!String.IsNullOrEmpty(info.AssetId)) ? info.AssetId : null;
     User         = (!String.IsNullOrEmpty(info.User)) ? info.User : null;
     Location     = (!String.IsNullOrEmpty(info.Location)) ? info.Location : null;
 }
Esempio n. 4
0
        /// <summary>
        /// Gets a Device ID, from a variety of sources (email, serial number, asset id, email)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static BasicDeviceInfo GetDeviceId(String input)
        {
            if (IsDeviceId(input)) // this is already a device ID
            {
                return(new BasicDeviceInfo
                {
                    DeviceId = input
                });
            }
            else if (input.Contains("@"))
            {
                string user = input.Split('@')[0];
                if (String.IsNullOrEmpty(user))
                {
                    return(new BasicDeviceInfo
                    {
                        ErrorText = "There was an error processing your email entry: I couldn't find the email.",
                        Error = true
                    });
                }
                return(GetDeviceByGAMQuery("user:"******":"))
            {
                return(GetDeviceByGAMQuery(input));
            }
            else

            {
                // must be a serial number/asset id.

                // obey the preference here
                if (Preferences.SerialNumberAssetIdPriority)
                {
                    BasicDeviceInfo firstTry = GetDeviceByGAMQuery("asset_id:" + input);
                    if (!firstTry.Error)
                    {
                        return(firstTry);
                    }
                    return(GetDeviceByGAMQuery("id:" + input));
                }
                else
                {
                    BasicDeviceInfo firstTry = GetDeviceByGAMQuery("id:" + input);
                    if (!firstTry.Error)
                    {
                        return(firstTry);
                    }
                    return(GetDeviceByGAMQuery("asset_id:" + input));
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Converts a BasicDeviceInfo object to a dictionary with the same key names.
        /// </summary>
        /// <param name="input">The BasicDeviceInfo object you'd like back as a dictionary.</param>
        /// <returns>
        /// A Dictionary(string, string) with the same data
        /// </returns>
        public static Dictionary <string, string> ToDictionary(BasicDeviceInfo input)
        {
            Dictionary <string, string> output = new Dictionary <string, string>();

            if (!String.IsNullOrEmpty(input.LastSync))
            {
                output.Add("LastSync", input.LastSync);
            }
            if (!String.IsNullOrEmpty(input.SerialNumber))
            {
                output.Add("SerialNumber", input.SerialNumber);
            }
            if (!String.IsNullOrEmpty(input.Status))
            {
                output.Add("Status", input.Status);
            }
            if (!String.IsNullOrEmpty(input.Notes))
            {
                output.Add("Notes", input.Notes);
            }
            if (!String.IsNullOrEmpty(input.AssetId))
            {
                output.Add("AssetId", input.AssetId);
            }
            if (!String.IsNullOrEmpty(input.Location))
            {
                output.Add("Location", input.Location);
            }
            if (!String.IsNullOrEmpty(input.User))
            {
                output.Add("User", input.User);
            }
            if (!String.IsNullOrEmpty(input.OrgUnitPath))
            {
                output.Add("OrgUnitPath", input.OrgUnitPath);
            }
            if (!String.IsNullOrEmpty(input.Error ? "true" : "false"))
            {
                output.Add("Error", input.Error ? "true" : "false");
            }
            if (!String.IsNullOrEmpty(input.ErrorText))
            {
                output.Add("ErrorText", input.ErrorText);
            }

            return(output);
        }
        /// <summary>
        /// Opposite of BasicDeviceInfo.ToDictionary.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static BasicDeviceInfo DictionaryToBasicDeviceInfo(Dictionary <string, string> input)
        {
            BasicDeviceInfo output = new BasicDeviceInfo
            {
                LastSync     = !String.IsNullOrEmpty(input["LastSync"]) ? input["LastSync"] : null,
                SerialNumber = !String.IsNullOrEmpty(input["SerialNumber"]) ? input["SerialNumber"] : null,
                Status       = !String.IsNullOrEmpty(input["Status"]) ? input["Status"] : null,
                Notes        = !String.IsNullOrEmpty(input["Notes"]) ? input["Notes"] : null,
                AssetId      = !String.IsNullOrEmpty(input["AssetId"]) ? input["AssetId"] : null,
                Location     = !String.IsNullOrEmpty(input["Location"]) ? input["Location"] : null,
                User         = !String.IsNullOrEmpty(input["User"]) ? input["User"] : null,
                Error        = !String.IsNullOrEmpty(input["Error"]) ? (input["Error"] == "true" ? true : false) : false,
                ErrorText    = !String.IsNullOrEmpty(input["ErrorText"]) ? input["ErrorText"] : null
            };

            return(output);
        }
        /// <summary>
        /// Essentially, run GAM.GetDeviceId() on whatever is entered into the text field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void SubmitDeviceId_Click(object sender, RoutedEventArgs e)
        {
            ToggleMainWindowButtons(false);
            ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Getting Device Info", 5, "Searching for devices...");

            if (deviceInputField.Text.Length < 1 || deviceInputField.Text.ToLower() == "enter a device id, asset id, serial number, query string or email...")
            {
                outputField.Text = "You must enter something into the field at the top.";
                progressBar.Close();
                return;
            }

            //outputField.Text = GAM.GetDeviceId(deviceInputField.Text);
            BasicDeviceInfo deviceInfo = GAM.GetDeviceId(deviceInputField.Text);

            Globals.ClearGlobals(); // clear the globals before adding new ones
            Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo);
            if (deviceInfo.Error)
            {
                outputField.Text = deviceInfo.ErrorText;
                progressBar.Close();
                return;
            }
            await progressBar.UpdateBarAndText(30, "Getting more device info...");


            BasicDeviceInfo fullDeviceInfo = GAM.GetAllDeviceInfo(deviceInfo.DeviceId);

            fullDeviceInfo.LastSync     = !string.IsNullOrEmpty(deviceInfo.LastSync) ? deviceInfo.LastSync : null;
            fullDeviceInfo.DeviceId     = deviceInfo.DeviceId;
            fullDeviceInfo.SerialNumber = !string.IsNullOrEmpty(deviceInfo.SerialNumber) ? deviceInfo.SerialNumber : null;
            fullDeviceInfo.Status       = !string.IsNullOrEmpty(deviceInfo.Status) ? deviceInfo.Status : null;
            fullDeviceInfo.User         = !string.IsNullOrEmpty(deviceInfo.User) ? deviceInfo.User : null;
            await progressBar.UpdateBarAndText(40, "Saving variables...");

            Globals.SetGlobalsFromBasicDeviceInfo(fullDeviceInfo);
            await progressBar.UpdateBarAndText(55, "Populating fields...");

            if (!String.IsNullOrEmpty(fullDeviceInfo.Notes))
            {
                NoteField.Text = fullDeviceInfo.Notes;
            }
            else
            {
                NoteField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.AssetId))
            {
                AssetIdField.Text = fullDeviceInfo.AssetId;
            }
            else
            {
                AssetIdField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.Location))
            {
                LocationField.Text = fullDeviceInfo.Location;
            }
            else
            {
                LocationField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.User))
            {
                UserField.Text = fullDeviceInfo.User;
            }
            else
            {
                UserField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.OrgUnitPath))
            {
                OrganizationalUnitField.Text = fullDeviceInfo.OrgUnitPath;
            }
            else
            {
                OrganizationalUnitField.Text = "";
            }

            if (!String.IsNullOrEmpty(fullDeviceInfo.Status))
            {
                switch (fullDeviceInfo.Status)
                {
                case "ACTIVE":
                    StatusActiveRadio.IsChecked        = true;
                    StatusDisabledRadio.IsEnabled      = true;
                    StatusActiveRadio.IsEnabled        = true;
                    StatusDeprovisionedRadio.IsEnabled = true;
                    break;

                case "DISABLED":
                    StatusDisabledRadio.IsChecked      = true;
                    StatusDisabledRadio.IsEnabled      = true;
                    StatusActiveRadio.IsEnabled        = true;
                    StatusDeprovisionedRadio.IsEnabled = true;
                    break;

                case "DEPROVISIONED":
                    StatusDeprovisionedRadio.IsChecked = true;
                    StatusDeprovisionedRadio.IsEnabled = false;
                    StatusActiveRadio.IsChecked        = false;
                    StatusActiveRadio.IsEnabled        = false;
                    StatusDisabledRadio.IsChecked      = false;
                    StatusDisabledRadio.IsEnabled      = false;
                    break;
                }
            }

            await progressBar.UpdateBarAndText(85, "Filling in output box...");

            outputField.Text = "Found device. ID: " + fullDeviceInfo.DeviceId + ".";
            if (!String.IsNullOrEmpty(fullDeviceInfo.SerialNumber))
            {
                outputField.Text += "\nSerial Number: " + fullDeviceInfo.SerialNumber;
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.LastSync))
            {
                outputField.Text += "\nLast Sync: " + fullDeviceInfo.LastSync;
            }

            await progressBar.UpdateBarAndText(100, "Done!");

            ToggleMainWindowButtons(true);
            progressBar.Close();
            //deviceInputField.Text = deviceId;
        }
        /// <summary>
        /// Essentially, run GAM.GetDeviceId() on whatever is entered into the text field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void SubmitDeviceId_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IsLoading = true;
                AutoComplete.Close(deviceInputFieldStack);
                if (deviceInputField.Text.Length < 1 || deviceInputField.Text.ToLower() == "enter a device id, asset id, serial number, query string or email...")
                {
                    outputField.Text = "You must enter something into the field at the top.";
                    return;
                }

                string input = deviceInputField.Text;
                List <BasicDeviceInfo> possibleDevices = await Task.Run(() => GAM.GetDeviceId(input));

                BasicDeviceInfo deviceInfo = BasicDeviceInfo.HandleGetDeviceId(possibleDevices);
                Globals.ClearGlobals(); // clear the globals before adding new ones
                Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo);
                if (deviceInfo.Error)
                {
                    outputField.Text = deviceInfo.ErrorText;
                    return;
                }

                Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo);
                NoteField.Text               = !string.IsNullOrEmpty(deviceInfo.Notes) ? deviceInfo.Notes : "";
                AssetIdField.Text            = !string.IsNullOrEmpty(deviceInfo.AssetId) ? deviceInfo.AssetId : "";
                LocationField.Text           = !string.IsNullOrEmpty(deviceInfo.Location) ? deviceInfo.Location : "";
                UserField.Text               = !string.IsNullOrEmpty(deviceInfo.User) ? deviceInfo.User : "";
                OrganizationalUnitField.Text = !string.IsNullOrEmpty(deviceInfo.OrgUnitPath) ? deviceInfo.OrgUnitPath : "";

                if (!String.IsNullOrEmpty(deviceInfo.Status))
                {
                    switch (deviceInfo.Status)
                    {
                    case "ACTIVE":
                        StatusActiveRadio.IsChecked        = true;
                        StatusDisabledRadio.IsEnabled      = true;
                        StatusActiveRadio.IsEnabled        = true;
                        StatusDeprovisionedRadio.IsEnabled = true;
                        break;

                    case "DISABLED":
                        StatusDisabledRadio.IsChecked      = true;
                        StatusDisabledRadio.IsEnabled      = true;
                        StatusActiveRadio.IsEnabled        = true;
                        StatusDeprovisionedRadio.IsEnabled = true;
                        break;

                    case "DEPROVISIONED":
                        StatusDeprovisionedRadio.IsChecked = true;
                        StatusDeprovisionedRadio.IsEnabled = false;
                        StatusActiveRadio.IsChecked        = false;
                        StatusActiveRadio.IsEnabled        = false;
                        StatusDisabledRadio.IsChecked      = false;
                        StatusDisabledRadio.IsEnabled      = false;
                        break;
                    }
                }

                outputField.Text = "Found device. ID: " + deviceInfo.DeviceId + ".";
                if (!String.IsNullOrEmpty(deviceInfo.SerialNumber))
                {
                    outputField.Text += "\nSerial Number: " + deviceInfo.SerialNumber;
                }
                if (!String.IsNullOrEmpty(deviceInfo.LastSync))
                {
                    outputField.Text += "\nLast Sync: " + deviceInfo.LastSync;
                }

                AutoComplete.AddItemToList(input);
                IsLoading = false;
                //deviceInputField.Text = deviceId;
            } catch (Exception err)
            {
                Debug.CaptureRichException(err, CollectFieldsForRichException());
                Debug.ShowErrorMessage();
            }
        }