private static string GetReferenceMetadata(DatabaseContext dbContext, string tableName) { const string caption = "Референтни връзки"; string[] headers = { "№", "Наименование", "Колона", "Реферирана таблица", "Реферирана колона" }; string[] properties = { "Ordinal", "Name", "ColumnName", "ForeignTableName", "ForeignColumnName" }; var items = dbContext.References .FromSql( $@"SELECT ROW_NUMBER() OVER (ORDER BY KCU1.COLUMN_NAME) AS 'ORDINAL_POSITION', KCU1.CONSTRAINT_NAME AS 'CONSTRAINT_NAME', KCU1.TABLE_NAME AS 'TABLE_NAME', KCU1.COLUMN_NAME AS 'COLUMN_NAME', KCU2.TABLE_NAME AS 'FOREIGN_TABLE_NAME', KCU2.COLUMN_NAME AS 'FOREIGN_COLUMN_NAME' FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU1 ON KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2 ON KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME WHERE KCU1.CONSTRAINT_SCHEMA = 'dbo' AND KCU1.TABLE_NAME = {tableName}" ) .ToArray(); if (items.Length > 0) { return(HTMLFormatter.GenerateTable(caption, headers, properties, items)); } return(string.Empty); }
private static string GetIndexMetadata(DatabaseContext dbContext, string tableName) { const string caption = "Индекси"; string[] headers = { "№", "Наименование", "Тип", "Колони" }; string[] properties = { "Ordinal", "Name", "Type", "ColumnNames" }; var items = dbContext.Indexes .FromSql( $@"SELECT ROW_NUMBER() OVER (ORDER BY I.name) AS 'ORDINAL_POSITION', T.name AS 'TABLE_NAME', I.name AS 'INDEX_NAME', I.type_desc AS 'TYPE', AC.name AS 'COLUMN_NAME' FROM sys.tables AS T INNER JOIN sys.indexes I ON T.object_id = I.object_id INNER JOIN sys.index_columns IC ON I.object_id = IC.object_id INNER JOIN sys.all_columns AC ON T.object_id = AC.object_id AND IC.column_id = AC.column_id WHERE T.name = {tableName} AND T.is_ms_shipped = 0 AND I.type_desc != 'HEAP'" ) .ToArray(); if (items.Length > 0) { return(HTMLFormatter.GenerateTable(caption, headers, properties, items)); } return(string.Empty); }
private static string GetIndexMetadata(DatabaseContext dbContext, string tableName) { const string caption = "Индекси"; string[] headers = { "№", "Наименование", "Тип", "Колони" }; string[] properties = { "Ordinal", "Name", "Type", "ColumnNames" }; var items = dbContext.Indexes .FromSql( $@"select row_number() OVER (order by indexname) as ordinal_position, tablename, indexname, indexdef from pg_indexes where schemaname = 'public' and tablename = {tableName}" ) .ToArray(); if (items.Length > 0) { for (var i = 0; i < items.Length; i++) { var usingInfo = items[i].Definition.Split(" USING ")[1]; var usingFragments = usingInfo.Split(" ("); items[i].Type = usingFragments[0]; items[i].ColumnNames = usingFragments[1].Split(')')[0]; } return(HTMLFormatter.GenerateTable(caption, headers, properties, items)); } return(string.Empty); }
private static string GetReferenceMetadata(DatabaseContext dbContext, string tableName) { const string caption = "Референтни връзки"; string[] headers = { "№", "Наименование", "Колона", "Реферирана таблица", "Реферирана колона" }; string[] properties = { "Ordinal", "Name", "ColumnName", "ForeignTableName", "ForeignColumnName" }; var items = dbContext.References .FromSql( $@"select row_number() over(order by kcu1.column_name) as ordinal_position, kcu1.constraint_name as constraint_name, kcu1.table_name as table_name, kcu1.column_name as column_name, kcu2.table_name as foreign_table_name, kcu2.column_name as foreign_column_name from information_schema.referential_constraints rc inner join information_schema.key_column_usage kcu1 on kcu1.constraint_name = rc.constraint_name inner join information_schema.key_column_usage kcu2 on kcu2.constraint_name = rc.unique_constraint_name where kcu1.constraint_schema = 'public' and kcu1.table_name = {tableName}" ) .ToArray(); if (items.Length > 0) { return(HTMLFormatter.GenerateTable(caption, headers, properties, items)); } return(string.Empty); }
public void FormatHTMLShouldMakeHTMLPage() { // Assign HTMLFormatter hTMLFormatter = new HTMLFormatter(); // Act string htmlPage = hTMLFormatter.FormatHTML(ReportMoc()); // Assert Assert.IsTrue(!string.IsNullOrWhiteSpace(htmlPage)); }
// Test Strings public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement() { var formatter = new HTMLFormatter(); var result = formatter.FormatAsBold("abc"); // Too Specific Assert.Equal("<strong>abc</strong>", result.ToLower()); //More general Assert.StartsWith("<strong>", result.ToLower()); Assert.EndsWith("</strong>", result.ToLower()); Assert.Contains("abc", result.ToLower()); }
public void FormatAsBold_WhenCalled_ShouldReturnStringWithStrongElement() { var htmlFormat = new HTMLFormatter(); var result = htmlFormat.FormatAsBold("abc"); //Specific assertion Assert.That(result, Is.EqualTo("<strong>abc</strong>")); //More general assertion Assert.That(result, Does.StartWith("<strong>")); //Better Assert.That(result, Does.Contain("abc")); }
private static string GetColumnMetadata(DatabaseContext dbContext, string tableName) { const string caption = "Колони"; string[] headers = { "№", "Наименование", "Тип на данните", "Mаксимална дължина", "Nullable", "Стойност по подразбиране" }; string[] properties = { "Ordinal", "Name", "Type", "MaxLength", "Nullable", "Default" }; var items = dbContext.Columns .Where(e => e.TableSchema == "dbo" && e.TableName == tableName) .OrderBy(e => e.Ordinal) .ToArray(); for (var i = 0; i < items.Length; i++) { if (items[i].Default?.Contains("newid(") == true) { items[i].Default = null; } } return(HTMLFormatter.GenerateTable(caption, headers, properties, items)); }
private string setHTMLSelectView(object sender, bool isEmail) { try { var olv = sender as BrightIdeasSoftware.ObjectListView; //If nothing is selected, show a dark empty background if (olv == null || (!isEmail && olv.SelectedItems.Count < 1)) { return("<body style = \"background-color: #2b2b2b\" />"); } int itemCount = 0; var htmlFormatter = new HTMLFormatter(); if (isEmail) { itemCount = olv.Items.Count; htmlFormatter.SetBody(null, ("FiOS Health Check - " + DateTime.Today.ToString("MM/dd/yyyy"))); } else { itemCount = olv.SelectedItems.Count; htmlFormatter.SetBody("#777677"); } //Create an array since OLV Item collections does not have an enumerator for linq BrightIdeasSoftware.OLVListItem[] selectedOlvLis = new BrightIdeasSoftware.OLVListItem[itemCount]; //If email, copy all items in OLV to array. Otherwise copy only selected items. if (isEmail) { olv.Items.CopyTo(selectedOlvLis, 0); } else { olv.SelectedItems.CopyTo(selectedOlvLis, 0); } //Group health rollups on the server role to be able to display the results under each role var roles = selectedOlvLis.Select(x => x.RowObject as HealthRollup).GroupBy(x => x.Server.HostRole) .Select(x => new { x.Key, HostNames = x.Select(y => y.Server) }); //loop through each role, creating the selected servers and displaying their result and any errors if they exist foreach (var role in roles.OrderBy(x => x.Key)) { htmlFormatter.SetRole(role.Key.ToString()); foreach (var svr in role.HostNames.OrderBy(x => !x.IsActive).ThenBy(x => x.HostName)) { if (!svr.IsActive) { htmlFormatter.BeginTable(string.Format("{0} (Inactive)", svr.HostName), "#2f285b"); } else { htmlFormatter.BeginTable(svr.HostName); } var hru = selectedOlvLis.Select(x => x.RowObject as HealthRollup).Where(x => x.Server.HostName.Equals(svr.HostName)).FirstOrDefault(); foreach (var err in hru.Errors) { writeVerbose(string.Format("{0} has {1} errors for check type {2}. Result: {3}", svr.HostName, err.Error.Count, err.HCType, err.Result)); htmlFormatter.AddStatusRow(err.HCType.ToString(), err.Result); if (err.Error.Count > 0) { writeVerbose(string.Format("{0} - Check Type {1} - Errors: {2}", svr.HostName, err.HCType, string.Join(System.Environment.NewLine, err.Error))); htmlFormatter.AddErrorDescriptionRows(err.Error); } } htmlFormatter.EndTable(); } } return(htmlFormatter.ToString()); } catch (Exception ex) { writeError(string.Format("Error in selection changed delegate. {0}", ex.Message), 10900, System.Diagnostics.TraceEventType.Error); return(string.Empty); } }
static void Main(string[] args) { var server = ServerConfigMgr.GetServers().Where(x => x.HostName.ToUpper().Equals("CTXV01PIMGD01")).FirstOrDefault(); bool isExempt = ServerHealthCheckConfigMgr.IsExempt(server, ExemptionType.HardDrive, "O"); var winServicesToCheck = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck() .Where ( x => x.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && x.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0 || x.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && x.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0 || !x.Function.Equals(ServerFunction.Unknown) && (x.Function.Equals(server.HostFunction) && x.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + x.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0) || ((x.Roles.Count + x.Servers.Count == 0) && (x.Function.Equals(ServerFunction.Unknown))) ).ToArray(); //hcWServices = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.OnePerGroup).ToArray(); foreach (var svc in ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.Name == "WAS")) { var count = svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count(); var count2 = svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count(); //if (svc.Roles.Count >= 1) //svc.Roles.ForEach(x => Console.WriteLine("{3} - {0} | {1} | {2}", x.Item1, x.Item2, x.Item3, svc.Name)); bool bol1 = svc.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0; bool bol2 = svc.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0; bool bol3 = (svc.Function.Equals(server.HostFunction) && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0); bool bol4 = ((svc.Roles.Count + svc.Servers.Count == 0) && (svc.Function.Equals(ServerFunction.Unknown))); bool bol5 = svc.Servers.Where(y => y.Item1 && y.Item2.HostName == server.HostName).Count() > 0 && svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0 || svc.Roles.Where(y => y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() > 0 && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() == 0 || (svc.Function.Equals(server.HostFunction) && svc.Servers.Where(y => !y.Item1 && y.Item2.HostName == server.HostName).Count() + svc.Roles.Where(y => !y.Item1 && y.Item2 == server.HostRole && y.Item3 == server.HostFunction).Count() == 0) || ((svc.Roles.Count + svc.Servers.Count == 0) && (svc.Function.Equals(ServerFunction.Unknown))); Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8}", svc.Name, count, server.HostFunction, server.HostRole, count2, bol1, bol2, bol3, bol4, bol5); } //var roleCheck = ServerHealthCheckConfigMgr.GetWindowsServicesToCheck().Where(x => x.Roles.Where(y => y.Item1 && y.Item2 == svr.HostRole).Count() > 0); foreach (var service in winServicesToCheck) { Console.WriteLine("Name:\t\t{0}", service.Name); Console.WriteLine("Display:\t{0}", service.DisplayName); if (service.CheckStatus.Count > 0) { service.CheckStatus.ForEach(x => Console.WriteLine("Status:\t\t{0}", x.ToString())); } if (service.CheckStartupType.Count > 0) { service.CheckStartupType.ForEach(x => Console.WriteLine("StartupType:\t{0}", x.ToString())); } if (service.CheckLogonAs.Count > 0) { service.CheckLogonAs.ForEach(x => Console.WriteLine("LogonAs:\t{0} - {1}", x, GenericChecks.GetWindowsServiceLogonAccount("B1ZHN32", service.Name))); } if (service.Roles.Count > 0) { service.Roles.ForEach((x) => { if (x.Item1) { Console.WriteLine("INCLUDE ROLES"); } else { Console.WriteLine("EXCLUDE ROLES"); } Console.WriteLine("Role:\t\t{0}", x.Item2.ToString()); Console.WriteLine("Function:\t{0}", x.Item3.ToString()); }); } if (service.Servers.Count > 0) { service.Servers.ForEach((x) => { if (x.Item1) { Console.WriteLine("INCLUDE SERVERS"); } else { Console.WriteLine("EXCLUDE SERVERS"); } Console.WriteLine("Server Name:\t{0}", x.Item2.HostName); Console.WriteLine("Server IP:\t{0}", x.Item2.IPAddress); Console.WriteLine("Server Location:\t{0}", x.Item2.HostLocation.ToString()); }); } Console.WriteLine("OnePerGroup:\t{0}", service.OnePerGroup); Console.WriteLine(); } Console.WriteLine("Press Enter to Continue..."); Console.ReadLine(); HTMLFormatter formatter = new HTMLFormatter(); formatter.SetRole(ServerRole.NSP.ToString()); formatter.BeginTable("NSPTXCAWAPV01"); formatter.AddStatusRow("Server Status", StatusResult.Ok); formatter.AddStatusRow("Web Services", StatusResult.Error); List <string> errors = new List <string>(); errors.Add("Config file mismatch with NSPTXCAWAPV02"); errors.Add("Web API returned error"); formatter.AddErrorDescriptionRows(errors); formatter.AddStatusRow("Database", StatusResult.Error); errors.Clear(); errors.Add("Missing data in table"); formatter.AddErrorDescriptionRows(errors); formatter.EndTable(); formatter.BeginTable("NSPTXCAWAPV02"); formatter.AddStatusRow("Server Status", StatusResult.Ok); formatter.AddStatusRow("Web Services", StatusResult.Error); errors.Clear(); errors.Add("Config file mismatch with NSPTXCAWAPV01"); formatter.AddErrorDescriptionRows(errors); formatter.AddStatusRow("Database", StatusResult.Ok); formatter.EndTable(); formatter.BeginTable("NSPTXCAWAPV03"); formatter.AddStatusRow("Server Status", StatusResult.Critical); errors.Clear(); errors.Add("Server is unreachable."); formatter.AddErrorDescriptionRows(errors); formatter.AddStatusRow("Web Services", StatusResult.Ok); formatter.AddStatusRow("Database", StatusResult.Ok); formatter.EndTable(); Toolset.SendEmail("mailrelay.corp.pvt", null, 25, false, "HealthCheck Test Email", formatter.ToString(), "*****@*****.**", new string[1] { "*****@*****.**" }, null); var servers = ServerConfigMgr.GetServers().ToList(); foreach (var svr in servers.Where(x => x.HostRole == ServerRole.IMG)) { if (svr is FiOSDbServer) { Console.WriteLine("\nDATABASE:\n"); Console.WriteLine((svr as FiOSDbServer).DatabaseType); } else if (svr is FiOSWebServer) { Console.WriteLine("\nIIS SERVER:\n"); } else { Console.Write("\nFiOS Server:\n"); } Console.WriteLine(svr.HostName); Console.WriteLine(svr.HostFullName); Console.WriteLine(svr.HostFunction); Console.WriteLine(svr.HostLocation); Console.WriteLine(svr.HostLocationName); Console.WriteLine(svr.HostName); Console.WriteLine(svr.HostRole); Console.WriteLine(svr.IsOnline); try { if (svr is FiOSWebServer) { using (var iisMgr = new IISServerMgr(svr)) { try { var Sites = iisMgr.GetSiteCollection(); foreach (var site in Sites) { Console.WriteLine("Site: {0} - {1} - {2}", site.Name, site.ServerAutoStart, site.State); foreach (var app in site.Applications) { Console.WriteLine("App Pool: {0} - {1}", app.ApplicationPoolName, app.Path); foreach (var vd in app.VirtualDirectories) { Console.WriteLine("Virtual Dir: {0} - {1}", vd.Path, vd.PhysicalPath); foreach (var attr in vd.Attributes) { Console.WriteLine("Attribute: {0} - {1}", attr.Name, attr.Value); } foreach (var ce in vd.ChildElements) { foreach (var attr in ce.Attributes) { Console.WriteLine("Child Attribute: {0} - {1}", attr.Name, attr.Value); } } } } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Failed to get Sites for {0}. {1}", svr.HostName, ex.Message); Console.ResetColor(); } } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("General Error: {0}", ex.Message); Console.ResetColor(); } } Console.WriteLine("\n\nPress any key to exit..."); Console.ReadLine(); }