Ejemplo n.º 1
0
        GenResult GenerateNinjectConfigBase(Database db, string fileName, string relativePath, bool overwrite)
        {
            string text = File.ReadAllText(fileName);

            ReplaceVars(ref text);

            relativePath = Path.Combine(Path.GetDirectoryName(relativePath), "NinjectConfig.cs");

            var bDal = new StringBuilder();
            var bBll = new StringBuilder();
            foreach (var pair in entities)
            {
                var entity = pair.Value;
                bDal.AppendFormat("\t\t\tkernel.Bind<{0}>().To<{1}>();\r\n", entity.IRepositoryName, entity.RepositoryName);
                bBll.AppendFormat("\t\t\tkernel.Bind<{0}>().To<{1}>();\r\n", entity.IBusinessName, entity.BusinessName);
            }

            Helper.Replace(ref text, "[ConfigDAL]", bDal.ToString());
            Helper.Replace(ref text, "[ConfigBLL]", bBll.ToString());

            return new GenResult
            {
                Code = text,
                Overwrite = overwrite,
                Root = file.DirWeb,
                RelativePath = relativePath,
                FileName = Path.Combine(file.DirWeb, relativePath),
                Info = info
            };
        }
Ejemplo n.º 2
0
        public List<GenResult> Generate(Database db)
        {
            var list = new List<GenResult>();

            var fileNames = Directory.GetFiles(dirTemplate, "*.*", SearchOption.AllDirectories);

            foreach (var fileName in fileNames)
            {
                string name = Path.GetFileName(fileName);

                string relativePath = fileName.Substring(dirTemplate.Length, fileName.Length - dirTemplate.Length);
                if (relativePath.StartsWith("\\"))
                    relativePath = relativePath.Substring(1);
                // retira o nome do primeiro diretório
                relativePath = relativePath.Substring(relativePath.IndexOf("\\"));
                if (relativePath.StartsWith("\\"))
                    relativePath = relativePath.Substring(1);

                vars = new Vars();
                vars.DbName = db.Connection.Database;
                vars.EntityName = null;
                vars.NameSpaceBLL = file.NameSpaceBLL;
                vars.NameSpaceDAL = file.NameSpaceDAL;
                vars.NameSpaceModel = file.NameSpaceModel;
                vars.NameSpaceApp = file.NameSpaceApp;

                // Faz uma chamada sem tabelName, apenas para carregar os demais valores
                vars.SetNames(file, "");

                // por aquivo
                //if (name.Equals("Sys.cs", StringComparison.OrdinalIgnoreCase))
                //{
                //    list.Add(GenerateSys(db, fileName, relativePath, false));
                //}
                //else if (name.Equals("SysBase.cs", StringComparison.OrdinalIgnoreCase))
                //{
                //    list.Add(GenerateSys(db, fileName, relativePath, true));
                //}
                //else if (name.Equals("DALStart.cs", StringComparison.OrdinalIgnoreCase))
                //{
                //    list.Add(GenerateDALStart(db, fileName, relativePath, true));
                //}
                if (name.Equals("Context.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateContext(db, fileName, relativePath, false));
                }
                else if (name.Equals("ContextBase.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateContext(db, fileName, relativePath, true));
                }
                else
                {
                    // por tabelas
                    foreach (var table in tables)
                    {
                        LoadTableVars(table);

                        if (!entities.TryGetValue(table.FullName, out info))
                        {
                            info = new EntityInfo
                            {
                                IRepositoryName = vars.IRepositoryName,
                                RepositoryName = vars.RepositoryName,
                                IBusinessName = vars.IBusinessName,
                                BusinessName = vars.BusinessName
                            };
                            entities.Add(table.FullName, info);
                        }

                        if (name.Equals("EntityBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateEntityBase(table, fileName, relativePath));
                        }
                        else if (name.Equals("Entity.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateEntity(table, fileName, relativePath));
                        }
                        else if (name.Equals("IRepository.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateIRepository(table, fileName, relativePath, false));
                        }
                        else if (name.Equals("IRepositoryBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateIRepository(table, fileName, relativePath, true));
                        }
                        else if (name.Equals("Repository.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateRepository(table, fileName, relativePath, false));
                        }
                        else if (name.Equals("RepositoryBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateRepository(table, fileName, relativePath, true));
                        }
                        else if (name.Equals("Configuration.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateRepositoryConfiguration(table, fileName, relativePath, false));
                        }
                        else if (name.Equals("ConfigurationBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateRepositoryConfiguration(table, fileName, relativePath, true));
                        }
                        else if (name.Equals("IBusiness.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateIBusiness(table, fileName, relativePath, false));
                        }
                        else if (name.Equals("IBusinessBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateIBusiness(table, fileName, relativePath, true));
                        }
                        else if (name.Equals("Business.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateBusiness(table, fileName, relativePath, false));
                        }
                        else if (name.Equals("BusinessBase.cs", StringComparison.OrdinalIgnoreCase))
                        {
                            list.Add(GenerateBusiness(table, fileName, relativePath, true));
                        }
                    }
                }
            }

            foreach (var fileName in fileNames)
            {
                string name = Path.GetFileName(fileName);

                string relativePath = fileName.Substring(dirTemplate.Length, fileName.Length - dirTemplate.Length);
                if (relativePath.StartsWith("\\"))
                    relativePath = relativePath.Substring(1);
                // retira o nome do primeiro diretório
                relativePath = relativePath.Substring(relativePath.IndexOf("\\"));
                if (relativePath.StartsWith("\\"))
                    relativePath = relativePath.Substring(1);

                vars = new Vars();
                vars.DbName = db.Connection.Database;
                vars.EntityName = null;
                vars.NameSpaceBLL = file.NameSpaceBLL;
                vars.NameSpaceDAL = file.NameSpaceDAL;
                vars.NameSpaceModel = file.NameSpaceModel;
                vars.NameSpaceApp = file.NameSpaceApp;
                vars.ContextName = file.Variables.ContextName;

                if (name.Equals("NinjectConfig.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateNinjectConfig(db, fileName, relativePath, false));
                }
                else if (name.Equals("NinjectConfigBase.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateNinjectConfigBase(db, fileName, relativePath, true));
                }
                else if (name.Equals("DryIoCConfig.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateDryIoCConfig(db, fileName, relativePath, false));
                }
                else if (name.Equals("DryIoCConfigBase.cs", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(GenerateDryIoCConfigBase(db, fileName, relativePath, true));
                }
            }

            //checa se o arqvivo existe e se foi alterado
            foreach (var item in list)
            {
                if (!File.Exists(item.FileName))
                {
                    item.FileChanged = EnumFileChanged.New;
                }
                else if (File.ReadAllText(item.FileName).Equals(item.Code))
                {
                    item.FileChanged = EnumFileChanged.Unchanged;
                }
                else
                {
                    item.FileChanged = EnumFileChanged.Modified;
                }
            }

            return list;
        }
Ejemplo n.º 3
0
        GenResult GenerateNinjectConfig(Database db, string fileName, string relativePath, bool overwrite)
        {
            string text = File.ReadAllText(fileName);

            ReplaceVars(ref text);

            //relativePath = Path.Combine(Path.GetDirectoryName(relativePath), vars.ContextName + ".cs");

            return new GenResult
            {
                Code = text,
                Overwrite = overwrite,
                Root = file.DirWeb,
                RelativePath = relativePath,
                FileName = Path.Combine(file.DirWeb, relativePath),
                Info = info
            };
        }