public void QueryACF2s(WqlConnectionManager connection,String[] ACF2s,int subThread) { try { int i = 1; foreach (String id in ACF2s) { int counter = 0; List<NodeItem> nodes = new List<NodeItem>(); IResultObject query = scope.QueryProcessor.ExecuteQuery (@"Select distinct SMS_R_SYSTEM.NetbiosName, SMS_R_SYSTEM.OperatingSystemNameandVersion, SMS_R_SYSTEM.CreationDate, SMS_SITE.SiteName, SMS_R_SYSTEM.Active, SMS_R_SYSTEM.LastLogonUserName, SMS_R_SYSTEM.employeeId, SMS_R_SYSTEM.AgentTime, SMS_R_SYSTEM.AgentName, SMS_G_SYSTEM_COMPUTER_SYSTEM.Model, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.NumberOfConsoleLogons, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.TotalUserConsoleMinutes, SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.TotalConsoleTime, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.LastConsoleUse from SMS_G_SYSTEM_SYSTEM_CONSOLE_USER INNER JOIN SMS_R_SYSTEM on SMS_R_SYSTEM.ResourceID = SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.ResourceID LEFT JOIN SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE on SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.ResourceID = SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.ResourceID LEFT JOIN SMS_G_SYSTEM_SYSTEM_ENCLOSURE on SMS_G_SYSTEM_SYSTEM_ENCLOSURE.ResourceID = SMS_R_SYSTEM.ResourceID INNER JOIN SMS_G_SYSTEM_COMPUTER_SYSTEM on SMS_G_SYSTEM_COMPUTER_SYSTEM.ResourceID = SMS_R_SYSTEM.ResourceID left join SMS_Site on SMS_Site.SiteCode=SMS_R_SYSTEM.SMSAssignedSites Where SMS_R_SYSTEM.employeeId = '" + id + @"' Or SMS_R_SYSTEM.LastLogonUserName = '******' AND SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.TotalConsoleTime != 0"); foreach (IResultObject o in query) { foreach (IResultObject thing in o) { Dictionary<String, String> results = new Dictionary<string, string>(); List<IResultObject> obj = thing.GenericsArray; foreach (IResultObject obj2 in obj) { foreach (KeyValuePair<string, string> kvpPair in obj2.PropertyList) { //Console.WriteLine(kvpPair.Value + " " + kvpPair.Key); results.Add(kvpPair.Key, kvpPair.Value); } } NodeItem item = populateItemWin7(results); if (item != null) { nodes.Add(item); counter++; } //Console.WriteLine(); } } /*The above query will not produce any US results * Try and find all results for that user */ if (counter == 0) { query = scope.QueryProcessor.ExecuteQuery("Select * From SMS_R_SYSTEM left join SMS_Site on SMS_Site.SiteCode=SMS_R_SYSTEM.SMSAssignedSites where NetbiosName = '" + id + "' OR LastLogonUserName = '******'"); foreach (IResultObject o in query) { foreach (IResultObject thing in o) { Dictionary<String, String> results = new Dictionary<string, string>(); List<IResultObject> obj = thing.GenericsArray; foreach (IResultObject obj2 in obj) { foreach (KeyValuePair<string, string> kvpPair in obj2.PropertyList) { results.Add(kvpPair.Key, kvpPair.Value); } } nodes.Add(populateItemWinXP(results)); counter++; //Console.WriteLine(); } } } Sorter sorter = new Sorter(); nodes = sorter.removeDuplicateNodes(nodes); //PERFORM SELECTION LOGIC AND INSERT INTO active ACF2 //Console.WriteLine("Making Selections"); if (counter > 0) { String log = ""; //Way to return two variables to keep track of selection logging //Key will contain the list of Nodes //Value will contain the log KeyValuePair<List<NodeItem>,String> selections = sorter.selectBest(nodes,id,safety, log); nodes = sorter.sortByDescendingDate(nodes); lock (active_ACF2) { active_ACF2.Add(new ACF2 { ID = id, Nodes = nodes, SelectedNodes = selections.Key, log = selections.Value }); } } else { //Add node to rejection list lock (rejections) { rejections.Add(new Rejections { ID = id }); } } //Console.WriteLine("Selections have been made"); counter++; lock (sem) { completed++; String[] objects = new String[3]; objects[0] = completed.ToString(); objects[1] = id; objects[2] = totalACF2s.ToString(); if (subThread == 1) _backgroundWorker.ReportProgress((100 * completed) / totalACF2s, objects); else _backgroundWorker2.ReportProgress((100 * completed) / totalACF2s, objects); } i++; } } catch (SmsException ex) { Console.WriteLine("Failed to query List: " + ex.Message); //throw; } catch (Exception ex) { Console.WriteLine("Error occured: " + ex.Message); //throw; } }
/* * Basic Sort Features * Only for specific tabs are currently available */ private void sortButton_Click(object sender, DataGridViewCellMouseEventArgs e) { List<NodeItem> list = active_ACF2.Find( delegate(ACF2 user) { return user.ID == current_User; }).Nodes; Sorter sort = new Sorter(); if (e.ColumnIndex >= 0 && e.RowIndex == -1) { if (nodeList.Columns[e.ColumnIndex].Name == "Node") { active_ACF2.Find( delegate(ACF2 user) { return user.ID == current_User; }).Nodes = sort.sortByAscendingNode(list); displayACF2(current_User); } else if (nodeList.Columns[e.ColumnIndex].Name == "HeartBeat") { active_ACF2.Find( delegate(ACF2 user) { return user.ID == current_User; }).Nodes = sort.sortByDescendingDate(list); displayACF2(current_User); } else if (nodeList.Columns[e.ColumnIndex].Name == "DateCreated") { active_ACF2.Find( delegate(ACF2 user) { return user.ID == current_User; }).Nodes = sort.sortByDescendingCreation(list); displayACF2(current_User); } } }
public void QueryACF2s(WqlConnectionManager connection, String[] ACF2s, int subThread) { try { int i = 1; foreach (String id in ACF2s) { int counter = 0; List <NodeItem> nodes = new List <NodeItem>(); IResultObject query = scope.QueryProcessor.ExecuteQuery (@"Select distinct SMS_R_SYSTEM.NetbiosName, SMS_R_SYSTEM.OperatingSystemNameandVersion, SMS_R_SYSTEM.CreationDate, SMS_SITE.SiteName, SMS_R_SYSTEM.Active, SMS_R_SYSTEM.LastLogonUserName, SMS_R_SYSTEM.employeeId, SMS_R_SYSTEM.AgentTime, SMS_R_SYSTEM.AgentName, SMS_G_SYSTEM_COMPUTER_SYSTEM.Model, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.NumberOfConsoleLogons, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.TotalUserConsoleMinutes, SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.TotalConsoleTime, SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.LastConsoleUse from SMS_G_SYSTEM_SYSTEM_CONSOLE_USER INNER JOIN SMS_R_SYSTEM on SMS_R_SYSTEM.ResourceID = SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.ResourceID LEFT JOIN SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE on SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.ResourceID = SMS_G_SYSTEM_SYSTEM_CONSOLE_USER.ResourceID LEFT JOIN SMS_G_SYSTEM_SYSTEM_ENCLOSURE on SMS_G_SYSTEM_SYSTEM_ENCLOSURE.ResourceID = SMS_R_SYSTEM.ResourceID INNER JOIN SMS_G_SYSTEM_COMPUTER_SYSTEM on SMS_G_SYSTEM_COMPUTER_SYSTEM.ResourceID = SMS_R_SYSTEM.ResourceID left join SMS_Site on SMS_Site.SiteCode=SMS_R_SYSTEM.SMSAssignedSites Where SMS_R_SYSTEM.employeeId = '" + id + @"' Or SMS_R_SYSTEM.LastLogonUserName = '******' AND SMS_G_SYSTEM_SYSTEM_CONSOLE_USAGE.TotalConsoleTime != 0"); foreach (IResultObject o in query) { foreach (IResultObject thing in o) { Dictionary <String, String> results = new Dictionary <string, string>(); List <IResultObject> obj = thing.GenericsArray; foreach (IResultObject obj2 in obj) { foreach (KeyValuePair <string, string> kvpPair in obj2.PropertyList) { //Console.WriteLine(kvpPair.Value + " " + kvpPair.Key); results.Add(kvpPair.Key, kvpPair.Value); } } NodeItem item = populateItemWin7(results); if (item != null) { nodes.Add(item); counter++; } //Console.WriteLine(); } } /*The above query will not produce any US results * Try and find all results for that user */ if (counter == 0) { query = scope.QueryProcessor.ExecuteQuery("Select * From SMS_R_SYSTEM left join SMS_Site on SMS_Site.SiteCode=SMS_R_SYSTEM.SMSAssignedSites where NetbiosName = '" + id + "' OR LastLogonUserName = '******'"); foreach (IResultObject o in query) { foreach (IResultObject thing in o) { Dictionary <String, String> results = new Dictionary <string, string>(); List <IResultObject> obj = thing.GenericsArray; foreach (IResultObject obj2 in obj) { foreach (KeyValuePair <string, string> kvpPair in obj2.PropertyList) { results.Add(kvpPair.Key, kvpPair.Value); } } nodes.Add(populateItemWinXP(results)); counter++; //Console.WriteLine(); } } } Sorter sorter = new Sorter(); nodes = sorter.removeDuplicateNodes(nodes); //PERFORM SELECTION LOGIC AND INSERT INTO active ACF2 //Console.WriteLine("Making Selections"); if (counter > 0) { String log = ""; //Way to return two variables to keep track of selection logging //Key will contain the list of Nodes //Value will contain the log KeyValuePair <List <NodeItem>, String> selections = sorter.selectBest(nodes, id, safety, log); nodes = sorter.sortByDescendingDate(nodes); lock (active_ACF2) { active_ACF2.Add(new ACF2 { ID = id, Nodes = nodes, SelectedNodes = selections.Key, log = selections.Value }); } } else { //Add node to rejection list lock (rejections) { rejections.Add(new Rejections { ID = id }); } } //Console.WriteLine("Selections have been made"); counter++; lock (sem) { completed++; String[] objects = new String[3]; objects[0] = completed.ToString(); objects[1] = id; objects[2] = totalACF2s.ToString(); if (subThread == 1) { _backgroundWorker.ReportProgress((100 * completed) / totalACF2s, objects); } else { _backgroundWorker2.ReportProgress((100 * completed) / totalACF2s, objects); } } i++; } } catch (SmsException ex) { Console.WriteLine("Failed to query List: " + ex.Message); //throw; } catch (Exception ex) { Console.WriteLine("Error occured: " + ex.Message); //throw; } }