コード例 #1
0
        public static StreamElement ToError(this StreamElement stream, StreamErrorCondition condition = StreamErrorCondition.UndefinedCondition, string text = null)
        {
            var tag = "";

            switch (condition)
            {
            case StreamErrorCondition.BadFormat: tag = "bad-format"; break;

            case StreamErrorCondition.BadNamespacePrefix: tag = "bad-namespace-prefix"; break;

            case StreamErrorCondition.Conflict: tag = "conflict"; break;

            case StreamErrorCondition.ConnectionTimeout: tag = "connection-timeout"; break;

            case StreamErrorCondition.HostGone: tag = "host-gone"; break;

            case StreamErrorCondition.HostUnknown: tag = "host-unknown"; break;

            case StreamErrorCondition.ImproperAddressing: tag = "improper-addressing"; break;

            case StreamErrorCondition.InternalServerError: tag = "internal-server-error"; break;

            case StreamErrorCondition.InvalidFrom: tag = "invalid-from"; break;

            case StreamErrorCondition.InvalidId: tag = "invalid-id"; break;

            case StreamErrorCondition.InvalidNamespace: tag = "invalid-namespace"; break;

            case StreamErrorCondition.InvalidXml: tag = "invalid-xml"; break;

            case StreamErrorCondition.NotAuthorized: tag = "not-authorized"; break;

            case StreamErrorCondition.PolicyViolation: tag = "policy-violation"; break;

            case StreamErrorCondition.RemoteConnectionFailed: tag = "remote-connection-failed"; break;

            case StreamErrorCondition.ResourceConstraint: tag = "resource-constraint"; break;

            case StreamErrorCondition.RestrictedXml: tag = "restricted-xml"; break;

            case StreamErrorCondition.SeeOtherHost: tag = "see-other-host"; break;

            case StreamErrorCondition.SystemShutdown: tag = "system-shutdown"; break;

            case StreamErrorCondition.UnknownCondition: tag = "unknown-condition"; break;

            case StreamErrorCondition.UnsupportedEncoding: tag = "unsupported-encoding"; break;

            case StreamErrorCondition.UnsupportedStanzaType: tag = "unsupported-stanza-type"; break;

            case StreamErrorCondition.UnsupportedVersion: tag = "unsupported-version"; break;

            case StreamErrorCondition.XmlNotWellFormed: tag = "xml-not-well-formed"; break;

            case StreamErrorCondition.UndefinedCondition:
            default: tag = "undefined-condition"; break;
            }

            stream.C(tag, ns: Namespaces.STANZAS);

            if (!string.IsNullOrEmpty(text))
            {
                stream.C("text", text, Namespaces.STANZAS);
            }

            return(stream);
        }