public ResponseDataBase <HttpRequestCfgDataUI> HttpRequestCfgGet(string webname, int level, HttpTaskModel.TaskStatus status)
        {
            ResponseDataBase <HttpRequestCfgDataUI> obj = new ResponseDataBase <HttpRequestCfgDataUI>();

            try
            {
                datapro.EnterReadLock();
                HttpTaskDBContext db = new HttpTaskDBContext();
                var d = db.HttpRequestCfg.Where(x => ((x.WebName.Trim() == webname.Trim() || string.IsNullOrEmpty(webname)) || (level == -1 ? x.Level >= 0 : x.Level == level)) && x.IsDelete == false && x.TaskStatus == status).Include(x => x.HttpRequestChildCfgs);

                foreach (var item in d)
                {
                    item.TaskStatus = HttpTaskModel.TaskStatus.ServerSent;
                    var o = new HttpRequestCfgDataUI()
                    {
                        Cookie = item.Cookie, Level = item.Level, CreatedTime = item.CreatedTime, DeletedTime = item.DeletedTime, HasChildTask = item.HasChildTask, Host = item.Host, Id = item.Id, Key = item.Key, IsDelete = item.IsDelete, ProcessName = item.ProcessName, Quartz = item.Quartz, SeqNo = item.SeqNo, TaskStatus = item.TaskStatus, TaskTimeOut = item.TaskTimeOut, UpdatedTime = item.UpdatedTime, WebName = item.WebName
                    };
                    o.HttpRequestChildCfgs = item.HttpRequestChildCfgs;
                    obj.data.Add(o);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                obj = ResponseBase.GetResponseByException <ResponseDataBase <HttpRequestCfgDataUI> >(ex);
            }
            finally
            {
                datapro.ExitReadLock();
            }
            return(obj);
        }
        public ResponseDataBase <HttpRequestCfgDataUI> HttpRequestCfgSingleGet(int level, int count)
        {
            ResponseDataBase <HttpRequestCfgDataUI> obj = new ResponseDataBase <HttpRequestCfgDataUI>();

            try
            {
                datapro.EnterReadLock();
                HttpTaskDBContext db = new HttpTaskDBContext();
                var d = db.HttpRequestCfg.Where(x => (level == -1 ? x.Level >= 0 : x.Level == level) && x.IsDelete == false).Take(count).Include(x => x.HttpRequestChildCfgs);// && x.TaskStatus == HttpTaskModel.TaskStatus.Ready

                foreach (var item in d)
                {
                    item.TaskStatus = HttpTaskModel.TaskStatus.ServerSent;
                    var o = new HttpRequestCfgDataUI()
                    {
                        Cookie = item.Cookie, Level = item.Level, CreatedTime = item.CreatedTime, DeletedTime = item.DeletedTime, HasChildTask = item.HasChildTask, Host = item.Host, Id = item.Id, Key = item.Key, IsDelete = item.IsDelete, ProcessName = item.ProcessName, Quartz = item.Quartz, SeqNo = item.SeqNo, TaskStatus = item.TaskStatus, TaskTimeOut = item.TaskTimeOut, UpdatedTime = item.UpdatedTime, WebName = item.WebName, CurrentDate = item.CurrentDate, CurrentPage = item.CurrentPage, DateMax = item.DateMax, DateMin = item.DateMin, info = item.info, PageMax = item.PageMax, PageMin = item.PageMin, SchedulerType = item.SchedulerType, SearchKey = item.SearchKey, SearchKeys = item.SearchKeys
                    };
                    o.HttpRequestChildCfgs = item.HttpRequestChildCfgs;
                    obj.data.Add(o);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                obj = ResponseBase.GetResponseByException <ResponseDataBase <HttpRequestCfgDataUI> >(ex);
            }
            finally
            {
                datapro.ExitReadLock();
            }
            return(obj);
        }
Exemple #3
0
        void RunPage(HttpRequestCfgDataUI data)
        {
            HttpServer _HotelServer = new HttpServer();
            HttpResult _Result;
            string     info = "";
            var        item = data.HttpRequestChildCfgs[0];

            _HotelServer = _createHttpserver(item);
            if (data.CurrentPage == -1)
            {
                data.CurrentPage = data.PageMin;
            }
            while (data.CurrentPage <= data.PageMax)
            {
                _HotelServer.Url      = _HotelServer.Url.Replace("{page}", data.CurrentPage.ToString());
                _HotelServer.PostData = _HotelServer.PostData.Replace("{page}", data.CurrentPage.ToString());
                _Result = _HotelServer.GetHttpResult();
                bool r = saveresult(_Result, item, data, out info);
                data.info = info;
                if (!r)
                {
                    data.TaskStatus = HttpTaskModel.TaskStatus.TaskFailed;
                    break;
                }
                var d = _RequestContract.HttpRequestCfgSaveStatus(data.Id, data.TaskStatus, data.CurrentPage, data.CurrentDate, info);
                data.CurrentPage++;
                Thread.Sleep(2000);
            }
        }
Exemple #4
0
        void RunDate(HttpRequestCfgDataUI data)
        {
            HttpServer _HotelServer = new HttpServer();
            HttpResult _Result;
            string     info = "";
            var        item = data.HttpRequestChildCfgs[0];

            _HotelServer         = _createHttpserver(item);
            _HotelServer.Cookies = item.CookieContainer;
            while (data.CurrentDate <= data.DateMax)
            {
                _HotelServer.Url      = string.Format(_HotelServer.Url, data.CurrentDate.Value.AddDays(1).ToString("yyyy-MM-DD HH:mm:ss"), data.CurrentDate.Value.ToString("yyyy-MM-DD HH:mm:ss"));
                _HotelServer.PostData = string.Format(_HotelServer.PostData, data.CurrentDate.Value.AddDays(1).ToString("yyyy-MM-DD HH:mm:ss"), data.CurrentDate.Value.ToString("yyyy-MM-DD HH:mm:ss"));
                _Result = _HotelServer.GetHttpResult();
                bool r = saveresult(_Result, item, data, out info);
                data.info = info;
                if (!r)
                {
                    data.TaskStatus = HttpTaskModel.TaskStatus.TaskFailed;
                    break;
                }
                data.CurrentDate = data.CurrentDate.Value.AddDays(1);
                Thread.Sleep(2000);
            }
        }
        public ResponseBase HttpRequestCfgSave(HttpRequestCfgDataUI data)
        {
            ResponseBase obj = new ResponseBase();

            try
            {
                datapro.EnterWriteLock();
                using (HttpTaskDBContext db = new HttpTaskDBContext())
                {
                    HttpRequestCfg d = new HttpRequestCfg()
                    {
                        UpdatedTime  = data.UpdatedTime,
                        TaskStatus   = data.TaskStatus,
                        SeqNo        = data.SeqNo,
                        SearchKey    = data.SearchKey,
                        Cookie       = data.Cookie,
                        CreatedTime  = data.CreatedTime,
                        CurrentDate  = data.CurrentDate,
                        DateMax      = data.DateMax,
                        CurrentPage  = data.CurrentPage,
                        DateMin      = data.DateMin,
                        DeletedTime  = data.DeletedTime,
                        HasChildTask = data.HasChildTask,
                        Host         = data.Host,
                        //HttpRequestChildCfgs =data.HttpRequestChildCfgs,
                        Id            = data.Id,
                        info          = data.info,
                        IsDelete      = data.IsDelete,
                        Key           = data.Key,
                        Level         = data.Level,
                        PageMax       = data.PageMax,
                        PageMin       = data.PageMin,
                        ProcessName   = data.ProcessName,
                        Quartz        = data.Quartz,
                        SchedulerType = data.SchedulerType,
                        SearchKeys    = data.SearchKeys,
                        TaskTimeOut   = data.TaskTimeOut,
                        WebName       = data.WebName
                    };
                    db.HttpRequestCfg.Add(d);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                obj = ResponseBase.GetResponseByException <ResponseBase>(ex);
            }
            finally
            {
                datapro.ExitWriteLock();
            }
            return(obj);
        }
Exemple #6
0
        void RunSingle(HttpRequestCfgDataUI data)
        {
            HttpServer _HotelServer = new HttpServer();
            HttpResult _Result;
            string     info = "";

            foreach (var item in data.HttpRequestChildCfgs)
            {
                _HotelServer = _createHttpserver(item);
                _Result      = _HotelServer.GetHttpResult();
                bool r = saveresult(_Result, item, data, out info);
                data.info = info;
                if (!r)
                {
                    data.TaskStatus = HttpTaskModel.TaskStatus.TaskFailed;
                    break;
                }
                Thread.Sleep(2000);
            }
        }
Exemple #7
0
        public void RunSpider(HttpRequestCfgDataUI data)
        {
            switch (data.SchedulerType)
            {
            case SchedulerType.Single:
                break;

            case SchedulerType.Date:
                RunDate(data);
                break;

            case SchedulerType.Page:
                RunPage(data);
                break;
            }

            if (data.TaskStatus != HttpTaskModel.TaskStatus.TaskFailed)
            {
                data.TaskStatus = HttpTaskModel.TaskStatus.Complete;
            }
            _RequestContract.HttpRequestCfgSave(data);
        }