Beispiel #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));
            }
        }
Beispiel #2
0
        public static SharepointObject Read(SharepointSession session, ObjectId id)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            SharepointSiteId sharepointSiteId = id as SharepointSiteId;

            if (sharepointSiteId == null)
            {
                throw new ArgumentException("id");
            }
            if (sharepointSiteId is SharepointDocumentLibraryItemId)
            {
                return(SharepointDocumentLibraryItem.Read(session, sharepointSiteId));
            }
            if (sharepointSiteId is SharepointListId)
            {
                return(SharepointList.Read(session, sharepointSiteId));
            }
            throw new ObjectNotFoundException(sharepointSiteId, Strings.ExObjectNotFound(sharepointSiteId.ToString()));
        }