コード例 #1
0
        internal static async Task <ModelTypeAndContextModel> ValidateModelAndGetEFMetadata(
            CommonCommandLineModel commandLineModel,
            IEntityFrameworkService entityFrameworkService,
            IModelTypesLocator modelTypesLocator,
            string areaName)
        {
            ModelType model       = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", modelTypesLocator);
            ModelType dataContext = ValidationUtil.ValidateType(commandLineModel.DataContextClass, "dataContext", modelTypesLocator, throwWhenNotFound: false);

            // Validation successful
            Contract.Assert(model != null, MessageStrings.ValidationSuccessfull_modelUnset);

            var dbContextFullName = dataContext != null ? dataContext.FullName : commandLineModel.DataContextClass;

            var modelMetadata = await entityFrameworkService.GetModelMetadata(
                dbContextFullName,
                model,
                areaName);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                DbContextFullName = dbContextFullName,
                ContextProcessingResult = modelMetadata
            });
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="logger"></param>
 public XbCodeGenerator(
     IApplicationInfo applicationInfo,
     IServiceProvider serviceProvider,
     IModelTypesLocator modelTypesLocator,
     IEntityFrameworkService entityFrameworkService,
     ILogger logger
     )
 {
     try
     {
         this._applicationInfo = applicationInfo
                                 ?? throw new ArgumentNullException(nameof(applicationInfo));
         this._serviceProvider = serviceProvider
                                 ?? throw new ArgumentNullException(nameof(serviceProvider));
         this._modelTypesLocator = modelTypesLocator
                                   ?? throw new ArgumentNullException(nameof(modelTypesLocator));
         this._entityFrameworkService = entityFrameworkService
                                        ?? throw new ArgumentNullException(nameof(entityFrameworkService));
         this._logger = logger
                        ?? throw new ArgumentNullException(nameof(logger));
     }
     catch (Exception ex)
     {
         this._logger?.LogMessage(Xb.Util.GetErrorHighlighted(ex));
         throw ex;
     }
 }
コード例 #3
0
        public static ModelType ValidateType(string typeName,
                                             string argumentName,
                                             IModelTypesLocator modelTypesLocator,
                                             bool throwWhenNotFound = true)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException(string.Format("Please provide a valid {0}", argumentName));
            }

            var candidateModelTypes = modelTypesLocator.GetType(typeName).ToList();

            int count = candidateModelTypes.Count;

            if (count == 0)
            {
                if (throwWhenNotFound)
                {
                    throw new ArgumentException(string.Format("A type with the name {0} does not exist", typeName));
                }
                return(null);
            }

            if (count > 1)
            {
                throw new ArgumentException(string.Format(
                                                "Multiple types matching the name {0} exist:{1}, please use a fully qualified name",
                                                typeName,
                                                string.Join(",", candidateModelTypes.Select(t => t.Name).ToArray())));
            }

            return(candidateModelTypes.First());
        }
コード例 #4
0
        public ReadMeGenerator(
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IModelTypesLocator modelTypesLocator,
            ILibraryManager libraryManager,
            IApplicationEnvironment environment)
        {
            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            _codeGeneratorActionsService = codeGeneratorActionsService;
            _modelTypesLocator = modelTypesLocator;
            _libraryManager = libraryManager;
            _environment = environment;
        }
コード例 #5
0
        public XbAreaGenerator(
            IApplicationInfo applicationInfo,
            IServiceProvider serviceProvider,
            IModelTypesLocator modelTypesLocator,
            ILogger logger
            )
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            this._serviceProvider   = serviceProvider;
            this._logger            = logger;
            this._appInfo           = applicationInfo;
            this._modelTypesLocator = modelTypesLocator;
        }
