Beispiel #1
0
        private void AddSourceTask(ICaptchaHarvesterTask harvesterTask = null, bool isAuto = true)
        {
            RecaptchaParameter taskParameter = harvesterTask?.Parameter as RecaptchaParameter;

            RecaptchaParameter parameter = new RecaptchaParameter()
            {
                SiteKey  = taskParameter?.SiteKey ?? SiteKey,
                SitePath = taskParameter?.SitePath ?? SitePath
            };

            ICaptchaSolutionSourceTask sourceTask = null;

            if (isAuto)
            {
                sourceTask = GetSolutionSource()?.GetSolution(parameter);
            }
            else
            {
                sourceTask = m_manualSource.GetSolution(parameter);
            }

            if (sourceTask != null)
            {
                sourceTask.SolutionReleased += SolutionReleaseEventHanlder;

                m_sourceTasks[sourceTask] = taskParameter != null ? harvesterTask : null;
            }
        }
Beispiel #2
0
        private void ProcessSourceTask(ICaptchaSolutionSourceTask sourceTask)
        {
            if (sourceTask.Solution != null)
            {
                ICaptchaHarvesterTask harvesterTask     = null;
                RecaptchaSolution     recaptchaSolution = null;

                lock (m_lock)
                {
                    harvesterTask = m_sourceTasks[sourceTask] != null ? m_sourceTasks[sourceTask] : m_tasks.FirstOrDefault(t => !m_sourceTasks.ContainsValue(t));

                    m_tasks.Remove(harvesterTask);

                    recaptchaSolution = new RecaptchaSolution(sourceTask.Solution as string);
                }

                AddSolution(recaptchaSolution, harvesterTask);
            }

            lock (m_lock)
            {
                sourceTask.SolutionReleased -= SolutionReleaseEventHanlder;
                m_sourceTasks.Remove(sourceTask);
            }

            RestoreBalance();

            lock (m_lock)
            {
                if (m_manualSource.CurrentTask == null)
                {
                    AddSourceTask(m_tasks.FirstOrDefault(), false);
                }
            }
        }
Beispiel #3
0
        protected override bool ProcessTask(ICaptchaHarvesterTask task)
        {
            bool ret = false;

            if (task.Parameter != null)
            {
                lock (m_lock)
                {
                    AddSourceTask(task);
                }
            }
            else
            {
                RecaptchaSolution solution = GetOne();

                if (solution != null)
                {
                    task.Solution = solution;

                    ret = true;
                }
            }

            return(ret);
        }
Beispiel #4
0
        protected void ReleaseTask(ICaptchaHarvesterTask task)
        {
            lock (m_lock)
            {
                m_tasks.Remove(task);
            }

            task.SolutionReadyEvent.Set();

            OnPropertyChanged("TasksInQueue");
        }
Beispiel #5
0
        public void GetSolution(ICaptchaHarvesterTask task)
        {
            if (!ProcessTask(task))
            {
                lock (m_lock)
                {
                    m_tasks.Add(task);
                }

                OnPropertyChanged("TasksInQueue");
            }
            else
            {
                task.SolutionReadyEvent.Set();
            }
        }
Beispiel #6
0
        private void AddSolution(RecaptchaSolution solution, ICaptchaHarvesterTask harvesterTask = null)
        {
            if (harvesterTask != null)
            {
                harvesterTask.Solution = solution;

                ReleaseTask(harvesterTask);
            }
            else
            {
                lock (m_lock)
                {
                    m_solutions.Add(solution);

                    if (m_solutions.Count == 1)
                    {
                        m_oldestSolution = m_solutions.First();
                        m_liveTimer.Change(m_solutionLiveTime, Timeout.Infinite);
                    }
                }

                OnPropertyChanged("SolutionsCount");
            }
        }
Beispiel #7
0
 protected virtual bool ProcessTask(ICaptchaHarvesterTask task)
 {
     throw new NotImplementedException();
 }