Example #1
0
        public async Task <IEnumerable <string> > DtmiResolver(IReadOnlyCollection <Dtmi> dtmis)
        {
            List <string> resolvedModels = new List <string>();
            List <string> knownDmtis     = new List <string>();

            foreach (var dtmi in dtmis)
            {
                if (!knownDmtis.Contains(dtmi.AbsoluteUri))
                {
                    foreach (string repo in repoList)
                    {
                        logger.LogInformation($"Resolving {dtmi.AbsoluteUri} in repo {repo}.");
                        var path = DtmiConvention.Dtmi2Path(dtmi.AbsoluteUri);

                        string url = repo + path;
                        logger.LogTrace("Request: " + url);
                        if (await http.Head(url, logger))
                        {
                            resolvedModels.Add(await http.Get(url, logger));
                            knownDmtis.Add(dtmi.AbsoluteUri);
                            logger.LogTrace("Found:" + url);
                            break;
                        }
                    }
                }
            }
            return(await Task.FromResult(resolvedModels));
        }
        public async Task <IEnumerable <string> > DtmiResolver(IReadOnlyCollection <Dtmi> dtmis)
        {
            List <string> resolvedModels = new List <string>();

            foreach (var dtmi in dtmis)
            {
                logger.LogInformation($"Resolving {dtmi.AbsoluteUri}");
                var           path = DtmiConvention.Dtmi2Path(dtmi.AbsoluteUri);
                DirectoryInfo di   = new DirectoryInfo(baseFolder);
                string        uri  = di.FullName;
                foreach (var f in path.Split('/'))
                {
                    uri = Path.Combine(uri, f);
                }
                if (File.Exists(uri))
                {
                    logger.LogTrace("Reading: " + uri);
                    resolvedModels.Add(File.ReadAllText(uri));
                    logger.LogTrace("OK:" + uri);
                }
                else
                {
                    logger.LogWarning($"{dtmi.AbsoluteUri} not found in {di.FullName}");
                }
            }
            return(await Task.FromResult(resolvedModels));
        }
        public async Task <IEnumerable <string> > DtmiResolver(IReadOnlyCollection <Dtmi> dtmis)
        {
            List <string> resolvedModels = new List <string>();

            foreach (var dtmi in dtmis)
            {
                logger.LogInformation($"Resolving {dtmi.AbsoluteUri}");
                var    path = DtmiConvention.Dtmi2Path(dtmi.AbsoluteUri);
                string url  = modelRepoUrl + path;
                logger.LogTrace("Request: " + url);
                resolvedModels.Add(await http.Get(url, logger));
                logger.LogTrace("OK:" + url);
            }
            return(await Task.FromResult(resolvedModels));
        }
        public async Task <IEnumerable <string> > DtmiResolver(IReadOnlyCollection <Dtmi> dtmis)
        {
            List <string> resolvedModels = new List <string>();

            foreach (var dtmi in dtmis)
            {
                string path    = DtmiConvention.Dtmi2Path(dtmi.AbsoluteUri);
                var    dlModel = await containerClient.GetBlobClient(path).DownloadAsync();

                using (var sr = new StreamReader(dlModel.Value.Content))
                {
                    resolvedModels.Add(sr.ReadToEnd());
                }
                logger.LogTrace("OK " + path);
            }
            return(await Task.FromResult(resolvedModels));
        }