Beispiel #1
0
        public IActionResult Get()
        {
            if (!_isEnabled)
            {
                return(NotFound());
            }

            var uriSegments = _xsdFileInformationProvider.Schemas();

            if (!uriSegments.Any())
            {
                return(Ok(new Dictionary <string, object> [0]));
            }

            return(Ok(
                       uriSegments
                       .Select(uriSegment => _xsdFileInformationProvider.XsdFileInformationByUriSegment(uriSegment))
                       .Select(
                           xsdFileInformation =>
                           new
            {
                description = xsdFileInformation.IsCore()
                                    ? $"Core schema ({xsdFileInformation.SchemaNameMap.LogicalName}) files for the data model"
                                    : $"Extension {xsdFileInformation.SchemaNameMap.LogicalName} blended with Core schema files for the data model",
                name = xsdFileInformation.SchemaNameMap.LogicalName,
                version = xsdFileInformation.Version,
                files = new Uri(
                    GetMetadataAbsoluteUrl("files", xsdFileInformation.SchemaNameMap.UriSegment))
            })));
        }
Beispiel #2
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            if (context.Request.Method != HttpMethods.Get)
            {
                await next(context);

                return;
            }

            var routeMatcher = new RouteMatcher();

            if (!routeMatcher.TryMatch(CreateRouteTemplate(), context.Request.Path, out RouteValueDictionary routeValues))
            {
                await next(context);

                return;
            }

            var schema = routeValues["schema"].ToString();

            var xsdFileInformationByUriSegment = _xsdFileInformationProvider.XsdFileInformationByUriSegment(schema);

            if (xsdFileInformationByUriSegment == default)
            {
                context.Response.StatusCode = StatusCodes.Status404NotFound;
                return;
            }

            string assemblyName          = xsdFileInformationByUriSegment.AssemblyName;
            string fullQualifiedFileName = $"Artifacts/Schemas/{routeValues["file"]}.xsd";

            var embeddedFileProvider = _embeddedFileProviderByAssemblyName.GetOrAdd(
                assemblyName, key => new EmbeddedFileProvider(_assembliesProvider.Get(assemblyName)));

            context.Response.ContentType = "application/xml";
            context.Response.StatusCode  = StatusCodes.Status200OK;

            await context.Response.SendFileAsync(embeddedFileProvider.GetFileInfo(fullQualifiedFileName));

            string CreateRouteTemplate()
            {
                string template = $"metadata/";

                if (_apiSettings.GetApiMode() == ApiMode.YearSpecific)
                {
                    template += RouteConstants.SchoolYearFromRoute;
                }

                if (_apiSettings.GetApiMode() == ApiMode.InstanceYearSpecific)
                {
                    template += RouteConstants.InstanceIdFromRoute;
                    template += RouteConstants.SchoolYearFromRoute;
                }

                return(template + "xsd/{schema}/{file}.xsd");
            }
        }
            public void SetUp()
            {
                _xsdFileInformationProvider = A.Fake <IXsdFileInformationProvider>();

                _assembliesProvider = A.Fake <IAssembliesProvider>();

                A.CallTo(() => _assembliesProvider.Get(A <string> ._))
                .Returns(Assembly.GetAssembly(typeof(Marker_EdFi_Ods_Standard)));

                A.CallTo(() => _xsdFileInformationProvider.XsdFileInformationByUriSegment("ed-fi"))
                .Returns(
                    new XsdFileInformation(
                        "EdFi.Ods.Standard",
                        "3.2.0-c",
                        new SchemaNameMap("Ed-Fi", "edfi", "ed-fi", "EdFi"),
                        new[] { "Ed-Fi-Core.xsd" }));

                A.CallTo(() => _xsdFileInformationProvider.XsdFileInformationByUriSegment("notfound"))
                .Returns(default);