|
// sqldoc
// coded by Jose A. Gonzalvo
// JAG Software 2004
// 09/06/04
using System;
using System.Data;
using System.Data.SqlClient;
namespace JAGSoftware.SqlDoc
{
/// <summary>
/// parses command line arguments to call SqlDoc.Document method
/// </summary>
class Class1
{
private const string STR_HELPMESSAGE = "use: SqlDoc\t[-U login_id]\n\r\t\t[-P password]\n\r\t\t[-E trusted connection]\n\r\t\t[-S server name]\n\r\t\t[-d database name]\n\r\t\t[-i xsl file]\n\r\t\t[-o output file name]";
public static void Main(string[] args)
{
// need at least the database name: -d DBNAME
if(args.Length == 0)
{
ShowHelp();
return;
}
System.Text.StringBuilder sb = new System.Text.StringBuilder("Data Source=");
// search server name -S
string server = GetParam("-S", args);
// if missing use localhost
if(server.Length == 0)
sb.Append("localhost");
else
sb.Append(server);
sb.Append(";Initial Catalog=");
// search database name -d
string dbName = GetParam("-d", args);
if(dbName.Length == 0)
{
ShowHelp();
return;
}
sb.Append(dbName);
sb.Append(";");
// search trusted connection -E
if(ExistParam("-E", args))
{
sb.Append("Integrated Security=SSPI;");
}
else
{
// try with user name and password
string userid = GetParam("-U", args);
string password = GetParam("-P", args);
if(userid.Length==0)
{
ShowHelp();
return;
}
sb.Append("user id=");
sb.Append(userid);
sb.Append(";pwd=");
sb.Append(password);
sb.Append(";");
}
// search output file
string outputFile = GetParam("-o", args);
if(outputFile.Length==0)
outputFile = "output.html";
try
{
SqlDoc.Document(sb.ToString(), "test.xslt", outputFile);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void ShowHelp()
{
Console.Write(STR_HELPMESSAGE);
}
private static string GetParam(string searchParam, string[] args)
{
int pos = Array.IndexOf(args, searchParam, 0);
if(pos>=0)
return args[pos+1];
else
return "";
}
private static bool ExistParam(string searchParam, string[]args)
{
if(Array.IndexOf(args, searchParam, 0)>=0)
return true;
else
return false;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.