Пример #1
0
 public CallLogResultEventArgs(String queryId, CallLogResult result, int count, string first, string last)
 {
     QueryId = queryId;
     Result  = result;
     Count   = count;
     First   = first;
     Last    = last;
 }
Пример #2
0
        /// <summary>
        /// Requests the XMPP entity with the specified JID a GET command.
        /// When the Result is received and it not not an error
        /// if fires the callback function
        /// </summary>
        /// <param name="jid">The JID of the XMPP entity to get.</param>
        /// <param name="queryId">The Id related to this query - it will be used to identify this request</param>
        /// <exception cref="ArgumentNullException">The jid parameter
        /// is null.</exception>
        /// <exception cref="NotSupportedException">The XMPP entity with
        /// the specified JID does not support the 'Ping' XMPP extension.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        public void RequestCustomIqAsync(string queryId, int max, string before = null, string after = null)
        {
            var xml = Xml.Element("query", "jabber:iq:telephony:call_log");

            xml.SetAttribute("queryid", queryId);
            var xmlParam = Xml.Element("set", "http://jabber.org/protocol/rsm");

            if (max > 0)
            {
                xmlParam.Child(Xml.Element("max").Text(max.ToString()));
            }
            if (before == null)
            {
                xmlParam.Child(Xml.Element("before"));
            }
            else
            {
                xmlParam.Child(Xml.Element("before").Text(before));
            }
            if (after != null)
            {
                xmlParam.Child(Xml.Element("after").Text(after));
            }
            xml.Child(xmlParam);

            //The Request is Async
            im.IqRequestAsync(IqType.Set, null, im.Jid, xml, null, (id, iq) =>
            {
                //For any reply we execute the callback
                if (iq.Type == IqType.Error)
                {
                    CallLogResult.Raise(this, new CallLogResultEventArgs());
                    return;
                }

                if (iq.Type == IqType.Result)
                {
                    string queryid         = "";
                    CallLogResult complete = Sharp.Xmpp.Extensions.CallLogResult.Error;
                    int count    = 0;
                    string first = "";
                    string last  = "";
                    try
                    {
                        if ((iq.Data["query"] != null) && (iq.Data["query"]["set"] != null))
                        {
                            XmlElement e = iq.Data["query"];

                            queryid  = e.GetAttribute("queryid");
                            complete = (e.GetAttribute("complete") == "false") ? Sharp.Xmpp.Extensions.CallLogResult.InProgress : Sharp.Xmpp.Extensions.CallLogResult.Complete;

                            if (e["set"]["count"] != null)
                            {
                                count = Int16.Parse(e["set"]["count"].InnerText);
                            }

                            if (e["set"]["first"] != null)
                            {
                                first = e["set"]["first"].InnerText;
                            }

                            if (e["set"]["last"] != null)
                            {
                                last = e["set"]["last"].InnerText;
                            }

                            //log.LogDebug("[Input] call log result received - queryid:[{0}] - complete:[{1}] - count:[{2}] - first:[{3}] - last:[{4}]"
                            //                , queryid, complete, count, first, last);
                            CallLogResult.Raise(this, new CallLogResultEventArgs(queryid, complete, count, first, last));
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        log.LogError("RequestCustomIqAsync - an error occurred ...");
                    }

                    CallLogResult.Raise(this, new CallLogResultEventArgs(queryid, Sharp.Xmpp.Extensions.CallLogResult.Error, count, first, last));
                }
            });
        }