コード例 #6
0
        public EntityFrameworkModelProcessor(
            string dbContextFullTypeName,
            ModelType modelTypeSymbol,
            string areaName,
            ICodeGenAssemblyLoadContext loader,
            IDbContextEditorServices dbContextEditorServices,
            IModelTypesLocator modelTypesLocator,
            Workspace workspace,
            IProjectContext projectContext,
            IApplicationInfo applicationInfo,
            IFileSystem fileSystem,
            ILogger logger)
        {
            if (string.IsNullOrEmpty(dbContextFullTypeName))
            {
                throw new ArgumentException(nameof(dbContextFullTypeName));
            }

            _dbContextFullTypeName = dbContextFullTypeName;
            _modelTypeSymbol       = modelTypeSymbol;
            _areaName = areaName;
            _dbContextEditorServices = dbContextEditorServices;
            _modelTypesLocator       = modelTypesLocator;
            _logger          = logger;
            _loader          = loader;
            _projectContext  = projectContext;
            _applicationInfo = applicationInfo;
            _fileSystem      = fileSystem;
            _workspace       = workspace;

            _assemblyAttributeGenerator = GetAssemblyAttributeGenerator();
        }
コード例 #7
0
        public ReadMeGenerator(
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IModelTypesLocator modelTypesLocator,
            IProjectContext projectContext,
            IApplicationInfo applicationInfo)
        {
            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (projectContext == null)
            {
                throw new ArgumentNullException(nameof(projectContext));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            _codeGeneratorActionsService = codeGeneratorActionsService;
            _modelTypesLocator           = modelTypesLocator;
            _projectContext  = projectContext;
            _applicationInfo = applicationInfo;
        }
コード例 #8
0
        public ReadMeGenerator(
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IModelTypesLocator modelTypesLocator,
            ILibraryManager libraryManager,
            IApplicationInfo applicationInfo)
        {
            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            _codeGeneratorActionsService = codeGeneratorActionsService;
            _modelTypesLocator           = modelTypesLocator;
            _libraryManager  = libraryManager;
            _applicationInfo = applicationInfo;
        }
コード例 #9
0
        public static ModelType ValidateType(string typeName,
            string argumentName,
            IModelTypesLocator modelTypesLocator,
            bool throwWhenNotFound = true)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException(string.Format(CodeGenerators.Mvc.MessageStrings.ProvideValidArgument, argumentName));
            }

            var candidateModelTypes = modelTypesLocator.GetType(typeName).ToList();

            int count = candidateModelTypes.Count;
            if (count == 0)
            {
                if (throwWhenNotFound)
                {
                    throw new ArgumentException(string.Format(CodeGenerators.Mvc.MessageStrings.TypeDoesNotExist, typeName));
                }
                return null;
            }

            if (count > 1)
            {
                throw new ArgumentException(string.Format(
                    "Multiple types matching the name {0} exist:{1}, please use a fully qualified name",
                    typeName,
                    string.Join(",", candidateModelTypes.Select(t => t.Name).ToArray())));
            }

            return candidateModelTypes.First();
        }
コード例 #10
0
 public AdvancedGenerator(IModelTypesLocator modelTypesLocator,
                          IApplicationInfo applicationInfo,
                          IProjectContext projectContext,
                          ICodeGeneratorActionsService codeGeneratorActionsService)
 {
     this.modelTypesLocator           = modelTypesLocator;
     this.applicationInfo             = applicationInfo;
     this.projectContext              = projectContext;
     this.codeGeneratorActionsService = codeGeneratorActionsService;
 }
コード例 #11
0
 public ReadMeGenerator(
     [NotNull]ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull]IModelTypesLocator modelTypesLocator,
     [NotNull]ILibraryManager libraryManager,
     [NotNull]IApplicationEnvironment environment)
 {
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator = modelTypesLocator;
     _libraryManager = libraryManager;
     _environment = environment;
 }
コード例 #12
0
 public ReadMeGenerator(
     [NotNull] ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment)
 {
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator           = modelTypesLocator;
     _libraryManager = libraryManager;
     _environment    = environment;
 }
