Пример #1
0
        /// <summary>
        /// 格式化简历
        /// </summary>
        /// <param name="domFilesPath"></param>
        /// <param name="formatterFailFilesPath"></param>
        /// <param name="formatterSuccessFilesPath"></param>
        private void FormatResume(string domFilesPath, string formatterFailFilesPath, string formatterSuccessFilesPath)
        {
            while (true)
            {
                KeyValuePair <HtmlDocument, DateTime> keyValuePair;

                if (!resumeQueue.TryDequeue(out keyValuePair))
                {
                    continue;
                }

                var doc = keyValuePair.Key;

                var id = doc.DocumentNode.SelectSingleNode("//input[@id='resume_id']")?.Attributes["value"]?.Value;

                var name = doc.DocumentNode.SelectSingleNode("//input[@id='tt_username']")?.Attributes["value"]?.Value;

                var pathFile = $"{formatterSuccessFilesPath}{id}.json";

                var pathError = $"{formatterFailFilesPath}{id}.html";

                doc.Save($"{domFilesPath}{id}.html");

                try
                {
                    var resumeObj = Format.Convert_V0(ZhaopinHelper.ConvertTo_Dtl_V0(doc));

                    resumeObj.UpdateTime = keyValuePair.Value;

                    resumeObj.Reference.UpdateTime = keyValuePair.Value;

                    lock (resumeQueue)
                    {
                        File.WriteAllText(pathFile, JsonConvert.SerializeObject(resumeObj));
                    }

                    this.AsyncSetLog(this.tbx_Log, $"成功解析:{id}_{name}.json => 排队数:{resumeQueue.Count}");
                }
                catch (Exception ex)
                {
                    this.AsyncSetLog(this.tbx_Log, $"{ex.Message} => {id}_{name}.html => 排队数:{resumeQueue.Count}");

                    LogFactory.Warn($"{ex.Message} => {id}_{name}.html => 排队数:{resumeQueue.Count}");

                    lock (resumeQueue)
                    {
                        if (File.Exists(pathError))
                        {
                            File.Delete(pathError);
                        }

                        doc.Save(pathError);
                    }
                }
            }
        }
        /// <summary>
        /// 处理旧库投递的Dom简历
        /// </summary>
        public static void HandleOldDomResume()
        {
            var importCount = 0;

            while (true)
            {
                try
                {
                    var filePaths = Directory.GetFiles(handleDomFilePath);

                    if (filePaths.Length == 0)
                    {
                        Thread.Sleep(10 * 1000);

                        continue;
                    }

                    Console.WriteLine($"{DateTime.Now} > {filePaths.Length} Old Resume Dom Need Handle ! ");

                    foreach (var filePath in filePaths)
                    {
                        try
                        {
                            var htmlDocument = new HtmlDocument();

                            htmlDocument.LoadHtml(File.ReadAllText(filePath));

                            var resumeObj = Format.ConvertToZhaopin(ZhaopinHelper.ConvertTo_Dtl_V0(htmlDocument));

                            var fileName = Path.GetFileNameWithoutExtension(filePath);

                            resumeObj = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(resumeObj));

                            var releasedDateTime = DateTime.Parse(fileName.Substring(fileName.LastIndexOf("_", StringComparison.Ordinal) + 1).Replace(":", ":"));

                            resumeObj.detialJSonStr.DateLastReleased = releasedDateTime;

                            resumeObj.detialJSonStr.DateLastViewed = releasedDateTime;

                            resumeObj.detialJSonStr.DateModified = releasedDateTime;

                            File.WriteAllText($"{importFilePath}{resumeObj.resumeId}.json", JsonConvert.SerializeObject(resumeObj));

                            var path = handleDomSuccessPath + Path.GetFileName(filePath);

                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }

                            File.Move(filePath, path);

                            Console.WriteLine($"{DateTime.Now} > Handel Dom success ! ResumeId = {resumeObj.resumeId}, Import count = {++importCount}.");
                        }
                        catch (Exception ex)
                        {
                            var path = handleDomFailPath + Path.GetFileName(filePath);

                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }

                            File.Move(filePath, path);

                            Trace.WriteLine($"{DateTime.Now} > Handle Dom Error Message = {ex.Message}, Path = {path}.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"{DateTime.Now} > Handle Dom Error Message = {ex.Message}.");
                }
            }
        }