示例#1
0
        public IndexedDocumentSource(CopyFromIndexComponent component,
                                     string keyXPath, string valueXPath, XmlNamespaceManager context,
                                     int cacheSize) : this(component)
        {
            try
            {
                _keyExpression = XPathExpression.Compile(keyXPath);
            }
            catch (XPathException)
            {
                this.WriteMessage(MessageLevel.Error, String.Format(
                                      "The key expression '{0}' is not a valid XPath expression.", keyXPath));
            }
            _keyExpression.SetContext(context);

            try
            {
                _valueExpression = XPathExpression.Compile(valueXPath);
            }
            catch (XPathException)
            {
                this.WriteMessage(MessageLevel.Error, String.Format(
                                      "The value expression '{0}' is not a valid XPath expression.", valueXPath));
            }
            _valueExpression.SetContext(context);
        }
示例#2
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The configuration to use</param>
        protected IndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
                               XPathNavigator configuration)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            this.Component = component;

            // Get the name of the index
            this.Name = configuration.GetAttribute("name", String.Empty);

            if (String.IsNullOrWhiteSpace(this.Name))
            {
                component.WriteMessage(MessageLevel.Error, "Each index must have a unique name");
            }

            // Get the XPath for keys (relative to value nodes)
            string keyXPath = configuration.GetAttribute("key", String.Empty);

            if (String.IsNullOrWhiteSpace(keyXPath))
            {
                component.WriteMessage(MessageLevel.Error, "Each index element must have a key attribute " +
                                       "containing an XPath (relative to the value XPath) that evaluates to the entry key");
            }

            // Get the XPath for value nodes
            string valueXPath = configuration.GetAttribute("value", String.Empty);

            if (String.IsNullOrWhiteSpace(valueXPath))
            {
                component.WriteMessage(MessageLevel.Error, "Each index element must have a value attribute " +
                                       "containing an XPath that describes index entries");
            }

            try
            {
                this.KeyExpression = XPathExpression.Compile(keyXPath);
            }
            catch (XPathException)
            {
                component.WriteMessage(MessageLevel.Error, "The key expression '{0}' is not a valid XPath " +
                                       "expression", keyXPath);
            }

            this.KeyExpression.SetContext(context);

            try
            {
                this.ValueExpression = XPathExpression.Compile(valueXPath);
            }
            catch (XPathException)
            {
                component.WriteMessage(MessageLevel.Error, "The value expression '{0}' is not a valid XPath " +
                                       "expression", valueXPath);
            }

            this.ValueExpression.SetContext(context);
        }
示例#3
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The configuration to use</param>
        public ESentIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
                                 XPathNavigator configuration) : base(component, context, configuration)
        {
            settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;

            esentCaches = new List <PersistentDictionary <string, string> >();
        }
示例#4
0
 public MemoryIndexedDocumentSource(CopyFromIndexComponent component,
                                    string keyXPath, string valueXPath, XmlNamespaceManager context,
                                    int cacheSize)
     : base(component, keyXPath, valueXPath, context, cacheSize)
 {
     _documentCache = new MemoryIndexedDocumentCache(cacheSize, this);
     _keyFileIndex  = new Dictionary <string, string>();
 }
示例#5
0
 public IndexedDocumentSources(CopyFromIndexComponent component,
                               DatabaseIndexedDocumentSource database,
                               MemoryIndexedDocumentSource memory)
     : base(component)
 {
     _memorySource   = memory;
     _databaseSource = database;
 }
示例#6
0
 public DatabaseIndexedDocumentSource(CopyFromIndexComponent component,
                                      string keyXPath, string valueXPath, XmlNamespaceManager context,
                                      int cacheSize, bool isSystem)
     : base(component, keyXPath, valueXPath, context, cacheSize)
 {
     _document = new DatabaseIndexedDocument(isSystem);
     _cache    = new DatabaseIndexedDocumentCache(100);
 }
示例#7
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The configuration to use</param>
        public SqlIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
                               XPathNavigator configuration) : base(component, context, configuration)
        {
            settings = new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Fragment
            };

            sqlCaches = new List <SqlDictionary <string> >();
        }
示例#8
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The configuration to use</param>
        protected IndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
          XPathNavigator configuration)
        {
            if(component == null)
                throw new ArgumentNullException("component");

            this.Component = component;

            // Get the name of the index
            this.Name = configuration.GetAttribute("name", String.Empty);

            if(String.IsNullOrWhiteSpace(this.Name))
                component.WriteMessage(MessageLevel.Error, "Each index must have a unique name");

            // Get the xpath for keys (relative to value nodes)
            string keyXPath = configuration.GetAttribute("key", String.Empty);

            if(String.IsNullOrWhiteSpace(keyXPath))
                component.WriteMessage(MessageLevel.Error, "Each index element must have a key attribute " +
                    "containing an XPath (relative to the value XPath) that evaluates to the entry key");

            // Get the XPath for value nodes
            string valueXPath = configuration.GetAttribute("value", String.Empty);

            if(String.IsNullOrWhiteSpace(valueXPath))
                component.WriteMessage(MessageLevel.Error, "Each index element must have a value attribute " +
                    "containing an XPath that describes index entries");

            try
            {
                this.KeyExpression = XPathExpression.Compile(keyXPath);
            }
            catch(XPathException)
            {
                component.WriteMessage(MessageLevel.Error, "The key expression '{0}' is not a valid XPath " +
                    "expression", keyXPath);
            }

            this.KeyExpression.SetContext(context);

            try
            {
                this.ValueExpression = XPathExpression.Compile(valueXPath);
            }
            catch(XPathException)
            {
                component.WriteMessage(MessageLevel.Error, "The value expression '{0}' is not a valid XPath " +
                    "expression", valueXPath);
            }

            this.ValueExpression.SetContext(context);
        }
