예제 #1
0
 public TextBasedContent(TemplateStandard standard, TemplateFile templateFile, Type source, FileStream filer, string text) : base(standard)
 {
     this.text = text;
     _filer    = filer;
     _source   = source;
     file      = templateFile.ToFile();
 }
        private AutoDispatchResourceHandlerTemplateData(CodeGenerationContext context, CodeGenerationParameter autoDispatchParameter)
        {
            _restResourceName = ClassFormatter.SimpleNameOf(autoDispatchParameter.value);

            var queryStoreProviderParameters = TemplateParameters.With(TemplateParameter.StorageType, StorageType.StateStore).And(TemplateParameter.Model, ModelType.Query);
            var queryStoreProviderName       = new TemplateStandard(TemplateStandardType.StoreProvider).ResolveClassname(queryStoreProviderParameters);
            var aggregateProtocolClassName   = ClassFormatter.SimpleNameOf(autoDispatchParameter.RetrieveRelatedValue(Label.ModelProtocol));

            _parameters = TemplateParameters.With(TemplateParameter.PackageName, ClassFormatter.PackageOf(autoDispatchParameter.value))
                          .And(TemplateParameter.StateName, new TemplateStandard(TemplateStandardType.AggregateState).ResolveClassname(aggregateProtocolClassName))
                          .And(TemplateParameter.Queries, QueriesParameter.From(autoDispatchParameter))
                          .And(TemplateParameter.RestResourceName, Standard().ResolveClassname(_restResourceName))
                          .And(TemplateParameter.UriRoot, autoDispatchParameter.RetrieveRelatedValue(Label.UriRoot))
                          .And(TemplateParameter.RouteDeclarations, RouteDeclarationParameter.From(autoDispatchParameter))
                          .And(TemplateParameter.ModelProtocol, autoDispatchParameter.RetrieveRelatedValue(Label.ModelProtocol))
                          .And(TemplateParameter.ModelActor, autoDispatchParameter.RetrieveRelatedValue(Label.ModelActor))
                          .And(TemplateParameter.HandlersConfigName, autoDispatchParameter.RetrieveRelatedValue(Label.HandlersConfigName))
                          .And(TemplateParameter.StoreProviderName, queryStoreProviderName).And(TemplateParameter.RouteMethod, new List <string>())
                          .And(TemplateParameter.AutoDispatchMappingName, _restResourceName).And(TemplateParameter.UseAutoDispatch, true)
                          .And(TemplateParameter.DataObjectName, new TemplateStandard(TemplateStandardType.DataObject).ResolveClassname(aggregateProtocolClassName))
                          .And(TemplateParameter.UseCqrs, context.ParameterOf <bool>(Label.Cqrs, x => bool.TrueString.ToLower() == x))
                          .AddImports(ResolveImports(context, autoDispatchParameter, queryStoreProviderName));

            DependOn(RouteMethodTemplateData.From(autoDispatchParameter, _parameters));
        }
예제 #3
0
        private static void InferModelParameters(CodeGenerationParameter aggregateParameter, List <ContentBase> contents)
        {
            var modelActor = new TemplateStandard(TemplateStandardType.Aggregate).ResolveClassname(aggregateParameter.value);
            var modelProtocolQualifiedName = ContentQuery.FindFullyQualifiedClassName(new TemplateStandard(TemplateStandardType.AggregateProtocol), aggregateParameter.value, contents);
            var modelActorQualifiedName    = ContentQuery.FindFullyQualifiedClassName(new TemplateStandard(TemplateStandardType.Aggregate), modelActor, contents);

            aggregateParameter.Relate(Label.ModelProtocol, modelProtocolQualifiedName).Relate(Label.ModelActor, modelActorQualifiedName);
        }
예제 #4
0
        private string FindQueryMethodName(string aggregateName, List <TemplateData> queriesTemplateData)
        {
            if (queriesTemplateData == null || queriesTemplateData.Count == 0)
            {
                return(string.Empty);
            }

            string expectedQueriesName = new TemplateStandard(TemplateStandardType.Queries).ResolveClassname(aggregateName);

            return(queriesTemplateData.Select(x => x.Parameters()).Where(x => x.HasValue(TemplateParameter.QueriesName, expectedQueriesName)).Select(x => x.Find <string>(TemplateParameter.QueryAllMethodName)).First());
        }
