Exemplo n.º 1
0
        /// <summary>
        /// Sends a mail synchronously
        /// </summary>
        /// <param name="mail">Mail Message to send</param>
        /// <param name="inReplyTo">The unique id of the mail to which this is a reply</param>
        /// <returns>The unique id of the mail just sent</returns>
        public string Send(MailSoap12TransportBinding mail, string inReplyTo)
        {
            if (_serverConfiguration == null)
            {
                throw new MailServerConfigurationMissingException();
            }

            _state = OutboxState.Sending;

            // If we have a In-Reply-To id, set it
            if (inReplyTo != null)
            {
                mail.InReplyTo = inReplyTo;
            }

            lock (MailServerLockingToken) {
                LogOn();
                SendViaServer(mail);
                LogOff();
            }

            _state = OutboxState.Idle;

            return(mail.MessageId);
        }
Exemplo n.º 2
0
 private void DequeuePollingLoop()
 {
     // Set the name of the thread for debugging purposes
     Thread.CurrentThread.Name = "Inbox.Dequeue polling thread";
     try {
         while ((_state != InboxState.Faulted && _state != InboxState.Closed))
         {
             // Do we have any requestors?
             if (_requests.Count > 0)
             {
                 MailSoap12TransportBinding msg = Dequeue();
                 // Was there a message?
                 if (msg != null)
                 {
                     InboxRequest requestor = _requests[0];
                     requestor.msg = msg;
                     requestor.onFinished.Set();
                     lock (_requests) {
                         _requests.Remove(requestor);
                     }
                 }
             }
             Thread.Sleep(200);
         }
     }
     catch (Exception e) {
         SetState(InboxState.Faulted);
         RaiseExceptionEvent(e);
     }
     finally {
         // Release all requests for a mail, now that the polling is shut down
         ReleaseAllRequestors();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Logs on, polls until EndReceive() is called, and then logs off
        /// </summary>
        private void LogOn_KeepPolling_LogOff()
        {
            try {
                logging.WCFLogger.Write(TraceEventType.Verbose, "Using the 'Log on - Keep Polling - Log off' pattern");
                SetState(InboxState.AttemptingLogOn);
                TryLogOn();
                OnStartPolling.Set();

                // Keep polling until someone says stop
                while (_state == InboxState.Listening)
                {
                    MailSoap12TransportBinding msg = PollServer();
                    // If a message was fetched, lock the queue and add it
                    if (msg != null)
                    {
                        lock (pMailQueue) {
                            pMailQueue.Add(msg);
                            pMailEntryTimes.Add(msg, DateTime.Now);
                            logging.WCFLogger.Write(TraceEventType.Verbose, "Incoming mail received from " + msg.From + " in reply to '" + msg.InReplyTo + "'");
                        }
                        continue;
                    }
                    OnStopPolling.WaitOne(Utilities.TimeSpanInMilliseconds(InboxServerConfiguration.ConnectionPolicy.PollingInterval), false);
                }
                LogOff();
            }
            catch  {
                OnStartPolling.Set();
                SetState(InboxState.Faulted);
                throw;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// De-queues the first mail from the internal Inbox mail queue
 /// </summary>
 /// <returns>The first mail in queue</returns>
 public MailSoap12TransportBinding Dequeue()
 {
     lock (pMailQueue) {
         if (pMailQueue.Count < 1)
         {
             return(null);
         }
         else
         {
             MailSoap12TransportBinding mail = pMailQueue[0];
             pMailQueue.Remove(mail);
             pMailEntryTimes.Remove(mail);
             return(mail);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// De-queues the first mail
        /// </summary>
        /// <param name="inReplyToId">The In-Reply-To id of the mail requested. Can be used to find the reply to a specific mail sent.</param>
        /// <param name="timeout">Maximum time to wait for a mail to come</param>
        /// <param name="onAbortDequeueing">AutoResetEvent that if set will abort the de-queueing</param>
        public MailSoap12TransportBinding Dequeue(string inReplyToId, TimeSpan timeout, AutoResetEvent onAbortDequeueing)
        {
            DateTime startTime = DateTime.Now;

            // Poll to see if our mail has arrived
            while (DateTime.Now - startTime < timeout)
            {
                // If the mailbox is faulted, throw
                if (_state == InboxState.Closed || _state == InboxState.Faulted)
                {
                    throw new InboxInvalidStateException(_state);
                }

                lock (pMailQueue) {
                    for (int i = 0; i < pMailQueue.Count; i++)
                    {
                        if (pMailQueue[i].InReplyTo == inReplyToId)
                        {
                            MailSoap12TransportBinding mail = pMailQueue[i];
                            pMailQueue.Remove(mail);
                            pMailEntryTimes.Remove(mail);
                            return(mail);
                        }
                        else
                        {
                            //Check if mail is expired
                            if ((DateTime.Now - pMailEntryTimes[pMailQueue[i]]) >= _cacheingTime)
                            {
                                pMailEntryTimes.Remove(pMailQueue[i]);
                                pMailQueue.Remove(pMailQueue[i]);
                            }
                        }
                    }
                }

                // Sleep. If someone signals to abort, return null
                if (onAbortDequeueing.WaitOne(200, false))
                {
                    return(null);
                }
            }

            // We timed out
            //RaiseExceptionEvent(new TimeoutException());
            throw new TimeoutException();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Sends a WCF message over mail
 /// </summary>
 /// <param name="mail">The mail Message object</param>
 /// <returns>The id of the mail just sent</returns>
 public string Send(MailSoap12TransportBinding mail)
 {
     return(Send(mail, null));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Method that is to be implemented by a component that wraps a mail library
 ///
 /// Sends a mail via the mail server.
 /// </summary>
 /// <param name="mail">The message to be sent</param>
 protected abstract void SendViaServer(MailSoap12TransportBinding mail);
Exemplo n.º 8
0
 /// <summary>
 /// Begins sending a mail asynchronously
 /// </summary>
 /// <param name="mail">Mail Message to send</param>
 /// <param name="callback">Callback method</param>
 /// <param name="inReplyTo">The id the of the mail which we are responding to</param>
 public IAsyncResult BeginSending(MailSoap12TransportBinding mail, string inReplyTo, AsyncCallback callback)
 {
     _asyncSend = new AsyncSend(Send);
     return(_asyncSend.BeginInvoke(mail, inReplyTo, callback, _asyncSend));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Starts sending a message
 /// </summary>
 /// <param name="mail">the mail message to send</param>
 /// <param name="inReplyTo">The id of the mail to which this is a reply</param>
 /// <param name="callback">callback method</param>
 /// <returns>iasync result</returns>
 public virtual IAsyncResult BeginSending(MailSoap12TransportBinding mail, string inReplyTo, AsyncCallback callback)
 {
     return(_outbox.BeginSending(mail, inReplyTo, callback));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Sends a message
 /// </summary>
 /// <param name="mail">the meil message to send</param>
 /// <param name="inReplyTo">The In-Reply-To id of the mail we're sending. Can be used to match an outgoing mail with it's reply.</param>
 /// <returns>The unique id of the mail just sent</returns>
 public virtual string Send(MailSoap12TransportBinding mail, string inReplyTo)
 {
     return(_outbox.Send(mail, inReplyTo));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Sends a message
 /// </summary>
 /// <param name="mail">the mail message to send</param>
 /// <returns>The unique id of the mail just sent</returns>
 public virtual string Send(MailSoap12TransportBinding mail)
 {
     return(_outbox.Send(mail));
 }