Пример #1
0
        public void AddDocument(DatabaseIndexedBuilder builder, string file)
        {
            BuildComponentExceptions.NotNull(builder, "builder");
            BuildComponentExceptions.NotNull(file, "file");

            // load the document
            XPathDocument document = new XPathDocument(file);

            // search for value nodes
            XPathNodeIterator valueNodes =
                document.CreateNavigator().Select(builder.ValueExpression);

            // get the key string for each value node and record it in the index
            foreach (XPathNavigator valueNode in valueNodes)
            {
                XPathNavigator keyNode = valueNode.SelectSingleNode(
                    builder.KeyExpression);
                if (keyNode == null)
                {
                    continue;
                }

                // The outer container interferes with the processing, so
                // we use the inner XML of the node...
                _indexedDocument[keyNode.Value] = valueNode.InnerXml;
            }
        }
Пример #2
0
        public VersionInfo(string assemblyName, string assemblyVersion,
                           string fileVersion, VersionInfoType infoType)
        {
            BuildComponentExceptions.NotNullNotEmpty(assemblyName, "assemblyName");
            BuildComponentExceptions.NotNullNotEmpty(assemblyVersion, "assemblyVersion");

            _infoType        = infoType;
            _fileVersion     = fileVersion;
            _assemblyName    = assemblyName;
            _assemblyVersion = assemblyVersion;

            if (String.IsNullOrEmpty(fileVersion))
            {
                _infoType    = VersionInfoType.Assembly;
                _versionText = assemblyVersion;
            }
            else
            {
                if (_infoType == VersionInfoType.Assembly)
                {
                    _versionText = assemblyVersion;
                }
                else
                {
                    _versionText = String.Format("{0} ({1})", assemblyVersion, fileVersion);
                }
            }
        }
Пример #3
0
        protected IndexedDocumentSource(BuildComponent component)
        {
            BuildComponentExceptions.NotNull(component, "component");

            _component = component;
            _thisType  = this.GetType();
            _assembler = component.BuildAssembler;
        }
Пример #4
0
        public VersionInfo(VersionInfo source)
        {
            BuildComponentExceptions.NotNull(source, "source");

            _infoType        = source._infoType;
            _fileVersion     = source._fileVersion;
            _assemblyName    = source._assemblyName;
            _assemblyVersion = source._assemblyVersion;
        }
Пример #5
0
        public MemoryIndexedDocumentCache(int cacheSize,
                                          MemoryIndexedDocumentSource source)
        {
            BuildComponentExceptions.NotNull(source, "source");

            if (cacheSize < 0)
            {
                throw new ArgumentOutOfRangeException("cacheSize");
            }

            _cacheSize      = cacheSize;
            _documentSource = source;

            // set up the cache
            _cacheStorage = new Dictionary <string, WeakReference>(
                cacheSize, StringComparer.OrdinalIgnoreCase);

            _cacheQueue = new Queue <string>(cacheSize);
        }
Пример #6
0
        public IndexedDocumentController(CopyFromIndexComponent component,
                                         XPathNavigator configuration, CustomContext context,
                                         IDictionary <string, object> globalData)
        {
            BuildComponentExceptions.NotNull(component, "component");

            _component = component;
            _thisType  = this.GetType();
            _assembler = component.BuildAssembler;

            _documentSources = new Dictionary <string, IndexedDocumentSources>(
                StringComparer.OrdinalIgnoreCase);

            // set up the indices
            XPathNodeIterator indexNodes = configuration.Select("index");

            foreach (XPathNavigator indexNode in indexNodes)
            {
                // get the name of the index
                string name = indexNode.GetAttribute("name", String.Empty);
                if (String.IsNullOrEmpty(name))
                {
                    throw new BuildComponentException("Each index must have a unique name.");
                }

                if (String.Equals(name, "reflection",
                                  StringComparison.OrdinalIgnoreCase))
                {
                    this.ProcessReflectionIndex(indexNode, context, globalData);
                }
                else if (String.Equals(name, "comments",
                                       StringComparison.OrdinalIgnoreCase))
                {
                    this.ProcessCommentsIndex(indexNode, context, globalData);
                }
                else
                {
                    this.ProcessIndex(indexNode, context, globalData);
                }
            }
        }
