public static ExecutionContext Create(Data.ConnectionDetails connectionDetails) { Data.DatabaseConnector.TestResult oResult = Data.DatabaseConnector.Test(connectionDetails); if (!oResult.Success) { throw new ApplicationException(oResult.Message); } return(new ExecutionContext(new Data.DatabaseConnector(connectionDetails))); }
private static ExecutionContext GetContextFromCommandLine(string [] args) { if (args == null || args.Length == 0) { return(null); } ExecutionContext oContext = null; string sServer = null; string sDB = null; Data.DatabaseConnectionType nConnectionType = Data.DatabaseConnectionType.WindowsIntegrated; string sPwd = null; string sUser = null; foreach (string sArg in args) { if (System.Text.RegularExpressions.Regex.IsMatch(sArg, @"^[-/]([Hh?]|help|Help|HELP)$")) { MessageBox.Show("Sharepoint2003.DBExporter.exe -s:<server> -d:<database> -a:W|S [-u:<username> -p:<password>]\n\n" + "s:<server> = server name\n" + "d:<database> = database name\n"+ "a:W|S = authentication mode ([W]indows integrated or [S]QL server)\n"+ "u:<username> = username for sql server authentication\n"+ "p:<password> = password for sql server authentication"); return(ExecutionContext.None); } System.Text.RegularExpressions.Match oMatch = null; oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]s:(?<val>[^ ]+)$"); if (oMatch.Success) { sServer = oMatch.Groups["val"].Value; } oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]d:(?<val>[^ ]+)$"); if (oMatch.Success) { sDB = oMatch.Groups["val"].Value; } oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]a:(?<val>[WwSs])$"); if (oMatch.Success) { nConnectionType = (oMatch.Groups["val"].Value.ToLower() == "w") ? Data.DatabaseConnectionType.WindowsIntegrated : Data.DatabaseConnectionType.SQLAuthentication; } oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]p:(?<val>[^ ]+)$"); if (oMatch.Success) { sPwd = oMatch.Groups["val"].Value; } oMatch = System.Text.RegularExpressions.Regex.Match(sArg, @"^[-/]u:(?<val>[^ ]+)$"); if (oMatch.Success) { sUser = oMatch.Groups["val"].Value; } } if (sServer != null && sServer.Length > 0) { Data.ConnectionDetails oDetails = new Data.ConnectionDetails(sServer, sDB, nConnectionType, sUser, sPwd, 0); Data.DatabaseConnector.TestResult oResult = Data.DatabaseConnector.Test(oDetails); if (oResult.Success) { oContext = ExecutionContext.Create(oDetails); } else { MessageBox.Show(oResult.Message); } } return(oContext); }