#region License // Copyright 2005-2009 Paul Kohler (http://pksoftware.net/MiniSqlQuery/). All rights reserved. // This source code is made available under the terms of the Microsoft Public License (Ms-PL) // http://minisqlquery.codeplex.com/license #endregion using System; using System.Collections.Generic; using System.IO; using System.Text; namespace MiniSqlQuery.Core { /// /// Provides a defition of database connections by provider and name. /// [Obsolete] public class ConnectionDefinition { /// /// The character used to "split" the definition text into its components. /// public const char SplitChar = '^'; /// /// The prefix character for comments in the definition text. /// public const string CommentPrefix = "#"; /// /// Gets or sets the name. /// /// The name. public string Name { get; set; } /// /// Gets or sets the name of the provider. /// /// The name of the provider. public string ProviderName { get; set; } /// /// Gets or sets the connection string. /// /// The connection string. public string ConnectionString { get; set; } /// /// A default connection, an MSSQL db on localhost connecting to "master". /// public static readonly ConnectionDefinition Default; /// /// Initializes the class. /// static ConnectionDefinition() { Default = new ConnectionDefinition() { Name = "Default - MSSQL Master@localhost", ProviderName = "System.Data.SqlClient", ConnectionString = @"Server=.; Database=Master; Integrated Security=SSPI" }; } /// /// Initializes a new instance of the class. /// public ConnectionDefinition() { } /// /// Parses the specified string. /// /// The definition string, e.g. "Default - MSSQL Master@localhost ^ System.Data.SqlClient ^ Server=.; Database=master; Integrated Security=SSPI". /// A new object or null. public static ConnectionDefinition Parse(string definition) { ConnectionDefinition connDef = null; if (string.IsNullOrEmpty(definition) == false) { if (definition.StartsWith(CommentPrefix) == false) { string[] parts = definition.Split(new char[] { SplitChar }, StringSplitOptions.RemoveEmptyEntries); if (parts != null) { if (parts.Length == 3) { connDef = new ConnectionDefinition() { Name = parts[0].Trim(), ProviderName = parts[1].Trim(), ConnectionString = parts[2].Trim() }; } } } } return connDef; } /// /// Parses the specified definitions. /// /// The definitions. /// An array of objects. public static ConnectionDefinition[] Parse(string[] definitions) { List conDefs = new List(); if (definitions != null) { foreach (string definition in definitions) { ConnectionDefinition conDef = ConnectionDefinition.Parse(definition); if (conDef != null) { conDefs.Add(conDef); } } } return conDefs.ToArray(); } /// /// Converts the data to a parsable format. /// /// public string ToParsableFormat() { return string.Concat(Name, SplitChar, ProviderName, SplitChar, ConnectionString); } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override string ToString() { return Name ?? GetType().FullName; } } }