Ejemplo n.º 1
0
            protected override void Arrange()
            {
                _codeRepositoryProvider = Stub <ICodeRepositoryProvider>();
                var codeRepositoryHelper = new CodeRepositoryHelper(TestContext.CurrentContext.TestDirectory);

                A.CallTo(() => _codeRepositoryProvider.GetCodeRepositoryByName(A <string> ._))
                .Returns(codeRepositoryHelper[CodeRepositoryConventions.Implementation]);

                A.CallTo(() => _includeExtensionsProvider.IncludePlugins())
                .Returns(false);

                _domainModelDefinitionProvidersProvider = new DomainModelDefinitionProvidersProvider(_codeRepositoryProvider, _includeExtensionsProvider);
            }
        public IEnumerable <AssemblyData> Get()
        {
            if (!_includePluginsProvider.IncludePlugins())
            {
                return(new List <AssemblyData>());
            }

            var path = _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                CodeRepositoryConventions.ExtensionsRepositoryName,
                CodeRepositoryConventions.Extensions);

            var assemblyData = Directory.GetFiles(
                path,
                AssemblyMetadataSearchString,
                SearchOption.AllDirectories)
                               .Select(_assemblyDataHelper.CreateAssemblyData)
                               .ToList();

            assemblyData.ForEach(x => _logger.Debug($"Found file matching '{AssemblyMetadataSearchString}' at '{x.Path}'"));

            return(assemblyData);
        }
        private Dictionary <string, IDomainModelDefinitionsProvider> CreateDomainModelDefinitionsByPath()
        {
            DirectoryInfo[] directoriesToEvaluate;

            var domainModelDefinitionsByPath =
                new Dictionary <string, IDomainModelDefinitionsProvider>(StringComparer.InvariantCultureIgnoreCase);

            string edFiOdsImplementationApplicationPath = _solutionPath;

            string edFiOdsApplicationPath = _solutionPath.Replace(
                CodeRepositoryConventions.EdFiOdsImplementationFolderName,
                CodeRepositoryConventions.EdFiOdsFolderName);

            directoriesToEvaluate = GetProjectDirectoriesToEvaluate(edFiOdsImplementationApplicationPath)
                                    .Concat(GetProjectDirectoriesToEvaluate(edFiOdsApplicationPath))
                                    .ToArray();

            var extensionPaths = _extensionPluginsProviderProvider.GetExtensionLocationPlugins();

            extensionPaths.ToList().ForEach(
                x =>
            {
                if (!Directory.Exists(x))
                {
                    throw new Exception(
                        $"Unable to find extension Location project path  at location {x}.");
                }

                directoriesToEvaluate = directoriesToEvaluate
                                        .Concat(GetProjectDirectoriesToEvaluate(x))
                                        .Append(new DirectoryInfo(x)).ToArray();
            });

            if (_includePluginsProvider.IncludePlugins() && Directory.Exists(_extensionsPath))
            {
                directoriesToEvaluate = directoriesToEvaluate
                                        .Concat(GetProjectDirectoriesToEvaluate(_extensionsPath))
                                        .ToArray();
            }


            var modelProjects = directoriesToEvaluate
                                .Where(p => p.Name.IsExtensionAssembly() || p.Name.IsStandardAssembly());

            foreach (var modelProject in modelProjects)
            {
                var modelsPath = modelProject.Name.IsStandardAssembly()
                    ? StandardModelsPath
                    : ExtensionModelsPath;

                var metadataFile = new FileInfo(Path.Combine(modelProject.FullName, modelsPath));

                Logger.Debug($"Loading ApiModels for {metadataFile}.");

                if (!metadataFile.Exists)
                {
                    throw new Exception(
                              $"Unable to find model definitions file for extensions project {modelProject.Name} at location {metadataFile.FullName}.");
                }

                if (domainModelDefinitionsByPath.ContainsKey(modelProject.Name))
                {
                    throw new Exception($"Cannot process duplicate extension projects for '{modelProject.Name}'.");
                }

                domainModelDefinitionsByPath.Add(
                    modelProject.Name,
                    new DomainModelDefinitionsJsonFileSystemProvider(metadataFile.FullName));
            }

            return(domainModelDefinitionsByPath);

            DirectoryInfo[] GetProjectDirectoriesToEvaluate(string basePath)
            {
                var directory = new DirectoryInfo(basePath);

                if (directory.Exists)
                {
                    return(directory.GetDirectories("", SearchOption.AllDirectories));
                }

                return(new DirectoryInfo[0]);
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <AssemblyData> Get()
        {
            _logger.Debug($"Getting all paths to assemblyMetadata.json");

            // List of known assemblies with the assemblyMetaData.json file
            var assemblyDatas = Directory.GetFiles(
                _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                    CodeRepositoryConventions.Implementation,
                    CodeRepositoryConventions.Application),
                AssemblyMetadataSearchString,
                SearchOption.AllDirectories)
                                .Concat(
                Directory.GetFiles(
                    _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                        CodeRepositoryConventions.Ods,
                        "Application"),
                    AssemblyMetadataSearchString,
                    SearchOption.AllDirectories))
                                .Select(Create)
                                .ToList();

            if (_includePluginsProvider.IncludePlugins())
            {
                var extensionsPath = _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                    CodeRepositoryConventions.ExtensionsFolderName,
                    "Extensions");

                if (Directory.Exists(extensionsPath))
                {
                    assemblyDatas.AddRange(
                        Directory.GetFiles(
                            extensionsPath,
                            AssemblyMetadataSearchString,
                            SearchOption.AllDirectories)
                        .Select(Create)
                        .ToList()
                        );
                }
            }

            // Add database specific code generation... this is a code smell but is a convention. Sql generation should be done in metaed.
            assemblyDatas.Add(
                new AssemblyData
            {
                AssemblyName = "ODS Database Specific",
                Path         = _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                    CodeRepositoryConventions.Ods,
                    CodeRepositoryConventions.Database),
                TemplateSet = TemplateSetConventions.Database,
                IsProfile   = false,
                IsExtension = false,
                SchemaName  = EdFiConventions.PhysicalSchemaName
            });

            // Convention based location of profiles and extensions (backwards compatibility)
            _logger.Debug($"Getting any extension and profile assemblies from the implementation folder");

            var legacyAssemblyDatas = Directory.GetFiles(
                _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                    CodeRepositoryConventions.Implementation,
                    CodeRepositoryConventions.Application),
                ProfilesSearchString,
                SearchOption.AllDirectories)
                                      .Select(
                x => new AssemblyData
            {
                Path         = Path.GetDirectoryName(x),
                TemplateSet  = TemplateSetConventions.Profile,
                AssemblyName = GetAssemblyName(x),
                IsProfile    = true,
                IsExtension  = false,
                SchemaName   = EdFiConventions.PhysicalSchemaName
            })
                                      .Concat(
                Directory.GetFiles(
                    _codeRepositoryProvider.GetResolvedCodeRepositoryByName(
                        CodeRepositoryConventions.Implementation,
                        CodeRepositoryConventions.Application),
                    ExtensionsSearchString,
                    SearchOption.AllDirectories)
                .Select(
                    x =>
            {
                string assemblyName = GetAssemblyName(x);

                string schemaName = _domainModelsDefinitionsProvidersByProjectName[assemblyName]
                                    .GetDomainModelDefinitions()
                                    .SchemaDefinition
                                    .LogicalName;

                return(new AssemblyData
                {
                    Path = Path.GetDirectoryName(x),
                    TemplateSet = TemplateSetConventions.Extension,
                    AssemblyName = assemblyName,
                    IsExtension = true,
                    IsProfile = false,
                    SchemaName = schemaName
                });
            }))
                                      .ToList();

            foreach (AssemblyData legacyAssemblyData in legacyAssemblyDatas
                     .Where(a => !assemblyDatas.Any(x => x.AssemblyName.EqualsIgnoreCase(a.AssemblyName))))
            {
                _logger.Debug($"Adding legacy assembly {legacyAssemblyData.AssemblyName} for processing.");
                assemblyDatas.Add(legacyAssemblyData);
            }

            return(assemblyDatas);

            AssemblyData Create(string assemblyMetadataPath)
            {
                var assemblyMetadata = _jsonFileProvider.Load <AssemblyMetadata>(assemblyMetadataPath);

                bool isExtension = assemblyMetadata.AssemblyModelType.EqualsIgnoreCase(TemplateSetConventions.Extension);

                string assemblyName = GetAssemblyName(assemblyMetadataPath);

                var schemaName = isExtension
                    ? _domainModelsDefinitionsProvidersByProjectName[assemblyName]
                                 .GetDomainModelDefinitions()
                                 .SchemaDefinition.LogicalName
                    : EdFiConventions.ProperCaseName;

                var assemblyData = new AssemblyData
                {
                    AssemblyName = assemblyName,
                    Path         = Path.GetDirectoryName(assemblyMetadataPath),
                    TemplateSet  = assemblyMetadata.AssemblyModelType,
                    IsProfile    = assemblyMetadata.AssemblyModelType.EqualsIgnoreCase(TemplateSetConventions.Profile),
                    SchemaName   = schemaName,
                    IsExtension  = isExtension
                };

                return(assemblyData);
            }
        }