コード例 #13
0
 public DocumentationGenerator(
     IModelTypesLocator modelTypesLocator,
     ICodeGeneratorActionsService codeGeneratorActionsService,
     IServiceProvider serviceProvider,
     Microsoft.Extensions.Logging.ILogger logger)
     : base(PlatformServices.Default.Application)
 {
     ModelTypesLocator           = modelTypesLocator;
     ServiceProvider             = serviceProvider;
     CodeGeneratorActionsService = codeGeneratorActionsService;
 }
コード例 #14
0
        // Todo: Instead of each generator taking services, provide them in some base class?
        // However for it to be effective, it should be property dependecy injection rather
        // than constructor injection.
        public ViewGenerator(
            ILibraryManager libraryManager,
            IApplicationInfo applicationInfo,
            IModelTypesLocator modelTypesLocator,
            IEntityFrameworkService entityFrameworkService,
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IServiceProvider serviceProvider,
            ILogger logger)
            : base(applicationInfo)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (entityFrameworkService == null)
            {
                throw new ArgumentNullException(nameof(entityFrameworkService));
            }

            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _libraryManager = libraryManager;
            _codeGeneratorActionsService = codeGeneratorActionsService;
            _modelTypesLocator           = modelTypesLocator;
            _entityFrameworkService      = entityFrameworkService;
            _serviceProvider             = serviceProvider;
            _logger = logger;
        }
コード例 #15
0
        // Todo: Instead of each generator taking services, provide them in some base class?
        // However for it to be effective, it should be property dependecy injection rather
        // than constructor injection.
        public ViewGenerator(
            ILibraryManager libraryManager,
            IApplicationEnvironment environment,
            IModelTypesLocator modelTypesLocator,
            IEntityFrameworkService entityFrameworkService,
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IServiceProvider serviceProvider,
            ILogger logger)
            : base(environment)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (entityFrameworkService == null)
            {
                throw new ArgumentNullException(nameof(entityFrameworkService));
            }

            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _libraryManager = libraryManager;
            _codeGeneratorActionsService = codeGeneratorActionsService;
            _modelTypesLocator = modelTypesLocator;
            _entityFrameworkService = entityFrameworkService;
            _serviceProvider = serviceProvider;
            _logger = logger;
        }
コード例 #16
0
ファイル: ViewGenerator.cs プロジェクト: nsavga/Scaffolding
 // Todo: Instead of each generator taking services, provide them in some base class?
 // However for it to be effective, it should be property dependecy injection rather
 // than constructor injection.
 public ViewGenerator(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IEntityFrameworkService entityFrameworkService,
     [NotNull] ICodeGeneratorActionsService codeGeneratorActionsService)
 {
     _libraryManager              = libraryManager;
     _applicationEnvironment      = environment;
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator           = modelTypesLocator;
     _entityFrameworkService      = entityFrameworkService;
 }
コード例 #17
0
 public ControllerWithContextGenerator(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IEntityFrameworkService entityFrameworkService,
     [NotNull] ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull] IServiceProvider serviceProvider,
     [NotNull] ILogger logger)
     : base(libraryManager, environment, codeGeneratorActionsService, serviceProvider, logger)
 {
     ModelTypesLocator      = modelTypesLocator;
     EntityFrameworkService = entityFrameworkService;
 }
コード例 #18
0
 public EntityFrameworkServices(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IAssemblyLoaderEngine loader,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IDbContextEditorServices dbContextEditorServices)
 {
     _libraryManager          = libraryManager;
     _environment             = environment;
     _loader                  = loader;
     _modelTypesLocator       = modelTypesLocator;
     _dbContextEditorServices = dbContextEditorServices;
 }
