internal static MultiValuedProperty <CultureInfo> CheckSharePointSite(SmtpAddress teamMailboxEmailAddress, ref Uri sharePointUrl, ADRawEntry actAsUser, OrganizationId actAsUserOrgId, ADUser executingUser, out SharePointMemberShip executingUserMembership, out Uri webCollectionUrl, out Guid webId) { MultiValuedProperty <CultureInfo> multiValuedProperty = new MultiValuedProperty <CultureInfo>(); executingUserMembership = SharePointMemberShip.Others; try { using (ClientContext clientContext = new ClientContext(sharePointUrl.AbsoluteUri)) { clientContext.RequestTimeout = 60000; bool flag; TeamMailboxHelper.GetCredentialAndConfigureClientContext(actAsUser, actAsUserOrgId, clientContext, true, out flag); Web web = clientContext.Web; clientContext.Load <Web>(web, new Expression <Func <Web, object> >[] { (Web x) => x.AllProperties, (Web x) => x.Url, (Web x) => (object)x.Language, (Web x) => x.Features, (Web x) => (object)x.Id }); Feature byId = web.Features.GetById(new Guid("{502A2D54-6102-4757-AAA0-A90586106368}")); clientContext.Load <Feature>(byId, new Expression <Func <Feature, object> > [0]); Group associatedOwnerGroup = clientContext.Web.AssociatedOwnerGroup; Group associatedMemberGroup = clientContext.Web.AssociatedMemberGroup; clientContext.Load <UserCollection>(associatedOwnerGroup.Users, new Expression <Func <UserCollection, object> > [0]); clientContext.Load <UserCollection>(associatedMemberGroup.Users, new Expression <Func <UserCollection, object> > [0]); Site site = clientContext.Site; clientContext.Load <Site>(site, new Expression <Func <Site, object> >[] { (Site x) => x.Url }); bool flag2 = false; try { clientContext.ExecuteQuery(); if (byId.ServerObjectIsNull != null) { flag2 = !byId.ServerObjectIsNull.Value; } } catch (UnauthorizedAccessException) { } if (!flag2) { throw new RecipientTaskException(Strings.ErrorTeamMailboxFeatureNotInstalled(web.Url)); } if (clientContext.ServerVersion.Major < 15) { throw new RecipientTaskException(Strings.ErrorTeamMailboxSharePointServerVersionInCompatible); } if (web.AllProperties.FieldValues.ContainsKey("ExchangeTeamMailboxEmailAddress") && (teamMailboxEmailAddress == SmtpAddress.Empty || !string.Equals(teamMailboxEmailAddress.ToString(), (string)web.AllProperties["ExchangeTeamMailboxEmailAddress"], StringComparison.OrdinalIgnoreCase))) { throw new RecipientTaskException(Strings.ErrorTeamMailboxSharePointSiteAlreadyLinkedWithOtherTM(sharePointUrl.ToString(), (string)web.AllProperties["ExchangeTeamMailboxEmailAddress"])); } webCollectionUrl = TeamMailbox.GetUrl(site.Url); webId = web.Id; if (webCollectionUrl == null) { throw new RecipientTaskException(Strings.ErrorSharePointSiteHasNoValidWebCollectionUrl(site.Url)); } multiValuedProperty.Add(new CultureInfo((int)web.Language)); try { foreach (User spUser in associatedOwnerGroup.Users) { if (TeamMailboxHelper.ExchangeSharePointUserMatch(executingUser, spUser)) { executingUserMembership = SharePointMemberShip.Owner; break; } } if (executingUserMembership == SharePointMemberShip.Others) { foreach (User spUser2 in associatedMemberGroup.Users) { if (TeamMailboxHelper.ExchangeSharePointUserMatch(executingUser, spUser2)) { executingUserMembership = SharePointMemberShip.Member; break; } } } } catch (CollectionNotInitializedException) { executingUserMembership = SharePointMemberShip.Others; } string uriString = null; if (!MaintenanceSynchronizer.TryEscapeAndGetWellFormedUrl(web.Url, out uriString)) { throw new RecipientTaskException(Strings.ErrorSharePointSiteHasNoValidUrl(web.Url)); } Uri uri = new Uri(uriString); if (uri != sharePointUrl) { sharePointUrl = uri; } } } catch (ClientRequestException ex) { throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSite(sharePointUrl.AbsoluteUri, ex.Message)); } catch (ServerException ex2) { throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSiteWithCorrelationId(sharePointUrl.AbsoluteUri, ex2.Message, ex2.ServerErrorTraceCorrelationId)); } catch (TimeoutException ex3) { throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSite(sharePointUrl.AbsoluteUri, ex3.Message)); } catch (IOException ex4) { throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSite(sharePointUrl.AbsoluteUri, ex4.Message)); } catch (WebException e) { SharePointException ex5 = new SharePointException(sharePointUrl.AbsoluteUri, e, false); throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSite(sharePointUrl.AbsoluteUri, ex5.DiagnosticInfo)); } catch (FormatException ex6) { throw new RecipientTaskException(Strings.ErrorTeamMailboxContactSharePointSite(sharePointUrl.AbsoluteUri, ex6.Message)); } return(multiValuedProperty); }
protected override void InternalProcessRecord() { ADUser dataObject = this.DataObject; TeamMailbox teamMailbox = TeamMailbox.FromDataObject(dataObject); this.teamMailboxHelper = new TeamMailboxHelper(teamMailbox, base.ExchangeRunspaceConfig.ExecutingUser, base.ExchangeRunspaceConfig.ExecutingUserOrganizationId, (IRecipientSession)base.DataSession, new TeamMailboxGetDataObject <ADUser>(base.GetDataObject <ADUser>)); TeamMailboxMembershipHelper teamMailboxMembershipHelper = new TeamMailboxMembershipHelper(teamMailbox, (IRecipientSession)base.DataSession); Exception ex = null; ADUser aduser = TeamMailboxADUserResolver.Resolve((IRecipientSession)base.DataSession, this.executingUserId, out ex); if (aduser == null) { base.WriteError(new RecipientTaskException(Strings.ErrorExecutingUserIsNull), ExchangeErrorCategory.Client, null); } if (base.Fields.IsModified("DisplayName")) { teamMailbox.DisplayName = this.DisplayName; } teamMailbox.SetPolicy(this.provisioningPolicy); base.WriteVerbose(Strings.SiteMailboxPolicySet(this.provisioningPolicy.ToString())); teamMailbox.SetMyRole(this.executingUserId); Uri sharePointUrl = this.SharePointUrl; SharePointMemberShip sharePointMemberShip = SharePointMemberShip.Others; Uri webCollectionUrl = null; Guid empty = Guid.Empty; if (base.Fields.IsModified("SharePointUrl") && !base.Fields.IsModified("Force")) { try { TeamMailboxHelper.CheckSharePointSite(SmtpAddress.Empty, ref sharePointUrl, base.ExchangeRunspaceConfig.ExecutingUser, base.ExchangeRunspaceConfig.ExecutingUserOrganizationId, aduser, out sharePointMemberShip, out webCollectionUrl, out empty); } catch (RecipientTaskException exception) { base.WriteError(exception, ExchangeErrorCategory.Client, null); } } teamMailbox.SharePointUrl = sharePointUrl; teamMailbox.SetSharePointSiteInfo(webCollectionUrl, empty); teamMailbox.SharePointLinkedBy = this.executingUserId; List <ADObjectId> list = new List <ADObjectId>(); List <ADObjectId> list2 = new List <ADObjectId>(); IList <ADObjectId> list3 = null; IList <ADObjectId> usersToRemove = null; if (TeamMailboxMembershipHelper.IsUserQualifiedType(aduser)) { if (sharePointMemberShip == SharePointMemberShip.Owner) { list.Add(this.executingUserId); teamMailboxMembershipHelper.UpdateTeamMailboxUserList(teamMailbox.Owners, list, out list3, out usersToRemove); teamMailboxMembershipHelper.UpdateTeamMailboxUserList(teamMailbox.OwnersAndMembers, list, out list3, out usersToRemove); } else if (sharePointMemberShip == SharePointMemberShip.Member) { list2.Add(this.executingUserId); teamMailboxMembershipHelper.UpdateTeamMailboxUserList(teamMailbox.OwnersAndMembers, list2, out list3, out usersToRemove); } } Exception ex2 = null; try { teamMailboxMembershipHelper.SetTeamMailboxUserPermissions(list3, usersToRemove, new SecurityIdentifier[] { WellKnownSids.SiteMailboxGrantedAccessMembers }, false); if (list3 != null) { base.WriteVerbose(Strings.SiteMailboxCreatorSet(list3[0].ToString())); } } catch (OverflowException ex3) { ex2 = ex3; } catch (COMException ex4) { ex2 = ex4; } catch (UnauthorizedAccessException ex5) { ex2 = ex5; } catch (TransientException ex6) { ex2 = ex6; } catch (DataSourceOperationException ex7) { ex2 = ex7; } if (ex2 != null) { base.WriteError(new RecipientTaskException(Strings.ErrorSetTeamMailboxUserPermissions(teamMailbox.DisplayName, ex2.Message)), ExchangeErrorCategory.Client, null); } base.InternalProcessRecord(); if (base.Fields.IsModified("SharePointUrl") && !base.Fields.IsModified("Force")) { try { this.teamMailboxHelper.LinkSharePointSite(sharePointUrl, true, false); base.WriteVerbose(Strings.SiteMailboxLinkedToSharePointSite(sharePointUrl.AbsoluteUri)); } catch (RecipientTaskException exception2) { base.DataSession.Delete(this.DataObject); base.WriteError(exception2, ExchangeErrorCategory.Client, null); } } IList <Exception> list4; teamMailboxMembershipHelper.SetShowInMyClient(list3, usersToRemove, out list4); foreach (Exception ex8 in list4) { this.WriteWarning(Strings.ErrorTeamMailboxResolveUser(ex8.Message)); } EnqueueResult enqueueResult = EnqueueResult.Success; if (this.databaseLocationInfo != null) { int num = 0; for (;;) { base.WriteVerbose(new LocalizedString(string.Format("Trying to send membership sync request to server {0} for MailboxGuid {1} using domain controller {2}", this.databaseLocationInfo.ServerFqdn, dataObject.ExchangeGuid, this.lastUsedDc))); enqueueResult = RpcClientWrapper.EnqueueTeamMailboxSyncRequest(this.databaseLocationInfo.ServerFqdn, dataObject.ExchangeGuid, QueueType.TeamMailboxMembershipSync, base.CurrentOrganizationId, "NewTMCMD_" + base.ExecutingUserIdentityName, this.lastUsedDc, SyncOption.Default); base.WriteVerbose(new LocalizedString(string.Format("The membership sync result is {0}", enqueueResult.Result))); if (enqueueResult.Result == EnqueueResultType.Successful) { goto IL_409; } if (num > 12) { break; } Thread.Sleep(5000); num++; } this.WriteWarning(Strings.ErrorTeamMailboxEnqueueMembershipSyncEvent(enqueueResult.ResultDetail)); goto IL_414; IL_409: base.WriteVerbose(Strings.SiteMailboxMembershipSyncEventEnqueued); IL_414: enqueueResult = RpcClientWrapper.EnqueueTeamMailboxSyncRequest(this.databaseLocationInfo.ServerFqdn, dataObject.ExchangeGuid, QueueType.TeamMailboxDocumentSync, base.CurrentOrganizationId, "NewTMCMD_" + base.ExecutingUserIdentityName, this.lastUsedDc, SyncOption.Default); base.WriteVerbose(new LocalizedString(string.Format("Document sync request to server {0} for MailboxGuid {1} using domain controller {2}. The result is: {3}", new object[] { this.databaseLocationInfo.ServerFqdn, dataObject.ExchangeGuid, this.lastUsedDc, enqueueResult.ResultDetail }))); return; } this.WriteWarning(Strings.ErrorTeamMailboxEnqueueMembershipSyncEvent("No database location information available")); }