static void Main(string[] args) { PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; if (myPISystem == null) { throw new InvalidOperationException("Default PISystem was not found."); } AFDatabase myDB = myPISystem.Databases["PE"]; if (myDB == null) { throw new InvalidOperationException("Database was not found."); } AFElement element = myDB.Elements["El"]; int count; using (var search = new AFAnalysisSearch(myDB, "MyAnalysisSearch", string.Format(@"Target:'{0}'", element.GetPath()))) { search.CacheTimeout = TimeSpan.FromMinutes(10); count = search.GetTotalCount(); Console.WriteLine("Found {0} Analyses", count); foreach (var item in search.FindObjects(fullLoad: true)) { Console.Write("Analysis Name = {0},", item.Name); Console.Write("Analysis Description = {0},", item.Description); Console.Write("Analysis Target = {0}", item.Target); Console.WriteLine(); } } }
/// <summary> /// Removes the analysis from the AF Database if it exists. /// </summary> /// <param name="name">The name of the analysis to remove.</param> /// <param name="output">The output logger used for writing messages.</param> public void RemoveAnalysisIfExists(string name, ITestOutputHelper output) { Contract.Requires(output != null); AFAnalysis preCheckAnalysis; using (var search = new AFAnalysisSearch(AFDatabase, string.Empty, $"Name:'{name}'")) { var coll = new AFNamedCollectionList <AFAnalysis>(search.FindObjects()); preCheckAnalysis = coll[name]; } if (preCheckAnalysis != null) { output.WriteLine($"Analysis [{preCheckAnalysis}] exists, delete it."); preCheckAnalysis.Delete(); preCheckAnalysis.CheckIn(); } else { output.WriteLine($"Analysis [{name}] does not exist, can not be deleted."); } }