コード例 #1
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (CommentText.IsNotEmpty())
            {
                writer.WriteComment(CommentText);
            }

            var invokeMethod = InvocationCode(method);

            if (shouldWriteInUsingBlock(method))
            {
                writer.UsingBlock($"{returnActionCode(method)}{invokeMethod}", w => Next?.GenerateCode(method, writer));
            }
            else
            {
                writer.Write($"{returnActionCode(method)}{invokeMethod};");

                // This is just to make the generated code a little
                // easier to read
                if (CommentText.IsNotEmpty())
                {
                    writer.BlankLine();
                }

                Next?.GenerateCode(method, writer);
            }
        }
コード例 #2
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.BlankLine();
     writer.WriteComment($"From {nameof(BuildClientFrame)}");
     writer.Write($"var {Client.Usage} = {_factory.Usage}.{nameof(IHttpClientFactory.CreateClient)}(\"{_interfaceType.Name}\");");
     Next?.GenerateCode(method, writer);
 }
コード例 #3
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.BlankLine();
     writer.WriteComment($"From {nameof(FillUrlFrame)}");
     writer.Write($"var {Url.Usage} = $\"{Pattern}\";");
     Next?.GenerateCode(method, writer);
 }
コード例 #4
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteComment("Check if the saga has been completed");
            writer.Write($"BLOCK:if ({_handler.Usage}.{nameof(StatefulSagaOf<string>.IsCompleted)})");
            writer.WriteComment("Delete the saga state entity");
            writer.Write($"{_context.Usage}.{nameof(DbContext.Remove)}({_state.Usage});");
            writer.FinishBlock();
//            writer.Write("BLOCK:else");
//            writer.WriteComment("Persist the saga state entity");
//            writer.Write($"{_context.Usage}.{nameof(DbContext.Add)}({_state.Usage});");
//            writer.FinishBlock();

            writer.BlankLine();

            Next?.GenerateCode(method, writer);
        }
コード例 #5
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteComment(_commentText);

            // It's on you to call through to a possible next
            // frame to let it generate its code
            Next?.GenerateCode(method, writer);
        }
コード例 #6
0
            public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
            {
                writer.WriteComment("Enroll the DbContext & IMessagingContext in the outgoing Jasper outbox transaction");
                writer.Write(
                    $"await {typeof(JasperEnvelopeEntityFrameworkCoreExtensions).FullName}.{nameof(JasperEnvelopeEntityFrameworkCoreExtensions.EnlistInTransaction)}({_context.Usage}, {_dbContext.Usage});");

                Next?.GenerateCode(method, writer);
            }
コード例 #7
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var serializeMethodName = $"{typeof(JsonConvert).FullNameInCode()}.{nameof(JsonConvert.SerializeObject)}";

            writer.BlankLine();
            writer.WriteComment($"From {nameof(SerializeJsonFrame)}");
            writer.Write($"var {Json.Usage} = {serializeMethodName}({_input.Usage});");
            Next?.GenerateCode(method, writer);
        }
コード例 #8
0
ファイル: DeserializeObjectFrame.cs プロジェクト: yuzd/lamar
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var responseContent = $"await {_response.Usage}.Content.ReadAsStringAsync()";
            var methodName      = $"{typeof(JsonConvert).FullNameInCode()}.{nameof(JsonConvert.DeserializeObject)}";

            writer.BlankLine();
            writer.WriteComment($"From {nameof(DeserializeObjectFrame)}");
            writer.Write($"var {ReturnValue.Usage} = {methodName}<{ReturnValue.VariableType.FullNameInCode()}>({responseContent});");
            Next?.GenerateCode(method, writer);
        }
コード例 #9
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (CommentText.IsNotEmpty())
            {
                writer.WriteComment(CommentText);
            }

            var invokeMethod = invocationCode();

            var returnValue = "";

            if (IsAsync)
            {
                #if NET461 || NET48
                if (method.AsyncMode == AsyncMode.AsyncTask)
                {
                    invokeMethod = invokeMethod + ".ConfigureAwait(false)";
                }
#endif
                returnValue = method.AsyncMode == AsyncMode.ReturnFromLastNode ? "return " : "await ";
            }

            var isDisposable = false;
            if (shouldAssignVariableToReturnValue(method))
            {
#if !NET4x
                returnValue = ReturnVariable.VariableType.IsValueTuple() ? $"{ReturnVariable.Usage} = {returnValue}" : $"{ReturnVariable.AssignmentUsage} = {returnValue}";
                #else
                returnValue = $"{ReturnVariable.AssignmentUsage} = {returnValue}";
#endif


                isDisposable = ReturnVariable.VariableType.CanBeCastTo <IDisposable>();
            }

            if (isDisposable && DisposalMode == DisposalMode.UsingBlock)
            {
                writer.UsingBlock($"{returnValue}{invokeMethod}", w => Next?.GenerateCode(method, writer));
            }
            else
            {
                writer.Write($"{returnValue}{invokeMethod};");

                // This is just to make the generated code a little
                // easier to read
                if (CommentText.IsNotEmpty())
                {
                    writer.BlankLine();
                }

                Next?.GenerateCode(method, writer);
            }
        }
