Ejemplo n.º 1
0
        private object ParseCellValue(INode p)
        {
            if (p.NodeType == NodeType.Uri)
            {
                return((p as IUriNode).Uri);
            }
            else if (p.NodeType == NodeType.Literal)
            {
                ILiteralNode literalNode = p as ILiteralNode;

                if (literalNode.DataType == null)
                {
                    if (string.IsNullOrEmpty(literalNode.Language))
                    {
                        return(literalNode.Value);
                    }
                    else
                    {
                        return(new Tuple <string, string>(literalNode.Value, literalNode.Language));
                    }
                }

                return(XsdTypeMapper.DeserializeString(literalNode.Value, literalNode.DataType));
            }

            return(null);
        }
        /// <summary>
        /// Takes a data value from the _queryResults datatable and returns a marshalled data object.
        /// </summary>
        /// <param name="cellValue">A cell value from a Virtuoso results datatable.</param>
        /// <returns>A reference to the marshalled data object.</returns>
        private object ParseCellValue(object cellValue)
        {
            if (cellValue is SqlExtendedString)
            {
                SqlExtendedString extendedString = cellValue as SqlExtendedString;

                if (extendedString.IsResource())
                {
                    // NOTE: We create an UriRef for correct equality comparision with fragment identifiers.
                    return(new UriRef(extendedString.ToString(), UriKind.RelativeOrAbsolute));
                }
                else if (extendedString.IsString() || extendedString.IsBlankId())
                {
                    return(extendedString.ToString());
                }
            }
            else if (cellValue is SqlRdfBox)
            {
                SqlRdfBox box = cellValue as SqlRdfBox;

                if (box.StrType != null)
                {
                    try
                    {
                        // NOTE: We create an UriRef for correct equality comparision with fragment identifiers.
                        return(XsdTypeMapper.DeserializeString(box.Value.ToString(), new UriRef(box.StrType)));
                    }
                    catch (KeyNotFoundException)
                    {
                        // The given data type is not known by the XsdTypeMapper.
                        return(box.Value.ToString());
                    }
                }
                else if (box.Value is SqlExtendedString && box.StrLang != null)
                {
                    return(new Tuple <string, CultureInfo>(box.Value.ToString(), new CultureInfo(box.StrLang)));
                }
                else if (box.Value != null)
                {
                    return(box.Value.ToString());
                }
            }
            else if (cellValue is int)
            {
                // TODO: We need a different approach to store and read booleans.
                return(cellValue);
            }
            else if (cellValue is DateTime)
            {
                // Virtuoso delivers the time not as UTC but as "unspecified"
                // we convert it to local time
                return(((DateTime)cellValue).ToLocalTime());
            }
            else if (cellValue is VirtuosoDateTimeOffset)
            {
                return(((VirtuosoDateTimeOffset)cellValue).Value.UtcDateTime.ToUniversalTime());
            }

            return(cellValue);
        }
Ejemplo n.º 3
0
        protected object ParseValue(INode value)
        {
            switch (value.NodeType)
            {
            case (NodeType.Literal):
            {
                return(XsdTypeMapper.DeserializeLiteralNode(value as BaseLiteralNode));
            }

            case (NodeType.Uri):
            {
                return(new Resource((value as UriNode).Uri));
            }

            case (NodeType.GraphLiteral):
            {
                return(null);
            }

            case (NodeType.Variable):
            {
                return(null);
            }

            default:
            {
                return(null);
            }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a boolean literal value.
        /// </summary>
        /// <param name="factory">A node factory.</param>
        /// <param name="value">Value of the literal node.</param>
        /// <returns>A new literal node object.</returns>
        public static INode CreateLiteralNode(this NodeFactory factory, bool value)
        {
            var literalValue = XmlConvert.ToString(value);
            var literalType  = XsdTypeMapper.GetXsdTypeUri(typeof(bool));

            return(factory.CreateLiteralNode(literalValue, literalType));
        }
Ejemplo n.º 5
0
 private static Uri GetDataType(ConstantExpression constant)
 {
     if (constant.Type == typeof(string))
     {
         return(null);
     }
     else
     {
         return(XsdTypeMapper.GetXsdTypeUri(constant.Type));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Convert the expression into a node.
        /// </summary>
        /// <param name="constant">A constant expression.</param>
        /// <returns>A <c>Node</c> object.</returns>
        public static INode AsNode(this ConstantExpression constant)
        {
            if (typeof(Uri).IsAssignableFrom(constant.Type))
            {
                // If we have a URI constant, return a URI node.
                return(new NodeFactory().CreateUriNode(constant.Value as Uri));
            }
            else if (XsdTypeMapper.HasXsdTypeUri(constant.Type) || constant.Value is string)
            {
                // If we have a literal value, return literal nodes.
                string value    = GetValue(constant);
                Uri    datatype = GetDataType(constant);

                if (datatype == null)
                {
                    return(new NodeFactory().CreateLiteralNode(value));
                }
                else
                {
                    return(new NodeFactory().CreateLiteralNode(value, datatype));
                }
            }
            else if (typeof(Resource).IsAssignableFrom(constant.Type))
            {
                // If we have a constant of type Resource, return a URI node.
                Resource resource = constant.Value as Resource;

                return(new NodeFactory().CreateUriNode(resource.Uri));
            }
            else
            {
                // We cannot determine the Uri of generic reference types.
                string msg = string.Format("Unsupported constant type: {0}", constant.Type);
                throw new ArgumentException(msg);
            }
        }