示例#1
0
    public void Release()
    {
        CallbackObject execute = null;

        if (Interlocked.Increment(ref this.counter) < 0)
        {
            if (!queue.TryDequeue(out execute))
            {
                throw new NotImplementedException("ConcurrentQueue.TryDequeue failed");
            }
        }
        else
        {
            if (counter > maxCounter)
            {
                throw new SemaphoreFullException("Release was called too many times");
            }
        }

        if (execute != null)
        {
            execute.Callback(execute);
            execute.IsCompleted = true;
        }
    }
示例#2
0
        private void ReadCallback(IAsyncResult result)
        {
            try
            {
                CallbackObject obj = result.AsyncState as CallbackObject;

                Functions.ShowToast(obj.Text);

                CallbackObject callback = new CallbackObject
                {
                    Buffer = new byte[1024]
                };
                InStream.BeginRead(callback.Buffer, 0, callback.Length, ReadCallback, callback);
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(Name, "disconnected", e);
                ConnectionLost();
            }
            catch (Java.Lang.RuntimeException e)
            {
                Log.Error(Name, "disconnected", e);
                ConnectionLost();
            }
        }
示例#3
0
    public IAsyncResult BeginWait(AsyncCallback callback, object state)
    {
        if (callback == null)
        {
            throw new ArgumentNullException("callback", "callback cannot be null");
        }
        var o = new CallbackObject();

        o.AsyncState = state;
        o.Callback   = callback;
        bool execute = false;

        if (Interlocked.Decrement(ref this.counter) >= 0)
        {
            o.CompletedSynchronously = execute = true;
        }
        else
        {
            queue.Enqueue(o);
        }
        if (execute)
        {
            callback(o);
            o.IsCompleted = true;
        }
        return(o);
    }
示例#4
0
        public void CaptureImageWithCallbackTest()
        {
            CallbackObject userData = new CallbackObject();

            using (WimHandle wimHandle = WimgApi.CreateFile(CaptureWimPath, WimFileAccess.Write, WimCreationDisposition.CreateAlways, WimCreateFileOptions.None, WimCompressionType.Xpress))
            {
                WimgApi.SetTemporaryPath(wimHandle, TempPath);

                WimgApi.RegisterMessageCallback(wimHandle, CaptureImageWithCallbackTestCallback, userData);
                try
                {
                    using (WimHandle imageHandle = WimgApi.CaptureImage(wimHandle, CapturePath, WimCaptureImageOptions.None))
                    {
                    }
                }
                finally
                {
                    WimgApi.UnregisterMessageCallback(wimHandle, CaptureImageWithCallbackTestCallback);
                }
            }
            _captureWithCallbackCalled.ShouldBe(true, "The callback should have been called");

            userData.WasCalled.ShouldBe(true, "The callback should have set user data");

            _captureWithCallbackFileCount.ShouldBe(TestWimTemplate.FileCount);
        }
示例#5
0
        public static CallbackObject GetMappedObject <T>(object obj)
            where T : class
        {
            AdsConnection connection = CreateConnection();

            connection.Open();

            var cbo = new CallbackObject();

            var context = new AdsDataContext(connection);

            try
            {
                cbo.obj = context.Get <T>(obj);

                cbo.success = true;
            }
            catch (Exception e)
            {
                cbo.success = false;
                cbo.info    = e.Message + ", SQL: " + context.LastSqlCommandText;
            }
            finally
            {
                connection.Close();
            }

            return(cbo);
        }
 private void Initialize()
 {
     Logger.Info("Connector Initialize");
     _callbackObject = new CallbackObject(this);
     _context        = new InstanceContext(_callbackObject);
     _client         = new WCFServiceClient(_context, _binding, _endpoint);
 }