コード例 #19
0
 public SimpleReportGenerator(
     IApplicationInfo applicationInfo,
     IProjectContext projectContext,
     IModelTypesLocator modelTypesLocator,
     IFileSystem fileSystem,
     ILogger logger)
 {
     this.applicationInfo   = applicationInfo;
     this.projectContext    = projectContext;
     this.modelTypesLocator = modelTypesLocator;
     this.fileSystem        = fileSystem;
     this.logger            = logger;
 }
コード例 #20
0
ファイル: SecurityTests.cs プロジェクト: finlaysonc/Coalesce
        public SecurityTests()
        {
            _process     = Processes.StartDotNet();
            _dataContext = DependencyProvider.ProjectContext(@"..\..\..\..\..\Coalesce.Domain");

            IModelTypesLocator typeLocator = DependencyProvider.ModelTypesLocator(_dataContext);
            ModelType          dataModel   = ValidationUtil.ValidateType("AppDbContext", "dataContext", typeLocator, throwWhenNotFound: false);

            _models = ReflectionRepository
                      .AddContext((INamedTypeSymbol)dataModel.TypeSymbol)
                      .Where(m => m.PrimaryKey != null)
                      .ToList();
        }
コード例 #21
0
        public ControllerWithContextGenerator(
            ILibraryManager libraryManager,
            IApplicationEnvironment environment,
            IModelTypesLocator modelTypesLocator,
            IEntityFrameworkService entityFrameworkService,
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IServiceProvider serviceProvider,
            ILogger logger)
            : base(libraryManager, environment, codeGeneratorActionsService, serviceProvider, logger)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (entityFrameworkService == null)
            {
                throw new ArgumentNullException(nameof(entityFrameworkService));
            }

            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            ModelTypesLocator = modelTypesLocator;
            EntityFrameworkService = entityFrameworkService;
        }
コード例 #22
0
        public ControllerWithContextGenerator(
            ILibraryManager libraryManager,
            IApplicationInfo applicationInfo,
            IModelTypesLocator modelTypesLocator,
            IEntityFrameworkService entityFrameworkService,
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IServiceProvider serviceProvider,
            ILogger logger)
            : base(libraryManager, applicationInfo, codeGeneratorActionsService, serviceProvider, logger)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (entityFrameworkService == null)
            {
                throw new ArgumentNullException(nameof(entityFrameworkService));
            }

            if (codeGeneratorActionsService == null)
            {
                throw new ArgumentNullException(nameof(codeGeneratorActionsService));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            ModelTypesLocator      = modelTypesLocator;
            EntityFrameworkService = entityFrameworkService;
        }
コード例 #23
0
        internal static async Task <ModelTypeAndContextModel> ValidateModelAndGetCodeModelMetadata(
            CommonCommandLineModel commandLineModel,
            IEntityFrameworkService entityFrameworkService,
            IModelTypesLocator modelTypesLocator)
        {
            ModelType model = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", modelTypesLocator);

            Contract.Assert(model != null, MessageStrings.ValidationSuccessfull_modelUnset);
            var result = await entityFrameworkService.GetModelMetadata(model);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                ContextProcessingResult = result
            });
        }
コード例 #24
0
 // Todo: Instead of each generator taking services, provide them in some base class?
 // However for it to be effective, it should be property dependecy injection rather
 // than constructor injection.
 public ViewGenerator(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IEntityFrameworkService entityFrameworkService,
     [NotNull] ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull] IServiceProvider serviceProvider,
     [NotNull] ILogger logger)
     : base(environment)
 {
     _libraryManager = libraryManager;
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator           = modelTypesLocator;
     _entityFrameworkService      = entityFrameworkService;
     _serviceProvider             = serviceProvider;
     _logger = logger;
 }
