Example #1
0
        static void Main(string[] args)
        {
            var           dal  = new PlanDAL();
            DirectoryInfo root = new DirectoryInfo("D:/个人/Cherimoya20161008/Cherimoya20180726/Cherimoya/Mathy.Web/Repository/Plans1");

            FileInfo[] files = root.GetFiles();
            foreach (var n in files.OrderByDescending(m => m.CreationTime))
            {
                var text = File.ReadAllText(n.FullName, Encoding.UTF8);
                var plan = Plan.Parse(text);
                plan.Description = "";
                var f = JsonConvert.SerializeObject(plan);
                dal.AddPlanRepository(n.Name.Replace(".txt", ""), f);
            }
        }
        public ActionResult InitPlanRepo()
        {
            var           path = AppDomain.CurrentDomain.BaseDirectory + @"Repository\Plans";
            DirectoryInfo root = new DirectoryInfo(path);
            var           list = new List <PlanRepositoryEntity>();

            foreach (var n in root.GetFiles())
            {
                var pr = new PlanRepositoryEntity
                {
                    PlanID = n.Name.Split('.')[0],
                    Text   = System.IO.File.ReadAllText(n.FullName)
                };
                var dal = new PlanDAL();
                dal.AddPlanRepository(pr.PlanID, pr.Text);
                list.Add(pr);
            }
            return(Content("完成" + list.Count()));
        }
Example #3
0
        public Plan Save(string id, Stream stream)
        {
            string content = null;

            using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
            {
                content = reader.ReadToEnd();
            }
            Plan plan = null;

            try
            {
                plan = Plan.Parse(content);
            }
            catch (Exception ex)
            {
                throw new Exception("解析试验计划文件错误。\r\n通常是因为实验文件内容错误造成。请检查您的实验文件,或联系相关人员协助解决。\r\n错误信息:\r\n" + ex.Message);
            }
            var dal = new PlanDAL();

            //dal.
            dal.AddPlanRepository(id, content);
            return(plan);
        }