public void WriteTo(object obj, Stream stream, INamingScheme namingScheme = null)
        {
            Guard.ArgumentNotNull(obj, "obj");
            Guard.ArgumentNotNull(stream, "stream");

            var writer = new StreamWriter(stream);
            writer.Write(obj.ToString());
            writer.Flush();
        }
 public SDataQueryModelVisitor(INodeTypeProvider nodeTypeProvider = null, INamingScheme namingScheme = null)
 {
     _nodeTypeProvider = nodeTypeProvider ?? ExpressionTreeParser.CreateDefaultNodeTypeProvider();
     _namingScheme = namingScheme ?? NamingScheme.Default;
 }
Ejemplo n.º 3
0
 public SDataQueryable(ISDataClient client, string path, INamingScheme namingScheme)
     : this(QueryParser.CreateDefault(), client, path, namingScheme)
 {
 }
Ejemplo n.º 4
0
 private SDataQueryable(QueryParser queryParser, ISDataClient client, string path, INamingScheme namingScheme)
     : base(queryParser, new SDataQueryExecutor(client, path, queryParser.NodeTypeProvider, namingScheme))
 {
 }
Ejemplo n.º 5
0
 private PropertyPathExtractionVisitor(INodeTypeProvider nodeTypeProvider, bool selectMode, bool includeProtocolProps, INamingScheme namingScheme)
 {
     _nodeTypeProvider     = nodeTypeProvider;
     _selectMode           = selectMode;
     _includeProtocolProps = includeProtocolProps;
     _namingScheme         = namingScheme;
 }
Ejemplo n.º 6
0
        private static IList <IList <string> > ExtractPaths(Expression expression, INodeTypeProvider nodeTypeProvider, bool selectMode, bool includeProtocolProps, INamingScheme namingScheme)
        {
            var visitor = new PropertyPathExtractionVisitor(nodeTypeProvider, selectMode, includeProtocolProps, namingScheme);

            visitor.VisitExpression(expression);
            return(visitor._paths);
        }
Ejemplo n.º 7
0
        public static IList <string> ExtractPaths(Expression expression, INodeTypeProvider nodeTypeProvider, bool selectMode, bool includeProtocolProps, INamingScheme namingScheme, string separator)
        {
            var paths = ExtractPaths(expression, nodeTypeProvider, selectMode, includeProtocolProps, namingScheme);

            if (selectMode)
            {
                var lookup = paths.ToLookup(path => path[0] == "*");
                var dupes  = lookup[true].SelectMany(wildcard => lookup[false].Select(path => new { wildcard, path }))
                             .Where(pair => pair.wildcard.Skip(1).SequenceEqual(pair.path.Skip(1)))
                             .Select(pair => pair.path)
                             .ToList();
                paths = paths.Except(dupes).ToList();
            }
            return(paths
                   .Select(path => string.Join(separator, path.Reverse().ToArray()))
                   .Distinct()
                   .ToList());
        }
Ejemplo n.º 8
0
 public SerializerStrategy(INamingScheme namingScheme)
 {
     _namingScheme = namingScheme;
     _ctorCache    = new ReflectionUtils.ThreadSafeDictionary <Type, KeyValuePair <ParameterInfo[], ReflectionUtils.ConstructorDelegate> >(ConstructorFactory);
 }
Ejemplo n.º 9
0
 public static T Deserialize <T>(object value, INamingScheme namingScheme = null)
 {
     return((T) new SerializerStrategy(namingScheme ?? NamingScheme.Default).DeserializeObject(value, typeof(T)));
 }
Ejemplo n.º 10
0
 private SDataExpressionBuilderVisitor(INamingScheme namingScheme)
 {
     _namingScheme = namingScheme;
 }