コード例 #25
0
 public EntityFrameworkServices(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IAssemblyLoadContextAccessor loader,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IDbContextEditorServices dbContextEditorServices,
     [NotNull] IPackageInstaller packageInstaller,
     [NotNull] ILogger logger)
 {
     _libraryManager          = libraryManager;
     _environment             = environment;
     _loader                  = loader.GetLoadContext(typeof(EntityFrameworkServices).GetTypeInfo().Assembly);
     _modelTypesLocator       = modelTypesLocator;
     _dbContextEditorServices = dbContextEditorServices;
     _packageInstaller        = packageInstaller;
     _logger                  = logger;
 }
コード例 #26
0
ファイル: ViewGenerator.cs プロジェクト: jamiuaz/Scaffolding
 // Todo: Instead of each generator taking services, provide them in some base class?
 // However for it to be effective, it should be property dependecy injection rather
 // than constructor injection.
 public ViewGenerator(
     [NotNull]ILibraryManager libraryManager,
     [NotNull]IApplicationEnvironment environment,
     [NotNull]IModelTypesLocator modelTypesLocator,
     [NotNull]IEntityFrameworkService entityFrameworkService,
     [NotNull]ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull]IServiceProvider serviceProvider,
     [NotNull]ILogger logger)
 {
     _libraryManager = libraryManager;
     _applicationEnvironment = environment;
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator = modelTypesLocator;
     _entityFrameworkService = entityFrameworkService;
     _serviceProvider = serviceProvider;
     _logger = logger;
 }
コード例 #27
0
        private EntityFrameworkServices GetEfServices(string path, string applicationName, bool useSqlite)
        {
            _appInfo          = new ApplicationInfo(applicationName, Path.GetDirectoryName(path), "Debug");
            _logger           = new ConsoleLogger();
            _packageInstaller = new Mock <IPackageInstaller>();
            _serviceProvider  = new Mock <IServiceProvider>();

            _projectContext    = GetProjectInformation(path);
            _workspace         = new RoslynWorkspace(_projectContext);
            _loader            = new TestAssemblyLoadContext(_projectContext);
            _modelTypesLocator = new ModelTypesLocator(_workspace);
            var dbContextMock        = new Mock <IDbContextEditorServices>();
            var editSyntaxTreeResult = new EditSyntaxTreeResult()
            {
                Edited = true
            };

            dbContextMock.Setup(db => db.EditStartupForNewContext(It.IsAny <ModelType>(),
                                                                  It.IsAny <string>(),
                                                                  It.IsAny <string>(),
                                                                  It.IsAny <string>(),
                                                                  useSqlite))
            .Returns(editSyntaxTreeResult);

            var connectionStringsWriter = new Mock <IConnectionStringsWriter>();

            connectionStringsWriter.Setup(c => c.AddConnectionString(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()));

            var filesLocator       = new FilesLocator();
            var compilationService = new RoslynCompilationService(_appInfo, _loader, _projectContext);
            var templatingService  = new Templating.RazorTemplating(compilationService);

            _dbContextEditorServices = new DbContextEditorServices(_projectContext, _appInfo, filesLocator, templatingService, connectionStringsWriter.Object);

            return(new EntityFrameworkServices(
                       _projectContext,
                       _appInfo,
                       _loader,
                       _modelTypesLocator,
                       _dbContextEditorServices,
                       _packageInstaller.Object,
                       _serviceProvider.Object,
                       _workspace,
                       DefaultFileSystem.Instance,
                       _logger));
        }
コード例 #28
0
 public EntityFrameworkServices(
     [NotNull]ILibraryManager libraryManager,
     [NotNull]IApplicationEnvironment environment,
     [NotNull]IAssemblyLoadContextAccessor loader,
     [NotNull]IModelTypesLocator modelTypesLocator,
     [NotNull]IDbContextEditorServices dbContextEditorServices,
     [NotNull]IPackageInstaller packageInstaller,
     [NotNull]ILogger logger)
 {
     _libraryManager = libraryManager;
     _environment = environment;
     _loader = loader.GetLoadContext(typeof(EntityFrameworkServices).GetTypeInfo().Assembly);
     _modelTypesLocator = modelTypesLocator;
     _dbContextEditorServices = dbContextEditorServices;
     _packageInstaller = packageInstaller;
     _logger = logger;
 }