예제 #5
0
        public static QueriesParameter From(CodeGenerationParameter aggregateParameter, List <ContentBase> contents, bool useCQRS)
        {
            if (!useCQRS)
            {
                return(QueriesParameter.Empty());
            }

            var queriesProtocol = new TemplateStandard(TemplateStandardType.Queries).ResolveClassname(aggregateParameter.value);
            var queriesActor    = new TemplateStandard(TemplateStandardType.QueriesActor).ResolveClassname(aggregateParameter.value);

            return(new QueriesParameter(ContentQuery.FindFullyQualifiedClassName(new TemplateStandard(TemplateStandardType.Queries), queriesProtocol, contents), ContentQuery.FindFullyQualifiedClassName(new TemplateStandard(TemplateStandardType.QueriesActor), queriesActor, contents)));
        }
예제 #6
0
        private static string ResolveMethodSignatureWithParams(CodeGenerationParameter routeSignature)
        {
            var idParameter              = routeSignature.RetrieveRelatedValue(Label.RequireEntityLoading, x => bool.TrueString.ToLower() == x) ? string.Format(_methodParameterPattern, "String", "id") : string.Empty;
            var method                   = AggregateDetail.MethodWithName(routeSignature.Parent(), routeSignature.value);
            var dataClassname            = new TemplateStandard(TemplateStandardType.DataObject).ResolveClassname(routeSignature.Parent().value);
            var dataParameterDeclaration = string.Format(_methodParameterPattern, dataClassname, "data");
            var dataParameter            = method.HasAny(Label.MethodParameter) ? dataParameterDeclaration : "";
            var parameters               = string.Join(", ", new List <string>()
            {
                idParameter, dataParameter
            }.Where(param => param != string.Empty));

            return(string.Format(_methodSignaturePattern, routeSignature.value, parameters));
        }
예제 #7
0
 public void HandleDependencyOutcome(TemplateStandard standard, string outcome) => _parameters.Find <List <string> >(TemplateParameter.HandlerEntries).Add(outcome);
예제 #8
0
 public static IEnumerable <ContentBase> FilterByStandard(TemplateStandard standard, List <ContentBase> contents) => contents.Where(content => content.Has(standard));
예제 #9
0
 public static string FindPackage(TemplateStandard standard, string className, List <ContentBase> contents) => FilterByStandard(standard, contents).Where(content => content.RetrieveClassName() == className).Select(x => x.RetrievePackage()).FirstOrDefault() ?? string.Empty;
예제 #10
0
 public static string FindPackage(TemplateStandard standard, List <ContentBase> contents) => FilterByStandard(standard, contents).Select(x => x.RetrievePackage()).FirstOrDefault() ?? string.Empty;
예제 #11
0
 public static HashSet <string> FindFullyQualifiedClassNames(TemplateStandard standard, List <ContentBase> contents) => new HashSet <string>(FilterByStandard(standard, contents).Select(x => x.RetrieveQualifiedName()));
 public CodeGenerationContext AddContent(TemplateStandard standard, TemplateFile file, string text)
 {
     _contents.Add(ContentBase.With(standard, file, _filer, _source, text));
     return(this);
 }
예제 #13
0
 //TODO: IsPresent will be added
 public static bool Exists(TemplateStandard standard, List <ContentBase> contents) => FilterByStandard(standard, contents).ToList().Any();
예제 #14
0
 public TypeBasedContent(TemplateStandard standard, Type contentType) : base(standard)
 {
     this.contentType = contentType;
 }
예제 #15
0
 public ProtocolBasedContent(TemplateStandard standard, Type contentProtocolType, Type contentType) : base(standard, contentType)
 {
     this.contentProtocolType = contentProtocolType;
 }
예제 #16
0
 protected ContentBase(TemplateStandard standard) => this.standard = standard;
 public CodeGenerationContext AddContent(TemplateStandard standard, Type protocolType, Type actorType)
 {
     _contents.Add(ContentBase.With(standard, protocolType, actorType));
     return(this);
 }
예제 #18
0
 public static HashSet <string> FindClassNames(TemplateStandard standard, string packageName, List <ContentBase> contents) => new HashSet <string>(FilterByStandard(standard, contents).Where(content => content.RetrievePackage() == packageName).Select(x => x.RetrieveClassName()));
 public CodeGenerationContext AddContent(TemplateStandard standard, Type type)
 {
     _contents.Add(ContentBase.With(standard, type));
     return(this);
 }
예제 #20
0
 public static string FindFullyQualifiedClassName(TemplateStandard standard, string className, List <ContentBase> contents) => FindFullyQualifiedClassNames(standard, contents).Where(qualifiedClassName => qualifiedClassName.EndsWith(string.Concat(".", className))).FirstOrDefault() ?? throw new ArgumentException();