示例#9
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The indexed cache configuration</param>
        public InMemoryIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
                                    XPathNavigator configuration) : base(component, context, configuration)
        {
            string cacheValue = configuration.GetAttribute("cache", String.Empty);

            if (String.IsNullOrWhiteSpace(cacheValue) || !Int32.TryParse(cacheValue, out int size) || size < 1)
            {
                size = 15;
            }

            this.cacheSize = size;

            // Set up the cache
            queue = new ConcurrentQueue <string>();
            cache = new ConcurrentDictionary <string, IndexedDocument>(4 * Environment.ProcessorCount, size);
        }
示例#10
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);
                }
            }
        }
示例#11
0
        //=====================================================================

        /// <summary>
        /// Load a cached index
        /// </summary>
        /// <param name="index">The parent index node</param>
        /// <param name="name">The name of the index</param>
        /// <param name="cache">The cache settings</param>
        private void LoadCache(XPathNavigator index, string name,
                               XPathNavigator cache)
        {
            XPathDocument               xdoc;
            XPathNavigator              nav;
            CopyFromIndexComponent      copyComp = null;
            BinaryFormatter             bf = new BinaryFormatter();
            Dictionary <string, string> cachedIndex, actualIndex;
            FieldInfo  field;
            Object     cacheData;
            Type       type;
            FileStream fs = null;
            string     parent, config, path, cacheFile, tempName;

            cacheFile = cache.GetAttribute("cacheFile", String.Empty);

            if (String.IsNullOrEmpty(cacheFile))
            {
                throw new ConfigurationErrorsException("You must specify " +
                                                       "a cacheFile value on the cache element.");
            }

            // Create the folder if it doesn't exist
            cacheFile = Path.GetFullPath(Environment.ExpandEnvironmentVariables(
                                             cacheFile));
            path = Path.GetDirectoryName(cacheFile);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                // If it doesn't exist, create it on first use
                if (!File.Exists(cacheFile))
                {
                    base.WriteMessage(MessageLevel.Warn, cacheFile +
                                      " does not exist and is being created");

                    parent   = index.OuterXml;
                    config   = cache.OuterXml.Replace("<cache ", "<data ");
                    tempName = "@" + name;

                    parent = parent.Substring(0, parent.IndexOf('>') + 1).Replace(
                        "\"" + name + "\"", "\"" + tempName + "\"");
                    config = String.Format(CultureInfo.InvariantCulture,
                                           "<component>\r\n{0}\r\n{1}\r\n</index>\r\n</component>",
                                           parent, config);

                    // Create a second CopyFromIndex component and pass it
                    // just enough information to create the index.
                    xdoc     = new XPathDocument(new StringReader(config));
                    nav      = xdoc.CreateNavigator().SelectSingleNode("component");
                    copyComp = new CopyFromIndexComponent(this.BuildAssembler,
                                                          nav);

                    // Get the data from the temporary index
                    cacheData = BuildComponent.Data[tempName];
                    type      = cacheData.GetType();
                    field     = type.GetField("index", BindingFlags.NonPublic |
                                              BindingFlags.Instance);
                    cachedIndex = (Dictionary <string, string>)field.GetValue(
                        cacheData);

                    // Save the cached data for use in subsequent builds
                    fs = new FileStream(cacheFile, FileMode.Create);
                    bf.Serialize(fs, cachedIndex);

                    BuildComponent.Data.Remove(tempName);
                }
                else
                {
                    // Load the existing cached index
                    fs          = new FileStream(cacheFile, FileMode.Open);
                    cachedIndex = (Dictionary <string, string>)bf.Deserialize(fs);
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }

                if (copyComp != null)
                {
                    copyComp.Dispose();
                }
            }

            // Get the dictionary containing the user's index info
            cacheData = BuildComponent.Data[name];
            type      = cacheData.GetType();
            field     = type.GetField("index", BindingFlags.NonPublic |
                                      BindingFlags.Instance);
            actualIndex = (Dictionary <string, string>)field.GetValue(cacheData);

            // Add the cached info from the framework files.  If there's a
            // duplicate, the later copy will take precedence.
            foreach (string key in cachedIndex.Keys)
            {
                if (!actualIndex.ContainsKey(key))
                {
                    actualIndex.Add(key, cachedIndex[key]);
                }
                else
                {
                    base.WriteMessage(MessageLevel.Warn, String.Format(
                                          CultureInfo.InvariantCulture, "Key '{0}' in " +
                                          "this framework cache matches an item from a prior " +
                                          "cache with the same key.  The item from this cache " +
                                          "will take precedence.", key));
                    actualIndex[key] = cachedIndex[key];
                }
            }

            base.WriteMessage(MessageLevel.Info, String.Format(
                                  CultureInfo.InvariantCulture, "Loaded {0} items from the " +
                                  "cache file '{1}'", cachedIndex.Count, cacheFile));
        }
示例#12
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The configuration to use</param>
        public ESentIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
          XPathNavigator configuration) : base(component, context, configuration)
        {
            settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;

            esentCaches = new List<PersistentDictionary<string, string>>();
        }
示例#13
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param>
        /// <param name="context">A context to use with the key and value XPath expressions</param>
        /// <param name="configuration">The indexed cache configuration</param>
        public InMemoryIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context,
          XPathNavigator configuration) : base(component, context, configuration)
        {
            string cacheValue = configuration.GetAttribute("cache", String.Empty);
            int size;

            if(String.IsNullOrWhiteSpace(cacheValue) || !Int32.TryParse(cacheValue, out size) || size < 1)
                size = 15;

            this.cacheSize = size;

            // set up the cache
            queue = new Queue<string>(size);
            cache = new Dictionary<string, IndexedDocument>(size);
        }