コード例 #29
0
 public ControllerGenerator(
     [NotNull] ILibraryManager libraryManager,
     [NotNull] IApplicationEnvironment environment,
     [NotNull] IModelTypesLocator modelTypesLocator,
     [NotNull] IEntityFrameworkService entityFrameworkService,
     [NotNull] ICodeGeneratorActionsService codeGeneratorActionsService,
     [NotNull] ITypeActivator typeActivator,
     [NotNull] IServiceProvider serviceProvider,
     [NotNull] ILogger logger)
 {
     _libraryManager              = libraryManager;
     _applicationEnvironment      = environment;
     _codeGeneratorActionsService = codeGeneratorActionsService;
     _modelTypesLocator           = modelTypesLocator;
     _entityFrameworkService      = entityFrameworkService;
     _typeActivator   = typeActivator;
     _serviceProvider = serviceProvider;
     _logger          = logger;
 }
コード例 #30
0
        public ModelBasedViewScaffolder(
            IProjectContext projectContext,
            IApplicationInfo applicationInfo,
            IModelTypesLocator modelTypesLocator,
            IEntityFrameworkService entityFrameworkService,
            ICodeGeneratorActionsService codeGeneratorActionsService,
            IServiceProvider serviceProvider,
            ILogger logger)
            : base(projectContext, applicationInfo, codeGeneratorActionsService, serviceProvider, logger)
        {
            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (entityFrameworkService == null)
            {
                throw new ArgumentNullException(nameof(entityFrameworkService));
            }
            _modelTypesLocator      = modelTypesLocator;
            _entityFrameworkService = entityFrameworkService;
        }
コード例 #31
0
        public static ModelType ValidateType(string typeName,
                                             string argumentName,
                                             IModelTypesLocator modelTypesLocator,
                                             bool throwWhenNotFound = true)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException(string.Format(MessageStrings.ProvideValidArgument, argumentName));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            var candidateModelTypes = modelTypesLocator.GetType(typeName).ToList();

            int count = candidateModelTypes.Count;

            if (count == 0)
            {
                if (throwWhenNotFound)
                {
                    throw new ArgumentException(string.Format(MessageStrings.TypeDoesNotExist, typeName));
                }
                return(null);
            }

            if (count > 1)
            {
                throw new ArgumentException(string.Format(
                                                MessageStrings.MultipleTypesMatchingName,
                                                typeName,
                                                string.Join(",", candidateModelTypes.Select(t => t.Name).ToArray())));
            }

            return(candidateModelTypes.First());
        }
コード例 #32
0
ファイル: ValidationUtil.cs プロジェクト: nsavga/Scaffolding
        public static bool TryValidateType(string typeName,
                                           string argumentName,
                                           IModelTypesLocator modelTypesLocator,
                                           out ITypeSymbol type,
                                           out string errorMessage)
        {
            errorMessage = string.Empty;
            type         = null;

            if (string.IsNullOrEmpty(typeName))
            {
                //Perhaps for these kind of checks, the validation could be in the API.
                errorMessage = string.Format("Please provide a valid {0}", argumentName);
                return(false);
            }

            var candidateModelTypes = modelTypesLocator.GetType(typeName).ToList();

            int count = candidateModelTypes.Count;

            if (count == 0)
            {
                errorMessage = string.Format("A type with the name {0} does not exist", typeName);
                return(false);
            }

            if (count > 1)
            {
                errorMessage = string.Format(
                    "Multiple types matching the name {0} exist:{1}, please use a fully qualified name",
                    typeName,
                    string.Join(",", candidateModelTypes.Select(t => t.Name).ToArray()));
                return(false);
            }

            type = candidateModelTypes.First();
            return(true);
        }
