/// <summary> /// This is an alternative to Find and allows the use of jQuery selector syntax to locate elements on the page. /// </summary> /// <param name="query">The query to use to locate elements</param> /// <returns>An HtmlResult object containing zero or more matches</returns> public HtmlResult Select(string query) { var result = new HtmlResult(XQuery.Execute(query, XDocument).Select(CreateHtmlElement).ToList(), this); Log("Selected " + result.TotalElementsFound + " element(s) via jQuery selector: " + query, LogMessageType.Internal); return(result); }
/// <summary> Deletes the ventilation </summary> public void DeleteVentilation(int id) { // Check if (id < 1) { return; } // Check if any references XQuery q = new XQuery() .From <Glass>() .Where() .Column <Glass>(x => x.IdGlassVentilation).Equals().Value(id); List <Glass> glasses = repository.GetEntities <Glass>(q).ToList(); // If reference present, remove reference if (!glasses.IsNullOrEmpty()) { foreach (Glass glass in glasses) { glass.IdGlassVentilation = (int?)null; } repository.Update(glasses); } q = new XQuery() .Delete() .From <GlassVentilation>() .Where() .Column <GlassVentilation>(x => x.Id).Equals().Value(id); repository.Delete(q); }
static String test(String query) { MyDiagnosticHandler diagnosticHandler = new MyDiagnosticHandler(); InMemoryStore store = InMemoryStore.getInstance(); Zorba zorba = Zorba.getInstance(store); XQuery xquery = zorba.compileQuery(query, diagnosticHandler); StringBuilder sbuilder = new StringBuilder(); Iterator iter = xquery.iterator(); iter.open(); Item item = new Item(); while (iter.next(item)) { sbuilder.Append(item.getStringValue()); } iter.close(); iter.Dispose(); xquery.destroy(); xquery.Dispose(); zorba.shutdown(); InMemoryStore.shutdown(store); return(sbuilder.ToString()); }
public void Test_AllSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute("*", doc); Assert.AreEqual(doc.Descendants().Count(), elements.Length, "All elements in the document should have been returned"); }
public List <OrderData> GetOrderData(int[] ids = null, int[] orderIds = null) { if (ids != null && orderIds != null) { throw new CoreException("No Ids specified!"); } XQuery q = new XQuery() .From <OrderData>() .Where(); bool whereset = false; if (ids != null) { q.Column <OrderData>(x => x.Id).In(ids); whereset = true; } if (orderIds != null) { if (whereset) { q.And(); } q.Column <OrderData>(x => x.IdOrder).In(orderIds); } return(repository.GetEntities <OrderData>(q).ToList()); }
static string test(string query, string xml, string doc) { InMemoryStore store = InMemoryStore.getInstance(); Zorba zorba = Zorba.getInstance(store); XmlDataManager dataManager = zorba.getXmlDataManager(); Iterator docIter = dataManager.parseXML(xml); docIter.open(); Item idoc = new Item(); docIter.next(idoc); docIter.close(); docIter.Dispose(); DocumentManager docManager = dataManager.getDocumentManager(); docManager.put(doc, idoc); XQuery xquery = zorba.compileQuery(query); string result = xquery.execute(); xquery.destroy(); xquery.Dispose(); zorba.shutdown(); InMemoryStore.shutdown(store); return(result); }
public void Test_ElementSelector() { var doc = GetWindow(TestHtml.Basic2); var elements = XQuery.Execute("li", doc); Assert.AreEqual(7, elements.Length, "Exactly 7 elements should have been returned"); Assert.IsTrue(elements.All(e => e.Name.LocalName.ToLower() == "li"), "All elements should have been LI"); }
public void Test_DescendentSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute("ul li", doc); Assert.AreEqual(4, elements.Length, "Exactly 4 elements should have been returned"); Assert.IsTrue(elements.All(e => e.Name.LocalName.ToLower() == "li"), "All elements should have been LI"); }
public void Test_ClassSelector() { var doc = GetWindow(TestHtml.Basic2); var elements = XQuery.Execute(".highlight", doc); Assert.AreEqual(2, elements.Length, "Exactly 2 elements should have been returned"); Assert.IsTrue(elements.All(e => e.Name.LocalName.CaseInsensitiveCompare("p")), "Elements returned should have been P tags"); Assert.IsTrue(elements.All(e => e.GetAttributeCI("class") == "highlight"), "Element returned should have had class=highlight"); }
public void Test_IdSelector() { var doc = GetWindow(TestHtml.Basic2); var elements = XQuery.Execute("#link", doc); Assert.AreEqual(1, elements.Length, "Exactly 1 element should have been returned"); Assert.IsTrue(elements[0].Name.LocalName.CaseInsensitiveCompare("a"), "Element returned should have been an anchor tag"); Assert.AreEqual("link", elements[0].GetAttributeCI("id"), "Element returned should have had id=link"); }
private XQuery CompileQuery([NotNull] XQuerySettings staticSettings) { Assert.ArgumentNotNull(staticSettings, "staticSettings"); var path = XQuery.GetMetadata("FullPath"); using (var file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) return(XmlPrime.XQuery.Compile(file, staticSettings)); }
public void Test_ClassSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute(".highlight", doc); Assert.AreEqual(2, elements.Length, "Exactly 2 elements should have been returned"); Assert.IsTrue(elements.All(e => String.Compare(e.Name.LocalName, "p", true) == 0), "Elements returned should have been P tags"); Assert.IsTrue(elements.All(e => e.GetAttributeCI("class") == "highlight"), "Element returned should have had class=highlight"); }
public void Test_IdSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute("#link", doc); Assert.AreEqual(1, elements.Length, "Exactly 1 element should have been returned"); Assert.IsTrue(String.Compare(elements[0].Name.LocalName, "a", true) == 0, "Element returned should have been an anchor tag"); Assert.AreEqual("link", elements[0].GetAttributeCI("id"), "Element returned should have had id=link"); }
/// <summary> Gets all available languages (translated). </summary> /// <remarks> TODO: get all languages with the not translated. </remarks> public IEnumerable <LanguageData> GetTranslatedLanguages(int languageId) { XQuery q = new XQuery() .From <LanguageData>() .Where().Column <LanguageData>(x => x.LanguageId).Equals().Value(languageId) .OrderBy <LanguageData>(x => x.LanguageSrcId) .End(); return(repository.GetEntities <LanguageData>(q)); }
public void Test_CommaSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute("ul, ol", doc); Assert.AreEqual(3, elements.Length, "Exactly 3 elements should have been returned"); Assert.AreEqual("ul", elements[0].Name.LocalName.ToLower()); Assert.AreEqual("ul", elements[1].Name.LocalName.ToLower()); Assert.AreEqual("ol", elements[2].Name.LocalName.ToLower()); }
public List <People> GetPeoples() { XQuery q = new XQuery() .From <People>() .Where() .Column <People>(x => x.Id).GreaterThan().Value(0); List <People> peoples = repository.GetEntities <People>(q).ToList(); return(peoples); }
public void Test_AttributeSelector_ContainsPrefix() { var doc = GetTestDocument(); var elements = XQuery.Execute("[href|=http]", doc); Assert.AreEqual(1, elements.Count(), "Should have returned exactly one element"); Assert.AreEqual("http://validator.w3.org/", elements.First().GetAttribute("href"), "Element should have contained the string: http://validator.w3.org/"); elements = XQuery.Execute("head > meta[content|=text]", doc); Assert.AreEqual(1, elements.Count(), "Should have returned exactly one element"); Assert.AreEqual("text/html; charset=iso-8859-1", elements.First().GetAttribute("content"), "Element should have contained the string: text/html; charset=iso-8859-1"); }
public void Test_ChildSelector() { var doc = GetTestDocument(); var elements = XQuery.Execute("body > ul > li", doc); Assert.AreEqual(3, elements.Length, "Exactly 3 elements should have been returned"); Assert.IsTrue(elements.All(e => e.Name.LocalName.ToLower() == "li"), "All elements should have been LI"); Assert.AreEqual(elements[0].ElementsBeforeSelf().Count(), 0, "Element 0 should have been the first child element"); Assert.AreEqual(elements[0].ElementsAfterSelf().FirstOrDefault(), elements[1], "Element 0 should have been directly before element 1"); Assert.AreEqual(elements[1].ElementsAfterSelf().FirstOrDefault(), elements[2], "Element 1 should have been directly before element 2"); Assert.AreEqual(elements[2].ElementsAfterSelf().Count(), 0, "Element 2 should have been the last child element"); }
/// <summary> Invokes the generic 'From' Method of the XQuery object. </summary> private void InvokeXQueryFromMethod(XQuery xQuery, Type targetEntity) { string fromMethod = "From"; // Get method reference MethodInfo method = xQuery.GetType().GetMethod(fromMethod); // Add generic type constraint method = method.MakeGenericMethod(new Type[] { targetEntity }); // Invoke method.Invoke(xQuery, null); }
/// <summary> Get Ids of all known languages. </summary> public IEnumerable <int> GetLanguageIds() { // Create query XQuery q = new XQuery() .Select().Column <Language>(ld => ld.Id) .From <Language>() .End(); // Fetch QueryResult qr = repository.GetData(q); return(qr.ConvertToEnumerable <int>()); }
/// <summary> Get OrderDatas by orderId. </summary> /// <param name="orderId">The id of the order to retrieve data for.</param> public List <OrderData> GetOrderData(int orderId) { if (orderId < 1) { throw new CoreException("No OrderId Specified!"); } XQuery q = new XQuery() .From <OrderData>() .Where() .Column <OrderData>(x => x.IdOrder).Equals().Value(orderId); return(repository.GetEntities <OrderData>(q).ToList()); }
public List <OrderData> GetOrderData(int[] ids) { if (ids.Length < 1) { throw new CoreException("No Ids specified!"); } XQuery q = new XQuery() .From <OrderData>() .Where() .Column <OrderData>(x => x.Id).In(ids); return(repository.GetEntities <OrderData>(q).ToList()); }
/// <summary> Get multiple wood entities. </summary> public List <Wood> GetWood(int[] ids) { if (ids.IsNullOrEmpty()) { return(null); } XQuery q = new XQuery() .From <Wood>() .Where() .Column <Wood>(x => x.Id).In(ids); return(repository.GetEntities <Wood>(q).ToList()); }
/// <summary> Deletes the wood paint color. </summary> /// <param name="id">The id of the paint color to delete.</param> public void DeletePaintColor(int id) { if (id < 1) { return; } XQuery q = new XQuery() .Delete() .From <WoodPaintColor>() .Where() .Column <WoodPaintColor>(x => x.Id).Equals().Value(id); repository.Delete(q); }
public void DeletePerson(int id) { if (id <= 0) { throw new CoreException("Invalid person specified!"); } XQuery q = new XQuery() .Delete() .From <People>() .Where() .Column <People>(x => x.Id).Equals().Value(id); repository.Delete(q); }
/// <summary> Deletes the DoorGlass. </summary> /// <param name="ids">Ids of doorglass to delete.</param> /// <param name="doorIds">DoorIds of doorglass to delete.</param> public void DeleteDoorGlass(int[] ids = null, int[] doorIds = null) { if (ids.IsNullOrEmpty() && doorIds.IsNullOrEmpty()) { return; } // Get entities XQuery q = new XQuery() .Select <DoorGlass>(); bool whereSet = false; if (!ids.IsNullOrEmpty()) { q.Where() .Column <DoorGlass>(x => x.Id).In(ids); whereSet = true; } if (!doorIds.IsNullOrEmpty()) { if (whereSet) { q.And(); } else { q.Where(); } q.Column <DoorGlass>(x => x.IdDoor).In(doorIds); } List <DoorGlass> doorGlasses = repository.GetEntities <DoorGlass>(q).ToList(); // Delete repository.Delete(doorGlasses); // Delete childs foreach (DoorGlass doorGlass in doorGlasses) { if (doorGlass.IdGlass.HasValue) { gMan.DeleteGlass(doorGlass.IdGlass.Value); } } }
//=== Manage: Order /// <summary> Get all orders. </summary> public List <Order> GetOrders(bool orderByDecending = false) { XQuery q = new XQuery() .From <Order>() .Where() .Column <Order>(x => x.Id).GreaterThan().Value(0); if (orderByDecending) { q.OrderByDescending <Order>(x => x.Id); } List <Order> orders = repository.GetEntities <Order>(q).ToList(); return(orders); }
private void Explain([NotNull] XQuery query) { Assert.ArgumentNotNull(query, "query"); Assert.IsNotNull(Plan, "Plan"); var settings = new XdmWriterSettings { Indent = true }; var stream = File.OpenWrite(Plan.GetMetadata("FullPath")); using (var xdmWriter = XdmWriter.Create(stream, settings)) query.Explain(xdmWriter); }
//=== Manage: Door Wood /// <summary> Get Door Wood. </summary> public List <FrameWood> GetFrameWood(int idFrame) { if (idFrame < 1) { throw new CoreException("Invalid FrameId specified!"); } XQuery q = new XQuery() .From <FrameWood>() .Where() .Column <FrameWood>(x => x.IdFrame).Equals().Value(idFrame); List <FrameWood> frameWoods = repository.GetEntities <FrameWood>(q).ToList(); return(frameWoods); }
static String test(String query) { InMemoryStore store = InMemoryStore.getInstance(); Zorba zorba = Zorba.getInstance(store); XQuery xquery = zorba.compileQuery(query); String result = xquery.printPlanAsDOT(); xquery.destroy(); xquery.Dispose(); zorba.shutdown(); InMemoryStore.shutdown(store); return(result); }