public Compile ( string xpath ) : |
||
xpath | string | |
return |
/// <summary> /// Récupère la valeur de l'attribut du noeud recherché dans le fichier de configuration /// </summary> /// <param name="xPathString">Expression XPath de recherche du noeud</param> /// <param name="attribute">Attribut à rechercher</param> /// <returns>Une ArrayList contenant la liste des attributs recherchés</returns> public ArrayList GetAttributes(string xPathString, string attribute) { // Initilisation des variables XPathNodeIterator xpathNodeIterator; XPathExpression expr; ArrayList attributes = new ArrayList(); // Parcours du fichier XML try { xpathNavigator = xpathDoc.CreateNavigator(); expr = xpathNavigator.Compile(xPathString); xpathNodeIterator = xpathNavigator.Select(expr); while (xpathNodeIterator.MoveNext()) { // On récupère l'attribut attributes.Add(xpathNodeIterator.Current.GetAttribute(attribute, "")); } } catch (Exception e) { } return attributes; }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { string str = XPathMessageFunction.ToString(args[0]); string xpath = string.Format(CultureInfo.InvariantCulture, "/s11:Envelope/s11:Header/*[@s11:actor='{0}'] | /s12:Envelope/s12:Header/*[@s12:role='{1}']", new object[] { str, str }); XPathExpression expr = docContext.Compile(xpath); expr.SetContext((XmlNamespaceManager) xsltContext); return docContext.Evaluate(expr); }
public string GetValue(string xPathString) { xpathNavigator = xpathDoc.CreateNavigator(); XPathExpression expr = xpathNavigator.Compile(xPathString); XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(expr); xpathNodeIterator.MoveNext(); return xpathNodeIterator.Current.Value; }
static XPathNodeIterator Select(string expression, XPathNavigator source, params XPathVariable[] variables) { var expr = source.Compile(expression); var context = new DynamicContext(); foreach (var variable in variables) context.AddVariable(variable.Name, variable.Value); expr.SetContext(context); return source.Select(expr); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { if (this.expr == null) { XPathExpression expression = docContext.Compile("(sm:header()/wsa10:FaultTo | sm:header()/wsaAugust2004:FaultTo)[1]"); expression.SetContext((XmlNamespaceManager) new XPathMessageContext()); this.expr = expression; } return docContext.Evaluate(this.expr); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { if (this.expr == null) { XPathExpression expression = docContext.Compile("(/s11:Envelope/s11:Body | /s12:Envelope/s12:Body)[1]"); expression.SetContext(XPathMessageFunction.Namespaces); this.expr = expression; } return docContext.Evaluate(this.expr); }
/// <summary> /// Retrieves a cached compiled expression, or a newly compiled one. /// </summary> private static XPathExpression GetCompiledExpression(string expression, XPathNavigator source) { XPathExpression expr; if (!Cache.TryGetValue(expression, out expr)) { // No double checks. At most we will compile twice. No big deal. expr = source.Compile(expression); Cache[expression] = expr; } return expr.Clone(); }
private void Form1_Load(object sender, EventArgs e) { String path = @"..\..\..\data\categories.xml"; categories = new XPathDocument(path); nav = categories.CreateNavigator(); var expr = nav.Compile("//*"); XPathNodeIterator iter = nav.Select(expr); String category = null; List<TreeNode> subcats = new List<TreeNode>() ; while (iter.MoveNext()) { if(iter.Current.Name == "cat") { if(subcats.Count != 0) { TreeNode cat_node = new TreeNode(category, subcats.ToArray()); trv_categories.Nodes.Add(cat_node); subcats.Clear(); } category = iter.Current.Value; } else if(iter.Current.Name == "subcat") { subcats.Add(new TreeNode(iter.Current.Value)); } } path = @"..\..\..\data\"; synonyms = new Dictionary<string, List<string>>(); StreamReader reader = new StreamReader(path+"synonyms.txt", Encoding.UTF8); while (!reader.EndOfStream) { String line = reader.ReadLine(); if (line.Length <= 0) continue; line = line.Trim(); List<String> syms = line.Split(':','،',',').ToList<String>(); for (int i = 0; i < syms.Count; i++) syms[i] = syms[i].Trim(); String key = syms[0]; syms.RemoveAll(s => s.Length <= 0); syms.RemoveAt(0); if (synonyms.ContainsKey(key)) synonyms[key].Concat(syms); else synonyms.Add(key, syms); } }
/// <summary> /// Evaluates an XPath expression in a newly created context, making additional parameters available to the expression. /// </summary> /// <param name="nav"> /// Navigator indicating the current node; if <c>null</c>, a dummy navigator is used. /// </param> /// <param name="xpathExpr">XPath expression to evaluate.</param> /// <param name="param"> /// Values to be available while evaluating the expression as <c>$paramN</c>, where N is the /// index within this array. /// </param> /// <returns>The result of evaluating the expression</returns> public static object Evaluate(XPathNavigator nav, string xpathExpr, params object[] param) { Checker.NotNull(xpathExpr, "xpathExpr"); nav = EnsureNavigator(nav); var expr = nav.Compile(xpathExpr); var context = new TriflesXPathContext(); int i = 0; foreach (var paramN in param) { context.AddVariable(XNamespace.None + ("param" + i), paramN); i++; } expr.SetContext(context); return nav.Evaluate(expr); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { string actor = ToString(args[0]); string e = string.Format(CultureInfo.InvariantCulture, "/s11:Envelope/s11:Header/*[@s11:actor='{0}'] | /s12:Envelope/s12:Header/*[@s12:role='{1}']", actor, actor); XPathExpression expr = docContext.Compile(e); expr.SetContext(xsltContext); return docContext.Evaluate(expr); #if NO // PERF, [....], I drafted this implementation before we found out that a bug in the Fx implementation would // prevent us from constructing an XPathNodeIterator that they would accept. I'm keeping it // around in the hope that I will be able to use it by M5.4. If not, it will be deleted. XPathNavigator basicNav = docContext.Clone(); SeekableXPathNavigator nav = basicNav as SeekableXPathNavigator; if(nav == null) { nav = new GenericSeekableNavigator(basicNav); } string actor = (string)args[0]; NodeSequence seq = new NodeSequence(); XPathNodeIterator result = new NodeSequenceIterator(seq); nav.MoveToRoot(); if(!nav.MoveToFirstChild()) { return result; } if(nav.LocalName != "Envelope") { return result; } if(nav.NamespaceURI == XPathMessageContext.S11NS) { // Move to Header if(nav.MoveToFirstChild() && nav.LocalName == "Header" && nav.NamespaceURI == XPathMessageContext.S11NS) { // Move to first Header block if(nav.MoveToFirstChild()) { // Iterate over header blocks do { if(nav.MoveToAttribute("actor", XPathMessageContext.S11NS)) { if(nav.Value == actor) { seq.Add(nav); } nav.MoveToParent(); } } while(nav.MoveToNext()); } } } else if(nav.NamespaceURI == XPathMessageContext.S12NS) { // Move to Header if(nav.MoveToFirstChild() && nav.LocalName == "Header" && nav.NamespaceURI == XPathMessageContext.S12NS) { // Move to first Header block if(nav.MoveToFirstChild()) { // Iterate over header blocks do { if(nav.MoveToAttribute("role", XPathMessageContext.S12NS)) { if(nav.Value == actor) { seq.Add(nav); } nav.MoveToParent(); } } while(nav.MoveToNext()); } } } return result; #endif }
private int CalculateDrain(XPathNavigator nav, int force) { XPathExpression xprDV; // Calculate the Spell's Drain for the current Force. xprDV = nav.Compile(_strDV.Replace("F", force.ToString()).Replace("/", " div ")); decimal decDV = Convert.ToDecimal(nav.Evaluate(xprDV)?.ToString()); decDV = Math.Floor(decDV); int intDV = Convert.ToInt32(decDV); // Drain cannot be lower than 2. if (intDV < 2) intDV = 2; return intDV; }
/// <summary> /// Prepares the Xpath navigator to improve performance for GetNextId(). /// </summary> private void PrepareIdNavigator() { m_navigator = m_dictionary.CreateNavigator(); m_expression = m_navigator.Compile(m_basePath); m_expression.AddSort(m_XPathId, XmlSortOrder.Descending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { if (this.expr == null) { XPathExpression e = docContext.Compile("(sm:header()/wsa10:From | sm:header()/wsaAugust2004:From)[1]"); e.SetContext(new XPathMessageContext()); this.expr = e; } return docContext.Evaluate(this.expr); }
// Need to be implemented separately #endregion #region Public Methods public virtual void UpdateState(string name) { List<string> tempList = null; switch (name) { case "Initial": case "Multiline": case "Singleline": case "WholeWord": case "CaseSensitive": case "StopAfterFirstMatch": tempList = new List<string>(); if (CaseSensitive) tempList.Add("Case sensitive"); if (Multiline) tempList.Add("Multiline"); if (WholeWord) tempList.Add("Whole word"); if (Singleline) tempList.Add("Dot as new line"); if (StopAfterFirstMatch) tempList.Add("Stop after first match"); OptionsSummary = "["; if (tempList.Count == 0) { OptionsSummary += "None"; } else { for (int i = 0; i < tempList.Count; i++) { OptionsSummary += tempList[i]; if (i < tempList.Count - 1) OptionsSummary += ", "; } } OptionsSummary += "]"; if (Multiline) TextBoxStyle = "{StaticResource ExpandedTextbox}"; else TextBoxStyle = ""; CanReplace = false; break; case "UseFileSizeFilter": if (UseFileSizeFilter == FileSizeFilter.Yes) { IsSizeFilterSet = true; } else { IsSizeFilterSet = false; } break; case "FileFilters": // Set all properties to correspond to ON value if (FileFilters) { UseFileSizeFilter = FileSizeFilter.No; IncludeBinary = true; IncludeHidden = true; IncludeSubfolder = true; FilePattern = "*"; FilePatternIgnore = ""; TypeOfFileSearch = FileSearchType.Asterisk; CodePage = -1; } break; } if (name == "FileFilters" || name == "FilePattern" || name == "IncludeSubfolder" || name == "IncludeHidden" || name == "IncludeBinary" || name == "UseFileSizeFilter" || name == "FilePatternIgnore") { if (FileFilters) FileFiltersSummary = "[All files]"; else { tempList = new List<string>(); if (FilePattern != "*") tempList.Add(FilePattern); if (!IncludeSubfolder) tempList.Add("No subfolders"); if (!IncludeHidden) tempList.Add("No hidden"); if (!IncludeBinary) tempList.Add("No binary"); if (!string.IsNullOrEmpty(FilePatternIgnore)) tempList.Add("Exclusions"); if (UseFileSizeFilter == FileSizeFilter.Yes) tempList.Add("Size"); FileFiltersSummary = "["; if (tempList.Count == 0) { FileFiltersSummary += "All files"; } else { for (int i = 0; i < tempList.Count; i++) { FileFiltersSummary += tempList[i]; if (i < tempList.Count - 1) FileFiltersSummary += ", "; } } FileFiltersSummary += "]"; } } //Files found if (name == "FileOrFolderPath" || name == "SearchFor" || name == "FilePattern" || name == "FilePatternIgnore") { FilesFound = false; } //Change title if (name == "FileOrFolderPath" || name == "SearchFor") { if (string.IsNullOrWhiteSpace(FileOrFolderPath)) WindowTitle = "dnGREP"; else WindowTitle = string.Format("{0} in \"{1}\" - dnGREP", (SearchFor == null ? "Empty" : SearchFor.Replace('\n', ' ').Replace('\r', ' ')), FileOrFolderPath); } //Change validation if (name == "SearchFor" || name == "TypeOfSearch") { if (string.IsNullOrWhiteSpace(SearchFor)) { ValidationMessage = ""; } else if (TypeOfSearch == SearchType.Regex) { try { Regex regex = new Regex(SearchFor); ValidationMessage = "Regex is OK!"; } catch { ValidationMessage = "Regex is not valid!"; } } else if (TypeOfSearch == SearchType.XPath) { try { nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile(SearchFor); ValidationMessage = "XPath is OK!"; } catch { ValidationMessage = "XPath is not valid!"; } } else { ValidationMessage = ""; } } //Can search if (name == "FileOrFolderPath" || name == "CurrentGrepOperation" || name == "SearchFor") { if (Utils.IsPathValid(FileOrFolderPath) && CurrentGrepOperation == GrepOperation.None && (!string.IsNullOrEmpty(SearchFor) || settings.Get<bool>(GrepSettings.Key.AllowSearchingForFileNamePattern))) { CanSearch = true; } else { CanSearch = false; } // Refersh buttons CommandManager.InvalidateRequerySuggested(); } //Set all files if FileOrFolderPath is a file if (name == "FileOrFolderPath") { if (System.IO.File.Exists(FileOrFolderPath)) FileFilters = true; } //btnSearch.ShowAdvance if (name == "CurrentGrepOperation" || name == "Initial") { if (searchResults.Count > 0) { //TODO CanSearchInResults = true; SearchButtonMode = "Split"; } else { //TODO CanSearchInResults = false; SearchButtonMode = "Button"; } } //searchResults searchResults.FolderPath = FileOrFolderPath; // btnReplace if (name == "FileOrFolderPath" || name == "FilesFound" || name == "CurrentGrepOperation" || name == "SearchFor") { if (Utils.IsPathValid(FileOrFolderPath) && FilesFound && CurrentGrepOperation == GrepOperation.None && !string.IsNullOrEmpty(SearchFor)) { CanReplace = true; } else { CanReplace = false; } } //btnCancel if (name == "CurrentGrepOperation") { if (CurrentGrepOperation != GrepOperation.None) { CanCancel = true; } else { CanCancel = false; } } //Search type specific options if (name == "TypeOfSearch") { if (TypeOfSearch == SearchType.XPath) { IsCaseSensitiveEnabled = false; IsMultilineEnabled = false; IsSinglelineEnabled = false; IsWholeWordEnabled = false; CaseSensitive = false; Multiline = false; Singleline = false; WholeWord = false; } else if (TypeOfSearch == SearchType.PlainText) { IsCaseSensitiveEnabled = true; IsMultilineEnabled = true; IsSinglelineEnabled = false; IsWholeWordEnabled = true; Singleline = false; } else if (TypeOfSearch == SearchType.Soundex) { IsMultilineEnabled = true; IsCaseSensitiveEnabled = false; IsSinglelineEnabled = false; IsWholeWordEnabled = true; CaseSensitive = false; Singleline = false; } else if (TypeOfSearch == SearchType.Regex) { IsCaseSensitiveEnabled = true; IsMultilineEnabled = true; IsSinglelineEnabled = true; IsWholeWordEnabled = true; } } if (IsProperty(() => SearchFor, name) || IsProperty(() => ReplaceWith, name) || IsProperty(() => FilePattern, name)) { if (BookmarkLibrary.Instance.Bookmarks.Contains(new Bookmark(SearchFor, ReplaceWith, FilePattern, ""))) IsBookmarked = true; else IsBookmarked = false; } }
public object GetXPathScalar(XPathNavigator xpathnav, string expression, XmlNamespaceManager nsmgr) { if (xpathnav == null) { return null; } var expr = xpathnav.Compile(expression); expr.SetContext(nsmgr); var result = xpathnav.Evaluate(expr); switch (expr.ReturnType) { case XPathResultType.Number: if (result == null) { return 0; } else { return (double)result; } case XPathResultType.Boolean: if (result == null) { return false; } else { return (bool)result; } case XPathResultType.String: if (result == null) { return ""; } else { return (string)result; } case XPathResultType.NodeSet: return xpathnav.Select(expression, nsmgr); default: return result; } }
public static XPathNodeIterator SelectNodes(XPathNavigator navigator, string xpath, ref XPathExpression compiledExpression, bool multiThreaded) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (xpath == null) { throw new ArgumentNullException("xpath"); } XPathExpression expression = compiledExpression; if (expression == null) { expression = navigator.Compile(xpath); compiledExpression = expression; } else if (multiThreaded) { expression = expression.Clone(); } return navigator.Select(expression); }
public static void Upgrade26xTov270( XPathNavigator xPathNav ) { //Using the new updating API : http://api.civikey.invenietis.com AddEntryToSystemConf( "UpdateServerUrl", "http://api.civikey.invenietis.com/", "11C83441-6818-4A8B-97A0-1761E1A54251", "Update Checker", xPathNav ); //ADD : AutoBinder //<PluginStatus Guid="b63bb144-1c13-4a3b-93bd-ac5233f4f18e" Status="AutomaticStart"></PluginStatus> string xPathExp = "//System/PluginStatusCollection"; XPathNodeIterator iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); iterator.MoveNext(); iterator.Current.PrependChildElement( String.Empty, "PluginStatus", String.Empty, String.Empty ); iterator.Current.MoveToFirstChild(); //we are on the first PluginStatus, which we have just created iterator.Current.CreateAttribute( String.Empty, "Guid", String.Empty, "b63bb144-1c13-4a3b-93bd-ac5233f4f18e" ); iterator.Current.CreateAttribute( String.Empty, "Status", String.Empty, "AutomaticStart" ); //ADD : //<Plugins> // <p guid="f6b5d818-3c04-4a46-ad65-afc5458a394c" version="1.0.0" name="CK.WindowManager.WindowElementBinder"> // <data key="SerializableBindings" type="Structured" typeName="CK.WindowManager.WindowElementBinder+SerializableBindings, CK.WindowManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> // <Bindings> // <Bind Master="Azerty" Slave="Prediction" Position="Top" /> // <Bind Master="Ergonomique" Slave="Prediction" Position="Top" /> // <Bind Master="ClickSelector" Slave="AutoClick" Position="Top" /> // </Bindings> // </data> // </p> //</Plugins> xPathExp = "//System/Plugins"; iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); iterator.MoveNext(); iterator.Current.PrependChildElement( String.Empty, "p", String.Empty, String.Empty ); iterator.Current.MoveToFirstChild(); //We are on the <p> element iterator.Current.CreateAttribute( null, "guid", null, "f6b5d818-3c04-4a46-ad65-afc5458a394c" ); iterator.Current.CreateAttribute( null, "version", null, "1.0.0" ); iterator.Current.CreateAttribute( null, "name", null, "CK.WindowManager.WindowElementBinder" ); iterator.Current.PrependChildElement( String.Empty, "data", String.Empty, String.Empty ); iterator.Current.MoveToFirstChild(); //We are on the <data> element iterator.Current.CreateAttribute( null, "key", null, "SerializableBindings" ); iterator.Current.CreateAttribute( null, "type", null, "Structured" ); iterator.Current.CreateAttribute( null, "typeName", null, "CK.WindowManager.WindowElementBinder+SerializableBindings, CK.WindowManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" ); iterator.Current.PrependChildElement( String.Empty, "Bindings", String.Empty, String.Empty ); iterator.Current.MoveToFirstChild(); //We are on the <Bindings> element iterator.Current.AppendChild( "<Bind Master=\"Azerty\" Slave=\"Prediction\" Position=\"Top\" />" ); iterator.Current.AppendChild( "<Bind Master=\"Ergonomique\" Slave=\"Prediction\" Position=\"Top\" />" ); iterator.Current.AppendChild( "<Bind Master=\"ClickSelector\" Slave=\"AutoClick\" Position=\"Top\" />" ); //iterator.Current.MoveToFirstChild(); //We are on the <Bind> element //iterator.Current.CreateAttribute( null, "Master", null, "Azerty" ); //iterator.Current.CreateAttribute( null, "Slave", null, "Prediction" ); //iterator.Current.CreateAttribute( null, "Position", null, "Top" ); //iterator.Current.InsertElementAfter( String.Empty, "Bind", String.Empty, String.Empty ); //iterator.Current.MoveToFollowing( "Bind", String.Empty ); //iterator.Current.CreateAttribute( null, "Master", null, "Ergonomique" ); //iterator.Current.CreateAttribute( null, "Slave", null, "Prediction" ); //iterator.Current.CreateAttribute( null, "Position", null, "Top" ); //iterator.Current.InsertElementAfter( String.Empty, "Bind", String.Empty, String.Empty ); //iterator.Current.MoveToFollowing( "Bind", String.Empty ); //iterator.Current.CreateAttribute( null, "Master", null, "ClickSelector" ); //iterator.Current.CreateAttribute( null, "Slave", null, "AutoClick" ); //iterator.Current.CreateAttribute( null, "Position", null, "Top" ); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { if (this.expr == null) { XPathExpression e = docContext.Compile("(/s11:Envelope/s11:Header | /s12:Envelope/s12:Header)[1]"); e.SetContext(Namespaces); this.expr = e; } return docContext.Evaluate(this.expr); }
private static void CreateEntryToSystemConf( string key, string value, string pluginId, string pluginName, XPathNavigator xPathNav, ref string xPathExp, ref XPathNodeIterator iterator ) { xPathExp = "//System/Plugins"; iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); if( iterator.Count == 0 ) //if there is no pluginsData child { xPathExp = "//System"; iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); iterator.MoveNext(); iterator.Current.AppendChildElement( null, "Plugins", null, null ); iterator.Current.MoveToFirstChild(); while( iterator.Current.Name != "Plugins" ) iterator.Current.MoveToNext(); } else { iterator.MoveNext(); } bool pFound = false; //Adding the <p> if( iterator.Current.MoveToFirstChild() ) { //at least one "<p>" exists do { if( iterator.Current.GetAttribute( "guid", String.Empty ) == pluginId ) { //if the <p> corresponds to the updater data pFound = true; break; //We are on the right <p> } } while( iterator.Current.MoveToNext() ); if( !pFound ) { iterator.Current.InsertElementAfter( null, "p", null, null ); iterator.Current.MoveToNext(); iterator.Current.CreateAttribute( null, "guid", null, pluginId ); iterator.Current.CreateAttribute( null, "version", null, "1.0.0" ); iterator.Current.CreateAttribute( null, "name", null, pluginName ); } } else { //There is nothing in PluginsData, we add the updater's <p> iterator.Current.AppendChildElement( null, "p", null, null ); iterator.Current.MoveToFirstChild(); iterator.Current.CreateAttribute( null, "guid", null, pluginId ); iterator.Current.CreateAttribute( null, "version", null, "1.0.0" ); iterator.Current.CreateAttribute( null, "name", null, pluginName ); //We are on the right <p> } //Last step : adding the <data> if( iterator.Current.MoveToFirstChild() ) { InsertUpdateElementAfter( iterator, value, key ); } else { //There are no children yet AppendChildUpdateElement( iterator, value, key ); } }
/// <summary> /// /// </summary> /// <param name="iteratorSport"></param> /// <returns></returns> private IPeriod PeriodPinnacleParse(XPathNavigator matchEventNameNavigator, XPathNodeIterator iteratorBet) { XPathNavigator _betNameNavigator = iteratorBet.Current.Clone(); IPeriod _period = new Period(); // Add period to Match //handicap XPathExpression exprehandicap; exprehandicap = matchEventNameNavigator.Compile("spreads/spread"); XPathNodeIterator iteratorHandicap = matchEventNameNavigator.Select(exprehandicap); //total XPathExpression expretotal; expretotal = matchEventNameNavigator.Compile("totals/total"); XPathNodeIterator iteratorTotal = matchEventNameNavigator.Select(expretotal); //moneyline XPathExpression expremoneyline; expremoneyline = matchEventNameNavigator.Compile("moneyLine"); XPathNodeIterator iteratorMoneyLine = matchEventNameNavigator.Select(expremoneyline); while (iteratorHandicap.MoveNext()) { ISpread _spread = SpreadPinnacleParse(iteratorHandicap); if (_period.Spreads == null) { _period.Spreads = new List<ISpread>(); } _period.Spreads.Add(_spread); } while (iteratorTotal.MoveNext()) { ITotal _total = TotalPinnacleParse(iteratorTotal); if (_period.Totals == null) { _period.Totals = new List<ITotal>(); } _period.Totals.Add(_total); } while (iteratorMoneyLine.MoveNext()) { IMoneyLine _moneyline = MoneyLinePinnacleParse(iteratorMoneyLine); if (_period.MoneyLines == null) { _period.MoneyLines = new List<IMoneyLine>(); } _period.MoneyLines.Add(_moneyline); } if (_period.Totals != null && _period.MoneyLines != null && _period.Spreads != null) _period.Description = _betNameNavigator.SelectSingleNode("description").Value; return _period; }
private static XPathExpression CreateExpression(XPathNavigator nav, string xpath, XmlNamespaceManager ns) { XPathExpression expr = nav.Compile(xpath); expr.SetContext(ns); return expr; }
public bool IsMatch(XPathNavigator xpn, XmlNamespaceManager xnm) { if ( xpathExpression == null ) { xpathExpression=xpn.Compile(xpath); xpathExpression.SetContext(xnm); } return xpn.Matches(xpathExpression); // Debug.Assert(e.Name.Equals(name), "IsMatch called for incorrect element!"); // // TODO: L: bit messy // return Conditions == null || Conditions.Conditions ==null || // Conditions.Conditions.Count == 0 || Conditions.MatchesAll(e); }
private XPathNodeIterator CreateIterator(string queryString, XPathNavigator nav) { XPathExpression query = nav.Compile(queryString); XPathNodeIterator iter = nav.Select(query); return iter; }
private void createScenario(XPathNavigator navigator, XmlDocument document) { // Could move this to its own function if we start to use more. exprEvents = navigator.Compile("ChangeEngram | " + "CloseChatRoom | " + "Completion_Event | " + "Create_Event | " + "DefineEngram | " + "FlushEvents | " + "Launch_Event | " + "Move_Event | " + "OpenChatRoom | " + "Reiterate | " + "RemoveEngram | " + "Reveal_Event | " + "Species_Completion_Event | " + "StateChange_Event | " + "Transfer_Event"); // Set up component values String cType = "Scenario"; String cName = "Scenario"; XPathNavigator navScenario = navigator.SelectSingleNode("/Scenario"); XPathNavigator navScenarioName = navigator.SelectSingleNode("/Scenario/ScenarioName"); if (navScenarioName != null) { cName = navScenarioName.Value; } navScenario.CreateAttribute(String.Empty, "name", navScenario.NamespaceURI, cName); String cDescription = String.Empty; // Create component createComponent(ProjectConfiguration, document, cType, cName, cDescription); // Create parameters #region parameters createParameter(ProjectConfiguration, document, cName, "Component", "Scenario.Scenario Name", (navigator.SelectSingleNode("Scenario/ScenarioName") == null) ? String.Empty : navigator.SelectSingleNode("Scenario/ScenarioName").Value, String.Empty); createParameter(ProjectConfiguration, document, cName, "Component", "Scenario.Description", (navigator.SelectSingleNode("Scenario/Description") == null) ? String.Empty : navigator.SelectSingleNode("Scenario/Description").Value, String.Empty); createParameter(ProjectConfiguration, document, cName, "Component", "Scenario.Time To Attack", (navigator.SelectSingleNode("Scenario/TimeToAttack") == null) ? String.Empty : navigator.SelectSingleNode("Scenario/TimeToAttack").Value, String.Empty); if (navigator.SelectSingleNode("Scenario/ClientSideAssetTransfer") != null) { String clientSideAssetTransferValue = navigator.SelectSingleNode("Scenario/ClientSideAssetTransfer").Value; Boolean booleanValue = false; if (clientSideAssetTransferValue.Equals("0")) booleanValue = false; else if (clientSideAssetTransferValue.Equals("1")) booleanValue = true; else { Boolean result = Boolean.TryParse(clientSideAssetTransferValue, out booleanValue); if (!result) booleanValue = false; } createParameter(ProjectConfiguration, document, cName, "Component", "Scenario.Allow Asset Transfers", booleanValue.ToString(), String.Empty); } else createParameter(ProjectConfiguration, document, cName, "Component", "Scenario.Allow Asset Transfers", String.Empty, String.Empty); #endregion // Playfield is required. createPlayfield(navigator, document, navigator); // LandRegion is optional XPathNodeIterator itLandRegions = navigator.Select("/Scenario/LandRegion"); while (itLandRegions.MoveNext()) { createLandRegion(itLandRegions.Current, document, navigator); } // ActiveRegion is optional XPathNodeIterator itActiveRegions = navigator.Select("/Scenario/ActiveRegion"); while (itActiveRegions.MoveNext()) { itActiveRegions.Current.CreateAttribute(String.Empty, "name", itActiveRegions.Current.NamespaceURI, itActiveRegions.Current.SelectSingleNode("ID").Value); createActiveRegion(itActiveRegions.Current, document, navigator); } // Team is optional XPathNodeIterator itTeams = navigator.Select("/Scenario/Team"); while (itTeams.MoveNext()) { createTeam(itTeams.Current, document, navigator); } // DecisionMaker is optional XPathNodeIterator itDecisionMakers = navigator.Select("/Scenario/DecisionMaker"); while (itDecisionMakers.MoveNext()) { itDecisionMakers.Current.CreateAttribute(String.Empty, "name", itDecisionMakers.Current.NamespaceURI, itDecisionMakers.Current.SelectSingleNode("Identifier").Value); createDecisionMaker(itDecisionMakers.Current, document, navigator); } // Network is optional XPathNodeIterator itNetworks = navigator.Select("/Scenario/Network"); while (itNetworks.MoveNext()) { createNetwork(itNetworks.Current, document, navigator); } // DefineEngram is optional XPathNodeIterator itDefineEngrams = navigator.Select("/Scenario/DefineEngram"); while (itDefineEngrams.MoveNext()) { createEngram(itDefineEngrams.Current, document, navigator); } // Sensor is optional XPathNodeIterator itSensors = navigator.Select("/Scenario/Sensor"); while (itSensors.MoveNext()) { createSensor(itSensors.Current, document, navigator); } // Genus XPathNodeIterator itGenera = navigator.Select("/Scenario/Genus"); while (itGenera.MoveNext()) { createGenus(itGenera.Current, document, navigator); } // Species //Int32 speciesNum = 0; XPathNodeIterator itSpecies = navigator.Select("/Scenario/Species"); while (itSpecies.MoveNext()) { itSpecies.Current.CreateAttribute(String.Empty, "name", itSpecies.Current.NamespaceURI, itSpecies.Current.SelectSingleNode("Name").Value); createSpecies(itSpecies.Current, document, navigator); } // Events createEvents(navigator.SelectSingleNode("Scenario"), document, navigator); // Rule XPathNodeIterator itRules = navigator.Select("/Scenario/Rule"); while (itRules.MoveNext()) { itRules.Current.CreateAttribute(String.Empty, "name", itSpecies.Current.NamespaceURI, itRules.Current.SelectSingleNode("Name").Value); createRule(itRules.Current, document, navigator); } // Score XPathNodeIterator itScores = navigator.Select("/Scenario/Score"); while (itScores.MoveNext()) { itScores.Current.CreateAttribute(String.Empty, "name", itScores.Current.NamespaceURI, itScores.Current.SelectSingleNode("Name").Value); createScore(itScores.Current, document, navigator); } }
private static void AddEntryToSystemConf( string key, string value, string pluginId, string pluginName, XPathNavigator xPathNav ) { bool entrySet = false; string xPathExp = "//p[@guid='" + pluginId.ToUpper() + "']"; XPathNodeIterator iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); if( iterator.Count == 1 ) { entrySet = DoUpdateEntryToSystemConf( key, value, entrySet, iterator ); }//At the end of this if statement, we are either on the right data element, or a the end of the pluginsdata else { xPathExp = "//p[@guid='" + pluginId.ToLower() + "']"; iterator = xPathNav.Select( xPathNav.Compile( xPathExp ) ); if( iterator.Count == 1 ) { entrySet = DoUpdateEntryToSystemConf( key, value, entrySet, iterator ); } else //if the updater entry does not exist, create it { CreateEntryToSystemConf( key, value, pluginId, pluginName, xPathNav, ref xPathExp, ref iterator ); } } }
private static ComponentTemplateMetadata FindTemplateComponentMetadata(XPathNavigator nav) { ComponentTemplateMetadata template = null; //search for all references for template components metadata string templateType = typeof(ComponentTemplateMetadata).ToString(); XPathExpression expression = nav.Compile("//Metadata[starts-with(@type, '" + templateType + "')]"); XPathNavigator templateXmlNode = nav.SelectSingleNode(expression); if (templateXmlNode != null) { string label = templateXmlNode.GetAttribute("Label", String.Empty); IOSpec ioSpec = new IOSpec(); XPathNavigator ioSpecNav = templateXmlNode.SelectSingleNode("IOSpec"); ioSpec.ReadXml(ioSpecNav.ReadSubtree()); template = new ComponentTemplateMetadata(ioSpec, label); } return template; }
private void EditForm_Load(object sender, System.EventArgs e) { doc = new XPathDocument(FILE_NAME); nav = doc.CreateNavigator(); // Compile a standard XPath expression expr = nav.Compile("/catalog/cd/title"); iterator = nav.Select(expr); // Iterate on the node set comboBox1.Items.Clear(); try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); comboBox1.Items.Add(nav2.Value); } } catch(Exception ex) { Console.WriteLine(ex.Message); } comboBox1.SelectedIndex = 0; //save old title oldTitle = comboBox1.Text; }
internal void Compile(XPathNavigator nav) { if(Status == XPathSelectorStatus.Start) { GetXPath(nav); } if(Status == XPathSelectorStatus.Parsed) { xpath = nav.Compile(sXpath); xpath.SetContext(GetNSManager()); Status = XPathSelectorStatus.Compiled; } }
/// <summary> /// Upgrades the user configuration (from .NET 3.5 to .NET 4.0 and its breaking change - we now need a ContextProfileCollection in the UserConf) /// If the userConf, is in a 4.0 version, this method won't do anything /// It returns the contextpath found via the userconf, in case the context has been moved or renamed. /// Return String.Empty if a contextpath can't be found. /// </summary> /// <param name="xPathSystemNav"></param> /// <returns></returns> private static string UpgradeUser35To40( XPathNavigator xPathSystemNav ) { string xPathExp = "//UserProfile"; XmlDocument xPathDoc; XPathNavigator xPathUserNav; string userConfPath = String.Empty; string contextPath = String.Empty; XPathNodeIterator iterator = xPathSystemNav.Select( xPathSystemNav.Compile( xPathExp ) ); if( iterator.Count > 0 ) //if there is a path to a userConf { iterator.MoveNext(); if( iterator.Count > 1 ) //if there are more than one userProfile, find the last one. { while( iterator.Current.GetAttribute( "IsLast", "" ) != "True" ) iterator.MoveNext(); } userConfPath = iterator.Current.GetAttribute( "Address", "" ); if( !String.IsNullOrEmpty( userConfPath ) && File.Exists( userConfPath ) ) //and it exists { Console.Out.WriteLine( "Migrating from .NET 3.5 version to .NET 4.0 version..." ); xPathDoc = new XmlDocument(); xPathDoc.Load( userConfPath ); xPathUserNav = xPathDoc.CreateNavigator(); xPathExp = "//data[@key='LastContextPath']"; XPathNodeIterator userConfIterator = xPathUserNav.Select( xPathUserNav.Compile( xPathExp ) ); if( userConfIterator.Count == 1 ) // and we can find a LastContextPath ( -> this is a v3.5 userConf) { userConfIterator.MoveNext(); string contextPathTemp = userConfIterator.Current.Value; Uri uri = new Uri( contextPathTemp ); if( !String.IsNullOrEmpty( contextPathTemp ) && File.Exists( contextPathTemp ) ) //and that lastContextPath is reachable { contextPath = contextPathTemp; //Return the contextPath. //Remove the LastContextPath tag userConfIterator.Current.DeleteSelf(); //and add a ContextProfileCollection ( -> upgrade to v4) xPathUserNav = xPathDoc.CreateNavigator(); xPathExp = "//PluginStatusCollection"; userConfIterator = xPathUserNav.Select( xPathUserNav.Compile( xPathExp ) ); userConfIterator.MoveNext(); userConfIterator.Current.InsertElementAfter( "", "ContextProfileCollection", "", "" ); userConfIterator.Current.MoveToFollowing( "ContextProfileCollection", "" ); userConfIterator.Current.AppendChildElement( "", "ContextProfile", "", "" ); userConfIterator.Current.MoveToChild( "ContextProfile", "" ); userConfIterator.Current.CreateAttribute( "", "DisplayName", "", "Context" ); userConfIterator.Current.CreateAttribute( "", "Uri", "", @"file://" + contextPath.Replace( "\\", "/" ) ); xPathDoc.Save( userConfPath ); Console.Out.WriteLine( "Migration from .NET 3.5 version to .NET 4.0 version done" ); } } else { Console.Out.WriteLine( "Migration from .NET 3.5 version to .NET 4.0 version isn't necessary" ); } } else { Console.Out.WriteLine( "Migration from .NET 3.5 version to .NET 4.0 version isn't necessary" ); } } return contextPath; }
private void EditCand_Load(object sender, EventArgs e) { doc = new XPathDocument(FILE_NAME); nav = doc.CreateNavigator(); // Compile a standard XPath expression expr = nav.Compile("/config/voto/@puesto"); iterator = nav.Select(expr); // Iterate on the node set comboBox1.Items.Clear(); try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); comboBox1.Items.Add(nav2.Value); comboBox1.SelectedIndex = 0; } } catch (Exception ex) { MessageBox.Show(ex.Message); } //save old title oldTitle = comboBox1.Text; }