Пример #7
0
        public void AddDocument(IndexedDocumentSource source, string file)
        {
            BuildComponentExceptions.NotNull(source, "source");
            BuildComponentExceptions.NotNull(file, "file");

            // load the document
            try
            {
                XPathDocument document = new XPathDocument(file);

                // search for value nodes
                XPathNodeIterator valueNodes =
                    document.CreateNavigator().Select(source.ValueExpression);

                // get the key string for each value node and record it in the index
                foreach (XPathNavigator valueNode in valueNodes)
                {
                    XPathNavigator keyNode = valueNode.SelectSingleNode(
                        source.KeyExpression);
                    if (keyNode == null)
                    {
                        continue;
                    }

                    // The outer container interferes with the processing, so
                    // we use the inner XML of the node...
                    _indexedDocument[keyNode.Value] = valueNode.InnerXml;
                }
            }
            catch (IOException e)
            {
                source.WriteMessage(MessageLevel.Error,
                                    String.Format("An access error occurred while attempting to load the file '{0}'. The error message is: {1}", file, e.Message));
            }
            catch (XmlException e)
            {
                source.WriteMessage(MessageLevel.Error,
                                    String.Format("The indexed document '{0}' is not a valid XML document. The error message is: {1}", file, e.Message));
            }
        }
Пример #8
0
        public MemoryIndexedDocument(MemoryIndexedDocumentSource cache,
                                     string file) : this()
        {
            BuildComponentExceptions.NotNull(cache, "cache");
            BuildComponentExceptions.NotNull(file, "file");

            // remember the file
            this.file = file;

            // load the document
            try
            {
                //XPathDocument document = new XPathDocument(file, XmlSpace.Preserve);
                XPathDocument document = new XPathDocument(file);

                XPathNavigator docNavigator = document.CreateNavigator();
                XPathNavigator redirectNode = docNavigator.SelectSingleNode("doc");
                // search for value nodes
                XPathNodeIterator valueNodes =
                    docNavigator.Select(cache.ValueExpression);
                if ((valueNodes == null || valueNodes.Count == 0) &&
                    redirectNode != null)
                {
                    string redirectPath = redirectNode.GetAttribute(
                        "redirect", String.Empty);
                    if (!String.IsNullOrEmpty(redirectPath))
                    {
                        redirectPath = Path.GetFullPath(
                            Environment.ExpandEnvironmentVariables(redirectPath));

                        if (System.IO.File.Exists(redirectPath))
                        {
                            document = new XPathDocument(redirectPath);

                            docNavigator = document.CreateNavigator();
                            // search for value nodes
                            valueNodes = docNavigator.Select(cache.ValueExpression);
                        }
                    }
                }

                // get the key string for each value node and record it in the index
                foreach (XPathNavigator valueNode in valueNodes)
                {
                    XPathNavigator keyNode = valueNode.SelectSingleNode(
                        cache.KeyExpression);
                    if (keyNode == null)
                    {
                        continue;
                    }

                    string key = keyNode.Value;
                    index[key] = valueNode;
                    //if (!index.ContainsKey(key))
                    //{
                    //    //index.Add(key, valueNode);
                    //}
                    //else
                    //{
                    //}
                }
            }
            catch (IOException e)
            {
                cache.WriteMessage(MessageLevel.Error,
                                   String.Format("An access error occurred while attempting to load the file '{0}'. The error message is: {1}", file, e.Message));
            }
            catch (XmlException e)
            {
                cache.WriteMessage(MessageLevel.Error,
                                   String.Format("The indexed document '{0}' is not a valid XML document. The error message is: {1}", file, e.Message));
            }
        }