Exemplo n.º 1
0
        /// <summary>
        /// Builds the QueryOptions
        /// </summary>
        /// <param name="expression">The expression to convert</param>
        /// <returns>returns the query option for the PHP client library</returns>
        public PhpQueryOptions Convert(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            var odataUri = this.ExpressionConverter.ComputeUri(expression);

            var options = new PhpQueryOptions()
            {
                Filter      = odataUri.Filter,
                OrderBy     = odataUri.OrderBy,
                Count       = odataUri.IsCount(),
                InlineCount = odataUri.InlineCount == QueryOptions.InlineCountAllPages,
            };

            string inlineCount;

            if (odataUri.CustomQueryOptions.TryGetValue(QueryOptions.InlineCount, out inlineCount))
            {
                options.InlineCount = inlineCount == QueryOptions.InlineCountAllPages;
            }

            if (odataUri.Skip.HasValue)
            {
                options.Skip = odataUri.Skip.Value.ToString(CultureInfo.InvariantCulture);
            }

            if (odataUri.Top.HasValue)
            {
                options.Top = odataUri.Top.Value.ToString(CultureInfo.InvariantCulture);
            }

            if (odataUri.ExpandSegments.Count > 0)
            {
                options.Expand = this.UriToStringConverter.ConcatenateSegments(odataUri.ExpandSegments);
            }

            if (odataUri.SelectSegments.Count > 0)
            {
                options.Select = this.UriToStringConverter.ConcatenateSegments(odataUri.SelectSegments);
            }

            EntitySet expectedEntitySet;

            if (odataUri.TryGetExpectedEntitySet(out expectedEntitySet))
            {
                options.EntityContainer = expectedEntitySet.Container.Name;
                options.EntitySet       = expectedEntitySet.Name;
            }

            if (odataUri.IsEntity())
            {
                var key = odataUri.Segments.OfType <KeyExpressionSegment>().LastOrDefault();
                if (key != null)
                {
                    options.PrimaryKey = this.UriToStringConverter.ConvertToString(key);
                }
            }

            return(options);
        }
        /// <summary>
        /// Builds the QueryOptions 
        /// </summary>
        /// <param name="expression">The expression to convert</param>
        /// <returns>returns the query option for the PHP client library</returns>
        public PhpQueryOptions Convert(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            var odataUri = this.ExpressionConverter.ComputeUri(expression);

            var options = new PhpQueryOptions()
            {
                Filter = odataUri.Filter,
                OrderBy = odataUri.OrderBy,
                Count = odataUri.IsCount(),
                InlineCount = odataUri.InlineCount == QueryOptions.InlineCountAllPages,
            };

            string inlineCount;
            if (odataUri.CustomQueryOptions.TryGetValue(QueryOptions.InlineCount, out inlineCount))
            {
                options.InlineCount = inlineCount == QueryOptions.InlineCountAllPages;
            }

            if (odataUri.Skip.HasValue)
            {
                options.Skip = odataUri.Skip.Value.ToString(CultureInfo.InvariantCulture);
            }
            
            if (odataUri.Top.HasValue)
            {
                options.Top = odataUri.Top.Value.ToString(CultureInfo.InvariantCulture);
            }
            
            if (odataUri.ExpandSegments.Count > 0)
            {
                options.Expand = this.UriToStringConverter.ConcatenateSegments(odataUri.ExpandSegments);
            }

            if (odataUri.SelectSegments.Count > 0)
            {
                options.Select = this.UriToStringConverter.ConcatenateSegments(odataUri.SelectSegments);
            }

            EntitySet expectedEntitySet;
            if (odataUri.TryGetExpectedEntitySet(out expectedEntitySet))
            {
                options.EntityContainer = expectedEntitySet.Container.Name;
                options.EntitySet = expectedEntitySet.Name;
            }

            if (odataUri.IsEntity())
            {
                var key = odataUri.Segments.OfType<KeyExpressionSegment>().LastOrDefault();
                if (key != null)
                {
                    options.PrimaryKey = this.UriToStringConverter.ConvertToString(key);
                }
            }

            return options;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method to generate the PHP code
        /// </summary>
        /// <param name="expression">Expression from which PHP code is generated</param>
        /// <returns>The generated PHP code as string</returns>
        public string GenerateCode(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            this.options = this.ExpressionConverter.Convert(expression);

            using (this.phpCode = new StringWriter(CultureInfo.InvariantCulture))
            {
                this.AddInitialTags();
                this.WrapInTryBlock(() =>
                {
                    this.GenerateDataServiceClassObject();
                    this.GenerateCodeFromQueryExpression();
                    this.AddClosingTags();
                });
                this.AddCatchBlock();
                this.phpCode.WriteLine(PhpConstants.ClosingPhpTag);
                return(this.phpCode.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method to generate the PHP code
        /// </summary>
        /// <param name="expression">Expression from which PHP code is generated</param>
        /// <returns>The generated PHP code as string</returns>
        public string GenerateCode(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            this.options = this.ExpressionConverter.Convert(expression);

            using (this.phpCode = new StringWriter(CultureInfo.InvariantCulture))
            {
                this.AddInitialTags();
                this.WrapInTryBlock(() =>
                {
                    this.GenerateDataServiceClassObject();
                    this.GenerateCodeFromQueryExpression();
                    this.AddClosingTags();
                });
                this.AddCatchBlock();
                this.phpCode.WriteLine(PhpConstants.ClosingPhpTag);
                return this.phpCode.ToString();
            }
        }