Ejemplo n.º 11
0
 static NamingScheme()
 {
     Default = Basic;
 }
        private static object WriteSimpleCollection(XName name, IEnumerable <object> items, INamingScheme namingScheme, bool postMode)
        {
            var element   = new XElement(name);
            var prot      = items as ISDataProtocolObject;
            var info      = prot != null ? prot.Info : null;
            var localName = info != null ? info.XmlLocalName : null;
            var xmlNs     = info != null ? info.XmlNamespace : null;

            element.Add(items.Select(item =>
            {
                var itemProt = item as ISDataProtocolObject;
                var itemInfo = itemProt != null ? itemProt.Info : null;
                var itemName = XName.Get(localName ?? (itemInfo != null ? itemInfo.XmlLocalName : null) ?? item.GetType().Name,
                                         xmlNs ?? (itemInfo != null ? itemInfo.XmlNamespace : null) ?? name.NamespaceName);
                return(WriteItem(itemName, item, namingScheme, postMode));
            }));
            return(element);
        }
        private static object WriteResourceCollection(XName name, IEnumerable <IDictionary <string, object> > resources, INamingScheme namingScheme, bool postMode)
        {
            var element   = new XElement(name);
            var prot      = resources as ISDataProtocolObject;
            var info      = prot != null ? prot.Info : null;
            var localName = info != null ? info.XmlLocalName : null;
            var xmlNs     = info != null ? info.XmlNamespace : null;
            var elements  = resources.Select(item =>
            {
                var itemProt = item as ISDataProtocolObject;
                var itemInfo = itemProt != null ? itemProt.Info : null;
                var itemName = XName.Get(localName ?? (itemInfo != null ? itemInfo.XmlLocalName : null) ?? item.GetType().Name,
                                         xmlNs ?? (itemInfo != null ? itemInfo.XmlNamespace : null) ?? name.NamespaceName);
                return(WriteResource(itemName, item, namingScheme, postMode));
            });

            if (info != null)
            {
                if (info.XmlIsFlat)
                {
                    return(elements);
                }

                WriteAttributeValue(element, _sDataNs + "uri", info.Url != null ? info.Url.AbsoluteUri : null);
                WriteAttributeValue(element, _sDataNs + "deleteMissing", info.DeleteMissing);
            }

            element.Add(elements);
            return(element);
        }
        private static XElement WriteResource(XName name, IEnumerable <KeyValuePair <string, object> > resource, INamingScheme namingScheme, bool postMode)
        {
            var payload = new XElement(name);

            var prot = resource as ISDataProtocolObject;
            var info = prot != null ? prot.Info : null;

            if (info != null)
            {
                WriteAttributeValue(payload, _sDataNs + "key", info.Key);

                if (postMode || info.HttpMethod == HttpMethod.Post)
                {
                    if (info.Key != null)
                    {
                        return(payload);
                    }
                    postMode = true;
                }

                WriteAttributeValue(payload, _sDataNs + "uri", info.Url != null ? info.Url.AbsoluteUri : null);
                WriteAttributeValue(payload, _sDataNs + "uuid", info.Uuid);
                WriteAttributeValue(payload, _sDataNs + "lookup", info.Lookup);
                WriteAttributeValue(payload, _sDataNs + "descriptor", info.Descriptor);
                WriteAttributeValue(payload, _sDataNs + "isDeleted", info.IsDeleted);
            }

            payload.Add(resource.Select(item => WriteItem(name.Namespace + item.Key, item.Value, namingScheme, postMode)));
            return(payload);
        }
        private static XElement WriteEntry(ICollection <KeyValuePair <string, object> > resource, INamingScheme namingScheme)
        {
            var entry = new XElement(_atomNs + "entry");

            var prot = resource as ISDataProtocolObject;
            var info = prot != null ? prot.Info : null;

            if (info != null)
            {
                if (string.IsNullOrEmpty(info.XmlLocalName) && resource.Count > 0)
                {
                    throw new SDataClientException("XML local name must be specified when writing ATOM content");
                }

                WriteElementValue(entry, _atomNs + "id", info.Id);
                WriteElementValue(entry, _atomNs + "title", info.Title);
                WriteElementValue(entry, _atomNs + "updated", info.Updated);
                WriteElementValue(entry, _httpNs + "httpMethod", info.HttpMethod != null ? EnumEx.Format(info.HttpMethod).ToUpperInvariant() : null);
                WriteElementValue(entry, _httpNs + "httpStatus", (int?)info.HttpStatus);
                WriteElementValue(entry, _httpNs + "httpMessage", info.HttpMessage);
                WriteElementValue(entry, _httpNs + "location", info.Location);
                WriteElementValue(entry, _httpNs + "etag", info.ETag);
                WriteElementValue(entry, _httpNs + "ifMatch", info.IfMatch);

                var diagnoses = info.Diagnoses;
                if (diagnoses != null && diagnoses.Count > 0)
                {
                    foreach (var diagnosis in diagnoses)
                    {
                        entry.Add(SerializeObject(diagnosis));
                    }
                }

                var schema = info.Schema;
                if (!string.IsNullOrEmpty(schema))
                {
                    entry.Add(new XElement(_sDataNs + "schema", schema));
                }

                WriteLinks(entry, info.Links);

                var syncState = info.SyncState;
                if (syncState != null)
                {
                    entry.Add(SerializeObject(syncState));
                }

                if (info.XmlLocalName != null)
                {
                    var name = XName.Get(info.XmlLocalName, info.XmlNamespace ?? string.Empty);
                    entry.Add(new XElement(_sDataNs + "payload", WriteResource(name, resource, namingScheme, false)));
                }
            }

            return(entry);
        }
        private static XElement WriteFeed(IEnumerable <IDictionary <string, object> > resources, INamingScheme namingScheme)
        {
            var feed = new XElement(_atomNs + "feed");

            var prot = resources as ISDataProtocolObject;
            var info = prot != null ? prot.Info : null;

            if (info != null)
            {
                WriteElementValue(feed, _atomNs + "id", info.Id);
                WriteElementValue(feed, _atomNs + "title", info.Title);
                WriteElementValue(feed, _atomNs + "updated", info.Updated);
                WriteElementValue(feed, _openSearchNs + "totalResults", info.TotalResults);
                WriteElementValue(feed, _openSearchNs + "startIndex", info.StartIndex);
                WriteElementValue(feed, _openSearchNs + "itemsPerPage", info.ItemsPerPage);
                WriteElementValue(feed, _sDataNs + "syncMode", info.SyncMode);

                var diagnoses = info.Diagnoses;
                if (diagnoses != null && diagnoses.Count > 0)
                {
                    foreach (var diagnosis in diagnoses)
                    {
                        feed.Add(SerializeObject(diagnosis));
                    }
                }

                var schema = info.Schema;
                if (!string.IsNullOrEmpty(schema))
                {
                    feed.Add(new XElement(_sDataNs + "schema", schema));
                }

                WriteLinks(feed, info.Links);

                var syncDigest = info.SyncDigest;
                if (syncDigest != null)
                {
                    feed.Add(SerializeObject(syncDigest));
                }
            }

            feed.Add(resources.Select(resource => WriteEntry(resource, namingScheme)));
            return(feed);
        }