Limpieza usando recomendaciones de R#

This commit is contained in:
2014-09-09 12:47:52 +02:00
parent 00b1da5da7
commit 9d77bb552b
12 changed files with 222 additions and 313 deletions

View File

@@ -10,17 +10,17 @@ namespace ServerExplorer.Code
{
#region Data parameters
private string conString = "";
private string _conString = "";
[XmlAttribute("ConnectionString")]
public string ConnectionString
{
get { return conString; }
set { conString = value; }
get { return _conString; }
set { _conString = value; }
}
private List<TablaInfo> tablas = new List<TablaInfo>();
private readonly List<TablaInfo> _tablas = new List<TablaInfo>();
[XmlArray("Tablas")]
public List<TablaInfo> Tablas { get { return tablas; } }
public List<TablaInfo> Tablas { get { return _tablas; } }
#endregion
@@ -28,17 +28,17 @@ namespace ServerExplorer.Code
public void Guardar(String fichero)
{
XmlSerializer seriador = new XmlSerializer(typeof(Config));
StreamWriter escritor = new StreamWriter(fichero);
var seriador = new XmlSerializer(typeof(Config));
var escritor = new StreamWriter(fichero);
seriador.Serialize(escritor, this);
escritor.Close();
}
public static Config Cargar(String fichero)
{
XmlSerializer seriador = new XmlSerializer(typeof(Config));
StreamReader lector = new StreamReader(fichero);
Config config = (Config)seriador.Deserialize(lector);
var seriador = new XmlSerializer(typeof(Config));
var lector = new StreamReader(fichero);
var config = (Config)seriador.Deserialize(lector);
lector.Close();
return config;
}
@@ -49,20 +49,20 @@ namespace ServerExplorer.Code
[Serializable]
public class TablaInfo
{
private string esquema = string.Empty;
private string _esquema = string.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return esquema; }
set { esquema = value; }
get { return _esquema; }
set { _esquema = value; }
}
private string nombre = string.Empty;
private string _nombre = string.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return nombre; }
set { nombre = value; }
get { return _nombre; }
set { _nombre = value; }
}
}
}

