Dev2.PathOperations.Dev2FileSystemProvider.Delete C# (CSharp) Method

Delete() private method

private Delete ( IActivityIOPath src ) : bool
src IActivityIOPath
return bool
        public bool Delete(IActivityIOPath src)
        {
            bool result;
            try
            {

                if (!RequiresAuth(src))
                {
                    // We need sense check the value passed in ;)
                    result = DeleteHelper.Delete(src.Path);
                }
                else
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;
                    bool loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.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 = DeleteHelper.Delete(src.Path);


                                // remove impersonation now
                                impersonatedUser.Undo();
                            }
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + src.Username + " ] for resource [ " + src.Path + " ] ");
                    }
                }

            }
            catch (Exception)
            {
                //File is not found problem during delete
                result = false;
            }
            return result;
        }