コード例 #33
0
        public EntityFrameworkServices(
            ILibraryManager libraryManager,
            ILibraryExporter libraryExporter,
            IApplicationInfo applicationInfo,
            ICodeGenAssemblyLoadContext loader,
            IModelTypesLocator modelTypesLocator,
            IDbContextEditorServices dbContextEditorServices,
            IPackageInstaller packageInstaller,
            IServiceProvider serviceProvider,
            Workspace workspace,
            ILogger logger)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (libraryExporter == null)
            {
                throw new ArgumentNullException(nameof(libraryExporter));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (dbContextEditorServices == null)
            {
                throw new ArgumentNullException(nameof(dbContextEditorServices));
            }

            if (packageInstaller == null)
            {
                throw new ArgumentNullException(nameof(packageInstaller));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            _libraryManager          = libraryManager;
            _libraryExporter         = libraryExporter;
            _applicationInfo         = applicationInfo;
            _loader                  = loader;
            _modelTypesLocator       = modelTypesLocator;
            _dbContextEditorServices = dbContextEditorServices;
            _packageInstaller        = packageInstaller;
            _serviceProvider         = serviceProvider;
            _logger                  = logger;
            _workspace               = workspace;
        }
コード例 #34
0
        public EntityFrameworkServices(
            ILibraryManager libraryManager,
            ILibraryExporter libraryExporter,
            IApplicationEnvironment environment,
            IAssemblyLoadContextAccessor loader,
            IModelTypesLocator modelTypesLocator,
            IDbContextEditorServices dbContextEditorServices,
            IPackageInstaller packageInstaller,
            IServiceProvider serviceProvider,
            ILogger logger)
        {
            if (libraryManager == null)
            {
                throw new ArgumentNullException(nameof(libraryManager));
            }

            if (libraryExporter == null)
            {
                throw new ArgumentNullException(nameof(libraryExporter));
            }

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (dbContextEditorServices == null)
            {
                throw new ArgumentNullException(nameof(dbContextEditorServices));
            }

            if (packageInstaller == null)
            {
                throw new ArgumentNullException(nameof(packageInstaller));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _libraryManager = libraryManager;
            _libraryExporter = libraryExporter;
            _environment = environment;
            _loader = loader.GetLoadContext(typeof(EntityFrameworkServices).GetTypeInfo().Assembly);
            _modelTypesLocator = modelTypesLocator;
            _dbContextEditorServices = dbContextEditorServices;
            _packageInstaller = packageInstaller;
            _serviceProvider = serviceProvider;
            _logger = logger;
        }
コード例 #35
0
        public EntityFrameworkServices(
            IProjectContext projectContext,
            IApplicationInfo applicationInfo,
            ICodeGenAssemblyLoadContext loader,
            IModelTypesLocator modelTypesLocator,
            IDbContextEditorServices dbContextEditorServices,
            IPackageInstaller packageInstaller,
            IServiceProvider serviceProvider,
            Workspace workspace,
            IFileSystem fileSystem,
            ILogger logger)
        {
            if (projectContext == null)
            {
                throw new ArgumentNullException(nameof(projectContext));
            }

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            if (modelTypesLocator == null)
            {
                throw new ArgumentNullException(nameof(modelTypesLocator));
            }

            if (dbContextEditorServices == null)
            {
                throw new ArgumentNullException(nameof(dbContextEditorServices));
            }

            if (packageInstaller == null)
            {
                throw new ArgumentNullException(nameof(packageInstaller));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            _projectContext          = projectContext;
            _applicationInfo         = applicationInfo;
            _loader                  = loader;
            _modelTypesLocator       = modelTypesLocator;
            _dbContextEditorServices = dbContextEditorServices;
            _packageInstaller        = packageInstaller;
            _serviceProvider         = serviceProvider;
            _logger                  = logger;
            _workspace               = workspace;
            _fileSystem              = fileSystem;
        }