public static void reset() { objectConditionCompiler = null; existConditionCompiler = null; temporalConditionCompiler = null; testConditionCompiler = null; compilerProvider = null; }
private void UpdateSoftware(SoftwareInfo software) { software.Category = CategoryProvider.GetCategory(software); software.Source = SourceProvider.GetSource(software); software.Build = BuildProvider.GetBuild(software); software.Compiler = CompilerProvider.GetCompiler(software); software.Encoding = EncodingProvider.GetEncoding(software); }
public bool CompileClass(string sourceCode, TemplateItem ti) { _ICompiler = CompilerProvider.GetCompilerForTemplate(ti); _ti = ti; _ICompiler.ClassName = _namespace + "ClassWriter" + _ti.OutputFilePrefix + _ti.OutputFileSufix; return(_ICompiler.Compile(sourceCode, _RefAssemblies)); }
public static CompilerProvider getInstance(IRuleCompiler ruleCompiler) { if (compilerProvider == null) { objectConditionCompiler = new ObjectConditionCompiler(ruleCompiler); existConditionCompiler = new ExistConditionCompiler(objectConditionCompiler); temporalConditionCompiler = new TemporalConditionCompiler(ruleCompiler); testConditionCompiler = new TestConditionCompiler(ruleCompiler); compilerProvider = new CompilerProvider(); } return(compilerProvider); }
public static CompilerProvider getInstance(IRuleCompiler ruleCompiler) { if (compilerProvider == null) { objectConditionCompiler = new ObjectConditionCompiler(ruleCompiler); existConditionCompiler = new ExistConditionCompiler(objectConditionCompiler); temporalConditionCompiler = new TemporalConditionCompiler(ruleCompiler); testConditionCompiler = new TestConditionCompiler(ruleCompiler); compilerProvider = new CompilerProvider(); } return compilerProvider; }
private Assembly CompileSourceFiles() { LoggerProvider.EnvironmentLogger.Info(String.Format( "Compiling source files of the module [{0}]...", this.Name)); var sourceFiles = new HashSet <string>(); if (!string.IsNullOrEmpty(this.ProjectFile)) { var projectParser = new DefaultProjectFileParser(); var pfd = projectParser.Parse(System.IO.Path.Combine(this.Path, this.ProjectFile)); foreach (var sourceFile in pfd.SourceFilenames) { sourceFiles.Add(System.IO.Path.Combine(this.Path, sourceFile)); } } if (this.SourceFiles != null) { foreach (var file in this.SourceFiles) { sourceFiles.Add(System.IO.Path.Combine(this.Path, file)); } } //编译模块程序 if (sourceFiles.Count > 0) { var compiler = CompilerProvider.GetCompiler(this.SourceLanguage); var stopwatch = new Stopwatch(); stopwatch.Start(); var projectFilePath = System.IO.Path.Combine(this.Path, this.ProjectFile); var a = compiler.BuildProject(projectFilePath); stopwatch.Stop(); var time = stopwatch.Elapsed; LoggerProvider.EnvironmentLogger.Info(String.Format("Elapsed time: [{0}]", time)); LoggerProvider.EnvironmentLogger.Info(String.Format( "The module [{0}] has been compiled successfully.", this.Name)); return(a); } else { return(null); } }
public override async Task ExecuteAsync() { // 获取并锁定解答的详情。 _sfull = await _client.Lock(_spush.Id); if (_sfull == null) { _log.InfoExt(() => $"Failed to lock {_spush.Id}, move next."); return; } await UpdateQuestionData(); var compiler = CompilerProvider.GetCompiler(_spush.Language); CompileResult asm = compiler.Compile(_sfull.Source); if (asm.HasErrors) { await _client.Update(ClientJudgeModel.CreateCompileError(_spush.Id, asm.Output)); return; } else { await _client.UpdateInLock(_spush.Id, SolutionState.Judging); } IEnumerable <QuestionData> datas; using (var db = new JudgerDbContext()) { var dataIds = _sfull.QuestionDatas .Select(x => x.Id).ToArray(); datas = await db.FindDatasByIds(dataIds); } // Judging using (compiler) { await Judge(datas, asm, compiler.GetEncoding()); } }
private bool PrecheckEnvironment(SolutionPushModel _spush) { if (!CompilerProvider.IsLanguageAvailable(_spush)) { _log.InfoExt(() => string.Format("Skipped compiling {0}, Because {1} compiler is not availabel.", _spush.Id, _spush.Language)); return(false); } var info = new ComputerInfo(); if (info.AvailablePhysicalMemory < _spush.FullMemoryLimitMb * 1024 * 1024) { _log.InfoExt( () => string.Format("Skipped judging {0}, because system memory running low(Req {1}/ Need {2}).", _spush.Id, info.AvailablePhysicalMemory, _spush.FullMemoryLimitMb * 1024 * 1024) ); return(false); } return(true); }
public override async Task ExecuteAsync() { _lockM = await _client.LockProcess2(_spush.Id); if (_lockM == null) { _log.InfoExt($"Failed to lock {_spush.Id}, move next."); return; } await UpdateQuestionProcess2Code(); // _fullM 里面包含 评测进程 的源代码,因此它是 compiler1; // _lockM 里面包含 待评测进程 的源代码,因此它是 compiler2。 using (var judgerCompiler = CompilerProvider.GetCompiler(_fullM.Language)) using (var judgedCompiler = CompilerProvider.GetCompiler(_spush.Language)) { CompileResult res1 = judgerCompiler.Compile(_fullM.Code); if (res1.HasErrors) { await _client.Update(ClientJudgeModel.CreateCompileError(_spush.Id, res1.Output)); // 评测代码 编译失败,属系统错误 return; } CompileResult res2 = judgedCompiler.Compile(_lockM.Source); if (res2.HasErrors) { await _client.Update(ClientJudgeModel.CreateCompileError(_spush.Id, res2.Output)); // 待评测代码 编译失败,属用户错误 return; } await _client.UpdateInLock(_spush.Id, SolutionState.Judging); await Judge(res1, res2, judgedCompiler.GetEncoding()); } }
public override IConditionCompiler getCompiler(IRuleCompiler ruleCompiler) { CompilerProvider.getInstance(ruleCompiler); return(CompilerProvider.temporalConditionCompiler); }
public virtual IConditionCompiler getCompiler(IRuleCompiler ruleCompiler) { CompilerProvider.getInstance(ruleCompiler); return(CompilerProvider.testConditionCompiler); }
/// <summary> /// Compiles controllers into a method. /// </summary> /// <param name="controllers">The controllers to compile.</param> /// <returns>A compiled method of the controllers.</returns> public static MethodInfo CompileControllers(IEnumerable <ApiControllerMethodInfo> controllers, string apiClient) { var helper = new CompilerHelper(); helper.ReturnType = typeof(bool).Name; helper.Parameters.AddRange(new[] { string.Format("Client<{0}> client", apiClient.Replace("+", ".")), "CallSecurity callType", "ushort packetId", "SocketPacket packet" }); helper.Namespaces.AddRange(new[] { "CandyConquer.Security.Api", "CandyConquer.ApiServer", }); var subIdentities = new Dictionary <ushort, List <ApiControllerMethodInfo> >(); var mainIdentities = new Dictionary <ushort, ApiControllerMethodInfo>(); var cases = controllers.Where(method => method.CallAttribute != null) .Select(method => { if (method.CallAttribute.SubIdentity != uint.MaxValue) { if (!subIdentities.ContainsKey(method.CallAttribute.Identity)) { subIdentities.Add(method.CallAttribute.Identity, new List <ApiControllerMethodInfo>()); } subIdentities[method.CallAttribute.Identity].Add(method); return(null); } if (method.CallAttribute.TypeReturner) { mainIdentities.Add(method.CallAttribute.Identity, method); return(null); } string callTypeCheck = string.Empty; switch (method.CallAttribute.CallSecurity) { case CallSecurity.Idle: callTypeCheck = "if (callType != CallSecurity.Idle) return true;"; break; case CallSecurity.NonIdle: callTypeCheck = "if (callType != CallSecurity.NonIdle) return true;"; break; case CallSecurity.Once: callTypeCheck = "if (client.AddOrHasSingleCall(packetId)) return true;"; break; } return(CaseTemplate .Replace("@packetId", method.CallAttribute.Identity.ToString()) .Replace("@callTypeCheck", callTypeCheck) .Replace("@controllerCall", method.Call.Replace("+", "."))); }).Where(method => method != null).ToList(); foreach (var mainCall in mainIdentities) { var subCases = subIdentities[mainCall.Key] .Select(method => { string callTypeCheck = string.Empty; switch (method.CallAttribute.CallSecurity) { case CallSecurity.Idle: callTypeCheck = "if (callType != CallSecurity.Idle) return true;"; break; case CallSecurity.NonIdle: callTypeCheck = "if (callType != CallSecurity.NonIdle) return true;"; break; case CallSecurity.Once: callTypeCheck = "if (client.AddOrHasSingleCall(packetId)) return true;"; break; } return(SubCaseTemplate .Replace("@packetId", method.CallAttribute.SubIdentity.ToString()) .Replace("@callTypeCheck", callTypeCheck) .Replace("@controllerCall", method.Call.Replace("+", "."))); }); var subSwitch = SubCaseSwitchTemplate .Replace("@controllerCall", mainCall.Value.Call.Replace("+", ".")) .Replace("@packetId", mainCall.Key.ToString()) .Replace("@Cases", string.Join("\r\n", subCases)); #if LOCAL subSwitch = subSwitch.Replace("@packetLog", "client.LogPacket(packet, true, true, subPacket.SubTypeObject);"); #else subSwitch = subSwitch.Replace("@packetLog", string.Empty); #endif cases.Add(subSwitch); } helper.Code = SwitchTemplate .Replace("@Cases", string.Join("\r\n", cases)); #if LOCAL helper.Code = helper.Code.Replace("@packetLog", "client.LogPacket(packet, true);"); #else helper.Code = helper.Code.Replace("@packetLog", "client.LogPacket(packet, false);"); #endif var compilerResults = CompilerProvider.Compile <CSharpCodeProvider>(helper); if (compilerResults.Errors != null && compilerResults.Errors.Count > 0) { foreach (var error in compilerResults.Errors) { Console.WriteLine(error); } throw new CompilerException("Failed to compile."); } return(CompilerProvider.FindMethod(compilerResults.CompiledAssembly)); }