Example #1
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()));
        }
Example #2
0
        public static DocumentLibraryObjectId Parse(string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            if (str.Length == 0)
            {
                throw new ArgumentException("str");
            }
            Uri uri = null;

            try
            {
                uri = new Uri(str);
            }
            catch (UriFormatException innerException)
            {
                throw new CorruptDataException(str, Strings.ExCorruptData, innerException);
            }
            if (uri.IsUnc)
            {
                int num = str.IndexOf(UncObjectId.QueryPart);
                if (num < 0 || str[num - 1] != '?')
                {
                    throw new CorruptDataException(str, Strings.ExCorruptData);
                }
                UriFlags uriFlags;
                try
                {
                    uriFlags = (UriFlags)Enum.Parse(typeof(UriFlags), str.Substring(num + UncObjectId.QueryPart.Length));
                }
                catch (ArgumentException innerException2)
                {
                    throw new CorruptDataException(str, Strings.ExCorruptData, innerException2);
                }
                Uri uri2 = new Uri(str.Substring(0, num - 1));
                if (!Utils.IsValidUncUri(uri2))
                {
                    throw new CorruptDataException(str, Strings.ExCorruptData);
                }
                return(new UncObjectId(uri2, uriFlags));
            }
            else
            {
                if (uri.IsFile)
                {
                    throw new ArgumentException("str");
                }
                return(SharepointSiteId.Parse(str));
            }
        }
 internal SharepointSession(SharepointSiteId sharepointId, WindowsPrincipal windowsPrincipal)
 {
     if (sharepointId == null)
     {
         throw new ArgumentNullException("sharepointId");
     }
     if (windowsPrincipal == null)
     {
         throw new ArgumentNullException("windowsPrincipal");
     }
     this.windowsIdentity = (WindowsIdentity)windowsPrincipal.Identity;
     this.sharepointId    = sharepointId;
 }
Example #4
0
 internal SharepointObject(SharepointSiteId listId, SharepointSession session, XmlNode dataNode, Schema schema)
 {
     if (listId == null)
     {
         throw new ArgumentNullException();
     }
     if (session == null)
     {
         throw new ArgumentNullException();
     }
     if (dataNode == null)
     {
         throw new ArgumentNullException();
     }
     this.SharepointId = listId;
     this.Session      = session;
     this.DataNode     = dataNode.Clone();
     this.Schema       = schema;
 }
        public static SharepointSession Open(ObjectId objectId, IPrincipal authenticatedUser)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            if (authenticatedUser == null)
            {
                throw new ArgumentNullException("authenticatedUser");
            }
            SharepointSiteId sharepointSiteId = objectId as SharepointSiteId;
            WindowsPrincipal windowsPrincipal = authenticatedUser as WindowsPrincipal;

            if (sharepointSiteId == null)
            {
                throw new ArgumentException("objectId");
            }
            if (windowsPrincipal == null)
            {
                throw new ArgumentException("authenticatedUser");
            }
            return(new SharepointSession(sharepointSiteId, windowsPrincipal));
        }
Example #6
0
 internal SharepointWeb(string title, SharepointSiteId siteId)
 {
     this.title  = title;
     this.siteId = siteId;
 }
Example #7
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);
        }
Example #8
0
 internal static DocumentLibraryException TranslateException(SoapException ex, SharepointSiteId objectId)
 {
     return(new UnknownErrorException(objectId, Strings.ExUnknownError, ex));
 }
Example #9
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));
            }
        }