本文整理汇总了C#中Error.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Error.AppendChild方法的具体用法?C# Error.AppendChild怎么用?C# Error.AppendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error.AppendChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtocolViolationException
bool ISocketEventListener.OnRead(BaseSocket sock, byte[] buf, int offset, int length)
{
if (!m_running)
{
Debug.WriteLine("shutting down. extra bytes received.");
return false;
}
Debug.WriteLine("OnRead: " + ((HttpSocket)sock).Name);
// Parse out the first start tag or empty element, which will be
// <body/>.
XpNet.UTF8Encoding e = new XpNet.UTF8Encoding();
XpNet.ContentToken ct = new XpNet.ContentToken();
XpNet.TOK tok = e.tokenizeContent(buf, offset, offset + length, ct);
if ((tok != XpNet.TOK.START_TAG_WITH_ATTS) &&
(tok != XpNet.TOK.EMPTY_ELEMENT_WITH_ATTS))
{
m_listener.OnError(this, new ProtocolViolationException("Invalid HTTP binding XML. Token type: " + tok.ToString()));
return false;
}
string name = ENC.GetString(buf,
offset + e.MinBytesPerChar,
ct.NameEnd - offset - e.MinBytesPerChar);
Debug.Assert(name == "body");
Body b = new Body(m_doc);
string val;
int start;
int end;
for (int i = 0; i < ct.getAttributeSpecifiedCount(); i++)
{
start = ct.getAttributeNameStart(i);
end = ct.getAttributeNameEnd(i);
name = ENC.GetString(buf, start, end - start);
start = ct.getAttributeValueStart(i);
end = ct.getAttributeValueEnd(i);
val = ENC.GetString(buf, start, end - start);
if (!name.StartsWith("xmlns"))
b.SetAttribute(name, val);
}
if (b.SID != null)
m_sid = b.SID;
if (m_sid == null)
{
m_listener.OnError(this, new ProtocolViolationException("Invalid HTTP binding. No SID."));
return false;
}
if (b.Wait != -1)
m_wait = b.Wait;
if (StartStream)
{
StartStream = false;
m_authID = b.AuthID;
if (!FakeReceivedStream())
return false;
}
lock (m_queue)
{
if (!m_running)
return false;
if (b.Type == BodyType.terminate)
{
m_running = false;
Error err = new Error(m_doc);
err.AppendChild(m_doc.CreateElement(b.Condition.ToString(), URI.STREAM_ERROR));
byte[] sbuf = ENC.GetBytes(err.OuterXml);
m_listener.OnRead(this, sbuf, 0, sbuf.Length);
sbuf = ENC.GetBytes("</stream:stream>");
m_listener.OnRead(this, sbuf, 0, sbuf.Length);
Close();
return false;
}
}
if (tok == XpNet.TOK.START_TAG_WITH_ATTS)
{
// len(</body>) = 7
start = ct.TokenEnd;
if (m_listener.OnRead(this, buf, start, offset + length - start - 7))
RequestRead();
}
else
RequestRead();
lock (m_queue)
{
Monitor.Pulse(m_queue);
}
//.........这里部分代码省略.........
示例2: GetStreamError
/// <summary>
/// Get an error stanza with a urn:ietf:params:xml:ns:xmpp-streams condition.
/// </summary>
/// <param name="doc"></param>
/// <param name="type"></param>
/// <param name="code"></param>
/// <param name="condition"></param>
/// <returns></returns>
public static Error GetStreamError(XmlDocument doc, ErrorType type, int code, string condition)
{
Error error = new Error(doc);
error.ErrorType = type;
error.Code = code;
error.AppendChild(doc.CreateElement(condition, URI.STREAM));
return error;
}