private void SaveCacheByOss(KeyValuePair <KeyValuePair <int, string>, dynamic> tempData)
        {
            var resumeData = tempData.Value;

            var resumeDetail = JsonConvert.DeserializeObject(resumeData.detialJSonStr.ToString());

            var resumeId = resumeData.resumeId != null ? (int)resumeData.resumeId : resumeDetail.ResumeId != null ? (int)resumeDetail.ResumeId : 0;

            var resumeNumber = ((string)resumeData.resumeNo).Substring(0, 10);

            var model = new ResumeMatchResult
            {
                Cellphone    = null,
                Email        = null,
                ModifyTime   = BaseFanctory.GetTime((string)resumeDetail.DateModified).ToUniversalTime(),
                Name         = (string)resumeData.userDetials.userName,
                ResumeId     = resumeId,
                ResumeNumber = resumeNumber,
                UserExtId    = resumeDetail.UserMasterExtId.ToString(),
                UserId       = (int)resumeData.userDetials.userMasterId,
                Path         = $@"{savePath}\{resumeId}.json",
                CompanyId    = tempData.Key.Key,
                CreateTime   = BaseFanctory.GetTime((string)resumeDetail.DateCreated).ToUniversalTime()
            };

            uploadOssActionBlock.Post(new KeyValuePair <string, dynamic>($@"{savePath}\{resumeId}.json", tempData.Value));

            this.SaveResumeInfo(model);
        }
        /// <summary>
        /// 保存简历缓存到OSS队列
        /// </summary>
        private void SaveCacheByOss()
        {
            while (true)
            {
                string documentText;

                if (!cacheQueue.TryDequeue(out documentText))
                {
                    continue;
                }

                var savePath = $@"D:\Badoucai\OldZhaopinResume\{DateTime.Now:yyyyMMdd}";

                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }

                var resumeNumber = Regex.Match(documentText, "<input.+?name=\"extId\".+?value=\"(.+?)\"").Result("$1").Substring(0, 10);

                var modifyTimeMatch = Regex.Match(documentText, "resumeUpdateTime\">(.+?)</strong>");

                if (!modifyTimeMatch.Success)
                {
                    continue;
                }

                var model = new ResumeMatchResult
                {
                    Cellphone    = null,
                    Email        = null,
                    ModifyTime   = DateTime.Parse(modifyTimeMatch.Result("$1")),
                    Name         = Regex.Match(documentText, "<input.+?name=\"tt_username\".+?value=\"(.+?)\"").Result("$1"),
                    ResumeId     = Convert.ToInt32(Regex.Match(documentText, "<input.+?name=\"resume_id\".+?value=\"(.+?)\"").Result("$1")),
                    ResumeNumber = resumeNumber,
                    UserExtId    = null,
                    UserId       = Convert.ToInt32(Regex.Match(documentText, "<input.+?name=\"resumeUserId\".+?value=\"(.+?)\"").Result("$1")),
                    Path         = $@"{savePath}\{resumeNumber}.txt",
                    CompanyId    = companyId
                };

                File.WriteAllText($@"{savePath}\{resumeNumber}.txt", documentText);

                UploadResumeToOss($@"{savePath}\{resumeNumber}.txt");

                this.matchBusiness.SaveMatchedCache(model);

                this.AsyncSetLog(this.tbx_Log, $"ResumeNumber => {resumeNumber}{Environment.NewLine}WatchCount =>{++watchCount}");
            }
        }
        public void SaveResumeInfo(ResumeMatchResult model)
        {
            using (var xdb = new MangningXssDBEntities())
            {
                var user = xdb.ZhaopinUser.FirstOrDefault(f => f.Id == model.UserId);

                if (user == null)
                {
                    xdb.ZhaopinUser.Add(new ZhaopinUser
                    {
                        Id         = model.UserId,
                        Source     = "Watch",
                        ModifyTime = model.ModifyTime,
                        Cellphone  = model.Cellphone,
                        Email      = model.Email,
                        Name       = model.Name,
                        UpdateTime = DateTime.UtcNow,
                        CreateTime = model.CreateTime
                    });
                }
                else
                {
                    user.ModifyTime = model.ModifyTime;
                    user.UpdateTime = DateTime.UtcNow;
                    user.Name       = model.Name;
                }

                var resumeEntity = xdb.ZhaopinResume.FirstOrDefault(f => f.Id == model.ResumeId);

                var userExtId = Regex.IsMatch(model.UserExtId, @"^J[MRSL]\d{9}$") ? model.UserExtId : string.Empty;

                if (resumeEntity == null)
                {
                    xdb.ZhaopinResume.Add(new ZhaopinResume
                    {
                        Id           = model.ResumeId,
                        RandomNumber = model.ResumeNumber,
                        UserId       = model.UserId,
                        RefreshTime  = model.ModifyTime,
                        UpdateTime   = DateTime.UtcNow,
                        UserExtId    = userExtId,
                        Source       = "Watch"
                    });
                }
                else
                {
                    resumeEntity.RandomNumber = model.ResumeNumber;
                    resumeEntity.UserId       = model.UserId;
                    resumeEntity.RefreshTime  = model.ModifyTime;
                    if (string.IsNullOrEmpty(resumeEntity.UserExtId))
                    {
                        resumeEntity.UserExtId = userExtId;
                    }
                }

                var cache = xdb.ZhaopinMatchedCache.FirstOrDefault(f => f.ResumeId == model.ResumeId);

                if (cache == null)
                {
                    xdb.ZhaopinMatchedCache.Add(new ZhaopinMatchedCache
                    {
                        ResumeId     = model.ResumeId,
                        ModifyTime   = model.ModifyTime,
                        Cellphone    = model.Cellphone,
                        Email        = model.Email,
                        Name         = model.Name,
                        Path         = model.Path,
                        ResumeNumber = model.ResumeNumber,
                        UserExtId    = model.UserExtId,
                        UserId       = model.UserId
                    });
                }
                else
                {
                    cache.Cellphone = model.Cellphone;
                    cache.Email     = model.Email;
                    cache.UserExtId = model.UserExtId;
                }

                var watched = xdb.ZhaopinWatchedResume.FirstOrDefault(f => f.Id == model.ResumeId);

                if (watched == null)
                {
                    xdb.ZhaopinWatchedResume.Add(new ZhaopinWatchedResume
                    {
                        Id           = model.ResumeId,
                        ResumeNumber = model.ResumeNumber,
                        CompanyId    = model.CompanyId,
                        WatchTime    = DateTime.UtcNow
                    });
                }

                xdb.SaveChanges();
            }
        }
