Code Snippet
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewPage.aspx.cs" Inherits="TestConnection_NewPage" %>
- DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html >
- <head id="Head1" runat="server">
- head>
- <title>jQuery UI Tabs - Open on mouseovertitle>
- <link type="text/css" href="jquery-ui-1.8.custom.css" rel="Stylesheet"/>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js">script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.js">script>
- <style type="text/css">.style3 { FONT-SIZE: x-large; COLOR: #ffffff }
- .style4 { FONT-FAMILY: Verdana; TEXT-ALIGN: center }
- .style5 { FONT-SIZE: medium }
- .style6 { FONT-WEIGHT: bold; FONT-SIZE: medium; FILTER: dropshadow(color=#000000,offx=2,offy=2); COLOR: #0b77d3; FONT-FAMILY: Verdana; TEXT-ALIGN: center }
- .moduleGroupDivStyle {width:100%; }
- .appGroupHeadingStyle {width:100%; height:20px; padding-left:20px; text-align:left; vertical-align:bottom; font-weight:bold; font-size:12px; background-color:LightGrey;}
- .RadioButtonStyle {font-size:11px; }
- style>
- <script type="text/javascript">
- $(function () {
- $("#tabs").tabs({
- event: 'mouseover'
- });
- });
- script>
- <body>
- <div class="demo">
- <div id="displayLoading"><span style="background-color:Yellow;font-size:larger;">Loading.... span>div>
- <table cellspacing="0" cellpadding="0" width="100%" border="0">
- <tbody>
- <tr>
- <td valign="bottom" nowrap width="29%" background="di1.gif" height="55">
- td>
- <td class="style3" nowrap background="di1.gif" height="55">
- Validate Web.config td>
- <td valign="bottom" nowrap width="22%" background="di1.gif">
- td>
- tr>
- tbody>
- table>
- <table width="70%">
- <tr>
- <td width="10%"> td><td style="height:1cm"> td>
- tr>
- <tr>
- <td width="10%"> td><td><center><h5>Webservices, nHibernate Mapping Files, Database Connectionsh5>center>td>
- tr>
- <tr>
- <td> td><td> td>
- tr>
- <tr>
- <td>
- td>
- <td>
- <div id="tabs">
- <ul>
- <li><a href="#tabs-1">Web Service URLsa>li>
- <li><a href="#tabs-2">Nhibernate Mappinga>li>
- <li><a href="#tabs-3">Connection Stringa>li>
- ul>
- <div id="tabs-1">
- <p>
- <asp:Table ID="wsListTable" runat="server" BorderWidth="1" BackColor="AliceBlue"
- Font-Size="Larger" CellPadding="2" CellSpacing="2" BorderColor="Black">
- <asp:TableRow BorderWidth=1 Font-Bold="true">
- <asp:TableCell BorderWidth="1" Width="10%" VerticalAlign="Middle" align="center">Serial Noasp:TableCell>
- <asp:TableCell BorderWidth="1" Width="40%">URL/Connectionasp:TableCell>
- <asp:TableCell BorderWidth="1" Width="10%" align="center">Statusasp:TableCell>
- asp:TableRow>
- asp:Table>
- <br/>
- <br/>
- <button id="TestConn">Test Webservice button><span style="background-color:Yellow;font-size:larger;" id="lblstatus">span>
- p>
- div>
- <div id="tabs-2">
- <p>
- <span id="TestConnection">span>
- <br/>
- <br/>
- <button id="TestDatabase">Test Mappingbutton>
- p>
- div>
- <div id="tabs-3">
- <p><asp:Table ID="wsDatabaseConnection" runat="server" BorderWidth="1" BackColor="AliceBlue"
- Font-Size="Larger" CellPadding="2" CellSpacing="2" BorderColor="Black">
- <asp:TableRow BorderWidth=1 Font-Bold="true">
- <asp:TableCell BorderWidth="1" Width="10%" VerticalAlign="Middle" align="center">Nameasp:TableCell>
- <asp:TableCell BorderWidth="1" Width="30%">Connection stringasp:TableCell>
- <asp:TableCell BorderWidth="1" Width="10%" align="center">Providerasp:TableCell>
- asp:TableRow>
- asp:Table> p>
- div>
- div>
- td>
- tr>
- table>
- div>
- <script type="text/javascript">
- $(document).ready(function () {
- $("#displayLoading").hide();
- });
- $("#TestDatabase").click(function () {
- var webMethod = 'newpage.aspx/TestAllMapping'
- var resultId = "#ResultData";
- $.ajax({
- type: "POST",
- url: webMethod,
- data: "{'name': '" + $(this).attr("id") + "'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (msg) {
- $("#TestConnection").html(msg.d);
- },
- error: AjaxFailed
- });
- });
- $("#TestConn").click(function () {
- resetResults();
- testConnections();
- });
- function resetResults() {
- $("td").each(function () {
- var resultId = "#" + $(this).attr("id") + "Result";
- $(resultId).text("");
- });
- }
- function testConnections() {
- $("td").each(function () {
- if ($(this).text().substring(0, 4) == "http") {
- var webMethod = 'newpage.aspx/TestHTTP'
- var resultId = "#" + $(this).attr("id") + "Result";
- $.ajax({
- type: "POST",
- url: webMethod,
- timeout: 3000,
- data: "{'name': '" + $(this).attr("id") + "'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (msg) {
- if (msg.d == "False") {
- }
- $(resultId).html(msg.d);
- },
- async: false,
- error: AjaxFailed
- });
- }
- });
- }
- function AjaxFailed(result) {
- alert(result.status + ' ' + result.statusText);
- }
- script>
- body>
- html>
Code Snippet
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Data.OracleClient;
- using System.Data.SqlClient;
- using System.Net;
- using System.Text;
- using System.Web.UI.WebControls;
- public partial class TestConnection_NewPage : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- int nCounter = 0;
- foreach (string appKey in ConfigurationManager.AppSettings.AllKeys)
- {
- string appKeyValue = ConfigurationManager.AppSettings.Get(appKey);
- if (appKeyValue.Contains("http") && !appKeyValue.Contains("swe"))
- {
- TableRow tRow = new TableRow();
- tRow.BorderWidth = 1;
- // Create a new cell and add it to the row.
- TableCell tCell1 = new TableCell();
- tCell1.Text = (++nCounter).ToString();
- tCell1.BorderWidth = 1;
- tRow.Cells.Add(tCell1);
- TableCell tCell2 = new TableCell();
- tCell2.Text = appKeyValue;
- tCell2.BorderWidth = 1;
- tCell2.ID = appKey;
- tRow.Cells.Add(tCell2);
- TableCell tCell3 = new TableCell();
- tCell3.BorderWidth = 1;
- tCell3.ID = appKey.Trim() + "Result";
- tRow.Cells.Add(tCell3);
- wsListTable.Rows.Add(tRow);
- }
- }
- foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings)
- {
- string name = connection.Name;
- string provider = connection.ProviderName;
- string connectionString = connection.ConnectionString;
- string statusCheck = string.Empty;
- TableRow tRow = new TableRow();
- tRow.BorderWidth = 1;
- // Create a new cell and add it to the row.
- TableCell tCell1 = new TableCell();
- tCell1.Text = name;
- tCell1.BorderWidth = 1;
- tRow.Cells.Add(tCell1);
- TableCell tCell2 = new TableCell();
- tCell2.Text = connectionString;
- tCell2.BorderWidth = 1;
- tCell2.ID = name;
- tRow.Cells.Add(tCell2);
- try
- {
- if (provider == "System.Data.SqlClient")
- {
- SqlConnection conn = new SqlConnection(connectionString);
- conn.Open();
- if (conn.State == ConnectionState.Open)
- statusCheck = "Success";
- }
- if (provider == "System.Data.OracleClient")
- {
- OracleConnection conn = new OracleConnection(connectionString);
- conn.Open();
- if (conn.State == ConnectionState.Open)
- statusCheck = "Success";
- }
- }
- catch (Exception exp)
- {
- statusCheck = exp.Message.ToString();
- }
- TableCell tCell3 = new TableCell();
- tCell3.BorderWidth = 1;
- tCell3.ID = name.Trim() + "Result";
- tCell3.Text = statusCheck;
- tRow.Cells.Add(tCell3);
- wsDatabaseConnection.Rows.Add(tRow);
- }
- }
- [System.Web.Services.WebMethod]
- public static string TestHTTP(string name)
- {
- //= "url";
- string appKey = name;
- string appKeyValue = ConfigurationManager.AppSettings.Get(appKey);
- if (appKeyValue.Contains("http"))
- {
- if (!(appKeyValue.Contains("wsdl") || appKeyValue.Contains("WSDL")))
- {
- appKeyValue += "?wsdl";
- }
- }
- return ConnectionAvailable(appKeyValue) ? "<span style='color:Green'>Passedspan>" : "<span style='color:Red'>Failedspan>";
- }
- public static bool ConnectionAvailable(string strServer)
- {
- try
- {
- HttpWebRequest reqFP = (HttpWebRequest)HttpWebRequest.Create(strServer);
- HttpWebResponse rspFP = (HttpWebResponse)reqFP.GetResponse();
- if (HttpStatusCode.OK == rspFP.StatusCode)
- {
- // HTTP = 200 - Internet connection available, server online
- rspFP.Close();
- return true;
- }
- else
- {
- // Other status - Server or connection not available
- rspFP.Close();
- return false;
- }
- }
- catch (WebException)
- {
- // Exception - connection not available
- return false;
- }
- }
- [System.Web.Services.WebMethod]
- public static string TestAllMapping()
- {
- StringBuilder stb = new StringBuilder();
- stb.AppendFormat("<tr style='height:10'><td><b>{0}b>td><td><b>{1}b>td><td><b>{2}b>td>tr>", "Table Name", "Exception", "Nhibernate Object");
- using (OES.Library.nHibernate.Repository rep = new OES.Library.nHibernate.Repository())
- {
- IDictionary allClassMetadata = rep.Session.SessionFactory.GetAllClassMetadata();
- foreach (DictionaryEntry entry in allClassMetadata)
- {
- try
- {
- NHibernate.Persister.Entity.SingleTableEntityPersister tableEntity = entry.Value as NHibernate.Persister.Entity.SingleTableEntityPersister;
- if (tableEntity != null)
- {
- int index = tableEntity.ClassMetadata.EntityName.Split('.').Length;
- if (tableEntity.TableName.Split('.')[1] != tableEntity.ClassMetadata.EntityName.Split('.')[index - 1])
- {
- rep.Session.CreateCriteria((Type)entry.Key)
- .SetMaxResults(0).List();
- }
- }
- }
- catch (Exception exp)
- {
- NHibernate.Persister.Entity.SingleTableEntityPersister tableEntity = entry.Value as NHibernate.Persister.Entity.SingleTableEntityPersister;
- stb.AppendFormat("<tr><td>{0}td><td>{1}td><td>{2}td>tr>", tableEntity.TableName, exp.InnerException.Message, entry.Key);
- }
- }
- if (stb.Length == 0)
- {
- stb.Append("Sucess");
- }
- }
- return GenerateTable(stb).ToString();
- }
- private static StringBuilder GenerateTable(StringBuilder sbTableContent)
- {
- StringBuilder sbTable = new StringBuilder();
- sbTable.AppendFormat("<Table cellspacing='0' border='1'>{0}Table>", sbTableContent.ToString());
- return sbTable;
- }
- }
No comments:
Post a Comment