public string NewSession() { if (beagleVersion == 0) { DaemonInformationRequest infoReq = new DaemonInformationRequest(true, false, false, false); DaemonInformationResponse infoResp = (DaemonInformationResponse)infoReq.Send(); beagleVersion = (uint)VersionStringToInt(infoResp.Version); } Session session = new Session(); session.VendorId = "Beagle"; session.VendorVersion = beagleVersion; session.VendorDisplay = "The Beagle desktop search tool"; session.VendorXesam = 90; session.VendorOntologyFields = Ontologies.GetSupportedXesamFields(); session.VendorOntologySources = Ontologies.GetSupportedXesamSources(); session.VendorOntologyContents = Ontologies.GetSupportedXesamContents(); sessions.Add(Convert.ToString(sessionCount), session); if (Debug) { Console.Error.WriteLine("NewSession() -- {0}", sessionCount); } return(Convert.ToString(sessionCount++)); }
private static string ParseXesamField(XPathNavigator nav) { string field = nav.GetAttribute("name", String.Empty); // FIXME: Using just the first field is NOT correct field = Ontologies.XesamToBeagleField(field)[0]; if (field.Contains(":")) { field = "property:" + field; } return(field); }
// This should be usable for both <query> and <category> private static string ParseXesamSourcesAndContents(XPathNavigator nav) { string ret = "", attr; bool has_source = false; attr = nav.GetAttribute("source", String.Empty); if (!String.IsNullOrEmpty(attr) && (attr != "xesam:Source")) { string[] sources = attr.Split(','); has_source = true; ret += "( " + Ontologies.XesamToBeagleSource(sources[0]); for (int i = 1; i < sources.Length; i++) { ret += " OR " + Ontologies.XesamToBeagleSource(sources[i].Trim()); } ret += " )"; } attr = nav.GetAttribute("content", String.Empty); if (!String.IsNullOrEmpty(attr) && (attr != "xesam:Content")) { string[] contents = attr.Split(','); if (has_source) { ret = "( " + ret + " AND "; } ret += "( " + Ontologies.XesamToBeagleContent(contents[0]); for (int i = 1; i < contents.Length; i++) { ret += " OR " + Ontologies.XesamToBeagleContent(contents[i].Trim()); } ret += " )"; if (has_source) { ret += " )"; } } return(ret); }
public void Only_one_ontology() { Ontologies.Should().ContainSingle("graph must define exactly one ontology"); }
public Hit(uint id, Beagle.Hit hit, string[] fields, Query query) { this.id = id; bHit = hit; hitValue = new object[fields.Length]; int i = 0; uri = hit.Uri; foreach (string field in fields) { // We add String.Empty to attributes because they may be null and we cannot // return null objects over DBus string[] bfields = Ontologies.XesamToBeagleField(field); switch (bfields [0]) { case "uri": hitValue [i++] = hit.Uri.ToString(); break; case "mimetype": hitValue [i++] = hit.MimeType + String.Empty; break; case "date": hitValue [i++] = hit.Timestamp.ToString("s"); break; case "snippet": SnippetRequest sreq = new SnippetRequest(query, hit); SnippetResponse sresp = (SnippetResponse)sreq.Send(); hitValue [i++] = sresp.Snippet != null ? sresp.Snippet : String.Empty; break; default: // FIXME: This *will* break since we don't know what the expected // type here is, and we're always using strings List <string> values = new List <string> (); foreach (string bfield in bfields) { string[] prop = hit.GetProperties(bfield); if (prop != null) { values.AddRange(prop); } } if (values.Count == 0) { // No values found hitValue [i++] = String.Empty; } else if (values.Count == 1) { // Only one value -- return as string hitValue [i++] = values [0]; } else { // Multiple values -- returns as string[] hitValue [i++] = values.ToArray(); } break; } } }
public void Only_one_ontology() { Assert.AreEqual(1, Ontologies.Count()); }