public bool PathExist(IActivityIOPath dst)
{
bool result;
if (!RequiresAuth(dst))
{
result = PathIs(dst) == enPathType.Directory ? Directory.Exists(dst.Path) : File.Exists(dst.Path);
}
else
{
try
{
// handle UNC path
SafeTokenHandle safeTokenHandle;
bool loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);
if (loginOk)
{
using (safeTokenHandle)
{
WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
{
// Do the operation here
result = PathIs(dst) == enPathType.Directory ? Directory.Exists(dst.Path) : File.Exists(dst.Path);
// remove impersonation now
impersonatedUser.Undo();
}
newID.Dispose();
}
}
else
{
// login failed
throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
}
}
catch (Exception ex)
{
Dev2Logger.Log.Error(ex);
throw;
}
}
return result;
}