XPathObjectNode(XPathObjectContext context, object target, string name, XPathObjectNode parent, IList <XPathObjectNode> siblings, int index) { _context = context ?? throw new ArgumentNullException("context"); _target = target ?? throw new ArgumentNullException("target"); _parent = parent; _siblings = siblings; _index = index; if (string.IsNullOrEmpty(name)) { if (target is IXmlInfo info) { name = info.XmlNodeName(); } else { var type = target.GetType(); name = target.GetType().Name; if (type.IsGenericType) { name = name.Remove(name.IndexOf('`')); } } } _name = GetAtomicString(name); }
XPathObjectNavigator(XPathObjectNavigator that) { _context = that._context; _root = that._root; _node = that._node; _type = that._type; _index = that._index; }
XPathObjectNavigator(XPathObjectNavigator that) { _context = that._context; _root = that._root; _node = that._node; _type = that._type; _index = that._index; }
/// internal XPathObjectNavigator(object root, XPathObjectContext context) { if (root == null) throw new ArgumentNullException("root"); if (context == null) throw new ArgumentNullException("context"); _context = context; _root = new XPathObjectNode(context, root); //???? fails without it var type = root.GetType(); var name = type.FullName; if (type.IsGenericType) name = name.Remove(name.IndexOf('`')); _root.AddSpecialName("type", name); }
/// public override bool MoveTo(XPathNavigator other) { if (!(other is XPathObjectNavigator that)) { return(false); } _context = that._context; _root = that._root; _node = that._node; _type = that._type; _index = that._index; return(true); }
/// public override bool MoveTo(XPathNavigator other) { var that = other as XPathObjectNavigator; if (that == null) { return(false); } _context = that._context; _root = that._root; _node = that._node; _type = that._type; _index = that._index; return(true); }
/// internal XPathObjectNavigator(object root, XPathObjectContext context) { if (root == null) { throw new ArgumentNullException("root"); } _context = context ?? throw new ArgumentNullException("context"); _root = new XPathObjectNode(context, root); //???? fails without it var type = root.GetType(); var name = type.FullName; if (type.IsGenericType) { name = name.Remove(name.IndexOf('`')); } _root.AddSpecialName("type", name); }
/// public override bool MoveTo(XPathNavigator other) { var that = other as XPathObjectNavigator; if (that == null) return false; _context = that._context; _root = that._root; _node = that._node; _type = that._type; _index = that._index; return true; }
IEnumerable <FarFile> DoInvokeXPath(ProgressBox progress) { // object context var objectContext = new XPathObjectContext() { Filter = this.Filter, IncrementDirectoryCount = delegate(int count) { ProcessedDirectoryCount += count; if (progress == null) { return; } var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds; progress.Activity = string.Format(null, Res.SearchActivityDeep, FoundFileCount, ProcessedDirectoryCount, directoryPerSecond); progress.ShowProgress(); }, Stopping = delegate { return(Stopping || progress != null && UIUserStop()); } }; var xsltContext = new XPathXsltContext(objectContext.NameTable); if (_XVariables != null) { foreach (var kv in _XVariables) { xsltContext.AddVariable(kv.Key, kv.Value); } } // XPath text string xpath; if (string.IsNullOrEmpty(XFile)) { xpath = XPath; } else { var input = XPathInput.ParseFile(XFile); xpath = input.Expression; foreach (var kv in input.Variables) { xsltContext.AddVariable(kv.Key, kv.Value); } } var expression = XPathExpression.Compile(xpath); if (expression.ReturnType != XPathResultType.NodeSet) { throw new InvalidOperationException("Invalid expression return type."); } expression.SetContext(xsltContext); ++ProcessedDirectoryCount; var args = new GetFilesEventArgs(ExplorerModes.Find); foreach (var file in _RootExplorer.GetFiles(args)) { // stop? if (Stopping || progress != null && UIUserStop()) //???? progress to navigator { break; } // filter out a leaf if (Filter != null && !file.IsDirectory && !Filter(_RootExplorer, file)) { continue; } var xfile = new SuperFile(_RootExplorer, file); var navigator = new XPathObjectNavigator(xfile, objectContext); var iterator = navigator.Select(expression); while (iterator.MoveNext()) { // stop? if (Stopping || progress != null && UIUserStop()) //???? progress to navigator { break; } // found file or directory, ignore anything else if (!(iterator.Current.UnderlyingObject is SuperFile currentFile)) { continue; } // filter out directory, it is already done for files if (Filter != null && currentFile.IsDirectory && (!Directory || !Filter(currentFile.Explorer, currentFile.File))) { continue; } // add yield return(currentFile); ++FoundFileCount; } } }
IEnumerable<FarFile> DoInvokeXPath(ProgressBox progress) { // object context var objectContext = new XPathObjectContext() { Filter = this.Filter, IncrementDirectoryCount = delegate(int count) { ProcessedDirectoryCount += count; if (progress == null) return; var directoryPerSecond = ProcessedDirectoryCount / progress.ElapsedFromStart.TotalSeconds; progress.Activity = string.Format(null, Res.SearchActivityDeep, FoundFileCount, ProcessedDirectoryCount, directoryPerSecond); progress.ShowProgress(); }, Stopping = delegate { return Stopping || progress != null && UIUserStop(); } }; var xsltContext = new XPathXsltContext(objectContext.NameTable); if (_XVariables != null) { foreach (var kv in _XVariables) xsltContext.AddVariable(kv.Key, kv.Value); } // XPath text string xpath; if (string.IsNullOrEmpty(XFile)) { xpath = XPath; } else { var input = XPathInput.ParseFile(XFile); xpath = input.Expression; foreach (var kv in input.Variables) xsltContext.AddVariable(kv.Key, kv.Value); } var expression = XPathExpression.Compile(xpath); if (expression.ReturnType != XPathResultType.NodeSet) throw new InvalidOperationException("Invalid expression return type."); expression.SetContext(xsltContext); ++ProcessedDirectoryCount; var args = new GetFilesEventArgs(ExplorerModes.Find); foreach (var file in _RootExplorer.GetFiles(args)) { // stop? if (Stopping || progress != null && UIUserStop()) //???? progress to navigator break; // filter out a leaf if (Filter != null && !file.IsDirectory && !Filter(_RootExplorer, file)) continue; var xfile = new SuperFile(_RootExplorer, file); var navigator = new XPathObjectNavigator(xfile, objectContext); var iterator = navigator.Select(expression); while (iterator.MoveNext()) { // stop? if (Stopping || progress != null && UIUserStop()) //???? progress to navigator break; // found file or directory, ignore anything else var currentFile = iterator.Current.UnderlyingObject as SuperFile; if (currentFile == null) continue; // filter out directory, it is already done for files if (Filter != null && currentFile.IsDirectory && (!Directory || !Filter(currentFile.Explorer, currentFile.File))) continue; // add yield return currentFile; ++FoundFileCount; } } }
public XPathObjectNode(XPathObjectContext context, object target) : this(context, target, null, null, null, -1) { }