Beispiel #1
0
        public static void CreateText(string path, List <ExcelFormat> list)
        {
            List <string> conList = new List <string>();

            foreach (var item in list)
            {
                // 补充邮箱
                if (string.IsNullOrWhiteSpace(item.ObservedEmail))
                {
                    item.ObservedEmail = item.ObservedName + "@askform.cn";
                }
                if (string.IsNullOrWhiteSpace(item.ObserverEmail))
                {
                    item.ObserverEmail = item.ObserverName + "@askform.cn";
                }

                // 获取属性
                foreach (var pro in item.GetType().GetProperties())
                {
                    // 判断属性是否有值
                    if (!string.IsNullOrWhiteSpace(pro.GetValue(item) + ""))
                    {
                        // 判断属性是否已存
                        if (!conList.Contains(pro.Name))
                        {
                            conList.Add(pro.Name);
                        }
                    }
                }
            }

            ToolFile.CreatFile(path, string.Join("\t", conList), false);


            foreach (var item in list)
            {
                string line = "";
                Type   type = item.GetType();

                for (int i = 0; i < conList.Count; i++)
                {
                    if (i != 0)
                    {
                        line += "\t";
                    }
                    var val = type.GetProperty(conList[i]).GetValue(item) + "";
                    if (val == null)
                    {
                        val = " ";
                    }

                    line += val;
                }

                ToolFile.CreatFile(path, line, true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="logPath">日志路径</param>
        /// <param name="msg">日志消息</param>
        /// <param name="append">是否追加</param>
        /// <param name="hasDate">是否包含时间</param>
        protected void WriteLog(string logPath, string msg, bool append = true, bool hasDate = true)
        {
            logPath = ToolFile.GetAbsolutelyPath(logPath);
            if (File.Exists(logPath) && !append)
            {
                File.Delete(logPath);
            }

            ToolFile.CreatFile(logPath, (hasDate ? (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")) + "\t\t" : "") + msg, true);
        }
        public Result GetFun()
        {
            return(RunFun((logPath, dataPath) =>
            {
                int max = 50;

                ToolFile.CreatFile(dataPath, "取整", true);

                string line = "";

                for (int i = 1; i <= max; i++)
                {
                    line = i + "\t";

                    for (int j = 1; j <= i; j++)
                    {
                        line += "";
                    }
                }


                return Res;
            }));
        }
Beispiel #4
0
        /// <summary>
        /// 解析题目
        /// </summary>
        /// <param name="file">文件路径</param>
        /// <param name="isCheck">是否检查段落</param>
        /// <param name="analysis">开启横向解析</param>
        /// <returns></returns>
        public Result Fun1(string file, bool isCheck, bool analysis)
        {
            return(RunFun(logPath =>
            {
                string path = allPath + @"" + file + ".docx";
                string tigerPath = allTiger + @"" + file + ".txt";

                WriteLog(logPath, file + "," + isCheck);

                string exclude = allPath + "ExcludeList.json";

                if (File.Exists(exclude))
                {
                    ExcludeList = ToolString.ConvertObject <List <string> >(File.ReadAllText(exclude));
                }

                XWPFDocument document = ToolFile.ReadWord(path);
                StringBuilder builder = new StringBuilder();

                string subject = "";

                List <string> answerList = new List <string>();
                List <string> itemList = new List <string>();

                string[] typeArr = new string[] { "单项选择", "多项选择", "判断" };
                int index = -1, nextIndex = -1; // 题目类型
                int itemIndex = 0;              // 答案索引
                int subjectIndex = 1;           // 题目索引

                if (analysis)
                {
                    fun1Str5 = @"[  ((]*[A-H]{1}[ .、.))::]+";
                }
                foreach (XWPFParagraph para in document.Paragraphs)
                {
                    string paragraphs = para.ParagraphText.Trim();//.Replace(" ", "");

                    for (int i = 0; i < typeArr.Length; i++)
                    {
                        if (ToolRegular.Contains(paragraphs, ".*" + typeArr[i] + @"题[((][\d]*.*[))]"))
                        {
                            nextIndex = i;
                            subjectIndex = 1;
                            if (index == -1)
                            {
                                index = i;
                            }
                        }
                    }

                    List <string> list = paragraphs.Split('\n').ToList();

                    foreach (var line in list)
                    {
                        // 判断是否是题目开头
                        Regex reg = new Regex(fun1Str1);
                        if (IsSubject(para, isCheck) || (reg.IsMatch(line) && !isCheck))
                        {
                            // 输出上一题
                            if (!string.IsNullOrWhiteSpace(subject))
                            {
                                subject = ReplaceSubject(subject, "、", isCheck);


                                if (!string.IsNullOrWhiteSpace(subject))
                                {
                                    answerList = AnswerList(subject);
                                    subject = answerList[0];
                                    answerList.Remove(subject);

                                    if (index == -1)
                                    {
                                        index = 0; nextIndex = 0;
                                    }

                                    subject += "[" + typeArr[index] + "题]\n";

                                    AnswerList(answerList, itemList, typeArr[index]);

                                    foreach (var item in itemList)
                                    {
                                        subject += item + "\n";
                                    }

                                    builder.AppendLine(subject);

                                    index = nextIndex;

                                    WriteLog(allTiger + @"" + file + ".log", "[" + typeArr[index] + "题]\t" + ToolString.AddStrByLength(subjectIndex + "", " ", 3) + "\t" + ToolString.AddStrByLength(string.Join(",", answerList), " ", 10) + "\t[" + string.Join(",", itemList.Select(c => c[0])) + "]", true);
                                    subjectIndex++;
                                }
                            }

                            // 开始下一题
                            itemList = new List <string>();
                            answerList = new List <string>();
                            subject = line;
                            itemIndex = 0;
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(subject))
                            {
                                continue;
                            }
                            // 判断是否是选项开头
                            else if (IsItem(para, isCheck) || new Regex(fun1Str3).IsMatch(line))
                            {
                                itemList.AddRange(ItemList(line, para, isCheck, itemIndex++, analysis));
                                continue;
                            }
                            // 判断是否是换行题目
                            else if (itemList.Count <= 0 && !string.IsNullOrWhiteSpace(line) && (!isCheck || para.GetNumFmt() != "lowerRoman"))
                            {
                                subject += Br + line;
                            }
                        }
                    }
                }

                // 输出最后一题
                if (!string.IsNullOrWhiteSpace(subject))
                {
                    subject = ReplaceSubject(subject, "、", isCheck);


                    if (!string.IsNullOrWhiteSpace(subject))
                    {
                        answerList = AnswerList(subject);
                        subject = answerList[0];
                        answerList.Remove(subject);

                        subject += "[" + typeArr[index] + "题]\n";

                        AnswerList(answerList, itemList, typeArr[index]);

                        foreach (var item in itemList)
                        {
                            subject += item + "\n";
                        }

                        builder.AppendLine(subject);

                        index = nextIndex;
                        WriteLog(allTiger + @"" + file + ".log", "[" + typeArr[index] + "题]\t" + ToolString.AddStrByLength(subjectIndex + "", " ", 3) + "\t" + ToolString.AddStrByLength(string.Join(",", answerList), " ", 10) + "\t[" + string.Join(",", itemList.Select(c => c[0])) + "]", true);
                    }
                }

                ToolFile.CreatFile(tigerPath, builder.ToString(), false);

                return Res;
            }));
        }
Beispiel #5
0
        /// <summary>
        /// 返回选项列表
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public List <string> ItemList(string str, XWPFParagraph para, bool isCheck, int index, bool analysis)
        {
            List <string> list = new List <string>();

            string log = str;

            string t = "";

            if (isCheck)
            {
                t = (char)('A' + index) + "";
            }
            else
            {
                if (analysis)
                {
                    // 获取横排所有选项
                    List <string> tmp = ToolRegular.GetPoint(str, fun1Str5, 0).ToList();

                    for (int i = 0; i < tmp.Count; i++)
                    {
                        string str1 = tmp[i];
                        t = "";

                        str = str.Replace(str1, "灬").Trim();
                        // 获取选项字符
                        for (int j = 0; j < str1.Length; j++)
                        {
                            if ('A' <= str1[j] && str1[j] <= 'Z')
                            {
                                t += str1[j];
                            }
                        }

                        list.Add(t + ".");
                    }
                    tmp = str.Split('灬').Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.Trim()).ToList();

                    try
                    {
                        for (int i = 0; i < tmp.Count; i++)
                        {
                            list[i] += tmp[i];
                        }
                        return(list);
                    }
                    catch (Exception)
                    {
                        ToolFile.CreatFile(@"D:\111.log", log + "\t" + para.ParagraphText, true);
                    }
                }
                else
                {
                    string tmp = ToolRegular.GetPoint(str, fun1Str5, 0).FirstOrDefault();

                    str = str.Replace(tmp, "").Trim();
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        if ('A' <= tmp[i] && tmp[i] <= 'Z')
                        {
                            t += tmp[i];
                        }
                    }
                }
            }

            list.Add(t + "." + str);

            return(list);
        }
Beispiel #6
0
        /// <summary>
        /// 返回所有请求成功的数据
        /// </summary>
        /// <param name="date">几天之内</param>
        /// <returns></returns>
        private Result GetAllPost(int date)
        {
            return(RunFun((logpath, dataPath) =>
            {
                string allSend = "AllSend.log";
                string notSend = "NotSend.json";

                List <GeelyField> notSendList;
                List <string> isSendList;

                // 读取数据库
                if (!File.Exists(dataPath + notSend))
                {
                    string sqlDeclares = GetSqlParam($"Declare @Date int = {date}");

                    notSendList = GeelyField.GetAllPost(sqlDeclares, DbContent);
                    // 初始化,将数据库中已经发送过请求的数据
                    notSendList = GeelyField.GetSendList(notSendList, c => true);
                    // 放入待重新请求文件
                    ToolFile.CreatFile(dataPath + notSend, ToolString.ConvertJson(notSendList), false);
                }
                // 读取文件
                else
                {
                    notSendList = ToolString.ConvertObject <List <GeelyField> >(File.ReadAllText(dataPath + notSend));
                }

                // 过滤已发送的数据
                if (File.Exists(dataPath + allSend))
                {
                    // 所有获取所有已发送列表
                    isSendList = File.ReadAllLines(dataPath + allSend).ToList();
                    foreach (var item in isSendList)
                    {
                        GeelyField geely = notSendList.FirstOrDefault(c => c.cand == item);
                        if (geely != null)
                        {
                            notSendList.Remove(geely);
                        }
                    }
                }

                // 已处理过的数据日志,用于更新
                Res.Msg = dataPath + allSend;
                // 待处理的数据集
                Res.Object = notSendList;

                //foreach (var item in notSendList)
                //{
                //    string url = "http://local.askform.cn/Custom/CampusRecruitment.aspx";
                //    url += "?name=" + item.firstName + "&cand=" + item.cand + "&instr=" + item.instr + "&pid=" + item.pid + "&valid=" + item.valid + "&keyword=" + item.EntryID;

                //    string log = item.cand;

                //    try
                //    {
                //        log += "\t发起请求";
                //        string res = ToolHttp.RequestUrl(url);

                //        log += "\t请求成功";
                //        ToolFile.CreatFile(dataPath + allSend, item.cand, true);
                //    }
                //    catch (Exception ex)
                //    {
                //        log += "\t请求失败:" + ex.Message;
                //    }

                //    WriteLog(logpath, log);
                //}

                return Res;
            }));
        }