コード例 #10
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (_createsSession)
            {
                writer.BlankLine();
                writer.WriteComment("Open a new document session");
                writer.Write(
                    $"BLOCK:using (var {Session.Usage} = {_store.Usage}.{nameof(IDocumentStore.LightweightSession)}())");
            }

            if (_context != null && _isUsingPersistence)
            {
                writer.Write(
                    $"await {typeof(MessageContextExtensions).FullName}.{nameof(MessageContextExtensions.EnlistInTransaction)}({_context.Usage}, {Session.Usage});");
            }

            foreach (var loaded in _loadedDocs)
            {
                loaded.Write(writer, Session);
            }

            Next?.GenerateCode(method, writer);


            foreach (var saved in _saved)
            {
                writer.Write($"{Session.Usage}.{nameof(IDocumentSession.Store)}({saved.Usage});");
            }

            writer.BlankLine();
            writer.WriteComment("Commit the unit of work");
            writer.Write($"await {Session.Usage}.{nameof(IDocumentSession.SaveChangesAsync)}();");

            if (_createsSession)
            {
                writer.FinishBlock();
            }
        }
コード例 #11
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteComment($"Trying to match the pattern '{_route.Pattern}'");

            writer.WriteComment("First check the route length");
            writer.Write($"if ({_segments.Usage}.{nameof(Array.Length)} != {_route.Segments.Count()}) return false;");

            var firstSegment = _route.Segments.OfType <RouteArgument>().First();
            var segments     = _route.Segments.ToArray();

            for (int i = firstSegment.Position; i < segments.Length; i++)
            {
                var segment = segments[i];
                if (segment is Segment path)
                {
                    writer.Write($"if (!{nameof(RouteSelector.Matches)}(segments[{i}], \"{path.SegmentPath}\")) return false;");
                }
            }



            writer.Write("return true;");
        }
コード例 #12
0
ファイル: RouteNode.cs プロジェクト: waqasahmed0323/jasper
        public virtual void WriteSelectCode(ISourceWriter writer)
        {
            foreach (var route in ComplexArgRoutes)
            {
                writer.WriteComment("Look for odd shaped routes with complex parameter structures");
                writer.Write($"if (Matches{route.VariableName}(segments)) return {route.VariableName};");
            }


            if (_children.Any())
            {
                writer.Write($"BLOCK:if (segments.Length > {LeafDepth})");
                foreach (var node in _children)
                {
                    writer.IfCurrentSegmentEquals(Depth, node.Segment, node.WriteSelectCode);
                }

                if (SpreadRoute != null)
                {
                    writer.Return(SpreadRoute);
                }

                writer.ReturnNull();

                writer.FinishBlock();
            }

            foreach (var leaf in Leaves.OrderBy(x => x.LastSegment))
            {
                writer.IfCurrentSegmentEquals(Depth, leaf.LastSegment, w => w.Return(leaf));
            }

            if (TryFindLeafArgRoute(out var leafArg))
            {
                writer.Return(leafArg);
            }

            if (SpreadRoute != null)
            {
                writer.Return(SpreadRoute);
            }

            writer.ReturnNull();
        }
コード例 #13
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (CommentText.IsNotEmpty())
            {
                writer.WriteComment(CommentText);
            }

            var invokeMethod = invocationCode();

            var returnValue = "";

            if (IsAsync)
            {
                returnValue = method.AsyncMode == AsyncMode.ReturnFromLastNode ? "return " : "await ";
            }

            var isDisposable = false;

            if (shouldAssignVariableToReturnValue(method))
            {
#if !NET4x
                returnValue = ReturnVariable.VariableType.IsValueTuple() ? $"{ReturnVariable.Usage} = {returnValue}" : $"var {ReturnVariable.Usage} = {returnValue}";
                #else
                returnValue = $"var {ReturnVariable.Usage} = {returnValue}";
#endif


                isDisposable = ReturnVariable.VariableType.CanBeCastTo <IDisposable>();
            }

            if (isDisposable && DisposalMode == DisposalMode.UsingBlock)
            {
                writer.UsingBlock($"{returnValue}{invokeMethod}", w => Next?.GenerateCode(method, writer));
            }
            else
            {
                writer.Write($"{returnValue}{invokeMethod};");

                Next?.GenerateCode(method, writer);
            }
        }
コード例 #14
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.Write(
                $"await {typeof(JasperEnvelopeEntityFrameworkCoreExtensions).FullName}.{nameof(JasperEnvelopeEntityFrameworkCoreExtensions.EnlistInTransaction)}({_context.Usage}, {Context.Usage});");

            foreach (var loaded in _loadedDocs)
            {
                loaded.Write(writer, Context);
            }

            Next?.GenerateCode(method, writer);


            foreach (var saved in _saved)
            {
                writer.Write($"{Context.Usage}.{nameof(DbContext.Add)}({saved.Usage});");
            }

            writer.BlankLine();
            writer.WriteComment("Commit the unit of work");
            writer.Write($"await {Context.Usage}.{nameof(DbContext.SaveChangesAsync)}();");
        }
コード例 #15
0
 public static void Return(this ISourceWriter writer, Route route)
 {
     writer.WriteComment(route.Description);
     writer.Write($"return {route.VariableName};");
 }
コード例 #16
0
ファイル: Comment.cs プロジェクト: JasperFx/lamar
 public void Write(ISourceWriter writer)
 {
     writer.WriteComment(Text);
 }