示例#7
0
        private void Connected(BluetoothSocket bluetoothSocket)
        {
            Log.Debug(Name, $"create ConnectedThread");

            Socket = bluetoothSocket;

            try
            {
                InStream  = bluetoothSocket.InputStream;
                OutStream = bluetoothSocket.OutputStream;
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(Name, "temp sockets not created", e);
                ConnectionLost();
            }

            State = BluetoothState.Connected;

            Log.Info(Name, "BEGIN mConnectedThread");

            CallbackObject callback = new CallbackObject
            {
                Buffer = new byte[1024]
            };

            InStream.BeginRead(callback.Buffer, 0, callback.Length, ReadCallback, callback);
        }
        private void DeInitialize()
        {
            Logger.Info("Connector Deinitialize");
            StopHeartBeat();

            try
            {
                if (_client != null)
                {
                    if (_client.State != CommunicationState.Faulted)
                    {
                        _client.Close();
                    }
                    else
                    {
                        _client.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("DeInitialize", ex);
            }
            _client = null;

            try
            {
                if (_context != null)
                {
                    if (_context.State != CommunicationState.Faulted)
                    {
                        try
                        {
                            _context.Close(TimeSpan.FromSeconds(5));
                        }
                        catch (TimeoutException ex)
                        {
                            Logger.Error("DeInitialize connector", ex);
                        }
                    }
                    else
                    {
                        _context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("DeInitialize", ex);
            }
            _context = null;

            if (_callbackObject != null)
            {
                _callbackObject.Dispose();
            }

            _callbackObject = null;
        }
            public void ArrayType(string elementTypeDefinition)
            {
                if (callbackIndex >= expectedCallbacks.Length)
                {
                    Assert.Fail(String.Format("Only expected '{0}' callbacks but got more", expectedCallbacks.Length, callbackIndex));
                }
                CallbackObject expectedCallback = expectedCallbacks[callbackIndex++];

                expectedCallback.AssertArrayTypeCall(elementTypeDefinition);
            }
            public void ObjectType(SosObjectDefinition objectDefinition)
            {
                if (callbackIndex >= expectedCallbacks.Length)
                {
                    Assert.Fail(String.Format("Only expected '{0}' callbacks but got more", expectedCallbacks.Length, callbackIndex));
                }
                CallbackObject expectedCallback = expectedCallbacks[callbackIndex++];

                expectedCallback.AssertObjectTypeCall(objectDefinition);
            }
示例#11
0
            public override bool Equals(object obj)
            {
                CallbackObject callback = obj as CallbackObject;

                if (callback != null)
                {
                    return(callback.MessageId == MessageId && callback.Callback == Callback && callback.assembly == assembly);
                }
                return(false);
            }
            public void PrimitiveType(Type type)
            {
                if (callbackIndex >= expectedCallbacks.Length)
                {
                    Assert.Fail(String.Format("Only expected '{0}' callbacks but got more", expectedCallbacks.Length, callbackIndex));
                }
                CallbackObject expectedCallback = expectedCallbacks[callbackIndex++];

                expectedCallback.AssertPrimitiveTypeCall(type);
            }
示例#13
0
        public static void CallbackLoop()
        {
            while (!bCallbackThreadExitFlag)
            {
                if (MiniMem.ActiveCallbacks.Count < 1 || MiniMem.AttachedProcess.ProcessHandle == IntPtr.Zero)
                {
                    Thread.Sleep(500);
                    continue;
                }

                Debug.WriteLine($"[CALLBACK MONITOR] {MiniMem.ActiveCallbacks.Count} registered item(s) in Callback Monitor");

                for (int i = MiniMem.ActiveCallbacks.Count - 1; i >= 0; i--)
                {
                    if (bCallbackThreadExitFlag)
                    {
                        break;
                    }

                    CallbackObject cObj = MiniMem.ActiveCallbacks[i];
                    if (cObj.ObjectCallback == null)
                    {
                        continue;
                    }
                    if (cObj.ptr_HitCounter == IntPtr.Zero)
                    {
                        continue;
                    }

                    if (MiniMem.AttachedProcess.ProcessHandle == IntPtr.Zero)
                    {
                        continue;
                    }
                    uint r = MiniMem.ReadMemory <uint>(cObj.ptr_HitCounter.ToInt64());
                    if (r != cObj.LastValue)
                    {
                        MiniMem.ActiveCallbacks.Remove(cObj);

                        cObj.LastValue = r;
                        MiniMem.ActiveCallbacks.Add(cObj);
                        cObj.ObjectCallback?.Invoke(cObj);
                    }
                }
                if (bCallbackThreadExitFlag)
                {
                    break;
                }

                Thread.Sleep(25);
            }

            bCallbackThreadExitFlag = false;
        }
示例#14
0
        void IAssemblyObjectList.Remove(IAssemblyObject obj)
        {
            lock (syncRoot) {
                CallbackObject callbackObj = obj as CallbackObject;

                if (callbackObj != null && list[callbackObj.MessageId] != null)
                {
                    list[callbackObj.MessageId].Remove(callbackObj);

                    Debug.WriteLine(callbacksName + " callback removed (0x" + callbackObj.MessageId.ToString("X2") + ")", "Phoenix");
                }
            }
        }
        public static async Task <ISymbolSearchUpdateEngine> CreateEngineAsync(
            Workspace workspace,
            ISymbolSearchLogService logService,
            CancellationToken cancellationToken)
        {
            var client = await RemoteHostClient.TryGetClientAsync(workspace, cancellationToken).ConfigureAwait(false);

            if (client != null)
            {
                var callbackObject = new CallbackObject(logService);
                var session        = await client.CreateConnectionAsync(WellKnownServiceHubService.RemoteSymbolSearchUpdateEngine, callbackObject, cancellationToken).ConfigureAwait(false);

                return(new RemoteUpdateEngine(workspace, session));
            }

            // Couldn't go out of proc.  Just do everything inside the current process.
            return(CreateEngineInProcess(logService));
        }
示例#16
0
        private Exception runSeperateAppdomain(CallbackObject obj)
        {
            var appDomain = AppDomain.CreateDomain("TestRunnerNew");

            //appDomain.Load(new AssemblyName(TestsAssembly.FullName));

            appDomain.DoCallBack(obj.RunTest);

            var ex = (Exception)appDomain.GetData("TestException");

            try
            {
                AppDomain.Unload(appDomain);// this causes crashes in character controllers?
            }
            catch (Exception unloadEx)
            {
                Console.WriteLine(unloadEx);
            }
            return(ex);
        }
示例#17
0
        public static async Task <ISymbolSearchUpdateEngine> CreateEngineAsync(
            Workspace workspace,
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService,
            CancellationToken cancellationToken)
        {
            var client = await workspace.TryGetRemoteHostClientAsync(
                RemoteFeatureOptions.SymbolSearchEnabled, cancellationToken).ConfigureAwait(false);

            if (client != null)
            {
                var callbackObject = new CallbackObject(logService, progressService);
                var session        = await client.TryCreateKeepAliveSessionAsync(WellKnownServiceHubServices.RemoteSymbolSearchUpdateEngine, callbackObject, cancellationToken).ConfigureAwait(false);

                if (session != null)
                {
                    return(new RemoteUpdateEngine(workspace, session));
                }
            }

            // Couldn't go out of proc.  Just do everything inside the current process.
            return(new SymbolSearchUpdateEngine(logService, progressService));
        }
示例#18
0
        public void Add(byte id, MessageCallback callback, CallbackPriority priority)
        {
            lock (syncRoot) {
                if (list[id] == null)
                {
                    list[id] = new CallbacksCollection();
                }

                CallbackObject obj = new CallbackObject(id, callback, priority);

                if (list[id].Contains(obj))
                {
                    throw new ArgumentException("Callback is already registered for this message.");
                }

                RuntimeCore.AddAssemblyObject(obj, this);
                list[id].Add(obj);

                list[id].SortByPriority();

                Debug.WriteLine(callbacksName + " callback added (0x" + id.ToString("X2") + ", " + priority.ToString() + ")", "Phoenix");
            }
        }
    public void Release()
    {
        CallbackObject execute = null;

        lock (this)
        {
            if (!queue.Any())
            {
                if (++counter > maxCounter)
                {
                    throw new SemaphoreFullException("Release was called too many times");
                }
            }
            else
            {
                execute = queue.Dequeue();
            }
        }
        if (execute != null)
        {
            execute.Callback(execute);
            execute.IsCompleted = true;
        }
    }
示例#20
0
 private Exception runCurrentAppdomain(CallbackObject callbackObject)
 {
     callbackObject.RunTest();
     return(callbackObject.ThrowedException);
 }
示例#21
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     // Initialize everything
     this.callbackObj = new CallbackObject(Callback0);
     flipflop         = false;
 }
示例#22
0
        /// <summary>
        /// 释放当前电话号码
        /// </summary>
        /// <returns></returns>
        public int ReleaseMobile()
        {
            SMSResult result = new SMSResult() { Status = false };
            rtnList.Add(result);
            bFinishedList.Add(false);
            AsynHandler handler = new AsynHandler(smsInstance.ReleasePhoneNum);

            CallbackObject obj = new CallbackObject() { onHander = handler, mIndex = index };
            IAsyncResult ar = handler.BeginInvoke(AsyncCompleted, obj);
            return index++;
        }
示例#23
0
 private void Initialize()
 {
     _callbackObject = new CallbackObject(this);
     _context        = new InstanceContext(_callbackObject);
     _client         = new WCFConnectionClient(_context, _binding, _endpoint);
 }
示例#24
0
 public void AddCallback(CallbackObject callback)
 {
     m_Callbacks.Add(callback);
 }