Beispiel #4
0
        private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (webBrowser.ReadyState != WebBrowserReadyState.Complete)
            {
                return;
            }

            if (e.Url.AbsoluteUri.Contains("https://rd2.zhaopin.com/s/homepage.asp"))
            {
                webBrowser.Navigate("https://rdsearch.zhaopin.com/Home/SearchByCustom?source=rd");
            }

            if (e.Url.AbsoluteUri.Contains("https://rdsearch.zhaopin.com/Home/SearchByCustom"))
            {
                isSearchCompleted = true;
            }

            if (e.Url.AbsoluteUri.Contains("https://rd.zhaopin.com/resumepreview/resume/validateuser"))
            {
                while (true)
                {
                    if (!isWaitCheck)
                    {
                        if (this.webBrowser.Document?.Cookie == null)
                        {
                            break;
                        }

                        var cookieBytes = Encoding.UTF8.GetBytes(this.webBrowser.Document.Cookie);

                        var accountBytes = Encoding.UTF8.GetBytes(userName);

                        socket.Send(new CheckCodePackage
                        {
                            Id      = 0x05,
                            Length  = (short)(cookieBytes.Length + 15),
                            Cookie  = cookieBytes,
                            Status  = 0,
                            Account = accountBytes,
                            Type    = 1
                        }.Serialize());

                        isWaitCheck = true;
                    }
                    else
                    {
                        if (checkResult)
                        {
                            isWaitCheck = false;

                            break;
                        }

                        Thread.Sleep(1000);
                    }
                }

                webBrowser.Navigate(HttpUtility.UrlDecode(Regex.Match(e.Url.AbsoluteUri, "url=(\\S+)").Result("$1")));

                return;
            }

            if (e.Url.AbsoluteUri.Contains("https://rdsearch.zhaopin.com/Home/ResultForCustom"))
            {
                var match = Regex.Match(webBrowser.DocumentText, "共<span>(\\d+)</span>份简历");

                if (!match.Success)
                {
                    isListCompleted = true;

                    return;
                }

                var count = Convert.ToInt32(match.Result("$1"));

                if (count == 0 || count > 30)
                {
                    isListCompleted = true;

                    return;
                }

                if (companyId == 0)
                {
                    match = Regex.Match(webBrowser.DocumentText, "<input.+?name=\"companyId\".+?value=\"(.+?)\"");

                    companyId = Convert.ToInt32(match.Result("$1"));
                }

                Task.Run(() =>
                {
                    MatchCollection matchs = null;

                    this.Invoke((MethodInvoker) delegate
                    {
                        matchs = Regex.Matches(webBrowser.DocumentText, "rg=\"\\d+\".+?RedirectToRd/(.+?)','(.+?)','(.+?)',this");
                    });

                    foreach (Match matchResult in matchs)
                    {
                        var resumeCache = business.GetResumeOfCache(matchResult.Result("$1").Substring(0, 10));

                        if (resumeCache != null)
                        {
                            if (searchResume.SearchResumeId.Substring(2, 8) == match.Result("$1").Substring(1))
                            {
                                var model = new ResumeMatchResult
                                {
                                    Cellphone    = searchResume.Cellphone,
                                    Email        = searchResume.Email,
                                    ModifyTime   = resumeCache.ModifyTime,
                                    Name         = resumeCache.Name,
                                    ResumeId     = resumeCache.ResumeId,
                                    ResumeNumber = resumeCache.ResumeNumber,
                                    UserExtId    = searchResume.SearchResumeId,
                                    UserId       = resumeCache.UserId,
                                    CompanyId    = companyId
                                };

                                business.SaveMatchedCache(model);

                                business.ChangeResumeStatus(searchResume.SearchResumeId, true);

                                isListCompleted = true;

                                searchResume.IsMatched = true;

                                successCount++;

                                isDetailCompleted = true;
                            }
                        }
                        else
                        {
                            //Thread.Sleep(2000);

                            var detailUrl = $"https://rd.zhaopin.com/resumepreview/resume/viewone/2/{matchResult.Result("$1")}&t={matchResult.Result("$2")}&k={matchResult.Result("$3")}&v=";

                            isDetailCompleted = false;

                            webBrowser.Navigate(detailUrl);

                            SpinWait.SpinUntil(() => isDetailCompleted, TimeSpan.FromSeconds(30));

                            isDetailCompleted = false;
                        }

                        if (isListCompleted)
                        {
                            break;
                        }
                    }

                    isListCompleted = true;
                });
            }

            if (e.Url.AbsoluteUri.Contains("https://rd.zhaopin.com/resumepreview/resume/viewone"))
            {
                var match = Regex.Match(webBrowser.DocumentText, "<input.+?resumeUserId.+?value=\"(.+?)\"");

                if (!match.Success)
                {
                    isDetailCompleted = true;

                    return;
                }

                var savePath = $@"D:\Badoucai\OldZhaopinResume\{DateTime.Now:yyyyMMdd}";

                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }

                var resumeNumber = Regex.Match(webBrowser.DocumentText, "<input.+?name=\"extId\".+?value=\"(.+?)\"").Result("$1").Substring(0, 10);

                var model = new ResumeMatchResult
                {
                    Cellphone    = searchResume.Cellphone,
                    Email        = searchResume.Email,
                    ModifyTime   = DateTime.Parse(Regex.Match(webBrowser.DocumentText, "resumeUpdateTime\">(.+?)</strong>").Result("$1")),
                    Name         = Regex.Match(webBrowser.DocumentText, "<input.+?name=\"tt_username\".+?value=\"(.+?)\"").Result("$1"),
                    ResumeId     = Convert.ToInt32(Regex.Match(webBrowser.DocumentText, "<input.+?name=\"resume_id\".+?value=\"(.+?)\"").Result("$1")),
                    ResumeNumber = resumeNumber,
                    UserExtId    = searchResume.SearchResumeId,
                    UserId       = Convert.ToInt32(Regex.Match(webBrowser.DocumentText, "<input.+?name=\"resumeUserId\".+?value=\"(.+?)\"").Result("$1")),
                    Path         = $@"{savePath}\{resumeNumber}.txt",
                    CompanyId    = companyId
                };

                File.WriteAllText($@"{savePath}\{resumeNumber}.txt", this.webBrowser.DocumentText);

                UploadResumeToOss($@"{savePath}\{resumeNumber}.txt");

                if (searchResume.SearchResumeId.Substring(2, 8) == match.Result("$1").Substring(1))
                {
                    business.SaveMatchedCache(model);

                    business.ChangeResumeStatus(searchResume.SearchResumeId, true);

                    isListCompleted = true;

                    searchResume.IsMatched = true;

                    successCount++;
                }
                else
                {
                    model.Cellphone = null;

                    model.Email = null;

                    model.UserExtId = null;

                    business.SaveMatchedCache(model);
                }

                isDetailCompleted = true;
            }
        }