コード例 #1
0
        public bool ClearClosedAndDeletedTeamMailboxesInShowInMyClientList(ADUser userMailbox)
        {
            if (userMailbox == null)
            {
                throw new ArgumentNullException("userMailbox");
            }
            bool result            = false;
            List <ADObjectId> list = new List <ADObjectId>();

            foreach (ADObjectId item in userMailbox.TeamMailboxShowInClientList)
            {
                list.Add(item);
            }
            foreach (ADObjectId adobjectId in list)
            {
                Exception ex;
                ADUser    aduser = TeamMailboxADUserResolver.Resolve(this.DataSession, adobjectId, out ex);
                if (ex == null && (aduser == null || !TeamMailbox.FromDataObject(aduser).Active))
                {
                    userMailbox.TeamMailboxShowInClientList.Remove(adobjectId);
                    result = true;
                }
            }
            return(result);
        }
コード例 #2
0
        public bool SetShowInMyClient(ADObjectId userId, bool show, out bool maxPinnedReached, out Exception ex)
        {
            if (userId == null)
            {
                throw new ArgumentNullException("userId");
            }
            bool flag = false;

            maxPinnedReached = false;
            ex = null;
            ADUser aduser = TeamMailboxADUserResolver.ResolveBypassCache(this.DataSession, userId, out ex);

            if (ex == null && aduser != null && !aduser.RecipientTypeDetails.Equals(RecipientTypeDetails.MailUser))
            {
                ADObjectId id = this.TeamMailbox.Id;
                try
                {
                    flag             = this.ClearClosedAndDeletedTeamMailboxesInShowInMyClientList(aduser);
                    maxPinnedReached = (show && aduser.TeamMailboxShowInClientList.Count >= 10);
                    if (!maxPinnedReached)
                    {
                        if (show && !aduser.TeamMailboxShowInClientList.Contains(id))
                        {
                            aduser.TeamMailboxShowInClientList.Add(id);
                            flag = true;
                        }
                        else if (!show && aduser.TeamMailboxShowInClientList.Contains(id))
                        {
                            aduser.TeamMailboxShowInClientList.Remove(id);
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        try
                        {
                            this.DataSession.Save(aduser);
                        }
                        catch (TransientException arg)
                        {
                            ex = new Exception(string.Format("When setting ShowInMyClient for user {0}, an error happened: {1}", aduser.DisplayName, arg));
                        }
                        catch (DataSourceOperationException arg2)
                        {
                            ex = new Exception(string.Format("When setting ShowInMyClient for user {0}, an error happened: {1}", aduser.DisplayName, arg2));
                        }
                    }
                }
                catch (InvalidOperationException arg3)
                {
                    ex = new Exception(string.Format("When setting ShowInMyClient for user {0}, an error happened: {1}", aduser.DisplayName, arg3));
                }
            }
            return(flag);
        }
コード例 #3
0
		public List<Exception> SendNotification(IList<ADObjectId> recipients, string subject, string body, RemotingOptions remotingOptons = RemotingOptions.LocalConnectionsOnly)
		{
			if (recipients == null)
			{
				throw new ArgumentNullException("recipients");
			}
			if (subject == null)
			{
				throw new ArgumentNullException("subject");
			}
			if (body == null)
			{
				throw new ArgumentNullException("body");
			}
			List<Exception> list = new List<Exception>();
			if (recipients.Count > 0)
			{
				using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(ExchangePrincipal.FromADUser((ADUser)this.tm.DataObject, remotingOptons), CultureInfo.InvariantCulture, "Client=TeamMailbox;Action=Send_Notification"))
				{
					using (MessageItem messageItem = MessageItem.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Drafts)))
					{
						foreach (ADObjectId adobjectId in recipients)
						{
							Exception ex = null;
							ADUser aduser = TeamMailboxADUserResolver.Resolve(this.dataSession, adobjectId, out ex);
							if (ex != null)
							{
								list.Add(new Exception(string.Format("When resolving recipient {0}, got an excetion: {1}", adobjectId, ex)));
							}
							else if (aduser == null)
							{
								list.Add(new Exception("Cannot find recipient: " + adobjectId));
							}
							else
							{
								messageItem.Recipients.Add(new Participant(aduser.DisplayName, aduser.PrimarySmtpAddress.ToString(), "SMTP"));
							}
						}
						messageItem.Subject = subject;
						using (Stream stream = messageItem.Body.OpenWriteStream(new BodyWriteConfiguration(BodyFormat.TextHtml, Charset.Unicode)))
						{
							using (StreamWriter streamWriter = new StreamWriter(stream, Encoding.Unicode))
							{
								streamWriter.WriteLine(body);
							}
						}
						messageItem.AutoResponseSuppress = AutoResponseSuppress.All;
						messageItem.SendWithoutSavingMessage();
					}
				}
			}
			return list;
		}
コード例 #4
0
        private SecurityIdentifier GetUserSid(ADObjectId userId)
        {
            if (userId == null)
            {
                throw new ArgumentNullException("userId");
            }
            Exception ex;
            ADUser    aduser = TeamMailboxADUserResolver.Resolve(this.DataSession, userId, out ex);

            if (aduser == null)
            {
                return(null);
            }
            if (null != aduser.MasterAccountSid && !aduser.MasterAccountSid.IsWellKnown(WellKnownSidType.SelfSid))
            {
                return(aduser.MasterAccountSid);
            }
            return(aduser.Sid);
        }
コード例 #5
0
 public static ADUser ResolveBypassCache(IRecipientSession dataSession, ADObjectId id, out Exception ex)
 {
     TeamMailboxADUserResolver.RemoveIdIfExists(id);
     return(TeamMailboxADUserResolver.Resolve(dataSession, id, out ex));
 }
コード例 #6
0
 private ADUser ResolveUserFunction(ADObjectId id, out Exception ex)
 {
     return(TeamMailboxADUserResolver.Resolve(this.DataSession, id, out ex));
 }