using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.Serialization;
using Tdo;
using Tdo.Common;
using Tdo.Common.Programmability;
using Tdo.Common.Entities;
using Tdo.Common.Entities.Tables;
using Tdo.Common.Entities.Views;
using Tdo.Common.Helper;
using Tdo.Common.TdoSqlExpressionDom;
using Tdo.Common.TdoTypes;
namespace Tdo.Common{
/// <summary>
/// Utility static class. Provides common Tdo utility methods.
/// </summary>
public static class Utility
{
/// <summary>
/// Reads the connection string if exists.
/// </summary>
/// <param name="connectionStringName">Name of the connection string.</param>
/// <returns></returns>
public static string ReadConnectionStringIfExists(string connectionStringName)
{
if (System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName] != null)
return System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
else
return String.Empty;
}
/// <summary>
/// Return column.ObjectValue.ToString() if IsConstant property is true, column.TdoEntity.EntityName.columnName otherwise.
/// </summary>
/// <returns>Column or Value string</returns>
public static string ColumnOrValue(ITdoColumn column)
{
if (column.IsConstant)
return column.ObjectValue.ToString();
else
return (!String.IsNullOrEmpty(column.TdoEntity.EntityName) ? column.TdoEntity.EntityName + "." : String.Empty) + column.ColumnName + (!String.IsNullOrEmpty(column.Caption) ? " as [" + column.Caption + "] " : String.Empty);
}
/// <summary>
/// Return column.ObjectValue.ToString() if IsConstant property is true, column.TdoEntity.EntityName.columnName otherwise.
/// </summary>
/// <returns>Column or Value string without alias.</returns>
public static string ColumnOrValueWithoutAlias(ITdoColumn column)
{
if (column.IsConstant)
return column.ObjectValue.ToString();
else
return (!String.IsNullOrEmpty(column.TdoEntity.EntityName) ? column.TdoEntity.EntityName + "." : String.Empty) + column.ColumnName;
}
/// <summary>
/// Writes the current contents of the tdoEntityToSerialize as XML using the specified file.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to serialize</typeparam>
/// <param name="tdoEntityToSerialize">TdoEntity to serialize</param>
/// <param name="fileName">The file to which to write the XML data.</param>
public static void WriteTdoEntityXml<TdoEntityType>(TdoEntityType tdoEntityToSerialize, string fileName)
where TdoEntityType : ITdoEntity
{
FileStream fs = new FileStream(fileName, FileMode.Create);
Utility.WriteTdoEntityXml<TdoEntityType>(tdoEntityToSerialize, fs);
fs.Close();
}
/// <summary>
/// Writes the current contents of the tdoEntityToSerialize as XML using the specified file.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to serialize</typeparam>
/// <param name="tdoEntityToSerialize">TdoEntity to serialize</param>
/// <param name="stream">A System.IO.Stream object used to write to a file.</param>
public static void WriteTdoEntityXml<TdoEntityType>(TdoEntityType tdoEntityToSerialize, Stream stream)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
ser.Serialize(stream, tdoEntityToSerialize);
}
/// <summary>
/// Writes the current contents of the tdoEntityToSerialize as XML using the specified file.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to serialize</typeparam>
/// <param name="tdoEntityToSerialize">TdoEntity to serialize</param>
/// <param name="textWriter">The System.IO.TextWriter object with which to write.</param>
public static void WriteTdoEntityXml<TdoEntityType>(TdoEntityType tdoEntityToSerialize, TextWriter textWriter)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
ser.Serialize(textWriter, tdoEntityToSerialize);
}
/// <summary>
/// Writes the current contents of the tdoEntityToSerialize as XML using the specified file.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to serialize</typeparam>
/// <param name="tdoEntityToSerialize">TdoEntity to serialize</param>
/// <param name="xmlWriter">The System.Xml.XmlWriter with which to write.</param>
public static void WriteTdoEntityXml<TdoEntityType>(TdoEntityType tdoEntityToSerialize, XmlWriter xmlWriter)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
ser.Serialize(xmlWriter, tdoEntityToSerialize);
}
/// <summary>
/// Reads XML data into the TdoEntityType using the specified file.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to deserialize</typeparam>
/// <param name="fileName">The filename (including the path) from which to read.</param>
/// <returns>TdoEntityType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoEntityType ReadTdoEntityFromXml<TdoEntityType>(string fileName)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
FileStream fs = new FileStream(fileName, FileMode.Open);
TdoEntityType result = (TdoEntityType)ser.Deserialize(fs);
return result;
}
/// <summary>
/// Reads XML data into the TdoEntityType using the specified System.IO.Stream.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to deserialize</typeparam>
/// <param name="stream">An object that derives from System.IO.Stream.</param>
/// <returns>TdoEntityType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoEntityType ReadTdoEntityFromXml<TdoEntityType>(Stream stream)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
return (TdoEntityType)ser.Deserialize(stream);
}
/// <summary>
/// Reads XML data into the TdoEntityType using the specified System.IO.TextReader.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to deserialize</typeparam>
/// <param name="textReader">The System.IO.TextReader from which to read.</param>
/// <returns>TdoEntityType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoEntityType ReadTdoEntityFromXml<TdoEntityType>(TextReader textReader)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
return (TdoEntityType)ser.Deserialize(textReader);
}
/// <summary>
/// Reads XML data into the TdoEntityType using the specified System.IO.XmlReader.
/// </summary>
/// <typeparam name="TdoEntityType">Type of ITdoEntity to deserialize</typeparam>
/// <param name="xmlReader">The System.IO.XmlReader from which to read.</param>
/// <returns>TdoEntityType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoEntityType ReadTdoEntityFromXml<TdoEntityType>(XmlReader xmlReader)
where TdoEntityType : ITdoEntity
{
XmlSerializer ser = new XmlSerializer(typeof(TdoEntityType));
return (TdoEntityType)ser.Deserialize(xmlReader);
}
/// <summary>
/// Writes the current contents of the tdoHelperToSerialize as XML using the specified file.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to serialize</typeparam>
/// <param name="tdoHelperToSerialize">TdoHelper to serialize</param>
/// <param name="fileName">The file to which to write the XML data.</param>
public static void WriteTdoHelperToXml<TdoHelperType>(TdoHelperType tdoHelperToSerialize, string fileName)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
FileStream fs = new FileStream(fileName, FileMode.Create);
ser.Serialize(fs, tdoHelperToSerialize);
fs.Close();
}
/// <summary>
/// Writes the current contents of the tdoHelperToSerialize as XML using the specified System.IO.Stream.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to serialize</typeparam>
/// <param name="tdoHelperToSerialize">TdoHelper to serialize</param>
/// <param name="stream">A System.IO.Stream object used to write to a file.</param>
public static void WriteTdoHelperToXml<TdoHelperType>(TdoHelperType tdoHelperToSerialize, Stream stream)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
ser.Serialize(stream, tdoHelperToSerialize);
}
/// <summary>
/// Writes the current contents of the tdoHelperToSerialize as XML using the specified System.IO.TextWriter.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to serialize</typeparam>
/// <param name="tdoHelperToSerialize">TdoHelper to serialize</param>
/// <param name="textWriter">A System.IO.TextWriter object used to write to a file.</param>
public static void WriteTdoHelperToXml<TdoHelperType>(TdoHelperType tdoHelperToSerialize, TextWriter textWriter)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
ser.Serialize(textWriter, tdoHelperToSerialize);
}
/// <summary>
/// Writes the current contents of the tdoHelperToSerialize as XML using the specified System.IO.XmlWriter.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to serialize</typeparam>
/// <param name="tdoHelperToSerialize">TdoHelper to serialize</param>
/// <param name="xmlWriter">A System.IO.XmlWriter object used to write to a file.</param>
public static void WriteTdoHelperToXml<TdoHelperType>(TdoHelperType tdoHelperToSerialize, XmlWriter xmlWriter)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
ser.Serialize(xmlWriter, tdoHelperToSerialize);
}
/// <summary>
/// Reads XML data into the TdoHelperType using the specified file.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to deserialize</typeparam>
/// <param name="fileName">The filename (including the path) from which to read.</param>
/// <returns>TdoHelperType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoHelperType ReadTdoHelperFromXml<TdoHelperType>(string fileName)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
FileStream fs = new FileStream(fileName, FileMode.Open);
TdoHelperType result = (TdoHelperType)ser.Deserialize(fs);
return result;
}
/// <summary>
/// Reads XML data into the TdoHelperType using the specified System.IO.Stream.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to deserialize</typeparam>
/// <param name="stream">An object that derives from System.IO.Stream.</param>
/// <returns>TdoHelperType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoHelperType ReadTdoHelperFromXml<TdoHelperType>(Stream stream)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
return (TdoHelperType)ser.Deserialize(stream);
}
/// <summary>
/// Reads XML data into the TdoHelperType using the specified System.IO.XmlReader.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to deserialize</typeparam>
/// <param name="xmlReader">The System.IO.XmlReader from which to read.</param>
/// <returns>TdoHelperType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoHelperType ReadTdoHelperFromXml<TdoHelperType>(XmlReader xmlReader)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
return (TdoHelperType)ser.Deserialize(xmlReader);
}
/// <summary>
/// Reads XML data into the TdoHelperType using the specified System.IO.TextReader.
/// </summary>
/// <typeparam name="TdoHelperType">Type of ITdoHelper to deserialize</typeparam>
/// <param name="textReader">The System.IO.TextReader from which to read.</param>
/// <returns>TdoHelperType with data</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static TdoHelperType ReadTdoHelperFromXml<TdoHelperType>(TextReader textReader)
where TdoHelperType : ITdoHelper
{
XmlSerializer ser = new XmlSerializer(typeof(TdoHelperType));
return (TdoHelperType)ser.Deserialize(textReader);
}
}
}
|