예제 #1
0
        public SubjectManager(String testdir, subject s, ConfigureManager cm)
        {
            sub = s;
            String        parentdir = cm.getTestsDir() + @"\" + testdir + @"\" + sub.folder + @"\";
            DirectoryInfo subdir    = new DirectoryInfo(parentdir + s.folder);

            if (!subdir.Exists)
            {
                Valid = false;
                return;
            }

            FileInfo[] indata = subdir.GetFiles("*.in");
            if (indata.Length == 0)
            {
                Valid = false;
                return;
            }

            ArrayList pl = new ArrayList();

            for (int i = 0; i < indata.Length; ++i)
            {
                if (File.Exists(parentdir + s.folder + @"\" + Path.GetFileNameWithoutExtension(indata[i].Name) + ".out"))
                {
                    pl.Add(Path.GetFileNameWithoutExtension(indata[i].Name));
                }
            }

            if (pl.Count == 0)
            {
                Valid = false;
                return;
            }

            Pointlist = (String[])pl.ToArray();
        }
        public SubjectManager(String testdir,subject s,ConfigureManager cm)
        {
            sub = s;
            String parentdir = cm.getTestsDir() + @"\" + testdir + @"\" + sub.folder + @"\";
            DirectoryInfo subdir = new DirectoryInfo( parentdir + s.folder);

            if (!subdir.Exists)
            {
                Valid = false;
                return;
            }

            FileInfo[] indata = subdir.GetFiles("*.in");
            if (indata.Length == 0)
            {
                Valid = false;
                return;
            }

            ArrayList pl = new ArrayList();
            for (int i = 0; i < indata.Length; ++i)
            {
                if (File.Exists(parentdir + s.folder + @"\" + Path.GetFileNameWithoutExtension(indata[i].Name) + ".out" ))
                {
                    pl.Add(Path.GetFileNameWithoutExtension(indata[i].Name));
                }
            }

            if (pl.Count == 0)
            {
                Valid = false;
                return;
            }

            Pointlist = (String[]) pl.ToArray();
        }
        public TestInfo getTestInfo(String dir)
        {
            TestInfo ret = new TestInfo();

            JObject obj;
            String json = File.ReadAllText(getTestsDir() + @"\" + dir + @"\test.vanilla");
            try
            {
                obj = (JObject)JsonConvert.DeserializeObject(json);
            }
            catch(JsonReaderException)
            {
                MessageBox.Show(null,"文件夹 " + dir + " 中test.va读取失败!可能是json格式错误!","错误");
                ret.Exists = false;
                return ret;
            }

            ret.Exists = true;
            ret.dir = dir;
            try
            {
                ret.name = obj["info"]["name"].ToString();
                ret.desc = obj["info"]["desc"].ToString();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(null, "测试 " + dir + " 加载失败!","提示");
                ret.Exists = false;
                return ret;
            }

            subject[] sub = new subject[obj["subjects"].Count()];

            for (int i = 0; i < obj["subjects"].Count(); ++i)
            {
                try
                {
                sub[i].name = obj["subjects"][i]["name"].ToString();
                sub[i].memorylimit = int.Parse(obj["subjects"][i]["memorylimit"].ToString());
                sub[i].desc = obj["subjects"][i]["desc"].ToString();
                sub[i].folder = obj["subjects"][i]["folder"].ToString();
                sub[i].option = obj["subjects"][i]["option"].ToString();
                sub[i].points = int.Parse(obj["subjects"][i]["pointscount"].ToString());
                sub[i].timelimit = int.Parse(obj["subjects"][i]["timelimit"].ToString());
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show(null,"测试 " + ret.name + " 加载失败,可能存在缺少项!","提示");
                    ret.Exists = false;
                    return ret;
                }
                catch (FormatException)
                {
                    MessageBox.Show(null, "测试 " + ret.name + " 中test.va存在格式错误!","提示");
                }
            }

            ret.subjects = sub;

            //Additional options
            try
            {
                ret.additional = (JObject)obj["additional"];
            }
            catch (NullReferenceException) { };
            return ret;
        }
예제 #4
0
        public TestInfo getTestInfo(String dir)
        {
            TestInfo ret = new TestInfo();

            JObject obj;
            String  json = File.ReadAllText(getTestsDir() + @"\" + dir + @"\test.vanilla");

            try
            {
                obj = (JObject)JsonConvert.DeserializeObject(json);
            }
            catch (JsonReaderException)
            {
                MessageBox.Show(null, "文件夹 " + dir + " 中test.va读取失败!可能是json格式错误!", "错误");
                ret.Exists = false;
                return(ret);
            }

            ret.Exists = true;
            ret.dir    = dir;
            try
            {
                ret.name = obj["info"]["name"].ToString();
                ret.desc = obj["info"]["desc"].ToString();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(null, "测试 " + dir + " 加载失败!", "提示");
                ret.Exists = false;
                return(ret);
            }


            subject[] sub = new subject[obj["subjects"].Count()];

            for (int i = 0; i < obj["subjects"].Count(); ++i)
            {
                try
                {
                    sub[i].name        = obj["subjects"][i]["name"].ToString();
                    sub[i].memorylimit = int.Parse(obj["subjects"][i]["memorylimit"].ToString());
                    sub[i].desc        = obj["subjects"][i]["desc"].ToString();
                    sub[i].folder      = obj["subjects"][i]["folder"].ToString();
                    sub[i].option      = obj["subjects"][i]["option"].ToString();
                    sub[i].points      = int.Parse(obj["subjects"][i]["pointscount"].ToString());
                    sub[i].timelimit   = int.Parse(obj["subjects"][i]["timelimit"].ToString());
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show(null, "测试 " + ret.name + " 加载失败,可能存在缺少项!", "提示");
                    ret.Exists = false;
                    return(ret);
                }
                catch (FormatException)
                {
                    MessageBox.Show(null, "测试 " + ret.name + " 中test.va存在格式错误!", "提示");
                }
            }

            ret.subjects = sub;

            //Additional options
            try
            {
                ret.additional = (JObject)obj["additional"];
            }
            catch (NullReferenceException) { };
            return(ret);
        }