Example #1
0
        public bool TrySend(SnppMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (String.IsNullOrWhiteSpace(message.Message))
            {
                throw new ArgumentException(Resource.MessageRequired, "message");
            }
            if (!message.Pagers.Pagers.Any())
            {
                throw new ArgumentException(Resource.PagerRequired, "message");
            }

            try
            {
                return(Send(message).Code == ResponseCode.Success);
            }
            catch (Exception)//TODO: More specific exceptions
            {
                return(false);
            }
        }
Example #2
0
        public bool TrySend(SnppMessage message)
        {
            if (message == null)
                throw new ArgumentNullException("message");
            if (String.IsNullOrWhiteSpace(message.Message))
                throw new ArgumentException(Resource.MessageRequired, "message");
            if (!message.Pagers.Pagers.Any())
                throw new ArgumentException(Resource.PagerRequired, "message");

            try
            {
                return Send(message).Code == ResponseCode.Success;
            }
            catch (Exception)//TODO: More specific exceptions
            {
                return false;
            }
        }
Example #3
0
        /// <summary>
        /// Send a SnppMessage.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <returns>The response from the last command sent.  If an error occurs the operation will be aborted and the error response will be returned.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="message"/> parameter was null.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="message"/> parameter <see cref="SnppMessage.Message"/> was empty.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="message"/> parameter <see cref="SnppMessage.Pagers"/> contained no elements.</exception>
        public SnppResponse Send(SnppMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (String.IsNullOrWhiteSpace(message.Message))
            {
                throw new ArgumentException(Resource.MessageRequired, "message");
            }
            if (!message.Pagers.Pagers.Any())
            {
                throw new ArgumentException(Resource.PagerRequired, "message");
            }

            //This is super gross.
            //Should we throw instead of returning the response? I don't know if we should consider that exceptional.
            try
            {
                SnppResponse resp;

                if (!Client.Connect())
                {
                    return(SnppResponse.FatalResponse(Resource.ConnectionError));//Throw instead?
                }
                if (!String.IsNullOrWhiteSpace(LoginId))
                {
                    resp = Client.Login(LoginId, Password);//TODO: What if password is empty or whitespace?
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }

                foreach (var pager in message.Pagers.Pagers)
                {
                    resp = Client.Pager(pager);
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }

                if (!String.IsNullOrWhiteSpace(message.Subject))
                {
                    resp = Client.Subject(message.Subject);
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }

                if (message.Data.Count > 1)
                {
                    resp = Client.Data(message.Data);
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }
                else
                {
                    resp = Client.Message(message.Message);
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }

                if (message.ServiceLevel.HasValue)
                {
                    resp = Client.Level(message.ServiceLevel.Value);
                    if (resp.Code != ResponseCode.Success)
                    {
                        return(resp);
                    }
                }

                return(Client.Send());
            }
            finally
            {
                Client.Quit();//Not sure how well this will work.
            }
        }
Example #4
0
        /// <summary>
        /// Send a SnppMessage.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <returns>The response from the last command sent.  If an error occurs the operation will be aborted and the error response will be returned.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="message"/> parameter was null.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="message"/> parameter <see cref="SnppMessage.Message"/> was empty.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="message"/> parameter <see cref="SnppMessage.Pagers"/> contained no elements.</exception>
        public SnppResponse Send(SnppMessage message)
        {
            if (message == null)
                throw new ArgumentNullException("message");
            if (String.IsNullOrWhiteSpace(message.Message))
                throw new ArgumentException(Resource.MessageRequired, "message");
            if (!message.Pagers.Pagers.Any())
                throw new ArgumentException(Resource.PagerRequired, "message");

            //This is super gross.
            //Should we throw instead of returning the response? I don't know if we should consider that exceptional.
            try
            {
                SnppResponse resp;

                if (!Client.Connect())
                    return SnppResponse.FatalResponse(Resource.ConnectionError);//Throw instead?

                if (!String.IsNullOrWhiteSpace(LoginId))
                {
                    resp = Client.Login(LoginId, Password);//TODO: What if password is empty or whitespace?
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }

                foreach (var pager in message.Pagers.Pagers)
                {
                    resp = Client.Pager(pager);
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }

                if (!String.IsNullOrWhiteSpace(message.Subject))
                {
                    resp = Client.Subject(message.Subject);
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }

                if (message.Data.Count > 1)
                {
                    resp = Client.Data(message.Data);
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }
                else
                {
                    resp = Client.Message(message.Message);
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }

                if (message.ServiceLevel.HasValue)
                {
                    resp = Client.Level(message.ServiceLevel.Value);
                    if (resp.Code != ResponseCode.Success)
                        return resp;
                }

                return (Client.Send());
            }
            finally
            {
                Client.Quit();//Not sure how well this will work.
            }
        }