コード例 #1
0
        /// <summary>
        /// Parses the details of a <see cref="CoreResult"/> that could be parsed.
        /// </summary>
        /// <param name="node">The node to inspect.</param>
        /// <returns>The parsed <see cref="CoreResult"/>.</returns>
        private static CoreResult ParseCore(XElement node)
        {
            var core = new CoreResult();

            foreach (var propNode in node.Elements())
            {
                var nodeValue = propNode.Value;

                switch (propNode.Attribute("name").Value.ToLower())
                {
                case "name":
                    if (!string.IsNullOrEmpty(nodeValue))
                    {
                        core.Name = nodeValue;
                    }
                    break;

                case "isdefaultcore":
                    core.IsDefaultCore = bool.Parse(nodeValue);
                    break;

                case "instancedir":
                    if (!string.IsNullOrEmpty(nodeValue))
                    {
                        core.InstanceDir = nodeValue;
                    }
                    break;

                case "datadir":
                    if (!string.IsNullOrEmpty(nodeValue))
                    {
                        core.DataDir = nodeValue;
                    }
                    break;

                case "starttime":
                    if (!string.IsNullOrEmpty(nodeValue))
                    {
                        core.StartTime = DateTime.Parse(nodeValue);
                    }
                    break;

                case "uptime":
                    if (!string.IsNullOrEmpty(nodeValue))
                    {
                        core.Uptime = long.Parse(nodeValue);
                    }
                    break;

                case "index":
                    // Parse all Index responses.
                    core.Index = ParseCoreIndex(propNode);
                    break;
                }
            }

            return(core);
        }
コード例 #2
0
        /// <summary>
        /// Parses the details of a <see cref="CoreResult"/> that could be parsed.
        /// </summary>
        /// <param name="node">The node to inspect.</param>
        /// <returns>The parsed <see cref="CoreResult"/>.</returns>
        private static CoreResult ParseCore(XElement node)
        {
            var core = new CoreResult();

            foreach (var propNode in node.Elements()) {
                var nodeValue = propNode.Value;

                switch (propNode.Attribute("name").Value.ToLower()) {
                    case "name":
                        if (!string.IsNullOrEmpty(nodeValue))
                            core.Name = nodeValue;
                        break;
                    case "isdefaultcore":
                        core.IsDefaultCore = bool.Parse(nodeValue);
                        break;
                    case "instancedir":
                        if (!string.IsNullOrEmpty(nodeValue))
                            core.InstanceDir = nodeValue;
                        break;
                    case "datadir":
                        if (!string.IsNullOrEmpty(nodeValue))
                            core.DataDir = nodeValue;
                        break;
                    case "starttime":
                        if (!string.IsNullOrEmpty(nodeValue))
                            core.StartTime = DateTime.Parse(nodeValue);
                        break;
                    case "uptime":
                        if (!string.IsNullOrEmpty(nodeValue))
                            core.Uptime = long.Parse(nodeValue);
                        break;
                    case "index":
                        // Parse all Index responses.
                        core.Index = ParseCoreIndex(propNode);
                        break;
                }
            }

            return core;
        }
コード例 #3
0
ファイル: SolrCoreAdmin.cs プロジェクト: richtea/SolrNet
        /// <summary>
        /// Parses the status response.
        /// </summary>
        /// <param name="responseXml">The response XML.</param>
        /// <returns></returns>
        protected List<CoreResult> ParseStatusResponse(string responseXml)
        {
            // List of Core Results.
            var results = new List<CoreResult>();

            try {
                var xml = XDocument.Parse(responseXml);
                foreach (var lstNode in xml.Element("response").Elements()) {
                    if (!lstNode.Attribute("name").Value.ToLower().Equals("status"))
                        continue;

                    foreach (var coreNode in lstNode.Elements()) {
                        // Create a new Core.
                        var core = new CoreResult(coreNode.Attribute("name").Value);

                        // Parse all elements in the list.
                        foreach (var propEl in coreNode.Elements()) {
                            switch (propEl.Attribute("name").Value.ToLower()) {
                                case "name":
                                    if (!string.IsNullOrEmpty(propEl.Value))
                                        core.Name = propEl.Value;
                                    break;
                                case "instancedir":
                                    if (!string.IsNullOrEmpty(propEl.Value))
                                        core.InstanceDir = propEl.Value;
                                    break;
                                case "datadir":
                                    if (!string.IsNullOrEmpty(propEl.Value))
                                        core.DataDir = propEl.Value;
                                    break;
                                case "starttime":
                                    if (!string.IsNullOrEmpty(propEl.Value))
                                        core.StartTime = DateTime.Parse(propEl.Value);
                                    break;
                                case "uptime":
                                    if (!string.IsNullOrEmpty(propEl.Value))
                                        core.Uptime = long.Parse(propEl.Value);
                                    break;
                                case "index":
                                    // Parse the Index response.
                                    core.Index = new CoreIndexResult();

                                    foreach (var indexEl in propEl.Elements()) {
                                        switch (indexEl.Attribute("name").Value.ToLower()) {
                                            case "numdocs":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.DocumentCount = long.Parse(indexEl.Value);
                                                break;
                                            case "maxdoc":
                                                // Ignore.  Not normally important.
                                                break;
                                            case "version":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.Version = int.Parse(indexEl.Value);
                                                break;
                                            case "segmentcount":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.SegmentCount = int.Parse(indexEl.Value);
                                                break;
                                            case "current":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.IsCurrent = bool.Parse(indexEl.Value);
                                                break;
                                            case "hasdeletions":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.HasDeletions = bool.Parse(indexEl.Value);
                                                break;
                                            case "isoptimized":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.IsOptimized = bool.Parse(indexEl.Value);
                                                break;
                                            case "directory":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.Directory = indexEl.Value;
                                                break;
                                            case "lastmodified":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.LastModified = DateTime.Parse(indexEl.Value);
                                                break;
                                            case "sizeinbytes":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.SizeInBytes = long.Parse(indexEl.Value);
                                                break;
                                            case "size":
                                                if (!string.IsNullOrEmpty(indexEl.Value))
                                                    core.Index.Size = indexEl.Value;
                                                break;
                                            default:
                                                // Unknown or new property.  Ignore.
                                                break;
                                        }
                                    }
                                    break;
                                default:
                                    // Unkown or new property.  Ignore.
                                    break;
                            }
                        }

                        // Add the Core to the resultset.
                        results.Add(core);
                    }
                }
            } catch (Exception parseEx) {
                // Location to allow any exceptions be caught and handled.
            }

            // Return the results we got back from Solr.
            return results;
        }