Exemple #1
0
        public void TestSerializer()
        {
            TempTestClass classA = new TempTestClass
            {
                Id   = 1,
                Name = "NNN",
                Arr  = new[] { 1, 2, 3 }
            };

            string json  = SampleJsonSerializer.Serialize(classA, typeof(TempTestClass));
            string json2 = SampleJsonSerializer.Serialize(classA);

            //序列化是否成功
            Assert.True(json == json2);

            TempTestClass classB = SampleJsonSerializer.DeSerialize(json2, typeof(TempTestClass)) as TempTestClass;

            //反序列化是否成功
            Assert.True(Compare(classA, classB) && Compare(classA, classB));

            json   = json.Replace("NNN", "A");
            classB = SampleJsonSerializer.DeSerialize <TempTestClass>(json);
            TempTestClass classC = SampleJsonSerializer.DeSerialize <TempTestClass>(json2);

            //修改json的情况下是否正确
            Assert.False(Compare(classB, classC));
        }
Exemple #2
0
        /// <summary>
        /// 提交评测任务
        /// </summary>
        /// <param name="context">评测任务</param>
        /// <returns>提交是否成功</returns>
        public override bool Submit(JudgeContext context)
        {
            string         responseStr = HttpClient.UploadString(Config.ResultSubmitUrl, CreateRequestBody(context.Result), 3);
            ServerResponse response    = SampleJsonSerializer.DeSerialize <ServerResponse>(responseStr);

            if (response.Code == ResponseCode.Fail || response.Code == ResponseCode.WrongToken)
            {
                throw new FetcherException(context.Result.SubmitId + " submit failed: " + response.Message);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 尝试取回评测任务
        /// </summary>
        /// <returns>评测任务</returns>
        public override JudgeContext[] Fetch()
        {
            string         responseStr = HttpClient.UploadString(Config.TaskFetchUrl, CreateRequestBody());
            ServerResponse response    = SampleJsonSerializer.DeSerialize <ServerResponse>(responseStr);

            if (response.Code == ResponseCode.NoTask)
            {
                return(new JudgeContext[0]);
            }

            if (response.Code == ResponseCode.Fail || response.Code == ResponseCode.WrongToken)
            {
                throw new FetcherException(response.Message);
            }


            return(CreateTaskContexts(response.Data));
        }
        static ConfigManager()
        {
            FileHelper.TryReadAllText("Config.json", out string configJson);

            if (string.IsNullOrEmpty(configJson)) //创建新配置文件
            {
                Config = new Configuration
                {
                    Languages = GetDefaultLangConfigs(),
                    Databases = GetDefaultDbConfigs(),
                    Password  = RandomString.Next(16)
                };
                Config.AdditionalConfigs.Add("SampleKey", "SampleValue");
            }
            else
            {
                Config = SampleJsonSerializer.DeSerialize <Configuration>(configJson);
            }

            SetIsDbConfigField();
            SaveConfig();
        }