private void Gather(IGatherUpdates gatherer) { try { gatherer.GatherAndReport(m_Sink); } catch (Exception e) { m_Sink.WriteLine("Exception occurred executing the {0} => {1}", gatherer.GetType().ToString(), e.Message); } }
private static void RetrieveAndReportUpdates(IReportSink sink, ITargetServer targetServer) { var wmiNamespace = string.Format("\\\\{0}\\root\\CIMV2", targetServer.ServerName); var searcher = new ManagementObjectSearcher(wmiNamespace, "select * from Win32_QuickFixEngineering"); searcher.Options.UseAmendedQualifiers = true; searcher.Scope.Options.Locale = "MS_" + CultureInfo.CurrentCulture.LCID.ToString("X"); ManagementObjectCollection results = searcher.Get(); foreach (ManagementObject item in results) { sink.WriteLine("{0, -14}\t{1, -12}\t{2}", item["HotFixID"].ToString(), item["InstalledOn"].ToString(), item["Caption"].ToString()); } }
public void GatherAndReport(IReportSink sink) { sink.WriteLine(); sink.WriteLine("------------------------ ------------------------------------------------------"); sink.WriteLine("{0, -24} SqlServerVersionGatherer", DateTime.Now.ToUniversalTime().ToString()); sink.WriteLine(); foreach (ITargetSqlServer targetSqlServer in m_SqlServers) { using (var connection = new SqlConnection(targetSqlServer.ConnectionString)) { var command = connection.CreateCommand(); var adapter = new SqlDataAdapter(command); var table = new DataTable("MSVer"); command.CommandText = "xp_msver"; command.CommandType = CommandType.StoredProcedure; try { connection.Open(); adapter.Fill(table); var row = table.Select("[NAME] = 'ProductVersion'"); var version = row[0][3].ToString(); if (m_VersionMap.ContainsKey(version)) { sink.WriteLine("{0, -30}\t{1, -12}\t{2}", targetSqlServer.ServerName, version, m_VersionMap[version]); } else { sink.WriteLine("{0, -30}\t{1, -12}\tNOT FOUND IN MAP", targetSqlServer.ServerName, version); } } catch (Exception e) { sink.WriteLine("EXCEPTION! > {0} ==> {1}", targetSqlServer.ServerName, e.Message); } } } }
public void GatherAndReport(IReportSink sink) { sink.WriteLine(); sink.WriteLine("------------------------ ------------------------------------------------------"); sink.WriteLine("{0, -24} WindowsServerUpdateGatherer", DateTime.Now.ToUniversalTime().ToString()); sink.WriteLine(); foreach (ITargetServer targetServer in m_Servers) { try { sink.WriteLine(); sink.WriteLine(">>> {0}", targetServer.ServerName); RetrieveAndReportUpdates(sink, targetServer); } catch (Exception e) { sink.WriteLine("EXCEPTION! > {0} ==> {1}", targetServer.ServerName, e.Message); } } }