Ejemplo n.º 1
0
        public bool Process(FileContext fileContext, Stream stream)
        {
            var contextPrefix = LogContext.BuildContextPrefix(Path.GetFileNameWithoutExtension(fileContext.FileName));

            if (fileContext.NumberOfIdRefs == 0)
            {
                _log.Debug($"{contextPrefix} No file references are found. Skipping preload of references.");
                return(true);
            }

            var sw = new Stopwatch();

            sw.Start();

            var referenceCache = _referenceCacheProvider.GetXmlReferenceCache(fileContext.FileName);

            using (var reader = new XmlTextReader(stream))
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    var id = reader.GetAttribute("id");

                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }

                    using (var r = reader.ReadSubtree())
                    {
                        var referenceSource = XElement.Load(r);
                        referenceCache.PreloadReferenceSource(id, referenceSource);
                    }
                }

                _log.Info($"{contextPrefix} {referenceCache.NumberOfLoadedReferences} references preloaded.");
            }

            sw.Stop();

            _log.Debug($"{contextPrefix} finished preloading in {sw.Elapsed.TotalSeconds} seconds.");
            return(true);
        }
Ejemplo n.º 2
0
        public bool Process(FileContext fileContext, Stream stream)
        {
            var contextPrefix = LogContext.BuildContextPrefix(Path.GetFileNameWithoutExtension(fileContext.FileName));

            if (fileContext.NumberOfIdRefs == 0)
            {
                _log.Debug($"{contextPrefix} No file references are found. Skipping finding references.");
                return(true);
            }

            var sw = new Stopwatch();

            sw.Start();

            var total          = 0;
            var referenceCache = _referenceCacheProvider.GetXmlReferenceCache(fileContext.FileName);

            using (var reader = new XmlTextReader(stream))
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    var refId = reader.GetAttribute("ref");

                    if (!string.IsNullOrEmpty(refId))
                    {
                        referenceCache.LoadReference(refId);
                        total++;
                    }
                }

                _log.Info($"{contextPrefix} {total} references to {referenceCache.NumberOfReferences} resources found");
            }

            sw.Stop();

            _log.Debug($"Finished finding references in {sw.Elapsed.TotalSeconds} seconds.");
            return(true);
        }
Ejemplo n.º 3
0
        public bool Process(ApiLoaderWorkItem resourceWorkItem)
        {
            var values = new[]
            {
                $"{resourceWorkItem.ElementName}Extension", resourceWorkItem.ElementName
            };

            var xmlModelMetadata = _metadata.FirstOrDefault(x => values.Contains(x.Model));

            if (xmlModelMetadata == null)
            {
                return(false);
            }

            var targetModel = xmlModelMetadata.Model;

            var referenceCache =
                new Lazy <IXmlReferenceCache>(
                    () =>
                    _referenceCacheProvider.GetXmlReferenceCache(resourceWorkItem.SourceFileName));

            ResolveReferences(referenceCache, resourceWorkItem.XElement, targetModel);
            return(true);
        }