Exemple #1
0
        public override Element ToElement()
        {
            var e = new Error(error);

            if (error == ErrorCondition.InternalServerError)
            {
                e.Message = this.Message;
            }
            if (!string.IsNullOrEmpty(message))
            {
                e.Message = message;
            }
            if (stanza != null)
            {
                var iq = stanza as IQ;
                if (iq != null && iq.Type == IqType.error)
                {
                    return(iq);
                }
                if (!stanza.Switched && (iq == null || iq.Type != IqType.result))
                {
                    stanza.SwitchDirection();
                }
                stanza.SetAttribute("type", IqType.error.ToString());
                stanza.ReplaceChild(e);
                return(stanza);
            }
            else
            {
                return(e);
            }
        }
        public static Stanza ToErrorStanza(Stanza stanza, Error error)
        {
            if (stanza == null)
            {
                throw new ArgumentNullException("stanza");
            }
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            stanza.SetAttribute("type", "error");
            stanza.ReplaceChild(error);
            if (!stanza.Switched)
            {
                stanza.SwitchDirection();
            }
            return(stanza);
        }