示例#1
0
        public void watchClose(HClientWatch w, bool bSend)
        {
            // mark flag on watch itself, short circuit if already closed
            if (w.Closed)
            {
                return;
            }
            w.Closed = true;

            // remove it from my lookup table
            if (w.ID != null)
            {
                m_watches_Renamed.Remove(w.ID);
            }

            // optionally send close message to server
            if (bSend)
            {
                try
                {
                    HGridBuilder b = new HGridBuilder();
                    b.Meta.add("watchId", w.ID).add("close");
                    b.addCol("id");
                    call("watchUnsub", b.toGrid());
                }
                catch (Exception /*e*/)
                {
                    // YET TO DO - we aren't doing anything here, why?
                }
            }
        }
示例#2
0
        public void watchUnsub(HClientWatch w, HRef[] ids)
        {
            if (ids.Length == 0)
            {
                throw new ArgumentException("ids are empty", "ids");
            }
            if (w.ID == null)
            {
                throw new InvalidOperationException("nothing subscribed yet");
            }
            if (w.Closed)
            {
                throw new InvalidOperationException("watch is closed");
            }

            // grid meta
            HGridBuilder b = new HGridBuilder();

            b.Meta.add("watchId", w.ID);

            // grid rows
            b.addCol("id");
            for (int i = 0; i < ids.Length; ++i)
            {
                b.addRow(new HVal[] { ids[i] });
            }

            // make request
            HGrid req = b.toGrid();

            call("watchUnsub", req);
        }
示例#3
0
        public HGrid watchPoll(HClientWatch w, bool bRefresh)
        {
            if (w.ID == null)
            {
                throw new InvalidOperationException("nothing subscribed yet");
            }
            if (w.Closed)
            {
                throw new InvalidOperationException("watch is closed");
            }

            // grid meta
            HGridBuilder b = new HGridBuilder();

            b.Meta.add("watchId", w.ID);
            if (bRefresh)
            {
                b.Meta.add("refresh");
            }
            b.addCol("empty");

            // make request
            HGrid req = b.toGrid();

            try
            {
                return(call("watchPoll", req));
            }
            catch (CallErrException e)
            {
                // any server side error is considered close
                watchClose(w, false);
                throw e;
            }
        }
示例#4
0
        public HGrid watchSub(HClientWatch w, HRef[] ids, bool bChecked)
        {
            if (ids.Length == 0)
            {
                throw new ArgumentException("ids are empty", "ids");
            }
            if (w.Closed)
            {
                throw new InvalidOperationException("watch is closed");
            }

            // grid meta
            HGridBuilder b = new HGridBuilder();

            if (w.ID != null)
            {
                b.Meta.add("watchId", w.ID);
            }
            if (w.Lease != null)
            {
                b.Meta.add("lease", w.Lease);
            }
            b.Meta.add("watchDis", w.dis());

            // grid rows
            b.addCol("id");
            for (int i = 0; i < ids.Length; ++i)
            {
                b.addRow(new HVal[] { ids[i] });
            }

            // make request
            HGrid res;

            try
            {
                HGrid req = b.toGrid();
                res = call("watchSub", req);
            }
            catch (CallErrException e)
            {
                // any server side error is considered close
                watchClose(w, false);
                throw e;
            }

            // make sure watch is stored with its watch id
            if (w.ID == null)
            {
                w.ID    = res.meta.getStr("watchId");
                w.Lease = (HNum)res.meta.get("lease");
                m_watches_Renamed.Add(w.ID, w);
            }

            // if checked, then check it
            if (bChecked)
            {
                if (res.numRows != ids.Length && ids.Length > 0)
                {
                    throw new Exception("unknwon record " + ids[0]);
                }
                for (int i = 0; i < res.numRows; ++i)
                {
                    if (res.row(i).missing("id"))
                    {
                        throw new Exception("unknwon record " + ids[i]);
                    }
                }
            }
            return(res);
        }