Miscellaneous changes. Keep original end of line characters.

This commit is contained in:
2015-06-07 01:52:30 +02:00
parent ae8ce4a213
commit 7983598bbe
43 changed files with 4038 additions and 3839 deletions

View File

@@ -1,68 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class Config
{
#region Data parameters
private string _conString = "";
[XmlAttribute("ConnectionString")]
public string ConnectionString
{
get { return _conString; }
set { _conString = value; }
}
private readonly List<TablaInfo> _tablas = new List<TablaInfo>();
[XmlArray("Tablas")]
public List<TablaInfo> Tablas { get { return _tablas; } }
#endregion
#region Persistence methods
public void Guardar(String fichero)
{
var seriador = new XmlSerializer(typeof(Config));
var escritor = new StreamWriter(fichero);
seriador.Serialize(escritor, this);
escritor.Close();
}
public static Config Cargar(String fichero)
{
var seriador = new XmlSerializer(typeof(Config));
var lector = new StreamReader(fichero);
var config = (Config)seriador.Deserialize(lector);
lector.Close();
return config;
}
#endregion
}
[Serializable]
public class TablaInfo
{
private string _esquema = string.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return _esquema; }
set { _esquema = value; }
}
private string _nombre = string.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class Config
{
#region Data parameters
private string _conString = "";
[XmlAttribute("ConnectionString")]
public string ConnectionString
{
get { return _conString; }
set { _conString = value; }
}
private readonly List<TablaInfo> _tablas = new List<TablaInfo>();
[XmlArray("Tablas")]
public List<TablaInfo> Tablas { get { return _tablas; } }
#endregion
#region Persistence methods
public void Guardar(String fichero)
{
var seriador = new XmlSerializer(typeof(Config));
var escritor = new StreamWriter(fichero);
seriador.Serialize(escritor, this);
escritor.Close();
}
public static Config Cargar(String fichero)
{
var seriador = new XmlSerializer(typeof(Config));
var lector = new StreamReader(fichero);
var config = (Config)seriador.Deserialize(lector);
lector.Close();
return config;
}
#endregion
}
[Serializable]
public class TablaInfo
{
private string _esquema = string.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return _esquema; }
set { _esquema = value; }
}
private string _nombre = string.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ServerExplorer.Code.DataTransfer;
namespace ServerExplorer.Code.DataAccess
{
class DatabaseDA
{
public static List<Database> Database_GetRegs(string conexionString)
{
var databases = new List<Database>();
var cnx = new SqlConnection(conexionString);
cnx.Open();
DataTable dt = cnx.GetSchema("Databases");
cnx.Close();
foreach (DataRow dr in dt.Rows)
{
databases.Add(new Database
{
Name = (String) dr["database_name"],
CreateDate = (DateTime) dr["create_date"]
});
}
return databases;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Sql;
using ServerExplorer.Code.DataTransfer;
namespace ServerExplorer.Code.DataAccess
{
class ServerDA
{
public static List<Server> Server_GetRegs()
{
var servers = new List<Server>();
SqlDataSourceEnumerator enumerador = SqlDataSourceEnumerator.Instance;
DataTable dtServers = enumerador.GetDataSources();
foreach (DataRow dr in dtServers.Rows)
{
servers.Add(new Server
{
Name = (dr["ServerName"] == DBNull.Value) ? string.Empty : (String)dr["ServerName"],
Instance = (dr["InstanceName"] == DBNull.Value) ? string.Empty : (String)dr["InstanceName"],
Version = (dr["Version"] == DBNull.Value) ? "???" : (String)dr["Version"]
});
}
return servers;
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerExplorer.Code.DataAccess
{
class TableDA
{
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Column
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Type { get; set; }
[XmlAttribute]
public int Size { get; set; }
[XmlAttribute]
public bool PK { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Database
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public DateTime CreateDate { get; set; }
private readonly List<Table> _tables = new List<Table>();
[XmlArray]
public List<Table> Tables
{
get { return _tables; }
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
internal class Server
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Instance { get; set; }
[XmlAttribute]
public string Version { get; set; }
private readonly List<User> _users = new List<User>();
[XmlArray]
public List<User> Users
{
get { return _users; }
}
private readonly List<Database> _databases = new List<Database>();
[XmlArray]
public List<Database> Databases
{
get { return _databases; }
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Table
{
[XmlAttribute]
public string Schema { get; set; }
[XmlAttribute]
public string Name { get; set; }
private readonly List<Column> _columns = new List<Column>();
[XmlArray]
public List<Column> Columns
{
get { return _columns; }
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class User
{
[XmlAttribute]
public bool ImplicitUser { get; set; }
[XmlAttribute]
public string UserName { get; set; }
[XmlAttribute]
public string Password { get; set; }
}
}

View File

@@ -1,22 +1,22 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class DatabaseDesc
{
private string _nombre = string.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private readonly List<TablaDesc> _tablas = new List<TablaDesc>();
[XmlArray("Tablas")]
public List<TablaDesc> Tablas { get { return _tablas; } }
}
}
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class DatabaseDesc
{
private string _nombre = string.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private readonly List<TablaDesc> _tablas = new List<TablaDesc>();
[XmlArray("Tablas")]
public List<TablaDesc> Tablas { get { return _tablas; } }
}
}

View File

@@ -1,44 +1,44 @@
using System.IO;
namespace ServerExplorer.Code
{
public class DocGen
{
public static void GenerarDocumentacion(DatabaseDesc database)
{
// Abrir el documento que contendra la documentacion
string fixedDatabaseName = database.Nombre.Replace(' ', '_');
var escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
// Poner cabecera de la documentacion
escritor.WriteLine("<!DOCTYPE html>");
escritor.WriteLine("<html><head><title>" + database.Nombre + "</title></head>");
escritor.WriteLine("<body>");
// Iterar cada tabla
foreach (TablaDesc t in database.Tablas)
{
// Cabecera de la info de tabla
escritor.WriteLine("<h2>" + t.Esquema + "." + t.Nombre + "</h2>");
// Iterar las columnas
escritor.WriteLine("<table>");
escritor.WriteLine("<thead><tr><th>Nombre</th><th>Tipo</th><th>Tama&ntilde;o</th><th>Primaria</th></tr></thead>");
escritor.WriteLine("<tbody>");
foreach (ColumnaDesc c in t.Columnas)
{
escritor.WriteLine("<tr><td>" +
c.Nombre + "</td><td>" +
c.Tipo + "</td><td>" +
c.Tamanho + "</td><td>" +
c.Primaria + "</td></tr>");
}
escritor.WriteLine("</tbody></table>");
}
// Poner pie y cerrar fichero
escritor.WriteLine("</body></html>");
escritor.Close();
}
}
}
using System.IO;
namespace ServerExplorer.Code
{
public class DocGen
{
public static void GenerarDocumentacion(DatabaseDesc database)
{
// Abrir el documento que contendra la documentacion
string fixedDatabaseName = database.Nombre.Replace(' ', '_');
var escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
// Poner cabecera de la documentacion
escritor.WriteLine("<!DOCTYPE html>");
escritor.WriteLine("<html><head><title>" + database.Nombre + "</title></head>");
escritor.WriteLine("<body>");
// Iterar cada tabla
foreach (TablaDesc t in database.Tablas)
{
// Cabecera de la info de tabla
escritor.WriteLine("<h2>" + t.Esquema + "." + t.Nombre + "</h2>");
// Iterar las columnas
escritor.WriteLine("<table>");
escritor.WriteLine("<thead><tr><th>Nombre</th><th>Tipo</th><th>Tama&ntilde;o</th><th>Primaria</th></tr></thead>");
escritor.WriteLine("<tbody>");
foreach (ColumnaDesc c in t.Columnas)
{
escritor.WriteLine("<tr><td>" +
c.Nombre + "</td><td>" +
c.Tipo + "</td><td>" +
c.Tamanho + "</td><td>" +
c.Primaria + "</td></tr>");
}
escritor.WriteLine("</tbody></table>");
}
// Poner pie y cerrar fichero
escritor.WriteLine("</body></html>");
escritor.Close();
}
}
}

View File

@@ -1,280 +1,280 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class TablaDesc
{
#region Data parameters
private String _esquema = String.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return _esquema; }
set { _esquema = value; }
}
private String _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private readonly List<ColumnaDesc> _columnas = new List<ColumnaDesc>();
[XmlArray("Columnas")]
public List<ColumnaDesc> Columnas
{
get { return _columnas; }
}
#endregion
#region FillDesc
// Obtener una columna existente
private ColumnaDesc GetCol(String nombre)
{
foreach (ColumnaDesc col in Columnas)
{
if (String.Compare(col.Nombre, nombre, StringComparison.Ordinal) == 0)
{
return (col);
}
}
return null;
}
public void FillDesc(String esquema, String nombre, SqlConnection cnx)
{
// establecer esquema y nombre
Esquema = esquema;
Nombre = nombre;
// Preparar comando y parametros
var da = new SqlDataAdapter(@"
SELECT col.COLUMN_NAME AS Columna,
col.DATA_TYPE AS Tipo,
col.CHARACTER_MAXIMUM_LENGTH AS Tamanho,
c.CONSTRAINT_TYPE AS TipoClave,
col.IS_NULLABLE AS Nullable
FROM INFORMATION_SCHEMA.COLUMNS AS col
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON col.COLUMN_NAME=k.COLUMN_NAME AND
col.TABLE_NAME=k.TABLE_NAME AND
col.TABLE_SCHEMA=k.TABLE_SCHEMA
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c
ON k.CONSTRAINT_NAME=c.CONSTRAINT_NAME
WHERE col.TABLE_NAME=@nombreTabla AND
col.TABLE_SCHEMA=@nombreEsquema
ORDER BY col.ORDINAL_POSITION
", cnx);
var prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100) {Value = nombre};
da.SelectCommand.Parameters.Add(prm);
prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100) {Value = esquema};
da.SelectCommand.Parameters.Add(prm);
// Obtener datatable con las columnas
var dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Recorrer datatable estableciendo la lista de columnas
Columnas.Clear();
foreach (DataRow dr in dt.Rows)
{
// Obtener columna
ColumnaDesc col = GetCol((String) dr["Columna"]);
if (col == null)
{
col = new ColumnaDesc();
Columnas.Add(col);
}
// Establecer datos de la columna
col.Nombre = (String) dr["Columna"];
col.Tipo = ((String) dr["Tipo"]).ToLower();
if (dr["Tamanho"] != DBNull.Value)
{
col.Tamanho = (int) dr["Tamanho"];
}
if (dr["TipoClave"] != DBNull.Value)
{
if (((String) dr["TipoClave"]).Contains("PRIMARY"))
{
col.Primaria = true;
}
}
string strNullable = ((String) dr["Nullable"]).ToLower();
col.Nullable = (strNullable == "yes");
}
}
#endregion
}
#region TipoCol
public enum TipoCol
{
Unset,
Numerico,
AproxNumerico,
Tiempo,
Texto,
Binario,
Booleano,
Otro
}
#endregion
[Serializable]
public class ColumnaDesc
{
#region Data properties
private string _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private string _tipo = String.Empty;
[XmlAttribute("Tipo")]
public string Tipo
{
get { return _tipo; }
set { _tipo = value; }
}
private int _tamanho = -1;
[XmlAttribute("Tamanho")]
public int Tamanho
{
get { return _tamanho; }
set { _tamanho = value; }
}
private bool _nullable;
[XmlAttribute("Nullable")]
public bool Nullable
{
get { return _nullable; }
set { _nullable = value; }
}
private bool _primaria;
[XmlAttribute("Primaria")]
public bool Primaria
{
get { return _primaria; }
set { _primaria = value; }
}
#endregion
#region GetTipo
private TipoCol _tipoCol = TipoCol.Unset;
public TipoCol GetTipo()
{
string strTipo = Tipo.ToLower();
if (_tipoCol != TipoCol.Unset)
{
return _tipoCol;
}
// Numericos
if (
strTipo == "bigint" ||
strTipo == "int" ||
strTipo == "smallint" ||
strTipo == "tinyint" ||
strTipo == "bigint"
)
{
_tipoCol = TipoCol.Numerico;
}
// Aproximados numericos
if (
strTipo == "float" ||
strTipo == "real"
)
{
_tipoCol = TipoCol.AproxNumerico;
}
// Tiempo
if (
strTipo == "date" ||
strTipo == "datetimeoffset" ||
strTipo == "datetime2" ||
strTipo == "smalldatetime" ||
strTipo == "datetime" ||
strTipo == "time"
)
{
_tipoCol = TipoCol.Tiempo;
}
// Texto
if (
strTipo == "char" ||
strTipo == "varchar" ||
strTipo == "text" ||
strTipo == "nchar" ||
strTipo == "nvarchar" ||
strTipo == "ntext"
)
{
_tipoCol = TipoCol.Texto;
}
// Binario
if (
strTipo == "binary" ||
strTipo == "varbinary" ||
strTipo == "image"
)
{
_tipoCol = TipoCol.Binario;
}
// Booleano
if (
strTipo == "bit"
)
{
_tipoCol = TipoCol.Booleano;
}
// Otro
_tipoCol = TipoCol.Otro;
return _tipoCol;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Serialization;
namespace ServerExplorer.Code
{
[Serializable]
public class TablaDesc
{
#region Data parameters
private String _esquema = String.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return _esquema; }
set { _esquema = value; }
}
private String _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private readonly List<ColumnaDesc> _columnas = new List<ColumnaDesc>();
[XmlArray("Columnas")]
public List<ColumnaDesc> Columnas
{
get { return _columnas; }
}
#endregion
#region FillDesc
// Obtener una columna existente
private ColumnaDesc GetCol(String nombre)
{
foreach (ColumnaDesc col in Columnas)
{
if (String.Compare(col.Nombre, nombre, StringComparison.Ordinal) == 0)
{
return (col);
}
}
return null;
}
public void FillDesc(String esquema, String nombre, SqlConnection cnx)
{
// establecer esquema y nombre
Esquema = esquema;
Nombre = nombre;
// Preparar comando y parametros
var da = new SqlDataAdapter(@"
SELECT col.COLUMN_NAME AS Columna,
col.DATA_TYPE AS Tipo,
col.CHARACTER_MAXIMUM_LENGTH AS Tamanho,
c.CONSTRAINT_TYPE AS TipoClave,
col.IS_NULLABLE AS Nullable
FROM INFORMATION_SCHEMA.COLUMNS AS col
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON col.COLUMN_NAME=k.COLUMN_NAME AND
col.TABLE_NAME=k.TABLE_NAME AND
col.TABLE_SCHEMA=k.TABLE_SCHEMA
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c
ON k.CONSTRAINT_NAME=c.CONSTRAINT_NAME
WHERE col.TABLE_NAME=@nombreTabla AND
col.TABLE_SCHEMA=@nombreEsquema
ORDER BY col.ORDINAL_POSITION
", cnx);
var prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100) {Value = nombre};
da.SelectCommand.Parameters.Add(prm);
prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100) {Value = esquema};
da.SelectCommand.Parameters.Add(prm);
// Obtener datatable con las columnas
var dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Recorrer datatable estableciendo la lista de columnas
Columnas.Clear();
foreach (DataRow dr in dt.Rows)
{
// Obtener columna
ColumnaDesc col = GetCol((String) dr["Columna"]);
if (col == null)
{
col = new ColumnaDesc();
Columnas.Add(col);
}
// Establecer datos de la columna
col.Nombre = (String) dr["Columna"];
col.Tipo = ((String) dr["Tipo"]).ToLower();
if (dr["Tamanho"] != DBNull.Value)
{
col.Tamanho = (int) dr["Tamanho"];
}
if (dr["TipoClave"] != DBNull.Value)
{
if (((String) dr["TipoClave"]).Contains("PRIMARY"))
{
col.Primaria = true;
}
}
string strNullable = ((String) dr["Nullable"]).ToLower();
col.Nullable = (strNullable == "yes");
}
}
#endregion
}
#region TipoCol
public enum TipoCol
{
Unset,
Numerico,
AproxNumerico,
Tiempo,
Texto,
Binario,
Booleano,
Otro
}
#endregion
[Serializable]
public class ColumnaDesc
{
#region Data properties
private string _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return _nombre; }
set { _nombre = value; }
}
private string _tipo = String.Empty;
[XmlAttribute("Tipo")]
public string Tipo
{
get { return _tipo; }
set { _tipo = value; }
}
private int _tamanho = -1;
[XmlAttribute("Tamanho")]
public int Tamanho
{
get { return _tamanho; }
set { _tamanho = value; }
}
private bool _nullable;
[XmlAttribute("Nullable")]
public bool Nullable
{
get { return _nullable; }
set { _nullable = value; }
}
private bool _primaria;
[XmlAttribute("Primaria")]
public bool Primaria
{
get { return _primaria; }
set { _primaria = value; }
}
#endregion
#region GetTipo
private TipoCol _tipoCol = TipoCol.Unset;
public TipoCol GetTipo()
{
string strTipo = Tipo.ToLower();
if (_tipoCol != TipoCol.Unset)
{
return _tipoCol;
}
// Numericos
if (
strTipo == "bigint" ||
strTipo == "int" ||
strTipo == "smallint" ||
strTipo == "tinyint" ||
strTipo == "bigint"
)
{
_tipoCol = TipoCol.Numerico;
}
// Aproximados numericos
if (
strTipo == "float" ||
strTipo == "real"
)
{
_tipoCol = TipoCol.AproxNumerico;
}
// Tiempo
if (
strTipo == "date" ||
strTipo == "datetimeoffset" ||
strTipo == "datetime2" ||
strTipo == "smalldatetime" ||
strTipo == "datetime" ||
strTipo == "time"
)
{
_tipoCol = TipoCol.Tiempo;
}
// Texto
if (
strTipo == "char" ||
strTipo == "varchar" ||
strTipo == "text" ||
strTipo == "nchar" ||
strTipo == "nvarchar" ||
strTipo == "ntext"
)
{
_tipoCol = TipoCol.Texto;
}
// Binario
if (
strTipo == "binary" ||
strTipo == "varbinary" ||
strTipo == "image"
)
{
_tipoCol = TipoCol.Binario;
}
// Booleano
if (
strTipo == "bit"
)
{
_tipoCol = TipoCol.Booleano;
}
// Otro
_tipoCol = TipoCol.Otro;
return _tipoCol;
}
#endregion
}
}

View File

@@ -1,27 +1,27 @@
using System;
using System.IO;
namespace ServerExplorer.Code
{
public static class Utiles
{
public static void CrearDirectorio(this String path)
{
DirectoryInfo info;
try
{
info = new DirectoryInfo(path);
}
catch (Exception)
{
info = new DirectoryInfo(".");
}
CrearDirectorio(info);
}
public static void CrearDirectorio(this DirectoryInfo info)
{
if (info.Parent != null) CrearDirectorio(info.Parent);
if (!info.Exists) info.Create();
}
}
}
using System;
using System.IO;
namespace ServerExplorer.Code
{
public static class Utiles
{
public static void CrearDirectorio(this String path)
{
DirectoryInfo info;
try
{
info = new DirectoryInfo(path);
}
catch (Exception)
{
info = new DirectoryInfo(".");
}
CrearDirectorio(info);
}
public static void CrearDirectorio(this DirectoryInfo info)
{
if (info.Parent != null) CrearDirectorio(info.Parent);
if (!info.Exists) info.Create();
}
}
}