Example #1
0
 void UnImpersonateWindowsContext()
 {
     if (objImp != null)
     {
         objImp.UnImpersonate();
     }
 }
Example #2
0
 internal void Unimpersonate(Impersonation token)
 {
     try
     {
         if (token != null)
         {
             token.UnImpersonate();
         }
     }
     catch { }
 }
        protected bool GoodDirectory(string dir)
        {
            try
            {
                if (CheckDirectoryExists)
                {
                    if (!_LastTouched.ContainsKey(dir))
                    {
                        _LastTouched[dir] = new Touched {
                            Exists = false, LastAttempt = DateTime.MinValue
                        }
                    }
                    ;

                    if ((DateTime.UtcNow - _LastTouched[dir].LastAttempt).TotalSeconds > 180 || _LastTouched[dir].Exists)
                    {
                        if (!_LastTouched[dir].Exists)
                        {
                            if (DestinationPingable && !STEM.Sys.IO.Net.PingHost(STEM.Sys.IO.Path.IPFromPath(dir)))
                            {
                                _LastTouched[dir].LastAttempt = DateTime.UtcNow;
                                return(false);
                            }
                        }

                        if (!String.IsNullOrEmpty(DestinationPathUser) && !String.IsNullOrEmpty(DestinationPathPassword))
                        {
                            STEM.Sys.Security.Impersonation impersonation = new Impersonation();

                            try
                            {
                                impersonation.Impersonate(DestinationPathUser, DestinationPathPassword, DestinationPathImpersonationIsLocal);

                                if (DirectoryExists(dir))
                                {
                                    _LastTouched[dir].Exists = true;
                                }
                                else
                                {
                                    _LastTouched[dir].Exists = false;
                                }
                            }
                            finally
                            {
                                impersonation.UnImpersonate();
                            }
                        }
                        else
                        {
                            if (DirectoryExists(dir))
                            {
                                _LastTouched[dir].Exists = true;
                            }
                            else
                            {
                                _LastTouched[dir].Exists = false;
                            }
                        }

                        _LastTouched[dir].LastAttempt = DateTime.UtcNow;
                    }

                    return(_LastTouched[dir].Exists);
                }
                else
                {
                    return(true);
                }
            }
            catch { }

            return(false);
        }