protected override void InternalProcessRecord()
        {
            ADUser     aduser = null;
            string     empty  = string.Empty;
            ResultType type   = ResultType.Success;

            if (this.Mailbox != null)
            {
                aduser = (ADUser)base.GetDataObject(this.Mailbox);
                if (aduser == null && !this.AppOnly)
                {
                    base.ThrowTerminatingError(new MailboxUserNotFoundException(this.Mailbox.ToString()), ErrorCategory.ObjectNotFound, null);
                }
            }
            if (this.AppOnly)
            {
                if (this.Mailbox == null && string.IsNullOrEmpty(this.OrganizationDomain))
                {
                    base.ThrowTerminatingError(new NoUserOrOrganiztionProvidedException(), ErrorCategory.ObjectNotFound, null);
                }
                if (this.Service == ModServiceType.EWS)
                {
                    base.ThrowTerminatingError(new EwsNotSupportedException(), ErrorCategory.NotEnabled, null);
                }
            }
            else if (this.Mailbox == null)
            {
                base.ThrowTerminatingError(new MailboxParameterMissingException(), ErrorCategory.ObjectNotFound, null);
            }
            switch (this.Service)
            {
            case ModServiceType.EWS:
                type = TestOAuthConnectivityHelper.SendExchangeOAuthRequest(aduser, this.OrganizationDomain, this.TargetUri, out empty, this.AppOnly, this.UseCachedToken, this.ReloadConfig);
                break;

            case ModServiceType.AutoD:
                type = TestOAuthConnectivityHelper.SendAutodiscoverOAuthRequest(aduser, this.OrganizationDomain, this.TargetUri, out empty, this.AppOnly, this.UseCachedToken, this.ReloadConfig);
                break;

            case ModServiceType.Generic:
                type = TestOAuthConnectivityHelper.SendGenericOAuthRequest(aduser, this.OrganizationDomain, this.TargetUri, out empty, this.AppOnly, this.UseCachedToken, this.ReloadConfig);
                break;
            }
            ValidationResultNode sendToPipeline = new ValidationResultNode(Strings.TestApiCallUnderOauthTask(this.Service.ToString()), new LocalizedString(empty), type);

            base.WriteObject(sendToPipeline);
        }
Example #2
0
        protected override void InternalProcessRecord()
        {
            ValidationResultCollector validationResultCollector = new ValidationResultCollector();
            LocalConfiguration        localConfiguration        = LocalConfiguration.Load(validationResultCollector);

            foreach (ValidationResultNode sendToPipeline in validationResultCollector.Results)
            {
                base.WriteObject(sendToPipeline);
            }
            SharePointException ex = null;
            Uri uri = this.SharePointUrl ?? this.tmADObject.SharePointUrl;
            OAuthCredentials oauthCredentials = null;

            try
            {
                using (ClientContext clientContext = new ClientContext(uri))
                {
                    bool         flag = false;
                    ICredentials credentialAndConfigureClientContext = TeamMailboxHelper.GetCredentialAndConfigureClientContext(this.requestor, (this.requestor != null) ? this.requestor.OrganizationId : base.CurrentOrganizationId, clientContext, this.UseAppTokenOnly, out flag);
                    if (!flag)
                    {
                        base.WriteError(new InvalidOperationException(Strings.OauthIsTurnedOff), ErrorCategory.InvalidOperation, null);
                    }
                    oauthCredentials                    = (credentialAndConfigureClientContext as OAuthCredentials);
                    oauthCredentials.Tracer             = new TestSiteMailbox.TaskOauthOutboundTracer();
                    oauthCredentials.LocalConfiguration = localConfiguration;
                    Web web = clientContext.Web;
                    clientContext.Load <Web>(web, new Expression <Func <Web, object> > [0]);
                    clientContext.ExecuteQuery();
                }
            }
            catch (ClientRequestException e)
            {
                ex = new SharePointException(uri.AbsoluteUri, e);
            }
            catch (ServerException e2)
            {
                ex = new SharePointException(uri.AbsoluteUri, e2);
            }
            catch (IOException ex2)
            {
                ex = new SharePointException(uri.AbsoluteUri, new LocalizedString(ex2.Message));
            }
            catch (WebException e3)
            {
                ex = new SharePointException(uri.AbsoluteUri, e3, true);
            }
            if (ex != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(Strings.TestTeamMailboxOutboundOauthLog);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                stringBuilder.AppendLine(Strings.TestTeamMailboxSharePointResponseDetails);
                stringBuilder.AppendLine(ex.DiagnosticInfo);
                ValidationResultNode sendToPipeline2 = new ValidationResultNode(Strings.TestTeamMailboxSharepointCallUnderOauthTask, new LocalizedString(stringBuilder.ToString()), ResultType.Error);
                base.WriteObject(sendToPipeline2);
                return;
            }
            StringBuilder stringBuilder2 = new StringBuilder();

            stringBuilder2.AppendLine(Strings.TestTeamMailboxSharepointCallUnderOauthSuccess(uri.AbsoluteUri));
            stringBuilder2.AppendLine(Strings.TestTeamMailboxOutboundOauthLog);
            stringBuilder2.AppendLine(oauthCredentials.Tracer.ToString());
            ValidationResultNode sendToPipeline3 = new ValidationResultNode(Strings.TestTeamMailboxSharepointCallUnderOauthTask, new LocalizedString(stringBuilder2.ToString()), ResultType.Success);

            base.WriteObject(sendToPipeline3);
        }