示例#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 MembershipSettings GetMembershipSettings()
        {
            MembershipSettings     membershipSettings = new MembershipSettings();
            IEnumerable <XElement> elements           = ODataQuerier.GetCollection("Setting", null, "Catalog eq 'Membership'", null);

            foreach (XElement element in elements)
            {
                string name  = element.Element("Name").Value;
                string value = element.Element("Value").Value;
                switch (name)
                {
                case "PasswordFormat":
                    membershipSettings.PasswordFormat = int.Parse(value);
                    break;

                case "PasswordCrypto":
                    membershipSettings.PasswordCrypto = int.Parse(value);
                    break;

                case "PasswordHash":
                    membershipSettings.PasswordHash = int.Parse(value);
                    break;

                case "MaxInvalidPasswordAttempts":
                    membershipSettings.MaxInvalidPasswordAttempts = int.Parse(value);
                    break;

                case "PasswordAttemptWindow":
                    membershipSettings.PasswordAttemptWindow = int.Parse(value);
                    break;

                case "MinRequiredPasswordLength":
                    membershipSettings.MinRequiredPasswordLength = int.Parse(value);
                    break;

                case "MinRequiredNonAlphanumericCharacters":
                    membershipSettings.MinRequiredNonAlphanumericCharacters = int.Parse(value);
                    break;

                case "PasswordStrengthRegularExpression":
                    membershipSettings.PasswordStrengthRegularExpression = value;
                    break;
                }
            }
            return(membershipSettings);
        }
示例#3
0
        public bool Exists(string entity, IEnumerable <KeyValuePair <string, object> > propertyValues)
        {
            string filter = GenerateFilter(propertyValues, out IReadOnlyDictionary <string, object> parameters);
            string select = propertyValues.First().Key;

            ODataQuerier <XElement> oDataQuerier = ODataQuerier <XElement> .Create(Name, Schema);

            IEnumerable <XElement> result = oDataQuerier.GetCollection(entity, select, filter, null, parameters);

            return(result.Count() > 0);
        }
示例#4
0
        public bool IsUnique(string entity, IEnumerable <KeyValuePair <string, object> > propertyValues, IEnumerable <KeyValuePair <string, object> > excludedKey)
        {
            string filter = GenerateFilter(propertyValues, out IReadOnlyDictionary <string, object> parameters);
            string select = string.Join(",", excludedKey.Select(p => p.Key));

            ODataQuerier <XElement> oDataQuerier = ODataQuerier <XElement> .Create(Name, Schema);

            IEnumerable <XElement> result = oDataQuerier.GetCollection(entity, select, filter, null, parameters);

            int count = result.Count();

            if (count == 0)
            {
                return(true);
            }
            if (count > 1)
            {
                return(false);
            }

            XElement element = result.First();

            foreach (KeyValuePair <string, object> pair in excludedKey)
            {
                object obj = pair.Value;

                string value;
                if (obj.GetType() == typeof(bool))
                {
                    value = ((bool)obj) ? "true" : "false";
                }
                else if (obj.GetType() == typeof(DateTime))
                {
                    value = new DotNETDateFormatter().Format((DateTime)obj);
                }
                else
                {
                    value = obj.ToString();
                }
                if (element.Element(pair.Key).Value == value)
                {
                    continue;
                }

                return(false);
            }
            return(true);
        }
示例#5
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());
        }