Exemplo n.º 1
0
        public void AddFavoriteLibrary()
        {
            ExTraceGlobals.DocumentsCallTracer.TraceDebug((long)this.GetHashCode(), "DocumentLibraryEventHandler.AddFavoriteLibrary");
            string[] array = (string[])base.GetParameter("uri");
            bool     flag  = false;

            this.Writer.Write("<div id=divAFavLibs>");
            for (int i = 0; i < array.Length; i++)
            {
                ClassifyResult documentLibraryObjectId = DocumentLibraryUtilities.GetDocumentLibraryObjectId(array[i], base.UserContext);
                if (documentLibraryObjectId == null)
                {
                    ExTraceGlobals.DocumentsTracer.TraceDebug(0L, "Could not classify link: " + array[i]);
                }
                else
                {
                    DocumentLibraryObjectId objectId = documentLibraryObjectId.ObjectId;
                    if (objectId != null)
                    {
                        UriFlags        uriFlags        = objectId.UriFlags;
                        DocumentLibrary documentLibrary = new DocumentLibrary();
                        bool            flag2           = DocumentLibraryUtilities.IsNavigationToWSSAllowed(base.UserContext);
                        bool            flag3           = DocumentLibraryUtilities.IsNavigationToUNCAllowed(base.UserContext);
                        UriFlags        uriFlags2       = uriFlags;
                        switch (uriFlags2)
                        {
                        case UriFlags.Sharepoint:
                            {
                                if (!flag2)
                                {
                                    throw new OwaSegmentationException("Access to Sharepoint documents is disabled");
                                }
                                SharepointSession sharepointSession = base.UserContext.LogonIdentity.CreateSharepointSession(objectId);
                                documentLibrary.DisplayName = (string.IsNullOrEmpty(sharepointSession.DisplayName) ? LocalizedStrings.GetNonEncoded(-527057840) : sharepointSession.DisplayName);
                                documentLibrary.SiteName    = sharepointSession.DisplayName;
                                break;
                            }

                        case UriFlags.Unc:
                            {
                                if (!flag3)
                                {
                                    throw new OwaSegmentationException("Access to Unc documents is disabled");
                                }
                                UncSession uncSession = base.UserContext.LogonIdentity.CreateUncSession(objectId);
                                documentLibrary.DisplayName = uncSession.Title;
                                documentLibrary.SiteName    = uncSession.Uri.Host;
                                break;
                            }

                        case UriFlags.Sharepoint | UriFlags.Unc:
                        case UriFlags.DocumentLibrary:
                            goto IL_34F;

                        case UriFlags.SharepointDocumentLibrary:
                        {
                            if (!flag2)
                            {
                                throw new OwaSegmentationException("Access to Sharepoint documents is disabled");
                            }
                            SharepointSession         sharepointSession2        = base.UserContext.LogonIdentity.CreateSharepointSession(objectId);
                            SharepointDocumentLibrary sharepointDocumentLibrary = SharepointDocumentLibrary.Read(sharepointSession2, objectId);
                            documentLibrary.DisplayName = (string.IsNullOrEmpty(sharepointDocumentLibrary.Title) ? LocalizedStrings.GetNonEncoded(477016274) : sharepointDocumentLibrary.Title);
                            documentLibrary.SiteName    = sharepointSession2.DisplayName;
                            break;
                        }

                        case UriFlags.UncDocumentLibrary:
                        {
                            if (!flag3)
                            {
                                throw new OwaSegmentationException("Access to Unc documents is disabled");
                            }
                            UncSession         session            = base.UserContext.LogonIdentity.CreateUncSession(objectId);
                            UncDocumentLibrary uncDocumentLibrary = UncDocumentLibrary.Read(session, objectId);
                            documentLibrary.DisplayName = (string.IsNullOrEmpty(uncDocumentLibrary.Title) ? LocalizedStrings.GetNonEncoded(477016274) : uncDocumentLibrary.Title);
                            documentLibrary.SiteName    = uncDocumentLibrary.Uri.Host;
                            break;
                        }

                        default:
                            switch (uriFlags2)
                            {
                            case UriFlags.SharepointFolder:
                            {
                                if (!flag2)
                                {
                                    throw new OwaSegmentationException("Access to Sharepoint documents is disabled");
                                }
                                SharepointSession sharepointSession3 = base.UserContext.LogonIdentity.CreateSharepointSession(objectId);
                                SharepointDocumentLibraryFolder sharepointDocumentLibraryFolder = SharepointDocumentLibraryFolder.Read(sharepointSession3, objectId);
                                documentLibrary.DisplayName = (string.IsNullOrEmpty(sharepointDocumentLibraryFolder.DisplayName) ? LocalizedStrings.GetNonEncoded(-527057840) : sharepointDocumentLibraryFolder.DisplayName);
                                documentLibrary.SiteName    = sharepointSession3.DisplayName;
                                break;
                            }

                            case UriFlags.UncFolder:
                            {
                                if (!flag3)
                                {
                                    throw new OwaSegmentationException("Access to Unc documents is disabled");
                                }
                                UncSession session2 = base.UserContext.LogonIdentity.CreateUncSession(objectId);
                                UncDocumentLibraryFolder uncDocumentLibraryFolder = UncDocumentLibraryFolder.Read(session2, objectId);
                                documentLibrary.DisplayName = (string.IsNullOrEmpty(uncDocumentLibraryFolder.DisplayName) ? LocalizedStrings.GetNonEncoded(-527057840) : uncDocumentLibraryFolder.DisplayName);
                                documentLibrary.SiteName    = uncDocumentLibraryFolder.Uri.Host;
                                break;
                            }

                            default:
                                goto IL_34F;
                            }
                            break;
                        }
                        documentLibrary.Type = uriFlags;
                        documentLibrary.Uri  = array[i];
                        int num = 0;
                        if (DocumentLibraryUtilities.AddFavorite(documentLibrary, base.UserContext, out num) && num <= 1000)
                        {
                            DocumentLibraryUtilities.RenderLibraryItem(this.Writer, documentLibrary, base.UserContext, true);
                            flag = true;
                            goto IL_3A0;
                        }
                        goto IL_3A0;
                        IL_34F:
                        throw new OwaNotSupportedException("Unhandled document library type");
                    }
                    ExTraceGlobals.DocumentsTracer.TraceDebug(0L, "ObjectId could not be created from URI parameter: " + array[i]);
                }
                IL_3A0 :;
            }
            this.Writer.Write("</div>");
            if (flag)
            {
                this.Writer.Write("<div id=divMsgFav>");
                this.Writer.Write(LocalizedStrings.GetHtmlEncoded(344777715));
                this.Writer.Write("</div><div id=divMsgTtl>");
                this.Writer.Write(LocalizedStrings.GetHtmlEncoded(803639727));
            }
            else
            {
                this.Writer.Write("<div id=divNoLib>");
            }
            this.Writer.Write("</div>");
        }
