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); }
public static void RemoveMetadataFromLocalRepository() { string metadataFilePath = DtmiConventions.GetMetadataUri(new Uri(TestLocalModelsRepository)).LocalPath; if (File.Exists(metadataFilePath)) { File.Delete(metadataFilePath); } }
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); }
public void GetMetadataUri(string repository, string expectedUri) { Uri metadataUri = DtmiConventions.GetMetadataUri(new Uri(repository)); metadataUri.AbsoluteUri.Should().Be(expectedUri); }