Пример #1
0
 private void OnCleanButtonClick(object sender, RoutedEventArgs e)
 {
     TemplateGenarator.Clear();
     if (string.IsNullOrWhiteSpace(LocationInput.Text))
     {
         WinForms.MessageBox.Show("Please select a root directory", "no root directory", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         var directory = new DirectoryInfo(LocationInput.Text);
         if (!directory.Exists)
         {
             WinForms.MessageBox.Show("Directory not exists select a root directory", "no root directory", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             Action <string> deleteFolder = pathPart =>
             {
                 if (Directory.Exists(directory.FullName + "\\" + pathPart))
                 {
                     Directory.Delete(directory.FullName + "\\" + pathPart, true);
                 }
             };
             deleteFolder("base");
             deleteFolder("Objects");
             deleteFolder("Repositories");
             TemplateGenarator.Clear();
         }
     }
 }
Пример #2
0
        public static void WriteRepositories(List <Repository> repos)
        {
            var basedir    = Settings.RootDirectory + "\\Repositories";
            var core       = basedir + "\\Core";
            var impl       = basedir + "\\Implementation";
            var repository = impl + "\\Repository.cs";

            WriteFolderIfNotExists(basedir);
            WriteFolderIfNotExists(core);
            WriteFolderIfNotExists(impl);

            WriteFile(repository, TemplateGenarator.ReadTemplate("Repository"));

            foreach (var repo in repos)
            {
                WriteRepository(repo, basedir);
            }
        }
Пример #3
0
        public static void WriteBos(List <Bo> bos)
        {
            var directory        = Settings.RootDirectory;
            var objectsDirectory = new DirectoryInfo(directory.FullName + "\\Objects");
            var coreDirectory    = new DirectoryInfo(objectsDirectory.FullName + "\\Core");

            WriteFolderIfNotExists(objectsDirectory.FullName);
            WriteFolderIfNotExists(coreDirectory.FullName);

            var implementationDirectory = new DirectoryInfo(objectsDirectory + "\\Implementation");

            WriteFolderIfNotExists(implementationDirectory.FullName);

            var entity = new FileInfo(implementationDirectory.FullName + "\\Entity.cs");

            WriteFile(entity.FullName, TemplateGenarator.ReadTemplate("Entity"));

            foreach (var bo in bos)
            {
                WriteBo(bo, implementationDirectory.FullName);
            }
        }
Пример #4
0
        public static void WriteBase(List <Repository> repositories, List <View> views, List <Sp> sps)
        {
            var basedir      = Settings.RootDirectory + "\\Base";
            var core         = basedir + "\\Core";
            var impl         = basedir + "\\Implementation";
            var idbcontext   = core + "\\IDbContext.cs";
            var iunitofWork  = core + "\\IUnitOfWork.cs";
            var context      = impl + "\\" + Settings.ProjectName + "Context.cs";
            var unitofWork   = impl + "\\UnitOfWork.cs";
            var boCollection = impl + "\\BoCollection.cs";

            var iconnectionContainer = core + "\\IConnectionContainer.cs";
            var connectionContainer  = impl + "\\ConnectionContainer.cs";
            var iconnectionManager   = core + "\\IConnectionManager.cs";
            var connectionManager    = impl + "\\ConnectionManager.cs";

            WriteFolderIfNotExists(basedir);
            WriteFolderIfNotExists(core);
            WriteFolderIfNotExists(impl);

            var repositoryStringCore  = new StringBuilder();
            var repositoryString      = new StringBuilder();
            var repositoryFieldString = new StringBuilder();

            foreach (var repo in repositories)
            {
                repositoryStringCore.AppendFormat("\n\t\t{0}Repository {0}Repository {{ get; }}", repo.Name);
                repositoryFieldString.AppendFormat("\n\t\tprivate {0}Repository {1};", repo.Name, Converters.Convert.PropertyNameToFieldName(repo.Name) + "Repository");
                repositoryString.AppendFormat("\n\t\tpublic {1}Repository {1}Repository => {0} ?? ({0} = new {1}Repository(_context));", Converters.Convert.PropertyNameToFieldName(repo.Name) + "Repository", repo.Name);
            }

            var viewString = new StringBuilder();

            foreach (var view in views)
            {
                viewString.AppendFormat("\n\t\tpublic List<{0}Bo> {0}(object where=null){{return _context.QueryView<{0}Bo>(\"{0}\",where);}}", view.Name);
            }

            var spString = new StringBuilder();

            foreach (var sp in sps)
            {
                var parameters          = sp.StoredProcedure.Arguments;
                var parameterString     = parameters.Aggregate("", (current, param) => current + string.Format("{0} {1}", param.DataType.NetDataTypeCSharpName, param.Name) + ",");
                var parameterPassString = parameters.Aggregate("", (current, param) => current + string.Format("'\"+{0}+\"'", param.Name) + ",");
                spString.AppendFormat("\n\t\tpublic List<{0}Bo> {0}({1}){{ return _context.Query<{0}Bo>(\"EXEC {0} {2}\");}}", sp.StoredProcedure.Name, parameterString.TrimEnd(','), parameterPassString.TrimEnd(','));
            }

            WriteFile(iunitofWork, TemplateGenarator.ReadTemplate("IUnitOfWork").Replace("$repositories$", repositoryStringCore.ToString()));
            WriteFile(idbcontext, TemplateGenarator.ReadTemplate("IDbContext"));
            WriteFile(context, TemplateGenarator.ReadTemplate("Context"));
            WriteFile(unitofWork, TemplateGenarator.ReadTemplate("UnitOfWork")
                      .Replace("$repositories$", repositoryString.ToString())
                      .Replace("$repoFields$", repositoryFieldString.ToString())
                      .Replace("$views$", viewString.ToString())
                      .Replace("$storedProcedures$", spString.ToString()));
            WriteFile(boCollection, TemplateGenarator.ReadTemplate("BoCollection"));
            WriteFile(iconnectionContainer, TemplateGenarator.ReadTemplate("IConnectionContainer"));
            WriteFile(iconnectionManager, TemplateGenarator.ReadTemplate("IConnectionManager"));
            WriteFile(connectionContainer, TemplateGenarator.ReadTemplate("ConnectionContainer"));
            WriteFile(connectionManager, TemplateGenarator.ReadTemplate("ConnectionManager"));
        }