private void btnGetInfo_Click(object sender, EventArgs e) // peredelatb pod svoi celi // { lstFounded.Items.Clear(); try { IgObjs = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.deploymentStatusIs, EDeploymentStatus.notDeployed, EMatch.MatchCondition); if (!(IgObjs == null)) { foreach (IgObject igobj in IgObjs) { //lstFounded.Items.Add(igobj.HierarchicalName + "[" + igobj.Tagname + "]"); lstFounded.Items.Add(igobj.Tagname); //lstFounded.Items.Add(igobj.HierarchicalName); } } else { lstFounded.Items.Add("Nothing founded."); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private bool GetAllObjects() { GalaxyObjects = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, "thisshoulodnotmatch", EMatch.NotMatchCondition); foreach (IgObject myobject in GalaxyObjects) { bool _checkout = false; if (myobject.CheckoutStatus == ECheckoutStatus.notCheckedOut) { _checkout = false; } else { _checkout = true; } myObjects.Add(new MyObject { objectName = myobject.Tagname, objectRename = "", checkedOut = _checkout, template = true }); } GalaxyObjects = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.NameEquals, "thisshoulodnotmatch", EMatch.NotMatchCondition); foreach (IgObject myobject in GalaxyObjects) { bool _checkout = false; if (myobject.CheckoutStatus == ECheckoutStatus.notCheckedOut) { _checkout = false; } else { _checkout = true; } myObjects.Add(new MyObject { objectName = myobject.Tagname, objectRename = "", checkedOut = _checkout, template = false }); } return(false); }
/// <summary> /// Get a complete list of objects from galaxy /// </summary> /// <returns></returns> public IgObjects GetCompleteObjectList(bool ApplyFilters = false) { IgObjects returnGalaxyObjects; // Get an empty set of objects to start working with returnGalaxyObjects = GetEmptyIgObjects(); // Now get the template Objects into a GObjects set returnGalaxyObjects.AddFromCollection(_galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.namedLike, "%")); // Now get the template Objects into a GObjects set returnGalaxyObjects.AddFromCollection(_galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.namedLike, "%")); if (ApplyFilters) { this.ApplyCustomFilters(returnGalaxyObjects); } // Return the complete list return(returnGalaxyObjects); }
// Получает шаблон, если такой существует public ITemplate GetTemplateIfExists(string tagName) { if (string.IsNullOrWhiteSpace(tagName)) { throw new ArgumentNullException(nameof(tagName)); } var objects = _galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, tagName, EMatch.MatchCondition); GalaxyExceptions.ThrowIfNoSuccess(CommandResult); if (objects == null || objects.count == 0) { return(null); } return((ITemplate)(objects[tagName])); }
static void Main(string[] args) { string node; string galaxyName; string galaxyUser; string galaxyPass; List <string> protectedTemplates = new List <string>(); string line; Console.Write("Enter Galaxy Node name: "); node = Console.ReadLine(); Console.Write("Enter Galaxy Name: "); galaxyName = Console.ReadLine(); Console.Write("Enter Galaxy Username: "******"Enter Galaxy Password: "******"protectedObjects.txt"); while ((line = file.ReadLine()) != null) { protectedTemplates.Add(line.ToLower()); } try { log.Info("Attempting to connect to " + galaxyName + " using a username of " + galaxyUser); GRAccessApp grAccess = new GRAccessAppClass(); IGalaxies gals = grAccess.QueryGalaxies(node); log.Info("Found " + gals.count + " galaxies"); IGalaxy galaxy = gals[galaxyName]; log.Info("Attempting to log into galaxy"); galaxy.Login(galaxyUser, galaxyPass); IgObjects objs = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, "thisshouldnevermatch", EMatch.NotMatchCondition); log.Info("Found " + objs.count + " objects"); int x = 0; foreach (ITemplate template in objs) { IgObjects derivedtemplates = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.derivedOrInstantiatedFrom, template.Tagname, EMatch.MatchCondition); IgObjects derivedinstances = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.derivedOrInstantiatedFrom, template.Tagname, EMatch.MatchCondition); log.Info("Checking " + template.Tagname + " for derived templates"); if (derivedtemplates.count == 0) { log.Info(template.Tagname + " has no derived templates, checking instances now"); if (derivedinstances.count == 0) { if (!protectedTemplates.Contains(template.Tagname.ToLower())) { log.Info(template.Tagname + " has no instances, this template will be removed from the galaxy"); x++; template.DeleteTemplate(); } else { log.Info(template.Tagname + " has no instances but is a protected object so will not be deleted"); } } } } galaxy.Logout(); Console.WriteLine("Finished. {0} objects deleted, press return to exit", x.ToString()); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }