Exemplo n.º 1
0
 private IEnumerable<string> GenerateBinding(Database db)
 {
     List<string> res = new List<string>();
     foreach (DataStructure table in db.Tables)
     {
         res.Add($"Bind<I{table.ClrName}Provider>().To<{table.ClrName}Provider>().InSingletonScope();");
     }
     foreach (DataStructure view in db.Views)
     {
         res.Add($"Bind<I{view.ClrName}Provider>().To<{view.ClrName}Provider>().InSingletonScope();");
     }
     if (db.StoredProcedure.Any())
     {
         res.Add($"Bind<IStoredProcedureProvider>().To<StoredProcedureProvider>().InSingletonScope();");
     }
     return res;
 }
Exemplo n.º 2
0
 public void GenerateModule(Database database)
 {
     try
     {
         string template = ReadTemplate("NinjectModuleTemplate.txt");
         string moduleNamespace = _parameterReaderService.Get<string>("namespace", "module");
         string providerInterfaceNamespace = _parameterReaderService.Get<string>("namespace", "provider", "interface");
         string providerImplNamespace = _parameterReaderService.Get<string>("namespace", "provider", "impl");
         string filePath = _parameterReaderService.Get<string>("output", "baseDirectory");
         template = template.Replace("#NAMESPACE#", moduleNamespace);
         template = template.Replace("#DAL-NAME#", database.Name);
         template = template.Replace("#PROVIDER-NAMESPACE-INTERFACE#", providerInterfaceNamespace);
         template = template.Replace("#PROVIDER-NAMESPACE-IMPL#", providerImplNamespace);
         template = template.Replace("#BINDINGS#", string.Join(Environment.NewLine, GenerateBinding(database)));
         WriteFile(filePath, $"{database.Name}.generated.cs", template);
     }
     catch (Exception ex)
     {
         _logger.Exception(ex);
     }
 }
Exemplo n.º 3
0
 private Database GetDataModel()
 {
     Stopwatch sw = new Stopwatch();
     sw.Start();
     Database res = new Database();
     res.Name = _parameterReaderService.Get<string>("data","default","name");
     res.Tables = _tableProvider.GetAll().Select(t=>_mapper.Map(t)); ;
     foreach (DataStructure table in res.Tables)
     {
         table.Keys = _keyProvider.GetAllTableKeys(table.Name).Select(t => _mapper.Map(t)); ;
     }
     res.Views = _viewProvider.GetAll().Select(t => _mapper.Map(t)); ;
     foreach (DataStructure view in res.Views)
     {
         view.Keys = _keyProvider.GetAllViewKeys(view.Name).Select(t => _mapper.Map<Key>(t)); ;
     }
     res.StoredProcedure = _storedProcedureProvider.GetAll().Select(t => _mapper.Map(t));
     foreach (StoredProcedure storedProcedure in res.StoredProcedure)
     {
         storedProcedure.Parameters = _parameterProvider.GetAllStoredProcedureParameters(storedProcedure.Name).Select(t => _mapper.Map(t));
     }
     sw.Stop();
     return res;
 }