internal void FindVariable(IMethodVariables chain) { if (Variable == null) { Variable = chain.FindVariable(PropertyType); } }
internal void FindVariable(IMethodVariables chain) { if (this.Variable == null) { this.Variable = chain.FindVariable(this.PropertyType); } }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { // This in effect turns into "I need ILogger<IChain> injected into the // compiled class" _logger = chain.FindVariable(typeof(ILogger <IChain>)); yield return(_logger); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { var parameters = Method.GetParameters().ToArray(); for (var i = 0; i < parameters.Length; i++) { if (Arguments[i] != null) { continue; } var param = parameters[i]; Arguments[i] = findVariable(param, chain); } foreach (var variable in Arguments) { yield return(variable); } if (Method.IsStatic || IsLocal) { yield break; } if (Target == null) { Target = chain.FindVariable(HandlerType); } yield return(Target); }
/// <inheritdoc /> protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { var context = variables.FindVariable(typeof(ApiOperationContext)); var currentSpan = context.GetProperty(nameof(ApiOperationContext.ApmSpan)); writer.WriteLine($"{currentSpan}?.{nameof(IApmSpan.RecordException)}({this._exceptionVariable});"); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { if (AggregateType != null) { // You don't need it if you're in a Create method Aggregate = chain.TryFindVariable(AggregateType, VariableSource.All); if (Aggregate != null) { yield return(Aggregate); } } foreach (var inner in _inner.OfType <IEventHandlingFrame>()) { inner.Configure(this); } _event = chain.FindVariable(typeof(IEvent)); yield return(_event); foreach (var inner in _inner) { foreach (var variable in inner.FindVariables(chain)) { yield return(variable); } } }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { yield return(_setter); _scope = chain.FindVariable(typeof(Scope)); yield return(_scope); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _store = chain.FindVariable(typeof(IDocumentStore)); Session = chain.TryFindVariable(typeof(IDocumentSession), VariableSource.NotServices); if (Session == null) { _createsSession = true; Session = new Variable(typeof(IDocumentSession), this); } _isUsingPersistence = chain.IsUsingMartenPersistence(); // Inside of messaging. Not sure how this is gonna work for HTTP yet _context = chain.TryFindVariable(typeof(IMessageContext), VariableSource.NotServices); yield return(_store); if (_context != null) { yield return(_context); } if (Session != null) { yield return(Session); } }
public void Write(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer) { foreach (var frame in this) { frame.GenerateCode(variables, method, writer); } }
/// <inheritdoc /> protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { writer.Block("try"); next(); writer.FinishBlock(); foreach (var handler in this._context.ExceptionHandlers.OrderBy(k => k.Key, new CatchClauseComparer())) { writer.Block($"catch ({handler.Key.FullNameInCode()} e)"); // Key == exception type being caught var exceptionVariable = new Variable(handler.Key, "e"); var allFrames = handler.Value.SelectMany(v => v(exceptionVariable)).ToList(); foreach (var frame in allFrames) { frame.GenerateCode(variables, method, writer); } writer.FinishBlock(); } if (this._context.FinallyFrames.Any()) { writer.Block("finally"); foreach (var frame in this._context.FinallyFrames) { frame.GenerateCode(variables, method, writer); } writer.FinishBlock(); } }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _isUsingPersistence = chain.IsUsingSqlServerPersistence(); _connection = chain.FindVariable(typeof(SqlConnection)); yield return(_connection); if (ShouldFlushOutgoingMessages) { _context = chain.FindVariable(typeof(IMessageContext)); } else { // Inside of messaging. Not sure how this is gonna work for HTTP yet _context = chain.TryFindVariable(typeof(IMessageContext), VariableSource.NotServices); } if (_context != null) { yield return(_context); } }
/// <inheritdoc /> protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { var apiOperationContextVariable = variables.FindVariable(typeof(ApiOperationContext)); var activityVariable = apiOperationContextVariable.GetProperty(nameof(ApiOperationContext.Activity)); var operationTypeKey = ReflectionUtilities.PrettyTypeName(this._context.Descriptor.OperationType); writer.BlankLine(); // 2. For every property of the operation output a value to the exception.Data dictionary. All properties that are // not considered sensitive foreach (var prop in this._context.Descriptor.Properties) { if (SensitiveProperties.IsSensitive(prop)) { continue; } // Only support, for now, primitive values, strings and GUIDs to avoid pushing complex types as tags if (!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum && prop.PropertyType.GetNonNullableType() != typeof(string) && prop.PropertyType.GetNonNullableType() != typeof(Guid)) { continue; } writer.WriteLine( $"{activityVariable}?.{nameof(Activity.SetTag)}(\"{operationTypeKey}.{prop.Name}\", {variables.FindVariable(this._context.Descriptor.OperationType)}.{prop.Name});"); } next(); }
protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { var operationResultName = typeof(OperationResult).FullNameInCode(); if (typeof(OperationResult).IsAssignableFrom(this._resultVariable.VariableType)) { // If the declared type is already a type of OperationResult we can eliminate the ternary operator check and // immediately assign to the operationResult variable writer.WriteLine($"{operationResultName} {this._operationResultVariable} = {this._resultVariable};"); } else if (this._resultVariable.VariableType.IsAssignableFrom(typeof(OperationResult))) { // If the variable type _could_ be an OperationResult then we use a ternary operator to check whether it // actually is, and either use it directly or wrap in an OkResult var okResultName = typeof(OkResult).FullNameInCode(); writer.WriteLine($"{operationResultName} {this._operationResultVariable} = {this._resultVariable} is {operationResultName} r ? " + "r : " + $"new {okResultName}({this._resultVariable});"); } else { // The type is NOT related to OperationResult at all, so we always create a wrapping OkResult var okResultName = typeof(OkResult).FullNameInCode(); writer.WriteLine($"{operationResultName} {this._operationResultVariable} = new {okResultName}({this._resultVariable});"); } next(); }
protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { if (this.ReturnedVariable == null && this._returnType != null) { this.ReturnedVariable = variables.TryFindVariable(this._returnType); } if (this.ReturnedVariable == null) { writer.WriteLine("return;"); } else { var variableIsTask = this.ReturnedVariable.VariableType.IsGenericType && this.ReturnedVariable.VariableType.GetGenericTypeDefinition() == typeof(Task <>); var methodReturnsTask = method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>); // This method does not use async/await but _does_ return Task, but the variable to return is _not_ a Task<>, therefore we // need to use Task.FromResult to get the correct return type if (method.AsyncMode == AsyncMode.None && methodReturnsTask && !variableIsTask) { // What type are we expecting to return? var taskValueType = method.ReturnType.GenericTypeArguments[0]; writer.WriteLine( $"return {typeof(Task).FullNameInCode()}.{nameof(Task.FromResult)}(({taskValueType.FullNameInCode()}){this.ReturnedVariable});"); } else { writer.WriteLine($"return {this.ReturnedVariable};"); } } }
protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { writer.WriteLine( $"var {this._operationVariable} = ({this._operationVariable.VariableType.FullNameInCode()}) {this._operationContextVariable.GetProperty(nameof(ApiOperationContext.Operation))};"); next(); }
protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { var operationVariable = variables.FindVariable(typeof(OperationWithInjectable)); var diVariable = variables.FindVariable(typeof(T)); writer.WriteLine($"{operationVariable}.{nameof(OperationWithInjectable.InjectableProperty)} = {diVariable};"); next(); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _handler = chain.FindVariable(_handlerType); yield return(_handler); _state = chain.FindVariable(_stateType); yield return(_state); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _one = chain.FindVariableByName(typeof(int), "one"); yield return(_one); _two = chain.FindVariableByName(typeof(int), "two"); yield return(_two); }
public Variable Resolve(IMethodVariables variables) { Variable = _name.IsEmpty() ? variables.FindVariable(_variableType) : variables.FindVariableByName(_variableType, _name); return(Variable); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _endpoint = chain.FindVariable(_endpointType); yield return(_endpoint); _context = chain.FindVariable(typeof(ControllerContext)); yield return(_context); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _context = chain.FindVariable(typeof(IMessageContext)); yield return(_context); _dbContext = chain.FindVariable(_dbContextType); yield return(_dbContext); }
protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { var handlerFromSource = variables.FindVariable(typeof(IHandler)); writer.Comment(nameof(CustomFrame)); next(); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _context = chain.FindVariable(typeof(IInvocationContext)); yield return(_messages); yield return(_context); }
/// <inheritdoc /> protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { writer.If($"{this._activityVariable} != null"); writer.WriteLine($"{typeof(ActivityExtensions).FullNameInCode()}.{nameof(ActivityExtensions.SetStatus)}({this._activityVariable}, {this._statusVariableVariable});"); writer.FinishBlock(); next(); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { _message = chain.FindVariable(_messageType); yield return(_message); _envelope = chain.FindVariable(typeof(Envelope)); yield return(_envelope); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { if (_aggregate != null) { yield return(_aggregate); } yield return(_arg); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { yield return(_aggregate); foreach (var variable in Maybe.FindVariables(chain)) { yield return(variable); } }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { foreach (var variable in base.FindVariables(chain)) { yield return(variable); } _operations = chain.FindVariable(typeof(IDocumentOperations)); }
/// <inheritdoc /> protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next) { // Note that we cannot just get a variable of type IApmSpan as _we_ create one, which causes a loop and failed compilation var context = variables.FindVariable(typeof(ApiOperationContext)); var currentSpan = context.GetProperty(nameof(ApiOperationContext.ApmSpan)); writer.WriteLine($"using var {this._spanVariable} = {currentSpan}.{nameof(IApmSpan.StartSpan)}(\"{this._spanKind}\", \"{this._operationName}\", \"{this._type}\");"); next(); }
public override IEnumerable <Variable> FindVariables(IMethodVariables chain) { if (_return != null) { yield return(_return); } _response = chain.FindVariable(typeof(HttpResponse)); yield return(_response); }