Exemplo n.º 1
0
 public View AddField(string tableName, Type tableType, AbstractField field, string name = null)
 {
     if (!string.IsNullOrEmpty(tableName) && field != null)
     {
         Table table = null;
         if (Tables != null && Tables.Any() && Tables.Any(x => x.Name == tableName))
         {
             table = Tables.FirstOrDefault(x => x.Name == tableName);
         }
         else
         {
             table = new Table()
             {
                 Name = tableName,
                 Type = tableType
             };
             Tables = (Tables == null) ? new[] { table } : Tables.Concat(new[] { table });
         }
         if (table.Fields == null)
         {
             table.Fields = new Dictionary <string, AbstractField>();
         }
         var fieldName = (!string.IsNullOrEmpty(name)) ? name : field.Name;
         if (!table.Fields.ContainsKey(fieldName))
         {
             field.Table = table;
             table.Fields.Add(fieldName, field);
         }
     }
     return(this);
 }
Exemplo n.º 2
0
        public void Compile()
        {
            Console.WriteLine("Start compiling with selected options");

            var elements = Tables.Concat(Views);

            foreach (var tableInfoModel in elements)
            {
                SharedMethods.CompileTable(tableInfoModel, this);
            }

            foreach (var proc in StoredProcs)
            {
                if (proc.Exclude)
                {
                    continue;
                }

                var targetCsName = proc.GetClassName();
                var compiler     = new ProcedureCompiler(TargetDir, targetCsName);
                compiler.CompileHeader        = GenerateCompilerHeader;
                compiler.Namespace            = Namespace;
                compiler.GenerateConfigMethod = GenerateConfigMethod;
                compiler.TableName            = proc.NewTableName;
                if (proc.Parameter.ParamaterSpParams != null)
                {
                    foreach (var spParamter in proc.Parameter.ParamaterSpParams)
                    {
                        var targetType = DbTypeToCsType.GetClrType(spParamter.Type);
                        var spcName    = spParamter.Parameter.Replace("@", "");
                        compiler.AddProperty(spcName, targetType);
                    }
                }

                Console.WriteLine("Compile Procedure {0}", compiler.Name);
                compiler.Compile(new List <ColumInfoModel>(), SplitByType);
            }

            Console.WriteLine("Created all files");
        }
Exemplo n.º 3
0
 public NpgsqlProjectionScenario Then <T>(string schema, string tableName, params T[] documents) where T : class =>
 new NpgsqlProjectionScenario(Resolver, Messages,
                              Tables.Concat(new[] { new Table <T>(schema, tableName, documents) }).ToArray());
Exemplo n.º 4
0
        public void Compile()
        {
            WinConsole.WriteLine("Start compiling with selected options");
            WinConsole.WriteLine("Please define a output Directory");
            if (string.IsNullOrWhiteSpace(TargetDir))
            {
                TargetDir = Program.AutoConsole.GetNextOption();
            }

            TargetDir = Path.GetFullPath(TargetDir);

            Console.WriteLine($"Selected '{TargetDir}'");
            if (TargetDir == "temp")
            {
                TargetDir = Path.GetTempPath();
            }

            if (string.IsNullOrEmpty(TargetDir) || !Directory.Exists(TargetDir))
            {
                WinConsole.WriteLine("Invalid Directory ...");
                return;
            }

            var elements = Tables.Concat(Views).ToArray();

            elements.AsParallel().ForAll(tableInfoModel =>
            {
                SharedMethods.CompileTable(tableInfoModel, this);
            });

            //foreach (var proc in StoredProcs)
            //{
            //	if (proc.Exclude)
            //	{
            //		continue;
            //	}

            //	var targetCsName = proc.GetClassName();
            //	var compiler = new ProcedureCompiler(TargetDir, targetCsName);
            //	compiler.CompileHeader = GenerateCompilerHeader;
            //	compiler.Namespace = Namespace;
            //	compiler.GenerateConfigMethod = GenerateConfigMethod;
            //	compiler.TableName = proc.NewTableName;
            //	if (proc.Parameter.ParamaterSpParams != null)
            //	{
            //		foreach (var spParamter in proc.Parameter.ParamaterSpParams)
            //		{
            //			var targetType = DbTypeToCsType.GetClrType(spParamter.Type);
            //			var spcName = spParamter.Parameter.Replace("@", "");
            //			compiler.AddProperty(spcName, targetType);
            //		}
            //	}

            //	WinConsole.WriteLine("Compile Procedure {0}", compiler.Name);
            //	compiler.Compile(new List<ColumInfoModel>(), SplitByType);
            //}

            if (_optionsIncludeInVsProject)
            {
                WinConsole.WriteLine("Update csproj file");
                WinConsole.WriteLine("Search for csproj file");
                var realPath = Path.GetFullPath(TargetDir)
                               .Split('\\');

                for (var index = 0; index < realPath.Length; index++)
                {
                    var fullPath = realPath.Take(realPath.Length - index).Aggregate((e, f) => e + "\\" + f);
                    WinConsole.WriteLine($"Search in: '{fullPath}'");
                    var hasCsProject = Directory.EnumerateFiles(fullPath, "*.csproj").FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(hasCsProject))
                    {
                        WinConsole.WriteLine($"Found csproj file '{hasCsProject}'");
                        using (var collection = new ProjectCollection())
                        {
                            var proj = collection.LoadProject(hasCsProject);
                            var inProjectFolderName = TargetDir.Remove(0, fullPath.Length);
                            var modified            = false;
                            var pocoFilesInProject  = proj
                                                      .Items
                                                      .Where(e => e.ItemType == "Compile")
                                                      .Select(e =>
                            {
                                var path = Path.GetDirectoryName(e.EvaluatedInclude)
                                           .Trim('\\');
                                return(new
                                {
                                    Item = e,
                                    ScopeOfFolder = path.Equals(inProjectFolderName.Trim('\\')),
                                    Path = e.EvaluatedInclude
                                });
                            })
                                                      .Where(e => e.ScopeOfFolder)
                                                      .ToDictionary(e => e.Path, e => e.Item);

                            var newElements = elements.Select(e =>
                                                              Path.Combine(inProjectFolderName.Trim('\\'), e.GetClassName() + ".cs"))
                                              .ToArray();

                            foreach (var newElement in pocoFilesInProject)
                            {
                                if (newElements.Contains(newElement.Key))
                                {
                                    continue;
                                }
                                proj.RemoveItem(newElement.Value);
                                modified = true;
                            }

                            foreach (var tableInfoModel in elements)
                            {
                                var pathOfNew = Path.Combine(inProjectFolderName.Trim('\\'), tableInfoModel.GetClassName() + ".cs");
                                if (pocoFilesInProject.ContainsKey(pathOfNew))
                                {
                                    continue;
                                }

                                proj.AddItem("Compile", pathOfNew);
                                modified = true;
                            }

                            if (modified)
                            {
                                proj.MarkDirty();
                                proj.Save(hasCsProject);
                            }
                        }

                        break;
                    }
                }
            }

            WinConsole.WriteLine("Created all files");
            RenderMenuAction();
        }