Exemplo n.º 1
0
        internal static DocumentLibraryException TranslateException(WebException ex, SharepointSiteId objectId, bool objectOpened, Utils.MethodType methodType)
        {
            if (ex.Response != null)
            {
                HttpStatusCode statusCode     = ((HttpWebResponse)ex.Response).StatusCode;
                HttpStatusCode httpStatusCode = statusCode;
                if (httpStatusCode <= HttpStatusCode.NotFound)
                {
                    if (httpStatusCode != HttpStatusCode.Unauthorized)
                    {
                        if (httpStatusCode == HttpStatusCode.NotFound)
                        {
                            if (objectOpened)
                            {
                                return(new ObjectMovedOrDeletedException(objectId, "ObjectNotFound", ex));
                            }
                            return(new ObjectNotFoundException(objectId, "ObjectNotFound", ex));
                        }
                    }
                    else
                    {
                        if (methodType == Utils.MethodType.GetView)
                        {
                            throw new GetViewAccessDeniedException(objectId, Strings.ExAccessDeniedForGetViewUnder((objectId != null) ? objectId.ToString() : null), ex);
                        }
                        if (methodType == Utils.MethodType.GetStream)
                        {
                            throw new DocumentStreamAccessDeniedException(objectId, Strings.ExAccessDenied((objectId != null) ? objectId.ToString() : null), ex);
                        }
                        throw new AccessDeniedException(objectId, Strings.ExAccessDenied((objectId != null) ? objectId.ToString() : null), ex);
                    }
                }
                else if (httpStatusCode == HttpStatusCode.ProxyAuthenticationRequired || httpStatusCode == HttpStatusCode.BadGateway)
                {
                    return(new ProxyConnectionException(objectId, Strings.ExProxyConnectionFailure, ex));
                }
                return(new ConnectionException(objectId, Strings.ExConnectionFailure, ex));
            }
            switch (ex.Status)
            {
            case WebExceptionStatus.NameResolutionFailure:
                if (objectOpened)
                {
                    return(new ObjectMovedOrDeletedException(objectId, "ObjectNotFound", ex));
                }
                return(new ObjectNotFoundException(objectId, "ObjectNotFound", ex));

            case WebExceptionStatus.ConnectFailure:
            case WebExceptionStatus.ReceiveFailure:
            case WebExceptionStatus.SendFailure:
            case WebExceptionStatus.PipelineFailure:
            case WebExceptionStatus.RequestCanceled:
            case WebExceptionStatus.ProtocolError:
            case WebExceptionStatus.ConnectionClosed:
            case WebExceptionStatus.TrustFailure:
            case WebExceptionStatus.SecureChannelFailure:
            case WebExceptionStatus.ServerProtocolViolation:
            case WebExceptionStatus.KeepAliveFailure:
            case WebExceptionStatus.Pending:
            case WebExceptionStatus.Timeout:
            case WebExceptionStatus.MessageLengthLimitExceeded:
            case WebExceptionStatus.CacheEntryNotFound:
            case WebExceptionStatus.RequestProhibitedByCachePolicy:
                return(new ConnectionException(objectId, Strings.ExConnectionFailure, ex));

            case WebExceptionStatus.ProxyNameResolutionFailure:
            case WebExceptionStatus.RequestProhibitedByProxy:
                return(new ProxyConnectionException(objectId, Strings.ExProxyConnectionFailure, ex));

            case WebExceptionStatus.UnknownError:
                return(new UnknownErrorException(objectId, Strings.ExUnknownError, ex));

            default:
                return(new UnknownErrorException(objectId, Strings.ExUnknownError, ex));
            }
        }
Exemplo n.º 2
0
        internal static G DoSharepointTask <G>(WindowsIdentity identity, ObjectId itemToAccess, SharepointSiteId sharepointId, bool objectOpened, Utils.MethodType methodType, Utils.DoTask <G> doTask)
        {
            WindowsImpersonationContext windowsImpersonationContext = null;
            G result;

            try
            {
                windowsImpersonationContext = Utils.ImpersonateUser(identity);
                result = doTask();
            }
            catch (ObjectNotFoundException innerException)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (objectOpened)
                {
                    throw new ObjectMovedOrDeletedException(itemToAccess, itemToAccess.ToString(), innerException);
                }
                throw;
            }
            catch (AccessDeniedException innerException2)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (methodType == Utils.MethodType.GetView)
                {
                    throw new GetViewAccessDeniedException(itemToAccess, Strings.ExAccessDeniedForGetViewUnder((itemToAccess != null) ? itemToAccess.ToString() : null), innerException2);
                }
                if (methodType == Utils.MethodType.GetStream)
                {
                    throw new DocumentStreamAccessDeniedException(itemToAccess, Strings.ExAccessDenied((itemToAccess != null) ? itemToAccess.ToString() : null), innerException2);
                }
                throw new AccessDeniedException(itemToAccess, Strings.ExAccessDenied((itemToAccess != null) ? itemToAccess.ToString() : null), innerException2);
            }
            catch (SoapException ex)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw Utils.TranslateException(ex, sharepointId);
            }
            catch (WebException ex2)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw Utils.TranslateException(ex2, sharepointId, objectOpened, methodType);
            }
            catch
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw;
            }
            finally
            {
                Utils.UndoContext(ref windowsImpersonationContext);
            }
            return(result);
        }
Exemplo n.º 3
0
        internal static G DoUncTask <G>(WindowsIdentity identity, UncObjectId uncObjectId, bool objectOpened, Utils.MethodType methodType, Utils.DoTask <G> doTask)
        {
            WindowsImpersonationContext windowsImpersonationContext = Utils.ImpersonateUser(identity);
            G result;

            try
            {
                result = doTask();
            }
            catch (IOException ex)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw Utils.TranslateException(ex, uncObjectId, objectOpened);
            }
            catch (UnauthorizedAccessException innerException)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (methodType == Utils.MethodType.GetView)
                {
                    throw new GetViewAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
                }
                if (methodType == Utils.MethodType.GetStream)
                {
                    throw new DocumentStreamAccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
                }
                throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
            }
            catch (SecurityException innerException2)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (methodType == Utils.MethodType.GetView)
                {
                    throw new GetViewAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
                }
                if (methodType == Utils.MethodType.GetStream)
                {
                    throw new DocumentStreamAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
                }
                throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
            }
            catch
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw;
            }
            finally
            {
                Utils.UndoContext(ref windowsImpersonationContext);
            }
            return(result);
        }