Example #1
0
        /// <summary>
        ///
        /// </summary>
        public ExecuteResult Doit(ExecuteArgs args)
        {
            RemoteObject    obj = this.GetRemoteObject();
            CallbackWrapper w   = new CallbackWrapper(new ResultDelegate(Target));

            return(obj.Execute(args, w));
        }
 public IDisposable RegisterChangeCallback(Action <object> callback, object state)
 {
     lock (_lock)
     {
         var wrapper = new CallbackWrapper(callback, state, _callbacks, _lock);
         _callbacks.Add(wrapper);
         return(wrapper);
     }
 }
        public void RegisterCallback(int Reference, NEPCallback Callback)
        {
            CallbackWrapper cbw = new CallbackWrapper()
            {
                Callback = Callback, Key = Key, IV = IV, CryptoGen = CryptoGen
            };

            Wrapped.RegisterCallback(Reference, cbw.Wrapper);
        }
 void IAppDomainHelper.DoCallback(IntPtr pUnkAD, IntPtr pfnCallbackCB, IntPtr data)
 {
     CallbackWrapper wrapper = new CallbackWrapper(pfnCallbackCB, data);
     if (this._ad != AppDomain.CurrentDomain)
     {
         this._ad.DoCallBack(new CrossAppDomainDelegate(wrapper.ReceiveCallback));
     }
     else
     {
         wrapper.ReceiveCallback();
     }
 }
        void IAppDomainHelper.DoCallback(IntPtr pUnkAD, IntPtr pfnCallbackCB, IntPtr data)
        {
            CallbackWrapper wrapper = new CallbackWrapper(pfnCallbackCB, data);

            if (this._ad != AppDomain.CurrentDomain)
            {
                this._ad.DoCallBack(new CrossAppDomainDelegate(wrapper.ReceiveCallback));
            }
            else
            {
                wrapper.ReceiveCallback();
            }
        }
Example #6
0
        public void WrapCallback_Should_Return_Action_That_Invokes_Handler_And_Provided2(MethodInfo wrapCallbackMethod, Delegate action, object[] args, CallDetails callDetails)
        {
            var callbackWrapper            = new CallbackWrapper();
            var mockCallbackInvokedHandler = new Mock <ICallbackInvokedHandler>();

            callbackWrapper.InvokedHandler = mockCallbackInvokedHandler.Object;

            var wrappedAction = (Delegate)wrapCallbackMethod.Invoke(callbackWrapper, new object[] { action });

            wrappedAction.DynamicInvoke(args);

            callDetails.AssertCalled(args);
            mockCallbackInvokedHandler.Verify(m => m.Invoked());
        }
Example #7
0
    public void helloFromJS(string message, object callback)
    {
        Debug.LogFormat("message from js: {0}", message);

        var wrap = new CallbackWrapper(callback);

        if (message.Contains("hello"))
        {
            wrap.Send("hello, js");
        }
        else
        {
            wrap.Send("hmm...");
        }
    }
Example #8
0
        private IAsyncResult InternalBeginProcess(IDocument document, AsyncCallback callback, object context, bool isAsynchronous)
        {
            Util.ThrowOnNullArgument(document, "document");
            AsyncResult asyncResult = new AsyncResult(callback, context);

            this.DiagnosticsSession.TraceDebug <IIdentity>("Called begin process - {0} ", document.Identity);
            DocumentContext documentContext = new DocumentContext(document, asyncResult);

            if (isAsynchronous)
            {
                ThreadPool.QueueUserWorkItem(CallbackWrapper.WaitCallback(new WaitCallback(this.ProcessDocument)), documentContext);
            }
            else
            {
                this.ProcessDocument(documentContext);
            }
            return(asyncResult);
        }
Example #9
0
        /// <summary>
        ///  Creates an object with the unique device ID <c>uid</c> and adds  it to
        ///  the IPConnection <c>ipcon</c>.
        /// </summary>
        public BrickletIndustrialQuadRelay(string uid, IPConnection ipcon) : base(uid, ipcon)
        {
            this.apiVersion[0] = 2;
            this.apiVersion[1] = 0;
            this.apiVersion[2] = 0;
            callbackWrappers[CALLBACK_MONOFLOP_DONE] = new CallbackWrapper(OnMonoflopDone);

            responseExpected[FUNCTION_SET_VALUE]               = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_VALUE]               = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_MONOFLOP]            = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_MONOFLOP]            = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_GROUP]               = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_GROUP]               = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_SELECTED_VALUES]     = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_IDENTITY]            = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[CALLBACK_MONOFLOP_DONE]           = ResponseExpectedFlag.ALWAYS_FALSE;
        }
Example #10
0
        static void Test(TypeModel model)
        {
            CallbackWrapper orig = new CallbackWrapper
            {
                A = new CallbackWithNoContext(),
                B = new CallbackWithProtoContext()
#if REMOTING
                , C = new CallbackWithRemotingContext()
#endif
            }, clone;

            Assert.IsNull(orig.B.ReadState);
            Assert.IsNull(orig.B.WriteState);
#if REMOTING
            Assert.IsNull(orig.C.ReadState);
            Assert.IsNull(orig.C.WriteState);
#endif
            using (var ms = new MemoryStream())
            {
                SerializationContext ctx = new SerializationContext {
                    Context = new object()
                };
                model.Serialize(ms, orig, ctx);
                Assert.IsNull(orig.B.ReadState);
                Assert.AreSame(ctx.Context, orig.B.WriteState);
#if REMOTING
                Assert.IsNull(orig.C.ReadState);
                Assert.AreSame(ctx.Context, orig.C.WriteState);
#endif
                ms.Position = 0;
                ctx         = new SerializationContext {
                    Context = new object()
                };
                clone = (CallbackWrapper)model.Deserialize(ms, null, typeof(CallbackWrapper), -1, ctx);
                Assert.AreSame(ctx.Context, clone.B.ReadState);
                Assert.IsNull(clone.B.WriteState);
#if REMOTING
                Assert.AreSame(ctx.Context, clone.C.ReadState);
                Assert.IsNull(clone.C.WriteState);
#endif
            }
        }
