internal object CreateInstanceCore(object[] ctorArgs) { Contracts.Assert(Utils.Size(ctorArgs) == CtorTypes.Length + ((RequireEnvironment) ? 1 : 0)); try { if (InstanceGetter != null) { Contracts.Assert(Utils.Size(ctorArgs) == 0); return(InstanceGetter.Invoke(null, null)); } if (Constructor != null) { return(Constructor.Invoke(ctorArgs)); } if (CreateMethod != null) { return(CreateMethod.Invoke(null, ctorArgs)); } } catch (TargetInvocationException ex) { if (ex.InnerException != null && ex.InnerException.IsMarked()) { throw Contracts.Except(ex, "Error during class instantiation"); } else { throw; } } throw Contracts.Except("Can't instantiate class '{0}'", Type.Name); }
private void HandleCreateMethod(CreateMethod createMethod) { Result <Method> methodCreationResult = _repository.CreateMethod(createMethod); if (methodCreationResult.IsFailure) { MethodCreationFailed failedMethod = new MethodCreationFailed( methodCreationResult.Error, createMethod.LoggedInUserId, createMethod.SagaId ); _kafkaProducer.Produce(failedMethod, METHODS_TOPIC); return; } MethodCreated createdMethod = new MethodCreated( methodCreationResult.Value.Id, methodCreationResult.Value.Creator, methodCreationResult.Value.Name, methodCreationResult.Value.ApplicationRate, methodCreationResult.Value.CreationDate, createMethod.LoggedInUserId, createMethod.SagaId ); _kafkaProducer.Produce(createdMethod, METHODS_TOPIC); }
public IActionResult CreateExperimentWithMethods(ExperimentWithMethodsDTO experimentWithMethodsDTO) { long loggedInUserId = GetLoggedInUserIdMockUp(); if (loggedInUserId == -1) { return(Unauthorized()); } CreateExperiment createExperiment = new CreateExperiment(experimentWithMethodsDTO.Experiment.Creator, experimentWithMethodsDTO.Experiment.Name, loggedInUserId); List <CreateMethod> createMethods = new List <CreateMethod>(); foreach (var methodDTO in experimentWithMethodsDTO.Methods) { CreateMethod createMethod = new CreateMethod(methodDTO.Creator, methodDTO.Name, methodDTO.ApplicationRate, loggedInUserId); createMethods.Add(createMethod); } CreateMethods createMethodsCommand = new CreateMethods(createMethods, loggedInUserId); Guid sagaId = Guid.NewGuid(); StartCreatingExperimentWithMethods startCreatingExperimentWithMethods = new StartCreatingExperimentWithMethods(createExperiment, createMethodsCommand, loggedInUserId, sagaId); _kafkaProducer.Produce(startCreatingExperimentWithMethods, EXPERIMENTS_TOPIC); _logger.LogInformation("In Controller about to return"); return(Ok("Currently processing your request...")); }
public GenMethodContext(FileWriter writer, CreateMethod origMethod, CreateMethod method, string?attribute) { Writer = writer; OrigMethod = origMethod; Method = method; Attribute = attribute; }
void BuildCreatorHandle() { var gameType = typeof(T); var defaultCtor = gameType.GetConstructor(Type.EmptyTypes); if (defaultCtor == null) { throw new System.Exception($"类型:{gameType.FullName}无参数的构造方法"); } var method = new DynamicMethod("GetNewObject" , gameType , null , this.GetType() , true); //获取il编辑器 var il = method.GetILGenerator(); //变量声明 var ret = il.DeclareLocal(gameType); il.Emit(OpCodes.Newobj, defaultCtor); il.Emit(OpCodes.Stloc, ret); il.Emit(OpCodes.Ldloc, ret); il.Emit(OpCodes.Ret); CreateHandle = (CreateMethod)method.CreateDelegate(typeof(CreateMethod)); }
public void WriteDocs(FileWriter writer, CreateMethod method, string sectionTitle, Action?writeSection) { const string typeName = "Instruction"; docWriter.BeginWrite(writer); foreach (var doc in method.Docs) { docWriter.WriteDocLine(writer, doc, typeName); } docWriter.WriteLine(writer, string.Empty); if (writeSection is not null) { docWriter.WriteLine(writer, $"# {sectionTitle}"); docWriter.WriteLine(writer, string.Empty); writeSection(); docWriter.WriteLine(writer, string.Empty); } docWriter.WriteLine(writer, "# Arguments"); docWriter.WriteLine(writer, string.Empty); for (int i = 0; i < method.Args.Count; i++) { var arg = method.Args[i]; docWriter.Write($"* `{idConverter.Argument(arg.Name)}`: "); docWriter.WriteDocLine(writer, arg.Doc, typeName); } docWriter.EndWrite(writer); }
public CodeTypeMember BuildCreateMethod(CreateMethod createMethod, DomainClass domainClass) { var method = new CodeMemberMethod(); method.Attributes = MemberAttributes.Public | MemberAttributes.Final; var name = _nameBuilderUtil.CreateCommandName(domainClass, createMethod); method.Parameters.Add(new CodeParameterDeclarationExpression { Type = new CodeTypeReference(name), Name = "command" }); method.Name = $"{createMethod.Name}{domainClass.Name}"; method.ReturnType = new CodeTypeReference("async Task<IActionResult>"); method.Statements.Add(new CodeSnippetExpression($"CreationResult<{domainClass.Name}> createResult = {domainClass.Name}.{createMethod.Name}(command)")); var conditionalStatement = new CodeConditionStatement( new CodeSnippetExpression("createResult.Ok"), new CodeStatement[] { new CodeExpressionStatement(new CodeSnippetExpression("var hookResult = await EventStore.AppendAll(createResult.DomainEvents)")), new CodeConditionStatement( new CodeSnippetExpression("hookResult.Ok"), new CodeStatement[] { new CodeExpressionStatement(new CodeSnippetExpression($"await {domainClass.Name}Repository.{createMethod.Name}{domainClass.Name}(createResult.CreatedEntity)")), new CodeExpressionStatement(new CodeSnippetExpression(@"return new CreatedResult(""uri"", createResult.CreatedEntity)")) }), new CodeExpressionStatement(new CodeSnippetExpression(@"return new BadRequestObjectResult(hookResult.Errors)")) }); method.Statements.Add(conditionalStatement); method.Statements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression($@"new BadRequestObjectResult(createResult.DomainErrors)"))); return(method); }
public GenerateTryMethodContext(FileWriter writer, CreateMethod method, int opCount, string methodName) { Writer = writer; Method = method; OpCount = opCount; MethodName = methodName; TryMethodName = "try_" + methodName; }
public static void Start() { Console.WriteLine("CASE 03"); AutoMapperOperation.Start(); ExtensionMethod.Start(); CreateMethod.Start(); }
public GenMethodContext(FileWriter writer, CreateMethod origMethod, CreateMethod method, string?attribute, List <SplitArg>?splitArgs) { Writer = writer; OrigMethod = origMethod; Method = method; Attribute = attribute; SplitArgs = splitArgs ?? new List <SplitArg>(); }
private static object CheckActivator(CreateMethod activator, out Exception error) { try { error = null; return(activator()); } catch (Exception e) { error = e; return(null); } }
public void Add <TPs, TDs>(CreateMethod create, InitializeMethod method = null) where TPs : TP where TDs : TD { var p = typeof(TPs); var d = typeof(TDs); descProduct.Add(d, p); factories.Add(p, create); methods.Add(p, method); }
public string GetCreate(ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable table) { object[] parms = new object[] { table }; string body = (string)CreateMethod.Invoke(null, parms); if (body.StartsWith(" ")) { body = body.Substring(10); } return(body); }
public GeneratedMethodInfo(CreateMethod method, bool canFail, string rustMethodName, string pythonMethodName, IdentifierConverter rustIdConverter, IdentifierConverter pythonIdConverter) { Method = method; CanFail = canFail; RustMethodName = rustMethodName; PythonMethodName = pythonMethodName; ArgInfos = new MethodArgInfo[method.Args.Count]; for (int i = 0; i < method.Args.Count; i++) { var origName = method.Args[i].Name; var rustName = rustIdConverter.Argument(origName); var pythonName = pythonIdConverter.Argument(origName); ArgInfos[i] = new MethodArgInfo(rustName: rustName, pythonName: pythonName); } }
public IActionResult CreateMethod([FromBody] MethodDTO methodDTO) { long loggedInUserId = GetLoggedInUserIdMockUp(); if (loggedInUserId == -1) { return(Unauthorized()); } CreateMethod createMethod = new CreateMethod(methodDTO.Creator, methodDTO.Name, methodDTO.ApplicationRate, loggedInUserId); _kafkaProducer.Produce(createMethod, METHODS_TOPIC); return(Ok("Currently processing your request...")); }
public GeneratedMethodInfo(CreateMethod method, bool canFail, string rustMethodName, string luaMethodName, IdentifierConverter rustIdConverter, IdentifierConverter luaIdConverter) { Method = method; CanFail = canFail; RustMethodName = rustMethodName; LuaMethodName = luaMethodName; ArgInfos = new MethodArgInfo[method.Args.Count]; Overloads = new(); for (int i = 0; i < method.Args.Count; i++) { var origName = method.Args[i].Name; var rustName = rustIdConverter.Argument(origName); var luaName = luaIdConverter.Argument(origName); ArgInfos[i] = new MethodArgInfo(rustName: rustName, luaName: luaName); } }
public Result <Method> CreateMethod(CreateMethod createMethod) { Method method = new Method(createMethod.Creator, createMethod.Name, createMethod.ApplicationRate); MethodValidator methodValidator = new MethodValidator(); var validationResult = methodValidator.Validate(method); if (!validationResult.IsValid) { return(Result.Fail <Method>(string.Join(" ", validationResult.Errors))); } method.SetId(++lastIdValue); methodsMemoryDatabase.Add(method); return(Result.Ok <Method>(method)); }
/// <summary> /// 迷路を生成する /// </summary> /// <param name="method">迷路の生成方法</param> /// <param name="width">迷路の横幅</param> /// <param name="height">迷路の縦幅</param> /// <returns>false:迷路作成不可</returns> public bool CreateMaze(CreateMethod method, int width, int height) { if (Width < 5 || Width % 2 == 0 || Height < 5 || Height % 2 == 0) { return(false); } Width = width; Height = height; CreateMazeWithExtendMethod(); SetShortestPath(); return(true); }
static bool HasImmediateArg_8_16_32_64(CreateMethod method) { foreach (var arg in method.Args) { switch (arg.Type) { case MethodArgType.UInt8: case MethodArgType.UInt16: case MethodArgType.Int32: case MethodArgType.UInt32: case MethodArgType.Int64: case MethodArgType.UInt64: return(true); } } return(false); }
internal object CreateInstanceCore(object[] ctorArgs) { Contracts.Assert(Utils.Size(ctorArgs) == CtorTypes.Length + ((RequireEnvironment) ? 1 : 0)); if (InstanceGetter != null) { Contracts.Assert(Utils.Size(ctorArgs) == 0); return(InstanceGetter.Invoke(null, null)); } if (Constructor != null) { return(Constructor.Invoke(ctorArgs)); } if (CreateMethod != null) { return(CreateMethod.Invoke(null, ctorArgs)); } throw Contracts.Except("Can't instantiate class '{0}'", Type.Name); }
protected static CreateMethod GetMethod(InstructionGroup group, bool unsigned, bool useReg) { var(regCount, immCount, memCount) = GetOpKindCount(group, useReg); int regId = 1, immId = 1, memId = 1; string doc = group.Operands.Length switch { 0 => "Creates an instruction with no operands", 1 => "Creates an instruction with 1 operand", _ => $"Creates an instruction with {group.Operands.Length} operands", }; var method = new CreateMethod(doc); AddCodeArg(method); int opNum = -1; foreach (var op in group.Operands) { opNum++; switch (op.Split(useReg)) { case InstructionOperand.RegisterMemory: throw new InvalidOperationException(); case InstructionOperand.Register: method.Args.Add(new MethodArg($"op{opNum}: Register", MethodArgType.Register, GetArgName("register", regCount, regId++))); break; case InstructionOperand.Memory: method.Args.Add(new MethodArg($"op{opNum}: Memory operand", MethodArgType.Memory, GetArgName("memory", memCount, memId++))); break; case InstructionOperand.Imm32: method.Args.Add(new MethodArg($"op{opNum}: Immediate value", unsigned ? MethodArgType.UInt32 : MethodArgType.Int32, GetArgName("immediate", immCount, immId++))); break; case InstructionOperand.Imm64: method.Args.Add(new MethodArg($"op{opNum}: Immediate value", unsigned ? MethodArgType.UInt64 : MethodArgType.Int64, GetArgName("immediate", immCount, immId++))); break; default: throw new InvalidOperationException(); } } return(method);
private static CodeMemberMethod MakeCreateMethod(DomainClass domainClass, CreateMethod domainMethod) { var createMethod = new CodeMemberMethod { Name = $"Create{domainClass.Name}", ReturnType = new CodeTypeReference("async Task<IActionResult>") }; createMethod.Parameters.Add(new CodeParameterDeclarationExpression { Type = new CodeTypeReference($"[FromBody] {domainClass.Name}{domainMethod.Name}Command"), Name = "command" }); createMethod.Statements.Add( new CodeSnippetExpression($"return await Handler.Create{domainClass.Name}(command)")); createMethod.Attributes = MemberAttributes.Final | MemberAttributes.Public; return(createMethod); }
// Assumes it's a generic with_*() method (not a specialized method such as with_movsb() etc) public static bool HasTryMethod(CreateMethod method) => HasImmediateArg_8_16_32_64(method);
public static string GetCreateName(StringBuilder sb, CreateMethod method, GenCreateNameArgs genNames) { if (method.Args.Count == 0 || method.Args[0].Type != MethodArgType.Code) { throw new InvalidOperationException(); } sb.Clear(); sb.Append(genNames.CreatePrefix); var args = method.Args; for (int i = 1; i < args.Count; i++) { var arg = args[i]; switch (arg.Type) { case MethodArgType.Register: sb.Append(genNames.Register); break; case MethodArgType.Memory: sb.Append(genNames.Memory); break; case MethodArgType.Int32: sb.Append(genNames.Int32); break; case MethodArgType.UInt32: sb.Append(genNames.UInt32); break; case MethodArgType.Int64: sb.Append(genNames.Int64); break; case MethodArgType.UInt64: sb.Append(genNames.UInt64); break; case MethodArgType.Code: case MethodArgType.RepPrefixKind: case MethodArgType.UInt8: case MethodArgType.UInt16: case MethodArgType.PreferedInt32: case MethodArgType.ArrayIndex: case MethodArgType.ArrayLength: case MethodArgType.ByteArray: case MethodArgType.WordArray: case MethodArgType.DwordArray: case MethodArgType.QwordArray: case MethodArgType.ByteSlice: case MethodArgType.WordSlice: case MethodArgType.DwordSlice: case MethodArgType.QwordSlice: case MethodArgType.BytePtr: case MethodArgType.WordPtr: case MethodArgType.DwordPtr: case MethodArgType.QwordPtr: default: throw new InvalidOperationException(); } } return(sb.ToString()); }
/// <summary> /// Construct the genome factory. /// </summary> /// <param name="theFactory">The factory.</param> /// <param name="thePopulation">The population.</param> public MLMethodGenomeFactory(CreateMethod theFactory, IPopulation thePopulation) { this.factory = theFactory; this.population = thePopulation; }
public void WriteMethodDeclArgs(FileWriter writer, CreateMethod method) { bool comma = false; foreach (var arg in method.Args) { if (comma) { writer.Write(", "); } comma = true; var argName = idConverter.Argument(arg.Name); if (!IsSnakeCase(argName)) { writer.Write(RustConstants.AttributeAllowNonSnakeCase); writer.Write(" "); } writer.Write(argName); writer.Write(": "); switch (arg.Type) { case MethodArgType.Code: writer.Write(genTypes[TypeIds.Code].Name(idConverter)); break; case MethodArgType.Register: writer.Write(genTypes[TypeIds.Register].Name(idConverter)); break; case MethodArgType.RepPrefixKind: writer.Write(genTypes[TypeIds.RepPrefixKind].Name(idConverter)); break; case MethodArgType.Memory: writer.Write("MemoryOperand"); break; case MethodArgType.UInt8: writer.Write("u8"); break; case MethodArgType.UInt16: writer.Write("u16"); break; case MethodArgType.Int32: writer.Write("i32"); break; case MethodArgType.PreferedInt32: case MethodArgType.UInt32: writer.Write("u32"); break; case MethodArgType.Int64: writer.Write("i64"); break; case MethodArgType.UInt64: writer.Write("u64"); break; case MethodArgType.ByteSlice: writer.Write("&[u8]"); break; case MethodArgType.WordSlice: writer.Write("&[u16]"); break; case MethodArgType.DwordSlice: writer.Write("&[u32]"); break; case MethodArgType.QwordSlice: writer.Write("&[u64]"); break; case MethodArgType.ByteArray: case MethodArgType.WordArray: case MethodArgType.DwordArray: case MethodArgType.QwordArray: case MethodArgType.BytePtr: case MethodArgType.WordPtr: case MethodArgType.DwordPtr: case MethodArgType.QwordPtr: case MethodArgType.ArrayIndex: case MethodArgType.ArrayLength: default: throw new InvalidOperationException(); } } }
public string GetCreateName(CreateMethod method, GenCreateNameArgs genNames) => GetCreateName(sb, method, genNames);
private static object CheckActivator(CreateMethod activator) { Exception error; return(CheckActivator(activator, out error)); }
protected void CreateSomeRecords(List<object> list, CreateMethod create) { foreach (var o in list) { create(JObject.FromObject(o)); } }
protected abstract void GenCreateDeclareData(FileWriter writer, CreateMethod method, DeclareDataKind kind);
private static object CheckActivator(CreateMethod activator, out Exception error) { try { error = null; return activator(); } catch (Exception e) { error = e; return null; } }
private static object CheckActivator(CreateMethod activator) { Exception error; return CheckActivator(activator, out error); }
protected abstract void GenCreateDeclareDataArrayLength(FileWriter writer, CreateMethod method, DeclareDataKind kind, ArrayType arrayType);