Ejemplo n.º 1
0
        public ModelsRepositoryMetadata FetchMetadata(Uri repositoryUri, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(FileModelFetcher)}.{nameof(FetchMetadata)}");
            scope.Start();

            string metadataPath = DtmiConventions.GetMetadataUri(repositoryUri).LocalPath;

            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (File.Exists(metadataPath))
                {
                    string content = File.ReadAllText(metadataPath, Encoding.UTF8);
                    return(JsonSerializer.Deserialize <ModelsRepositoryMetadata>(content));
                }
            }
            catch (OperationCanceledException ex)
            {
                scope.Failed(ex);
                throw;
            }
            catch (Exception ex)
            {
                // Exceptions thrown from fetching Repository Metadata should not be terminal.
                scope.Failed(ex);
            }

            ModelsRepositoryEventSource.Instance.FailureProcessingRepositoryMetadata(metadataPath);
            return(null);
        }
Ejemplo n.º 2
0
        public static void RemoveMetadataFromLocalRepository()
        {
            string metadataFilePath = DtmiConventions.GetMetadataUri(new Uri(TestLocalModelsRepository)).LocalPath;

            if (File.Exists(metadataFilePath))
            {
                File.Delete(metadataFilePath);
            }
        }
Ejemplo n.º 3
0
        public static void AddMetadataToLocalRepository(bool supportsExpanded = true)
        {
            var metadata = new ModelsRepositoryMetadata();

            metadata.Features.Expanded = supportsExpanded;
            string metadataFilePath = DtmiConventions.GetMetadataUri(new Uri(TestLocalModelsRepository)).LocalPath;

            var options = new JsonSerializerOptions {
                WriteIndented = true
            };
            string metadataJsonString = JsonSerializer.Serialize(metadata, options);

            File.WriteAllText(metadataFilePath, metadataJsonString);
        }
Ejemplo n.º 4
0
        public void GetMetadataUri(string repository, string expectedUri)
        {
            Uri metadataUri = DtmiConventions.GetMetadataUri(new Uri(repository));

            metadataUri.AbsoluteUri.Should().Be(expectedUri);
        }