Example #11
0
        /// <include file='doc\ExportUtil.uex' path='docs/doc[@for="AppDomainHelper.IAppDomainHelper.DoCallback"]/*' />
        void IAppDomainHelper.DoCallback(IntPtr pUnkAD, IntPtr pfnCallbackCB, IntPtr data)
        {
#if _DEBUG
            AppDomain ad = (AppDomain)Marshal.GetObjectForIUnknown(pUnkAD);
            DBG.Assert(ad == _ad, "Call to AppDomainHelper.DoCallback for wrong AD");
#endif
            // DoCallback:
            CallbackWrapper wrap = new CallbackWrapper(pfnCallbackCB, data);

            if (_ad != AppDomain.CurrentDomain)
            {
                DBG.Info(DBG.Pool, "AppDomainHelper.DoCallback: the current domain differs from the passed domain.");
                _ad.DoCallBack(new CrossAppDomainDelegate(wrap.ReceiveCallback));
                DBG.Info(DBG.Pool, "AppDomainHelper.DoCallback: done with callback.");
            }
            else
            {
                DBG.Info(DBG.Pool, "AppDomainHelper.DoCallback: the current domain matches.");
                wrap.ReceiveCallback();
            }
        }
Example #12
0
 public RequestWrapper(RestRequest restRequest, CallbackWrapper onSuccess = null, CallbackWrapper onFailed = null)
 {
     RestRequest = restRequest;
     OnSuccess   = onSuccess;
     OnFailed    = onFailed;
 }
        /// <summary>
        ///  Creates an object with the unique device ID <c>uid</c> and adds  it to
        ///  the IPConnection <c>ipcon</c>.
        /// </summary>
        public BrickletIndustrialQuadRelay(string uid, IPConnection ipcon)
            : base(uid, ipcon)
        {
            this.apiVersion[0] = 2;
            this.apiVersion[1] = 0;
            this.apiVersion[2] = 0;
            callbackWrappers[CALLBACK_MONOFLOP_DONE] = new CallbackWrapper(OnMonoflopDone);

            responseExpected[FUNCTION_SET_VALUE] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_VALUE] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_MONOFLOP] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_MONOFLOP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_GROUP] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_GROUP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_SELECTED_VALUES] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_IDENTITY] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[CALLBACK_MONOFLOP_DONE] = ResponseExpectedFlag.ALWAYS_FALSE;
        }
Example #14
0
        /**
         * Processes the callbacks in the callback queue.
         */
        protected void ProcessCallbacks()
        {
            // If we are busy then nothing to do at the moment.

            RSCommandSequence safeSeq = null;

            lock (callbackQueue)
            {
                if (isBusy)
                {
                    return;
                }

                // Check if we have left-over work to do.
                if (currentCmdSequence != null)
                {
                    // Indicate that we are busy. This prevents any process_callbacks calls
                    // generated by the callbacks to be processed immediately.
                    isBusy = true;

                    // We need to split up the stored command sequence into chunks
                    // that are safe to send.
                    safeSeq = currentCmdSequence.GetSafeSubsequence();

                    // If no more commands left in m_current_cmd_sequence, set it to
                    // null. Otherwise keep it and process it again next call.
                    if (currentCmdSequence.Commands.Count == 0)
                    {
                        currentCmdSequence = null;
                    }

                    ProcessCommands(safeSeq);
                    return;
                }

                // If no callbacks in the queue, then we are done for now.
                if (callbackQueue.Count == 0)
                {
                    return;
                }

                // Indicate that we are busy.
                isBusy = true;

                // The command sequence we need to fill with commands from callbacks.
                RSCommandSequence seq = null;

                // Go through all the current callbacks (and any callbacks
                // added by those callbacks) until we hit a binary command
                // or a callback using a different stateData instance.
                int callbackCount = 0;
                while (callbackQueue.Count > 0)
                {
                    CallbackWrapper frontCallback = callbackQueue.Peek();

                    // Create the command sequence if not done yet.
                    if (seq == null)
                    {
                        seq = new RSCommandSequence(this, frontCallback.StateData);
                    }

                    // Check if the next callback is using the same StateData.
                    // If not we need to stop and process the current command
                    // sequence first.
                    if (frontCallback.StateData != seq.StateData)
                    {
                        break;
                    }

                    // Next callback is using the same state data, so call it
                    // and add the commands to seq.
                    frontCallback = callbackQueue.Dequeue();
                    try
                    {
                        frontCallback.Callback(seq);
                    }
                    catch (Exception e)
                    {
                        // Error
                        Logger.Log("error", "Error in callback: " + frontCallback + "\n- " + e.ToString());
                    }

                    callbackCount++;

                    // If we get a sequence containing binary commands we
                    // need to stop, otherwise continue calling callbacks if
                    // there are any left.
                    if (seq.ContainsRenderCommands)
                    {
                        break;
                    }
                }

                // We need to split up the command sequence into chunks that are safe to send.
                safeSeq = seq.GetSafeSubsequence();

                // If there are still commands in the sequence, then we need
                // to store it and continue processing it later.
                if (seq.Commands.Count > 0)
                {
                    currentCmdSequence = seq;
                }
            }

            ProcessCommands(safeSeq);
        }