kald af dll'er
HejsaJeg har overtaget ansvaret for noget C# software som jeg genrelt har fået ok styr på. Der er dog noget syntaks jeg ikke forstår. Jeg (tror) det bliver brugt til at definere en connectionsstring, men hvis der er der kan foreklare mig hvad dll'er praktisk gør ville det hjælpe meget:
der er først en række variabler der erklæres.
private SqlConnection con;
private string configFile;
private const bool debug_info = false;
private ArrayList errors = new ArrayList();
private const int LOGON32_LOGON_BATCH = 4;
private const int LOGON32_LOGON_INTERACTIVE = 2;
private const int LOGON32_LOGON_NETWORK = 3;
private const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
private const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
private const int LOGON32_LOGON_SERVICE = 5;
private const int LOGON32_LOGON_UNLOCK = 7;
private const int LOGON32_PROVIDER_DEFAULT = 0;
private Page page;
private StreamWriter sw;
private const bool UseDosDTSExecution = true;
…
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int CloseHandle(IntPtr hObject);
[DllImport("advapi32.dll", SetLastError=true)]
public static extern int ImpersonateLoggedOnUser(IntPtr hToken);
[DllImport("advapi32.dll", SetLastError=true)]
public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
[DllImport("advapi32.dll", SetLastError=true)]
private static extern int RevertToSelf();
De eksterne metoder bliver brugt i selve funktionen.
public string runXXX(string packageName, string password)
{
try
{
IntPtr ptr;
this.con = this.DBconnect();
if (!this.con.State.ToString().Equals("Open"))
{
return this.formatErrors();
}
SqlDataReader reader = new SqlCommand(("select errorcode from msdb..sysdtspackagelog where name = '" + this.request("package_name") + "' ") + "and starttime >= all (select starttime from msdb..sysdtspackagelog where name='" + packageName + "')", this.con).ExecuteReader();
while (reader.Read())
{
if (reader.IsDBNull(0))
{
return "";
}
}
reader.Close();
reader = new SqlCommand("select name, typeid from " + this.getConfigField("PARAM_TABLE") + " where job_name='" + packageName + "'", this.con).ExecuteReader();
string str2 = "";
while (reader.Read())
{
object obj2 = str2;
str2 = string.Concat(new object[] { obj2, " /A ", reader["name"], ":", reader["typeid"], "=", this.request("" + reader["name"]) });
}
reader.Close();
reader = new SqlCommand("select dtspassword from WEB_joblist where [name] = '" + packageName + "'", this.con).ExecuteReader();
reader.Read();
string str3 = reader[0].ToString();
this.con.Close();
string str = "dtsrun /S " + this.getConfigField("DB_SERVER") + " /E ";
if (str3 != "")
{
str = str + " /M " + str3;
}
str = str + " /N " + packageName + str2;
if (LogonUser(this.getConfigField("DB_USER2"), "Fjernet", this.getConfigField("DB_PASSWORD2"), 3, 0, out ptr) > 0)
{
ImpersonateLoggedOnUser(ptr);
string str4 = "dtsrun";
string str5 = " /S " + this.getConfigField("DB_SERVER") + " /E ";
if (str3 != "")
{
str5 = str5 + " /M " + str3;
}
str5 = str5 + " /N " + packageName + str2;
Process process = new Process();
process.StartInfo.FileName = str4;
process.StartInfo.Arguments = str5;
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
RevertToSelf();
CloseHandle(ptr);
}
return "<html><head></head></html>";
}
catch (Exception exception)
{
string message = exception.Message;
}
return "";
}