Utility.cs :  » Database » TDO » Tdo » Common » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Database » TDO 
TDO » Tdo » Common » Utility.cs
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);
        }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.