Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url">验证服务的URL</param>
        /// <param name="fileName">验证图片的文件名</param>
        /// <param name="alarmImg">验证图片</param>
        /// <param name="callback">回调函数(回调函数为null,则会出发验证完成事件)</param>
        public void ExecuteVerifyAsync(string url, string fileName, Image alarmImg, Action <VerifyResult> callback = null)
        {
            maxAccepted.WaitOne(); //获取信号量
            VerifyProcess tmpHandler = evtHandlers.Dequeue();

            if (tmpHandler != null)
            {
                if (!tmpRequest.ContainsKey(fileName) && callback != null)
                {
                    tmpRequest.Add(fileName, callback);
                }
                tmpHandler.VerifyPersonAsync(url, fileName, alarmImg);
            }
        }
Ejemplo n.º 2
0
        //操作完成后
        private void verTask_OnCompleted(VerifyProcess sender, VerifyResult arg)
        {
            evtHandlers.Enqueue(sender);
            maxAccepted.Release();

            if (tmpRequest.ContainsKey(arg.Key))
            {
                try
                {
                    Action <VerifyResult> callback = tmpRequest[arg.Key];
                    if (callback != null)
                    {
                        callback(arg);
                    }
                    else
                    {
                        if (OnVerifyCompleted != null)
                        {
                            OnVerifyCompleted(arg);
                        }
                    }
                }
                catch (Exception exp)
                {
                    Logger.AddLog(this.GetType(), "VerifyCenter.Part1", exp.Message);
                }
                finally
                {
                    tmpRequest.Remove(arg.Key);
                }
            }
            else
            {
                try
                {
                    if (OnVerifyCompleted != null)
                    {
                        OnVerifyCompleted(arg);
                    }
                }
                catch (Exception exp)
                {
                    Logger.AddLog(this.GetType(), "VerifyCenter.Part2", exp.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public VerifyResult ExecuteVerify(string url, string fileName, Image alarmImg)
        {
            maxAccepted.WaitOne(); //获取信号量
            VerifyProcess tmpHandler = evtHandlers.Dequeue();
            VerifyResult  result     = null;

            if (tmpHandler != null)
            {
                if (string.IsNullOrWhiteSpace(fileName))
                {
                    fileName = Guid.NewGuid().ToString();
                }
                result = tmpHandler.VerifyImage(url, fileName, alarmImg);
            }
            evtHandlers.Enqueue(tmpHandler);
            maxAccepted.Release();
            return(result);
        }
Ejemplo n.º 4
0
        private VerifyCenter(int maxTask)
        {
            try
            {
                MaxThreads = maxTask;

                this.maxAccepted = new Semaphore(MaxThreads, MaxThreads);

                tmpRequest = new Dictionary <string, Action <VerifyResult> >();

                evtHandlers = new PoolQueue <VerifyProcess>(MaxThreads + 2);
                for (int i = 0; i < MaxThreads; i++)
                {
                    VerifyProcess verTask = new VerifyProcess();
                    verTask.OnCompleted += verTask_OnCompleted;
                    evtHandlers.Enqueue(verTask);
                }
            }
            catch (Exception exp)
            {
                Logger.AddLog(this.GetType(), "VerifyCenter", exp.Message);
            }
        }