/// <remarks/>
 public void SetUserOofSettingsAsync(SetUserOofSettingsRequest SetUserOofSettingsRequest, object userState)
 {
     if ((this.SetUserOofSettingsOperationCompleted == null))
     {
         this.SetUserOofSettingsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetUserOofSettingsOperationCompleted);
     }
     this.InvokeAsync("SetUserOofSettings", new object[] {
                 SetUserOofSettingsRequest}, this.SetUserOofSettingsOperationCompleted, userState);
 }
 /// <remarks/>
 public System.IAsyncResult BeginSetUserOofSettings(SetUserOofSettingsRequest SetUserOofSettingsRequest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("SetUserOofSettings", new object[] {
                 SetUserOofSettingsRequest}, callback, asyncState);
 }
 /// <remarks/>
 public void SetUserOofSettingsAsync(SetUserOofSettingsRequest SetUserOofSettingsRequest)
 {
     this.SetUserOofSettingsAsync(SetUserOofSettingsRequest, null);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Set user mailbox Out of Office state.
        /// </summary>
        /// <param name="mailAddress">User's email address.</param>
        /// <param name="password">Password of user mailbox.</param>
        /// <param name="isOOF">If true, set OOF state, else make sure OOF state is not set (clear OOF state).</param>
        /// <returns>If the operation succeed then return true, otherwise return false.</returns>
        public bool SetUserOOFSettings(string mailAddress, string password, bool isOOF)
        {
            using (ExchangeServiceBinding service = new ExchangeServiceBinding())
            {
                service.Url = Common.GetConfigurationPropertyValue(Constants.SetOOFWebServiceURL, this.Site);
                if (service.Url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    this.AcceptServerCertificate();
                }

                service.Credentials = new System.Net.NetworkCredential(mailAddress, password);

                EmailAddress emailAddress = new EmailAddress
                {
                    Address = mailAddress, Name = string.Empty
                };
                UserOofSettings userSettings = new UserOofSettings
                {
                    // Identify the external audience.
                    ExternalAudience = ExternalAudience.Known
                };

                // Create the OOF reply messages.
                ReplyBody replyBody = new ReplyBody
                {
                    Message = Constants.MessageOfOOFReply
                };

                userSettings.ExternalReply = replyBody;
                userSettings.InternalReply = replyBody;

                // Set OOF state.
                if (isOOF)
                {
                    userSettings.OofState = OofState.Enabled;
                }
                else
                {
                    userSettings.OofState = OofState.Disabled;
                }

                // Create the request.
                SetUserOofSettingsRequest request = new SetUserOofSettingsRequest
                {
                    Mailbox         = emailAddress,
                    UserOofSettings = userSettings
                };

                bool success = false;

                try
                {
                    SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
                    if (response.ResponseMessage.ResponseCode == ResponseCodeType.NoError)
                    {
                        success = true;
                    }
                }
                catch (System.Xml.Schema.XmlSchemaValidationException e)
                {
                    // Catch the following critical exceptions, other unexpected exceptions will be emitted to protocol test framework.
                    Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                }
                catch (System.Xml.XmlException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                }
                catch (System.Reflection.TargetException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An operation exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                    throw;
                }
                catch (System.IO.IOException e)
                {
                    Site.Log.Add(LogEntryKind.Debug, "An IO exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
                    throw;
                }

                return(success);
            }
        }