private void TestXmlSerialization(SparqlResult r, bool fullEquality) { Console.WriteLine("Input: " + r.ToString()); System.IO.StringWriter writer = new System.IO.StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(SparqlResult)); serializer.Serialize(writer, r); Console.WriteLine("Serialized Form:"); Console.WriteLine(writer.ToString()); SparqlResult s = serializer.Deserialize(new StringReader(writer.ToString())) as SparqlResult; Console.WriteLine("Deserialized Form: " + s.ToString()); Console.WriteLine(); if (fullEquality) { Assert.AreEqual(r, s, "Results should be equal"); } else { Assert.AreEqual(r.ToString(), s.ToString(), "String forms should be equal"); } }
private void TestDataContractSerialization(SparqlResult r, bool fullEquality) { Console.WriteLine("Input: " + r.ToString()); System.IO.StringWriter writer = new System.IO.StringWriter(); DataContractSerializer serializer = new DataContractSerializer(typeof(SparqlResult)); serializer.WriteObject(new XmlTextWriter(writer), r); Console.WriteLine("Serialized Form:"); Console.WriteLine(writer.ToString()); SparqlResult s = serializer.ReadObject(XmlTextReader.Create(new StringReader(writer.ToString()))) as SparqlResult; Console.WriteLine("Deserialized Form: " + s.ToString()); Console.WriteLine(); if (fullEquality) { Assert.Equal(r, s); } else { Assert.Equal(r.ToString(), s.ToString()); } }
private void TestBinarySerialization(SparqlResult r, bool fullEquality) { MemoryStream stream = new MemoryStream(); BinaryFormatter serializer = new BinaryFormatter(null, new StreamingContext()); serializer.Serialize(stream, r); stream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Serialized Form:"); StreamReader reader = new StreamReader(stream); Console.WriteLine(reader.ReadToEnd()); stream.Seek(0, SeekOrigin.Begin); SparqlResult s = serializer.Deserialize(stream) as SparqlResult; reader.Close(); if (fullEquality) { Assert.AreEqual(r, s, "Results should be equal"); } else { Assert.AreEqual(r.ToString(), s.ToString(), "String forms should be equal"); } stream.Dispose(); }
public State ParseSparqlResultSetToState(SparqlResultSet resultSet) { if (resultSet != null) { if (resultSet.Count > 1) { return(State.Alarm()); } else if (resultSet.Count == 1) { SparqlResult result = resultSet[0]; var resultString = result["state"].ToString(); OnNewLogMessage(result.ToString().Substring(29)); return(ParseResultStringToState(resultString)); } else if (resultSet.Count == 0) { return(State.Good()); } } return(State.Undefined()); }
/// <summary> /// Formats a SPARQL Result using this Formatter to format the Node values for each Variable /// </summary> /// <param name="result">SPARQL Result</param> /// <returns></returns> public override String Format(SparqlResult result) { return(result.ToString(this)); }
/// <summary> /// Formats a SPARQL Result for the given format. /// </summary> /// <param name="result">SPARQL Result.</param> /// <returns></returns> public virtual String Format(SparqlResult result) { return(result.ToString(this)); }
/// <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; }
/// <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; }
/// <summary> /// Formats a SPARQL Result using this Formatter to format the Node values for each Variable /// </summary> /// <param name="result">SPARQL Result</param> /// <returns></returns> public virtual String Format(SparqlResult result) { return result.ToString(this); }
/// <summary> /// Formats a SPARQL Result using this Formatter to format the Node values for each Variable /// </summary> /// <param name="result">SPARQL Result</param> /// <returns></returns> public override String Format(SparqlResult result) { return result.ToString(this); }