Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
rfog #1
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Implementing XEP-0012
I'm implementing XEP-0012 (Last Activity) and I have a problem when working with the server answer.

I've create the next classes:

    public class XMPP_LastActivityElement:XmppXElement
    {
        public XMPP_LastActivityElement() : base("jabber:iq:last", "query")
        {
        }

        public string Seconds
        {
            get { return GetAttribute("seconds"); }
            set {SetAttribute("seconds",value);}
        }

        public static void Test()
        {
            var e = new XMPP_LastActivityElement() {Seconds = "100"};

            Debug.WriteLine("TEST XMPP_LastActivityElement");
            Debug.WriteLine(e);
        }
    }

    public class XMPP_LastActivityElementQuery:XmppXElement
    {
        public XMPP_LastActivityElementQuery()
            : base("jabber:iq:last", "query")
        {
        }

        public static void Test()
        {
            var e = new XMPP_LastActivityElementQuery();

            Debug.WriteLine("TEST XMPP_LastActivityElementQuery");
            Debug.WriteLine(e);
        }
    }

XMPP_LastActivityElement is for answer and XMPP_LastActivityElementQuery is for send the IQ. Both classes are registered in Matrix.

The IQ is defined as:

    public class XMPP_LastActivityIq : Iq
    {
        public XMPP_LastActivityIq()
        {
            From = XmppProcessor.Processor.MyJid;
            GenerateId();
            Type=IqType.get;
            LastActivity = new XMPP_LastActivityElement();
        }

        public XMPP_LastActivityIq(Jid to)
        {
            From = XmppProcessor.Processor.MyJid;
            GenerateId();
            To = to;
            Type = IqType.get;
            LastActivity = new XMPP_LastActivityElement();
           
        }

        public XMPP_LastActivityElement LastActivity
        {
            get { return Element<XMPP_LastActivityElement>(); }
            set { Replace(value); }
        }

        public static void Test()
        {
            var e = new XMPP_LastActivityIq();

            Debug.WriteLine("TEST XMPP_LastActivityIq default ctor");
            Debug.WriteLine(e);

            e = new XMPP_LastActivityIq(new Jid("juan","jabber.com","homelesman"));

            Debug.WriteLine("TEST XMPP_LastActivityIq default ctor");
            Debug.WriteLine(e);
        }
    }

When I receive answer from server, it contains the right value. When processing I do:

                        if (e.Iq.Type == IqType.result)
                        {
                            var elem = e.Iq.Element<XMPP_LastActivityElement>();
                            var s = elem.Seconds;

But elem always returns null.

What I'm doing wrong?  Other similar extensions implemented (and more complex) work fine but this not.

Thanks in advance.
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I have attached the Last classes which are in the next release. So you can see how to handle this in MatriX.
Let me know if it works, and id you have any questions.

Alex
The author has attached one file to this post:
Last.zip 826 Bytes
You have no permission to open this file.
This post was edited 2 times, last on 2012-11-15, 20:21 by Alex.
Avatar
rfog #3
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
Ups. It's more easy than I had figured.

Thanks.
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes, there is also a new generic IqQuery<T> class now. With that its very easy as well.

  1. var lastIq = new IqQuery<Last>();
  2. lastIq.Query.Seconds = 10;
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS