private void tagEnd(XmlReader reader) { // tag has ended // call onElement because a complete element is parsed if (this.OnXmlElementComplete != null) { this.OnXmlElementComplete(this.currentElement); } // end by setting current to parent if (this.currentElement.ParentNode != null) { // this is a safe cast because we know every node is created as an XmppNode this.currentElement = (XmppElement)this.currentElement.ParentNode; } else { // parent node is null, this means that we have hit the root node // call onDocumentEnd if (this.OnXmlDocumentEnd != null) { this.OnXmlDocumentEnd(this.currentElement); } } }
public void Send(XmppElement xmppDocument) { // convert document into bytes var data = Encoding.UTF8.GetBytes(xmppDocument.ToString()); // send through our socket this.asyncSocket.Send(data); }
private void onXmppDocumentEnd(XmppElement root) { // bubble event upwards if (this.OnDocumentComplete != null) { this.OnDocumentComplete(root); } }
private void onXmppElement(XmppElement node) { // bubble event upwards if (this.OnNewElement != null) { this.OnNewElement(node); } }
private void onXmppDocumentStart(XmppElement root) { // bubble event upwards if (this.OnNewDocument != null) { this.OnNewDocument(root); } }
private void tagStart(XmlReader reader) { // must parse namespaces first // reader will be moved to last attribute this.parseNamespaces(reader); // move it back to element reader.MoveToElement(); // get element name and ns var name = reader.LocalName; var ns = namespaceManager.LookupNamespace(reader.Prefix); // create new node using the XmppFactory! XmppElement newNode = null; if (!XmppElementFactory.TryCreateXmppElement(name, ns, reader.Prefix, receivingDocument, out newNode)) { // if no specific xmpp element is found, let's go with a regular one newNode = new XmppElement(reader.Prefix, name, ns, receivingDocument); } // if the code has reached this point, it means the tag/xml is parsable/no namespace issues // so we can parse and add namespace information directly into our document // this has to be run first so we have namespace information to run for attributes and such later // reader will be moved to last attribute //parseNamespaceDeclarations(ref newNode, reader); // attach the current node to the document bool isNewDocument = false; if (this.root == null) { // this is the start of a new document // init node root = currentElement = newNode; isNewDocument = true; } else { // this is a child element // so we append it to the current element currentElement.AppendChild(newNode); // after appending, the newnode becomes the current node currentElement = newNode; } // parse attributes if any // this has to be run after adding to the current tree // reader will be moved to last attribute this.parseAttributes(reader); // call document on start if required if (isNewDocument && this.OnXmlDocumentStart != null) { this.OnXmlDocumentStart(currentElement); } }
public override void OnNewElement(XmppElement element) { // check if is features element // check if is success element // check if is failure element if (element is Features) { // get mechanisms var mechanisms = (element as Features).GetMechanisms(); // loop through mechamisms and send authentications if they exist foreach (var mechanism in mechanisms.Mechanism) { string password; if (this.authenticationSets.TryGetValue(mechanism.Value, out password)) { // if such authentication mechanism exists // send the auth this.sendAuthentication(mechanism.Value, password); // save mechanism used for later events because it's not returned in auth response lastMechanismUsed = mechanism.Value; // no need to send multiple authentications return; } } } else if (element is Success) { // success element! // bubble event upwards if (this.OnAuthenticationSuccess != null) { this.OnAuthenticationSuccess(lastMechanismUsed); } } else if (element is Failure) { // failure element =( // bubble event upwards if (this.OnAuthenticationFailure != null) { this.OnAuthenticationFailure(lastMechanismUsed); } } }
public override void OnNewDocument(XmppElement element) { // do nothing }
public override void OnDocumentComplete(XmppElement element) { // do nothing }
public abstract void OnDocumentComplete(XmppElement element);
public abstract void OnNewElement(XmppElement element);
public static bool TryCreateXmppElement(string name, string ns, string prefix, XmlDocument parentDocument, out XmppElement xmppElement) { Type xmppType; if (typeWarehouse.TryGet(name, ns, out xmppType)) { // if we can find a specific xmpp type from the declared types // return a version of it var constructorInfo = xmppType.GetConstructor(derivedXmppElementConstuctorInfo); if (constructorInfo != null) { // make sure invoking type has required constructor xmppElement = (XmppElement)constructorInfo.Invoke(new object[] { prefix, parentDocument }); return(true); } else { // if there is no such constructor, it's as good as not present xmppElement = null; return(false); } } else { // otherwise, let's return false so use can handle it xmppElement = null; return(false); } }