示例#1
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);
        }
示例#2
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);
        }