Ejemplo n.º 1
0
        /// <summary>
        /// Easily get an org path. Handles all of the logic of opening the data selector window and finding which is the path.
        /// </summary>
        /// <returns>A string containing the full path to the organizational unit.</returns>
        public static string GetOrgUnitFromSelector()
        {
            List <List <string> > fixedOrgs = GAM.RunGAMCommasFixed("print orgs allfields");

            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)
            {
                return("There was an error getting your org units. You don't seem to have any.");
            }
            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..."))
            {
                return("Either you didn't enter anything or there was an error. Nothing has been changed.");
            }

            return(orgPath);
        }