public static bool TryReadDiscoveryMetadata(IEngineEnvironmentSettings environmentSettings, string cacheText, ISearchCacheConfig config, out TemplateDiscoveryMetadata discoveryMetadata) { JObject cacheObject = JObject.Parse(cacheText); // add the reader calls, build the model objects if (TryReadVersion(cacheObject, out string version) && TryReadTemplateList(environmentSettings, cacheObject, version, out IReadOnlyList <ITemplateInfo> templateList) && TryReadPackToTemplateMap(cacheObject, out IReadOnlyDictionary <string, PackToTemplateEntry> packToTemplateMap) && TryReadAdditionalData(cacheObject, config.AdditionalDataReaders, out IReadOnlyDictionary <string, object> additionalDta)) { discoveryMetadata = new TemplateDiscoveryMetadata(version, templateList, packToTemplateMap, additionalDta); return(true); } discoveryMetadata = null; return(false); }
public static bool TryReadDiscoveryMetadata(IEngineEnvironmentSettings environment, ISearchCacheConfig config, out TemplateDiscoveryMetadata discoveryMetadata) { Paths paths = new Paths(environment); string pathToConfig = Path.Combine(paths.User.BaseDir, config.TemplateDiscoveryFileName); string cacheText = paths.ReadAllText(pathToConfig); JObject cacheObject = JObject.Parse(cacheText); // add the reader calls, build the model objects if (TryReadVersion(cacheObject, out string version) && TryReadTemplateList(cacheObject, version, out IReadOnlyList <ITemplateInfo> templateList) && TryReadPackToTemplateMap(cacheObject, out IReadOnlyDictionary <string, PackToTemplateEntry> packToTemplateMap) && TryReadAdditionalData(cacheObject, config.AdditionalDataReaders, out IReadOnlyDictionary <string, object> additionalDta)) { discoveryMetadata = new TemplateDiscoveryMetadata(version, templateList, packToTemplateMap, additionalDta); return(true); } discoveryMetadata = null; return(false); }
internal static TemplateSearchCache ConvertTemplateDiscoveryMetadata(TemplateDiscoveryMetadata discoveryMetadata, IReadOnlyDictionary <string, Func <object, object> >?additionalDataReaders) { List <TemplatePackageSearchData> packageData = new List <TemplatePackageSearchData>(); foreach (var package in discoveryMetadata.PackToTemplateMap) { List <TemplateSearchData> templateData = new List <TemplateSearchData>(); foreach (var template in package.Value.TemplateIdentificationEntry) { var foundTemplate = discoveryMetadata.TemplateCache.FirstOrDefault(t => t.Identity.Equals(template.Identity, StringComparison.OrdinalIgnoreCase)); if (foundTemplate == null) { continue; } if (additionalDataReaders != null) { Dictionary <string, object> data = new Dictionary <string, object>(); foreach (var reader in additionalDataReaders) { if (discoveryMetadata.AdditionalData.TryGetValue(reader.Key, out object?legacyData)) { IDictionary?dict = legacyData as IDictionary; if (dict?.Contains(template.Identity) ?? false) { data[reader.Key] = dict[template.Identity]; } } } templateData.Add(new TemplateSearchData(foundTemplate, data)); } else { templateData.Add(new TemplateSearchData(foundTemplate)); } } packageData.Add(new TemplatePackageSearchData(new PackInfo(package.Key, package.Value.Version, package.Value.TotalDownloads, package.Value.Owners, package.Value.Verified), templateData)); } return(new TemplateSearchCache(packageData)); }
public static bool TryReadDiscoveryMetadata(IEngineEnvironmentSettings environmentSettings, ISearchCacheConfig config, out TemplateDiscoveryMetadata discoveryMetadata) { string pathToConfig = Path.Combine(environmentSettings.Paths.HostVersionSettingsDir, config.TemplateDiscoveryFileName); string cacheText = environmentSettings.Host.FileSystem.ReadAllText(pathToConfig); if (TryReadDiscoveryMetadata(environmentSettings, cacheText, config, out discoveryMetadata)) { return(true); } discoveryMetadata = null; return(false); }