예제 #1
0
        private bool BuildSourceBuilder(SourceBuilder Builder)
        {
            bool forceToRebuild = false;

            if (Builder.SelectedRule.DependencyModulesName != null)
            {
                foreach (string dep in Builder.SelectedRule.DependencyModulesName)
                {
                    if (!sourceBuilders.ContainsKey(dep))
                    {
                        ConsoleHelper.WriteWarning("Dependency [" + dep + "] doesn't exists");
                        continue;
                    }

                    SourceBuilder builder = sourceBuilders[dep];

                    if (builder == null)
                    {
                        return(false);
                    }

                    if (!BuildSourceBuilder(builder))
                    {
                        return(false);
                    }

                    if (builder.State == SourceBuilder.States.Built)
                    {
                        forceToRebuild = true;
                    }
                }
            }

            return(Builder.Build(forceToRebuild));
        }
예제 #2
0
        private static Source[] GetSource()
        {
            var builder = new SourceBuilder(new HostContext(null, null));

            builder.Directory(GetSourcePath("FromFile.Doc.ps1"));
            return(builder.Build());
        }
예제 #3
0
        private string CreateSource(Type type)
        {
            var builder = new SourceBuilder(type, Naming.MakeAccessorName(type));

            var no = 0;

            foreach (var method in type.GetMethods())
            {
                var attribute = method.GetCustomAttribute <MethodAttribute>(true);
                if (attribute == null)
                {
                    throw new AccessorGeneratorException($"Method is not supported for generation. type=[{type.FullName}], method=[{method.Name}]");
                }

                var nodes   = attribute.GetNodes(sqlLoader, option, method);
                var visitor = new ParameterResolveVisitor(method);
                visitor.Visit(nodes);
                var methodMetadata = new MethodMetadata(
                    no,
                    method,
                    attribute.CommandType,
                    attribute.MethodType,
                    (attribute as IReturnValueBehavior)?.ReturnValueAsResult ?? false,
                    nodes,
                    visitor.Parameters,
                    visitor.DynamicParameters);
                builder.AddMethod(methodMetadata);

                no++;
            }

            return(builder.Build());
        }
예제 #4
0
        protected override string ProcessClass(GeneratorExecutionContext context, ISymbol @class,
                                               IEnumerable <IFieldSymbol> fields, INamedTypeSymbol attribute)
        {
            var builder = new SourceBuilder(@class.ContainingNamespace);

            builder.Imports.AddRange(new[] {
                "System",
                "System.Xml.Serialization",
            });
            builder.Classes.AddRange(@class.ContainingTypes().Select(symbol => symbol.Name));
            builder.Classes.Add(@class.Name);

            // create properties for each field
            builder.Code.AddRange(fields.Select(field => ProcessField(context, field, attribute)));

            return(builder.Build());
        }
예제 #5
0
        public async Task <object> Get(string connectionString, string databaseName, string workspaceDir, LibType libType)
        {
            await Task.Yield();

            try
            {
                var scaffolder    = new Scaffolder();
                var sourceBuilder = new SourceBuilder();
                var scriptBuilder = new ScriptGenerator();

                var @namespace  = libType == LibType.Assembly ? "GeneratedNamespace" : "System";
                var contextName = $"{databaseName}Context";

                var userFolder = Environment.GetEnvironmentVariable("LocalAppData");
                var appFolder  = $"{userFolder}\\SqlMapper";
                var directory  = new DirectoryInfo(appFolder);
                if (!directory.Exists)
                {
                    directory.Create();
                }
                var libraryPath = libType == LibType.Assembly ? $"{appFolder}\\generatedAssembly.dll" : $"{appFolder}\\generatedAssembly.csx";
                var scriptPath  = $"{workspaceDir}\\main.csx";

                var queryableExtensionsSource = File.ReadAllText($"{AppContext.BaseDirectory}/IQueryableExtensions.cs");
                var scaffolding = scaffolder.ScaffoldDatabase(connectionString, @namespace, contextName);
                scaffolding.AdditionalFiles.Add(queryableExtensionsSource);

                var libraryData            = sourceBuilder.Build(scaffolding.AllFiles, libType);
                var firstDbsetPropertyName = scriptBuilder.GetPropertyName(scaffolding.DbContextSource);
                var script = scriptBuilder.BuildMainScript(@namespace, contextName, libraryPath, firstDbsetPropertyName);

                File.WriteAllBytes(libraryPath, libraryData);
                File.WriteAllText(scriptPath, script);

                return(new { ScriptPath = scriptPath });
            }
#pragma warning disable 168
            catch (Exception ex)
#pragma warning restore 168
            {
                throw;
            }
        }