コード例 #1
0
        /**
         * method used by the client for Registering or Adding a callback with the client channel
         *
         * @param CallbackId String
         * @param Callback the class that implements the method "execute"
         * @param OnRegisterCallbackFinish
         */
        public void registerCallback(String CallbackId, DBXCallback Callback, OnRegisterCallbackFinish onRegisterCallbackFinish = null)
        {
            TJSONValue Value = new TJSONTrue();

            if (wThread == null)
            {
                wThread = new WorkerThread(Connection.Clone(true), this);
                thread  = new Thread(new ThreadStart(wThread.run));
                dsadmin.ConsumeClientChannel(ChannelName,
                                             getManagerID(), CallbackId, ChannelName,
                                             getSecurityToken(), Value, (TJSONValue res) =>
                {
                    if (res is TJSONObject && ((TJSONObject)res).has("invoke"))
                    {
                        thread.Start();
                    }
                    if (onRegisterCallbackFinish != null)
                    {
                        onRegisterCallbackFinish();
                    }
                });
            }
            else
            {
                registerClientCallback(CallbackId);
                if (onRegisterCallbackFinish != null)
                {
                    onRegisterCallbackFinish();
                }
            }
            wThread.addCallback(CallbackId, Callback);
        }
コード例 #2
0
 public void addCallback(String callbackId, DBXCallback callback)
 {
     cbListLock();
     try
     {
         callbacks.Add(callbackId, callback);
     }
     finally
     {
         cbListUnLock();
     }
 }
コード例 #3
0
            /**
             * send the the contents of the server response at the "execute" method of our DBXCallback class
             * @param json the contents of the server response
             */
            private void invokeEvent(JObject json)
            {
                TJSONArray arr        = new TJSONArray(json.Value <JArray>("invoke"));
                String     callbackID = arr.getAsJsonString(0).getValue();

                arr.remove(0);
                DBXCallback cb = callbacks[callbackID];

                if (cb != null)
                {
                    cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value));
                }
                else
                {
                    throw new DBXException("Invalid callback response");
                }
            }
コード例 #4
0
            private void broadcastEvent(JObject json)
            {
                List <string> keys = new List <string>(callbacks.Keys);
                TJSONArray    arr  = new TJSONArray(json.Value <JArray>("broadcast"));

                foreach (String callbackskeys in keys)
                {
                    DBXCallback cb = callbacks[callbackskeys];
                    if (cb != null)
                    {
                        cb.Execute(arr.get(0), Convert.ToInt32(arr.getInt(1).Value));
                    }
                    else
                    {
                        throw new DBXException("Invalid callback response");
                    }
                }
            }
コード例 #5
0
 public void addCallback(String callbackId, DBXCallback callback)
 {
     cbListLock();
     try
     {
         callbacks.Add(callbackId, callback);
     }
     finally
     {
         cbListUnLock();
     }
 }
コード例 #6
0
 /**
  * method used by the client for Registering or Adding a callback with the client channel
  *
  * @param CallbackId String
  * @param Callback the class that implements the method "execute"
  * @param OnRegisterCallbackFinish
  */
 public void registerCallback(String CallbackId, DBXCallback Callback, OnRegisterCallbackFinish onRegisterCallbackFinish = null)
 {
     TJSONValue Value = new TJSONTrue();
     if (wThread == null)
     {
         wThread = new WorkerThread(Connection.Clone(true), this);
         thread = new Thread(new ThreadStart(wThread.run));
         dsadmin.ConsumeClientChannel(ChannelName,
           getManagerID(), CallbackId, ChannelName,
           getSecurityToken(), Value, (TJSONValue res) =>
                 {
                     if (res is TJSONObject && ((TJSONObject)res).has("invoke"))
                     {
                         thread.Start();
                     }
                     if (onRegisterCallbackFinish != null)
                         onRegisterCallbackFinish();
                 });
     }
     else
     {
         registerClientCallback(CallbackId);
         if (onRegisterCallbackFinish != null)
             onRegisterCallbackFinish();
     }
     wThread.addCallback(CallbackId, Callback);
 }