/// <summary> /// Returns true if the result is unique among the results so far received. /// </summary> /// <param name="obj">The object that is potentially to be added to the results collection.</param> /// <returns>true if there is no object among the <see cref="IncomingResults"/> with the same <see cref="OwlInstanceSupertype.InstanceUri"/>.</returns> private bool ObjectIsUniqueSoFar(OwlInstanceSupertype obj) { if (obj == null) { return(true); } return(IncomingResults .Cast <OwlInstanceSupertype>() .Where(o => o.InstanceUri == obj.InstanceUri) .Count() == 0); }
/// <summary> /// A callback interface that gets called by SemWeb when results are sent /// back from a remote SPARQL source. This gets each unique set of bindings /// in turn. It can either store the results or deserialise them on the spot. /// </summary> /// <returns>true if the deserialiser was able to use the result or false otherwise</returns> protected override void ProcessResult(SparqlResult result) { #region Tracing #line hidden if (Logger.IsDebugEnabled) { Logger.Debug("Got Result {0}.", result.ToString()); } #line default #endregion if (IsSelectMember(SelectExpression)) { IncomingResults.Add(ExtractMemberAccess(result)); return; } if (originalType == null) { throw new LinqToRdfException("need ontology type to create"); } object t; IEnumerable <MemberInfo> props = GetPropertiesToPopulate(originalType, instanceType); if (originalType == instanceType) { #region not using a projection t = Activator.CreateInstance(instanceType); #region Tracing #line hidden if (Logger.IsDebugEnabled) { Logger.Debug("created new instance of {0}.", t.GetType().Name); } #line default #endregion AssignDataContext(t as OwlInstanceSupertype, DataContext); AssignInstanceUri(t as OwlInstanceSupertype, InstanceName, result); foreach (PropertyInfo pi in props) { if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition().Name.StartsWith("Entity")) { continue; } try { PopulateProperty(result, t, pi); } catch (ArgumentException ae) { #region Tracing #line hidden if (Logger.IsErrorEnabled) { Logger.ErrorEx("Unable to populate property " + pi.Name, ae); Logger.Error("continuing"); } #line default #endregion } catch (Exception e) { #region Tracing #line hidden if (Logger.IsErrorEnabled) { Logger.ErrorEx("Unable to populate property " + pi.Name, e); } #line default #endregion return; } } #endregion } else { #region using a projection var args = new List <object>(); foreach (PropertyInfo pi in props) { try { if (result.HasValue(pi.Name)) { if (result[pi.Name] != null) { string vVal = result[pi.Name].ToString(); vVal = RemoveEnclosingQuotesOnString(vVal, pi); if (IsXsdtEncoded(vVal)) { vVal = DecodeXsdtString(vVal); } args.Add(Convert.ChangeType(vVal, pi.PropertyType)); } } } catch (Exception e) { Console.WriteLine(e); return; } } t = Activator.CreateInstance(instanceType, args.ToArray()); #endregion } if (Distinct) { if (ObjectIsUniqueSoFar(t as OwlInstanceSupertype)) { IncomingResults.Add(t); } } else { IncomingResults.Add(t); } return; }