View File

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

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using ServerExplorer.Code;
using System.IO;
namespace ServerExplorer.Code
{
@@ -13,7 +8,7 @@ namespace ServerExplorer.Code
{
// Abrir el documento que contendra la documentacion
string fixedDatabaseName = database.Nombre.Replace(' ', '_');
StreamWriter escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
var escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
// Poner cabecera de la documentacion
escritor.WriteLine("<!DOCTYPE html>");

View File

@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Xml.Serialization;
@@ -14,25 +11,31 @@ namespace ServerExplorer.Code
{
#region Data parameters
private String esquema = String.Empty;
private String _esquema = String.Empty;
[XmlAttribute("Esquema")]
public string Esquema
{
get { return esquema; }
set { esquema = value; }
get { return _esquema; }
set { _esquema = value; }
}
private String nombre = String.Empty;
private String _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return nombre; }
set { nombre = value; }
get { return _nombre; }
set { _nombre = value; }
}
private List<ColumnaDesc> columnas = new List<ColumnaDesc>();
private readonly List<ColumnaDesc> _columnas = new List<ColumnaDesc>();
[XmlArray("Columnas")]
public List<ColumnaDesc> Columnas { get { return columnas; } }
public List<ColumnaDesc> Columnas
{
get { return _columnas; }
}
#endregion
@@ -43,7 +46,7 @@ namespace ServerExplorer.Code
{
foreach (ColumnaDesc col in Columnas)
{
if (col.Nombre.CompareTo(nombre) == 0)
if (String.Compare(col.Nombre, nombre, StringComparison.Ordinal) == 0)
{
return (col);
}
@@ -53,41 +56,35 @@ namespace ServerExplorer.Code
public void FillDesc(String esquema, String nombre, SqlConnection cnx)
{
SqlParameter prm;
DataTable dt;
SqlDataAdapter da;
// establecer esquema y nombre
Esquema = esquema;
Nombre = nombre;
// Preparar comando y parametros
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);
prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100);
prm.Value = nombre;
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);
prm.Value = esquema;
prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100) {Value = esquema};
da.SelectCommand.Parameters.Add(prm);
// Obtener datatable con las columnas
dt = new DataTable();
var dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
@@ -96,10 +93,8 @@ namespace ServerExplorer.Code
Columnas.Clear();
foreach (DataRow dr in dt.Rows)
{
ColumnaDesc col;
// Obtener columna
col = GetCol((String)dr["Columna"]);
ColumnaDesc col = GetCol((String) dr["Columna"]);
if (col == null)
{
col = new ColumnaDesc();
@@ -107,20 +102,20 @@ namespace ServerExplorer.Code
}
// Establecer datos de la columna
col.Nombre = (String)dr["Columna"];
col.Tipo = ((String)dr["Tipo"]).ToLower();
col.Nombre = (String) dr["Columna"];
col.Tipo = ((String) dr["Tipo"]).ToLower();
if (dr["Tamanho"] != DBNull.Value)
{
col.Tamanho = (int)dr["Tamanho"];
col.Tamanho = (int) dr["Tamanho"];
}
if (dr["TipoClave"] != DBNull.Value)
{
if (((String)dr["TipoClave"]).Contains("PRIMARY"))
if (((String) dr["TipoClave"]).Contains("PRIMARY"))
{
col.Primaria = true;
}
}
string strNullable=((String)dr["Nullable"]).ToLower();
string strNullable = ((String) dr["Nullable"]).ToLower();
col.Nullable = (strNullable == "yes");
}
}
@@ -149,58 +144,64 @@ namespace ServerExplorer.Code
{
#region Data properties
private string nombre = String.Empty;
private string _nombre = String.Empty;
[XmlAttribute("Nombre")]
public string Nombre
{
get { return nombre; }
set { nombre = value; }
get { return _nombre; }
set { _nombre = value; }
}
private string tipo = String.Empty;
private string _tipo = String.Empty;
[XmlAttribute("Tipo")]
public string Tipo
{
get { return tipo; }
set { tipo = value; }
get { return _tipo; }
set { _tipo = value; }
}
private int tamanho = -1;
private int _tamanho = -1;
[XmlAttribute("Tamanho")]
public int Tamanho
{
get { return tamanho; }
set { tamanho = value; }
get { return _tamanho; }
set { _tamanho = value; }
}
private bool nullable = false;
private bool _nullable;
[XmlAttribute("Nullable")]
public bool Nullable
{
get { return nullable; }
set { nullable = value; }
get { return _nullable; }
set { _nullable = value; }
}
private bool primaria = false;
private bool _primaria;
[XmlAttribute("Primaria")]
public bool Primaria
{
get { return primaria; }
set { primaria = value; }
get { return _primaria; }
set { _primaria = value; }
}
#endregion
#region GetTipo
private TipoCol _tipo = TipoCol.Unset;
private TipoCol _tipoCol = TipoCol.Unset;
public TipoCol GetTipo()
{
string strTipo = Tipo.ToLower();
if (_tipo != TipoCol.Unset)
if (_tipoCol != TipoCol.Unset)
{
return _tipo;
return _tipoCol;
}
// Numericos
@@ -212,7 +213,7 @@ namespace ServerExplorer.Code
strTipo == "bigint"
)
{
_tipo = TipoCol.Numerico;
_tipoCol = TipoCol.Numerico;
}
// Aproximados numericos
@@ -221,7 +222,7 @@ namespace ServerExplorer.Code
strTipo == "real"
)
{
_tipo = TipoCol.AproxNumerico;
_tipoCol = TipoCol.AproxNumerico;
}
// Tiempo
@@ -234,7 +235,7 @@ namespace ServerExplorer.Code
strTipo == "time"
)
{
_tipo = TipoCol.Tiempo;
_tipoCol = TipoCol.Tiempo;
}
// Texto
@@ -247,7 +248,7 @@ namespace ServerExplorer.Code
strTipo == "ntext"
)
{
_tipo = TipoCol.Texto;
_tipoCol = TipoCol.Texto;
}
// Binario
@@ -257,7 +258,7 @@ namespace ServerExplorer.Code
strTipo == "image"
)
{
_tipo = TipoCol.Binario;
_tipoCol = TipoCol.Binario;
}
// Booleano
@@ -265,13 +266,13 @@ namespace ServerExplorer.Code
strTipo == "bit"
)
{
_tipo = TipoCol.Booleano;
_tipoCol = TipoCol.Booleano;
}
// Otro
_tipo = TipoCol.Otro;
_tipoCol = TipoCol.Otro;
return _tipo;
return _tipoCol;
}
#endregion

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ServerExplorer.Code
@@ -10,7 +7,7 @@ namespace ServerExplorer.Code
{
public static void CrearDirectorio(this String path)
{
DirectoryInfo info = null;
DirectoryInfo info;
try
{
info = new DirectoryInfo(path);