Пример #1
0
        public string Get()
        {
            DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create();

            if (dataSource.GetType() == typeof(PagingDataSource))
            {
                PagingDataSource ds = dataSource as PagingDataSource;

                IEnumerable <string> jsonCollection;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters);
                }
                else
                {
                    jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters);
                }
                string json = string.Format("[{0}]", string.Join(",", jsonCollection));

                int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                json = string.Format("{{\"@count\":{0},\"value\":{1}}}", count, json);
                return(json);
            }
            else if (dataSource.GetType() == typeof(CollectionDataSource))
            {
                CollectionDataSource ds = dataSource as CollectionDataSource;

                IEnumerable <string> jsonCollection;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters);
                }
                else
                {
                    jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters);
                }
                return(string.Format("[{0}]", string.Join(",", jsonCollection)));
            }
            else if (dataSource.GetType() == typeof(DefaultGetterDataSource))
            {
                DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource;
                return(ODataQuerier.GetDefault(dataSource.Entity, ds.Select));
            }
            else if (dataSource.GetType() == typeof(CountDataSource))
            {
                CountDataSource ds    = dataSource as CountDataSource;
                int             count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                return(string.Format("{{\"Count\": {0}}}", count));
            }

            throw new NotSupportedException(dataSource.GetType().ToString());
        }
Пример #2
0
        public XElement Get()
        {
            DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create();

            if (dataSource.GetType() == typeof(PagingDataSource))
            {
                PagingDataSource ds = dataSource as PagingDataSource;

                IEnumerable <XElement> xCollection;
                XElement xsd;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters, out xsd);
                }
                else
                {
                    xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters, out xsd);
                }
                string   collectionName = GetCollectionName(Schema, ds.Entity);
                XElement element        = new XElement(collectionName, xCollection);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);

                int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);

                return(Pack(element, count, xsd));
            }
            else if (dataSource.GetType() == typeof(CollectionDataSource))
            {
                CollectionDataSource ds = dataSource as CollectionDataSource;

                IEnumerable <XElement> xCollection;
                XElement xsd;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters, out xsd);
                }
                else
                {
                    xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters, out xsd);
                }
                string   collection = GetCollectionName(Schema, ds.Entity);
                XElement element    = new XElement(collection, xCollection);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);

                return(Pack(element, null, xsd));
            }
            else if (dataSource.GetType() == typeof(DefaultGetterDataSource))
            {
                DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource;
                XElement element           = ODataQuerier.GetDefault(dataSource.Entity, ds.Select, out XElement xsd);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);
                return(Pack(element, null, xsd));
            }
            else if (dataSource.GetType() == typeof(CountDataSource))
            {
                CountDataSource ds    = dataSource as CountDataSource;
                int             count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                return(new XElement("Count", count));
            }

            throw new NotSupportedException(dataSource.GetType().ToString());
        }