Ejemplo n.º 1
0
        internal TemplateSearchData(JObject jObject, ILogger logger, IReadOnlyDictionary <string, Func <object, object> >?additionalDataReaders = null)
        {
            if (jObject is null)
            {
                throw new ArgumentNullException(nameof(jObject));
            }

            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

#pragma warning disable CS0618 // Type or member is obsolete. The code will be moved to TemplateSearchData.Json when BlobStorageTemplateInfo is ready to be removed.
            TemplateInfo = BlobStorageTemplateInfo.FromJObject(jObject);
#pragma warning restore CS0618 // Type or member is obsolete

            //read additional data
            if (additionalDataReaders != null)
            {
                AdditionalData = TemplateSearchCache.ReadAdditionalData(jObject, additionalDataReaders, logger);
            }
            else
            {
                AdditionalData = new Dictionary <string, object>();
            }
        }
Ejemplo n.º 2
0
        private static bool TryReadTemplateList(
            ILogger logger,
            JObject cacheObject,
            out IReadOnlyList <ITemplateInfo>?templateList)
        {
            logger.LogDebug($"Reading template list");
            try
            {
                // This is lifted from TemplateCache.ParseCacheContent - almost identical
                if (cacheObject.TryGetValue(nameof(TemplateDiscoveryMetadata.TemplateCache), StringComparison.OrdinalIgnoreCase, out JToken? templateInfoToken))
                {
                    List <ITemplateInfo> buildingTemplateList = new List <ITemplateInfo>();

                    if (templateInfoToken is JArray arr)
                    {
                        foreach (JToken entry in arr)
                        {
                            if (entry != null && entry.Type == JTokenType.Object)
                            {
                                try
                                {
                                    buildingTemplateList.Add(BlobStorageTemplateInfo.FromJObject((JObject)entry));
                                }
                                catch (ArgumentException ex)
                                {
                                    logger.LogDebug($"Failed to read template info entry, missing mandatory fields. Details: {ex}");
                                }
                            }
                        }
                    }

                    logger.LogDebug($"Successfully read {buildingTemplateList.Count} templates.");
                    templateList = buildingTemplateList;
                    return(true);
                }

                logger.LogDebug($"Failed to read template info entries. Details: no TemplateCache property found.");
                templateList = null;
                return(false);
            }
            catch (Exception ex)
            {
                logger.LogDebug($"Failed to read template info entries. Details: {ex}");
                templateList = null;
                return(false);
            }
        }
        private static bool TryReadTemplateList(
            IEngineEnvironmentSettings environmentSettings,
            JObject cacheObject,
            string cacheVersion,
            out IReadOnlyList <ITemplateInfo> templateList)
        {
            try
            {
                // This is lifted from TemplateCache.ParseCacheContent - almost identical
                if (cacheObject.TryGetValue(nameof(TemplateDiscoveryMetadata.TemplateCache), StringComparison.OrdinalIgnoreCase, out JToken templateInfoToken))
                {
                    List <ITemplateInfo> buildingTemplateList = new List <ITemplateInfo>();

                    if (templateInfoToken is JArray arr)
                    {
                        foreach (JToken entry in arr)
                        {
                            if (entry != null && entry.Type == JTokenType.Object)
                            {
                                try
                                {
                                    buildingTemplateList.Add(BlobStorageTemplateInfo.FromJObject((JObject)entry));
                                }
                                catch (ArgumentException ex)
                                {
                                    environmentSettings.Host.LogDiagnosticMessage($"Failed to read template info entry, missing mandatory fields. Details: {ex}", "Search cache");
                                }
                            }
                        }
                    }

                    templateList = buildingTemplateList;
                    return(true);
                }

                templateList = null;
                return(false);
            }
            catch (Exception ex)
            {
                environmentSettings.Host.LogDiagnosticMessage($"Failed to read template info entries. Details: {ex}", "Search cache");
                templateList = null;
                return(false);
            }
        }