Exemplo n.º 2
0
        // Token: 0x06000741 RID: 1857 RVA: 0x00026D8C File Offset: 0x00024F8C
        public void Execute()
        {
            Uri uri = null;

            try
            {
                uri = new Uri(this.linkId);
            }
            catch (UriFormatException innerException)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "DocumentLibrarySearchProvider: Bad Uri {0} was specified!", new object[]
                {
                    this.linkId
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException, false);
            }
            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Processing Search command with Uri {0}.", uri.AbsoluteUri);
            if (!DocumentLibraryUtility.IsTrustedProtocol(uri.Scheme))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: untrusted protocol: {0}!", new object[]
                {
                    uri.Scheme
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadProtocolInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
            }
            if (!DocumentLibraryUtility.IsInternalUri(uri))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Uri must be internal: {0}!", new object[]
                {
                    uri.Host
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternalProtocolInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
            }
            AuthenticationContext authenticationContext = new AuthenticationContext();

            try
            {
                IPrincipal principal;
                if (this.userPassword == null)
                {
                    principal = this.user.WindowsPrincipal;
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrarySearchProvider: Created IPrincipal object from IAirSyncUser .");
                    if (principal == null)
                    {
                        if (GlobalSettings.EnableCredentialRequest && this.user.Context.Request.Version >= 121)
                        {
                            this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedPromptForCredsToProxy2");
                            throw new AirSyncPermanentException(StatusCode.Sync_InvalidWaitTime, false);
                        }
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedCredsToProxy2");
                        throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false);
                    }
                }
                else
                {
                    SecurityStatus securityStatus = authenticationContext.LogonUser(this.userName, this.userPassword);
                    this.userPassword.Dispose();
                    this.userPassword = null;
                    if (securityStatus != SecurityStatus.OK)
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "DocumentLibrarySearchProvider: Authentication failed with status {0}.", new object[]
                        {
                            securityStatus
                        }));
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, string.Format(CultureInfo.InvariantCulture, "AuthenticationErrorStatus{0}", new object[]
                        {
                            securityStatus
                        }));
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);
                    }
                    principal = new WindowsPrincipal(authenticationContext.Identity);
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrarySearchProvider: Created IPrincipal using AuthenticationContext LogonUser method.");
                }
                ClassifyResult classifyResult = LinkClassifier.ClassifyLinks(principal, new Uri[]
                {
                    uri
                })[0];
                if (classifyResult.Error != ClassificationError.None)
                {
                    AirSyncDiagnostics.TraceDebug <string, ClassificationError>(ExTraceGlobals.RequestsTracer, this, "The LinkClassifier failed to classify the link {0}, returned {1}", this.linkId, classifyResult.Error);
                    switch (classifyResult.Error)
                    {
                    case ClassificationError.ConnectionFailed:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassConnFailedInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_Conflict, null, false);

                    case ClassificationError.AccessDenied:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassDeniedInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);

                    case ClassificationError.ObjectNotFound:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassNotFoundInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ClientServerConversion, null, false);

                    case ClassificationError.UriTypeNotSupported:
                    case ClassificationError.InvalidUri:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassBadUriInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ProtocolError, null, false);
                    }
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassFailureInDocSearch");
                    throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false);
                }
                AirSyncDiagnostics.TraceDebug <UriFlags>(ExTraceGlobals.RequestsTracer, this, "Search command document type is {0}.", classifyResult.UriFlags);
                SharepointSession      sharepointSession     = null;
                UncSession             uncSession            = null;
                IDocumentLibraryItem   documentLibraryItem   = null;
                IDocumentLibrary       documentLibrary       = null;
                IDocumentLibraryFolder documentLibraryFolder = null;
                if ((classifyResult.UriFlags & UriFlags.Unc) == UriFlags.Unc)
                {
                    if (!DocumentLibraryUtility.IsUncAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    uncSession = UncSession.Open(classifyResult.ObjectId, principal);
                }
                else
                {
                    if ((classifyResult.UriFlags & UriFlags.Sharepoint) != UriFlags.Sharepoint)
                    {
                        AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Search", this.linkId, classifyResult.UriFlags);
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false);
                    }
                    if (!DocumentLibraryUtility.IsWssAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "WssDeniedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocSearch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    sharepointSession = SharepointSession.Open(classifyResult.ObjectId, principal);
                }
                UriFlags uriFlags = classifyResult.UriFlags;
                switch (uriFlags)
                {
                case UriFlags.Sharepoint:
                case UriFlags.Unc:
                    goto IL_645;

                case UriFlags.Sharepoint | UriFlags.Unc:
                case UriFlags.DocumentLibrary:
                    break;

                case UriFlags.SharepointDocumentLibrary:
                    documentLibrary = SharepointDocumentLibrary.Read(sharepointSession, classifyResult.ObjectId);
                    goto IL_645;

                case UriFlags.UncDocumentLibrary:
                    documentLibrary = UncDocumentLibrary.Read(uncSession, classifyResult.ObjectId);
                    goto IL_645;

                default:
                    switch (uriFlags)
                    {
                    case UriFlags.SharepointDocument:
                        documentLibraryItem = SharepointDocument.Read(sharepointSession, classifyResult.ObjectId);
                        goto IL_645;

                    case UriFlags.UncDocument:
                        documentLibraryItem = UncDocument.Read(uncSession, classifyResult.ObjectId);
                        goto IL_645;

                    default:
                        switch (uriFlags)
                        {
                        case UriFlags.SharepointFolder:
                            documentLibraryFolder = SharepointDocumentLibraryFolder.Read(sharepointSession, classifyResult.ObjectId);
                            goto IL_645;

                        case UriFlags.UncFolder:
                            documentLibraryFolder = UncDocumentLibraryFolder.Read(uncSession, classifyResult.ObjectId);
                            goto IL_645;
                        }
                        break;
                    }
                    break;
                }
                AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Search", this.linkId, classifyResult.UriFlags);
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch3");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false);
IL_645:
                if (documentLibrary != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() for document library...");
                    this.tableView = documentLibrary.GetView(null, DocumentLibrarySearchProvider.sortBy, DocumentLibraryQueryOptions.FoldersAndFiles, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps = documentLibrary.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (documentLibraryFolder != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() for document folder...");
                    this.tableView = documentLibraryFolder.GetView(null, DocumentLibrarySearchProvider.sortBy, DocumentLibraryQueryOptions.FoldersAndFiles, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps = documentLibraryFolder.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (documentLibraryItem != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Getting properties for the document item...");
                    this.rootProps = documentLibraryItem.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (sharepointSession != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() on Sharepoint session...");
                    this.tableView    = sharepointSession.GetView(ListBaseType.DocumentLibrary, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps    = new object[DocumentLibrarySearchProvider.airSyncProps.GetLength(0)];
                    this.rootProps[0] = sharepointSession.Uri;
                    this.rootProps[1] = sharepointSession.DisplayName;
                    this.rootProps[2] = true;
                }
                else
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() on UNC session...");
                    this.tableView    = uncSession.GetView(null, null, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps    = new object[DocumentLibrarySearchProvider.airSyncProps.GetLength(0)];
                    this.rootProps[0] = uncSession.Uri;
                    this.rootProps[1] = uncSession.Title;
                    this.rootProps[2] = true;
                }
            }
            catch (UnknownErrorException innerException2)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch4");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException2, false);
            }
            catch (AccessDeniedException innerException3)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocSearch2");
                throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException3, false);
            }
            catch (ConnectionException innerException4)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ConnFailedInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_Conflict, innerException4, false);
            }
            catch (ObjectNotFoundException innerException5)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException5, false);
            }
            catch (DocumentLibraryException innerException6)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FailureInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException6, false);
            }
            finally
            {
                if (authenticationContext != null)
                {
                    authenticationContext.Dispose();
                    authenticationContext = null;
                }
            }
        }