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 void btnFind_Click(object sender, EventArgs e) { lstFounded.Items.Clear(); object value = txtNameE.Text; try { IgObjs = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, value, 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()); } }
public bool Checkout() { try { string[] tagname = new string[] { Name }; if (IsTemplate) { _log.Debug(string.Format("Querying galaxy for {0}", Name)); IgObjects queryResult = Galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsTemplate, ref tagname); ICommandResult cmd = Galaxy.CommandResult; if (!cmd.Successful) { _log.Warn("QueryObjectsByName Failed:" + cmd.Text + " : " + cmd.CustomMessage); return(false); } ITemplate template = (ITemplate)queryResult[1];//can throw errors here if (template.CheckoutStatus != ECheckoutStatus.notCheckedOut) { _log.Warn(string.Format("Object [{0}] is already checked out by [{1}]", Name, template.checkedOutBy)); return(false); } _log.Debug(string.Format("Checking out {0}", Name)); template.CheckOut(); GRAccessObject = template; _log.Debug(string.Format("Checked out {0}", Name)); return(true); } else { _log.Debug(string.Format("Querying galaxy for {0}", Name)); IgObjects queryResult = Galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsInstance, ref tagname); ICommandResult cmd = Galaxy.CommandResult; if (!cmd.Successful) { _log.Warn("QueryObjectsByName Failed:" + cmd.Text + " : " + cmd.CustomMessage); return(false); } IInstance instance = (IInstance)queryResult[1];//can throw errors here if (instance.CheckoutStatus != ECheckoutStatus.notCheckedOut) { _log.Warn(string.Format("Object [{0}] is already checked out by [{1}]", Name, instance.checkedOutBy)); return(false); } _log.Debug(string.Format("Checking out {0}", Name)); instance.CheckOut(); GRAccessObject = instance; _log.Debug(string.Format("Checked out {0}", Name)); return(true); } } catch (Exception ex) { _log.Error(ex); return(false); } }
/// <summary> /// Filter the Galaxy object list based on custom filter information passed /// </summary> /// <returns></returns> private IgObjects ApplyCustomFilters(IgObjects GalaxyObjects) { List <String> galaxyObjectList = new List <String>(); IgObjects returnGalaxyObjects; string workingList = ""; string[] ObjectArray; // Get all of the items in the list. Only good way to do this is foreach (IgObject GObject in GalaxyObjects) { galaxyObjectList.Add(GObject.Tagname); } // Set the worklist to the beginning value which is all objects workingList = String.Join(",", galaxyObjectList.ToArray()); // Filter the Original List considering the Timestamp Filter if (this.ChangeLogTimestampStartFilter > DateTime.Parse("1/1/1970")) { workingList = GetObjectListForChangeLogAllObjectsAfterTimestampAsCSV(_changeLogTimestampStartFilter, ETemplateOrInstance.Both, workingList); } //Custom SQL if (_customSQLSelection != "") { workingList = GetObjectListFromCustomSQL(_customSQLSelection, ETemplateOrInstance.Both, workingList); } //Trim the leading and trailing " workingList = workingList.Trim('"'); // Split the working list in an array of string ObjectArray = workingList.Split(','); // Get an empty set of objects to start working with returnGalaxyObjects = GetEmptyIgObjects(); // Now get the template Objects into a GObjects set returnGalaxyObjects.AddFromCollection(_galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsTemplate, ObjectArray)); // Now get the template Objects into a GObjects set returnGalaxyObjects.AddFromCollection(_galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsInstance, ObjectArray)); // Check for any failures if ((returnGalaxyObjects == null) || (_galaxy.CommandResult.Successful != true) || returnGalaxyObjects.count == 0) { // Failed to retrieve any objects from the query throw new Exception("Failed to retrieve objects to export."); } return(returnGalaxyObjects); }
private void brnCreateObjOrInst_Click(object sender, EventArgs e) { // Создание объекта (UserDefined) string tagname = txtNameE.Text.ToString(); string parentname = txtCreateFrom.Text.ToString(); IgObjects parents = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, parentname, EMatch.MatchCondition); IgObject obj; ITemplate parent = (ITemplate)parents[parentname]; ITemplate result = parent.CreateTemplate(tagname, true); result.Save(); }
// Деплоим инстансы // TODO: сделать отслеивание какие конкретно объеты не азадеплоились public void DeployInstances(IgObjects gobjects) { if (gobjects == null) { throw new IgObjectsNullReferenceExceptions(); } gobjects.Deploy(EActionForCurrentlyDeployedObjects.redeployOriginal, ESkipIfCurrentlyUndeployed.dontSkipIfCurrentlyUndeployed, EDeployOnScan.doDeployOnScan, EForceOffScan.doForceOffScan, true); if (!gobjects.CommandResults.CompletelySuccessful) { throw new GalaxyObjectDeployException(gobjects.CommandResults); } }
/// <summary> /// Backup GObjects to a Single File /// </summary> /// <param name="ExportType"></param> /// <param name="GalaxyObjects"></param> /// <param name="BackupFileName"></param> /// <returns></returns> public int BackupToFile(EExportType ExportType, IgObjects GalaxyObjects, String BackupFileName) { try { // first verify connection if (!this.Connected) { throw new Exception("Galaxy not connected"); } // Make sure we have the right extension on the backup file BackupFileName = System.IO.Path.ChangeExtension(BackupFileName, CorrectExtension(ExportType)); // Check for file exists. Bail if the file already exists and we don't want to overwrite if (CheckandLogFileExists(BackupFileName)) { return(0); } log.Info("Backing up to " + BackupFileName); // Perform the actual export GalaxyObjects.ExportObjects(ExportType, BackupFileName); if (GalaxyObjects.CommandResults.CompletelySuccessful != true) { throw new Exception(GalaxyObjects.CommandResults.ToString()); } else { log.Info("Backup to " + BackupFileName + " succeeded."); } return(0); } catch (Exception ex) { log.Error(ex.ToString()); return(-1); } }
/// <summary> /// Create a delimited string with the object tagnames /// </summary> /// <param name="GalaxyObjects"></param> /// <param name="Delimiter"></param> /// <returns></returns> public static string AsDelimitedString(IgObjects GalaxyObjects, char Delimiter = ',') { StringBuilder workingValue = new StringBuilder(); string returnValue; if (GalaxyObjects.count == 0) { return(""); } foreach (IgObject Item in GalaxyObjects) { // Populate the single item array with the item's tagname workingValue.Append(Item.Tagname + Delimiter); } // Move over to string returnValue = workingValue.ToString().TrimEnd(Delimiter); // Return final value return(returnValue); }
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); }
private void button1_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in objectView.Rows) { if (row.Cells["checkedout"].Value.ToString() == "False") { if (row.Cells["renamed"].Value.ToString() != "") { if (row.Cells["template"].Value.ToString() == "True") { GalaxyObjects = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsTemplate, EConditionType.NameEquals, row.Cells["original"].Value.ToString(), EMatch.MatchCondition); template = (ITemplate)GalaxyObjects[1]; template.Tagname = row.Cells["renamed"].Value.ToString(); } else { GalaxyObjects = galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.NameEquals, row.Cells["original"].Value.ToString(), EMatch.MatchCondition); instance = (IInstance)GalaxyObjects[1]; instance.Tagname = row.Cells["renamed"].Value.ToString(); } } } } }
// Возвращает экземпляры производыне от заданного шаблона public IgObjects GetInstancesDerividedFrom(string tagName) { IgObjects gobjects = null; try { if (string.IsNullOrEmpty(tagName)) { throw new ArgumentNullException(nameof(tagName)); } gobjects = _galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.derivedOrInstantiatedFrom, tagName, EMatch.MatchCondition); GalaxyExceptions.ThrowIfNoSuccess(CommandResult); return(gobjects); } catch (Exception) { throw; } finally { gobjects = null; GC.Collect(); } }
static void Main(string[] args) { string nodeName = Environment.MachineName; string galaxyName = args[0]; string template = args[1]; string attribute = args[2]; string username = ""; string password = ""; if (args.Length >= 4) { username = args[3]; } if (args.Length >= 5) { password = args[4]; } GRAccessApp grAccess = new GRAccessAppClass(); IGalaxies gals = grAccess.QueryGalaxies(nodeName); if (gals == null || grAccess.CommandResult.Successful == false) { Console.WriteLine(grAccess.CommandResult.CustomMessage + grAccess.CommandResult.Text); return; } IGalaxy galaxy = gals[galaxyName]; ICommandResult cmd; if (galaxy == null) { Console.WriteLine("Galaxy '" + galaxyName + "' does not exist"); Console.WriteLine("Press return key to exit."); Console.ReadLine(); return; } galaxy.Login(username, password); cmd = galaxy.CommandResult; if (!cmd.Successful) { Console.WriteLine("Login to galaxy Example1 Failed :" + cmd.Text + " : " + cmd.CustomMessage); return; } string[] tagnames = { template }; IgObjects queryResult = galaxy.QueryObjectsByName( EgObjectIsTemplateOrInstance.gObjectIsTemplate, ref tagnames); ITemplate myTemplate = (ITemplate)queryResult[1]; myTemplate.CheckOut(); IAttributes myAttributes = myTemplate.Attributes; IAttribute myAttribute = myAttributes[attribute]; myAttribute.SetLocked(MxPropertyLockedEnum.MxUnLocked); myTemplate.Save(); myTemplate.CheckIn(); galaxy.Logout(); Console.WriteLine("The attribute should have been unlocked"); Console.WriteLine("Press return to exit"); Console.ReadLine(); }
static void Main(string[] args) { GRAccessApp grAccess = new GRAccessAppClass(); string machineName = Environment.MachineName; Console.Write("Enter Galaxy name:"); string galaxyName = Console.ReadLine(); IGalaxies gals = grAccess.QueryGalaxies(machineName); IGalaxy galaxy = gals[galaxyName]; if (galaxy == null) { Console.WriteLine("That galaxy does not exist"); Console.WriteLine("Press return to exit."); Console.ReadLine(); return; } Console.Write("Enter username, press return for blank:"); string galaxyUser = Console.ReadLine(); Console.Write("Enter password, press return for blank:"); string galaxyPass = Console.ReadLine(); galaxy.Login(galaxyUser, galaxyPass); if (!galaxy.CommandResult.Successful) { Console.WriteLine("Those login credentials are invalid"); Console.WriteLine("Press return to exit."); Console.ReadLine(); return; } string[] tagnames = new string[1]; Console.Write("Please enter the template name you wish to modify, please ensure it starts with $:"); tagnames[0] = Console.ReadLine(); IgObjects queryResult = galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsTemplate, ref tagnames); ITemplate myTemplate = (ITemplate)queryResult[1]; myTemplate.CheckOut(); string udaName = string.Format("uda_{0:yyyyMMddhhmmss}", DateTime.Now); myTemplate.AddUDA(udaName, MxDataType.MxBoolean, MxAttributeCategory.MxCategoryWriteable_USC_Lockable, MxSecurityClassification.MxSecurityOperate, false, null); myTemplate.Save(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { myTemplate.CheckIn(); } catch { Console.WriteLine("Caught Error"); if (stopWatch.IsRunning) { stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); } Console.ReadLine(); } stopWatch.Stop(); TimeSpan ts2 = stopWatch.Elapsed; string elapsedTime2 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime2); galaxy.Logout(); Console.WriteLine("Process has completed"); Console.ReadLine(); }
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); } }
/// <summary> /// Backup GObjects to multiple files in a single folder /// </summary> /// <param name="ExportType"></param> /// <param name="GalaxyObjects"></param> /// <param name="BackupFolderName"></param> /// <returns></returns> public int BackupToFolder(EExportType ExportType, IgObjects GalaxyObjects, String BackupFolderName) { String[] SingleItemName = new String[1]; IgObjects SingleObject; String BackupFileName; String Extension; String ConfigVersion; try { // first verify connection if (!this.Connected) { throw new Exception("Galaxy not connected"); } // Get Extension Extension = CorrectExtension(ExportType); //Create the Backup FOlder if it doesn't exist if (!System.IO.Directory.Exists(BackupFolderName)) { System.IO.Directory.CreateDirectory(BackupFolderName); } // Double check that we have the folder. If it's missing then error out if (!System.IO.Directory.Exists(BackupFolderName)) { throw new Exception("Missing Directory " + BackupFolderName); } //Need to iterate through the the objects foreach (IgObject Item in GalaxyObjects) { // Populate the single item array with the item's tagname SingleItemName[0] = Item.Tagname; //Default Config Version Text to Blank ConfigVersion = ""; //If we require config version in the filename then figure it out then add it if (_includeConfigVersion) { ConfigVersion = "-v" + Item.ConfigVersion.ToString(); } // Calculate the appropriate backup filename BackupFileName = BackupFolderName + "\\" + Item.Tagname + ConfigVersion + Extension; // Check for file exists. Bail if the file already exists and we don't want to overwrite // In this section it is actually a bit redundant but we don't want to perform the Galaxy query if not necessary if (CheckandLogFileExists(BackupFileName)) { continue; } // Figure out if we're dealing with a Template or Instance if (Item.Tagname.Substring(0, 1) == "$") { //Template SingleObject = _galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsTemplate, ref SingleItemName); } else { // Instance SingleObject = _galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsInstance, ref SingleItemName); } // Make sure we have an actual object in the collection if (SingleObject.count > 0) { // Perform the actual backup BackupToFile(ExportType, SingleObject, BackupFileName); } } return(0); } catch (Exception ex) { log.Error(ex.ToString()); return(-1); } }