コード例 #1
0
        private void UpdateUrlBuilder()
        {
            this.UrlBuilder.ResourceFirst  = this.resourceComboBox.Text;
            this.UrlBuilder.ResourceSecond = null;
            this.UrlBuilder.ResourceId     = null;

            this.UrlBuilder.FilterComponents.Clear();
            for (int index = 0; index < this.queryGridView.Rows.Count; index++)
            {
                DataGridViewRow row = this.queryGridView.Rows[index];
                if (row.IsNewRow)
                {
                    continue;
                }

                string logicalOperator    = row.Cells[LogicalOperatorColumnName].Value as string;
                string comparisonOperator = row.Cells[ComparisonOperatorColumnName].Value as string;
                string propertyName       = row.Cells[PropertyColumnName].Value as string;
                string value = row.Cells[ValueColumnName].Value as string;

                if ((index != 0 && String.IsNullOrWhiteSpace(logicalOperator) ||
                     String.IsNullOrWhiteSpace(comparisonOperator) ||
                     String.IsNullOrWhiteSpace(propertyName) ||
                     String.IsNullOrWhiteSpace(value)))
                {
                    return;
                }

                GraphApiEntityType entity = GetEntityType(this.resourceComboBox.Text);
                if (entity == null)
                {
                    return;
                }

                GraphApiProperty property = entity.Properties.SingleOrDefault(p => p.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
                if (property == null)
                {
                    return;
                }

                GraphApiUrlFilterComponent filterComponent = new GraphApiUrlFilterComponent
                {
                    LogicalOperator    = index > 0 ? logicalOperator : null,
                    Property           = property,
                    ComparisonOperator = comparisonOperator,
                    Value = value
                };

                this.UrlBuilder.FilterComponents.Add(filterComponent);
            }
        }
コード例 #2
0
        private string CreateFilterQuery(GraphApiUrlBuilder builder)
        {
            const string  LogicalOperatorFormat = @" {0} ";
            const string  AnyEqString           = @"{0}/any(p:p {1} '{2}')";
            const string  FunctionOperator      = @"{0}({1},'{2}')";
            const string  OperatorForStrings    = @"{0} {1} '{2}'";
            const string  OperatorForGuids      = @"{0} {1} '{2}'";
            const string  OperatorForOthers     = @"{0} {1} {2}";
            StringBuilder filterQueryBuilder    = new StringBuilder();

            foreach (GraphApiUrlFilterComponent filterComponent in builder.FilterComponents)
            {
                string           andOr    = filterComponent.LogicalOperator;
                string           op       = filterComponent.ComparisonOperator;
                GraphApiProperty property = filterComponent.Property;
                string           value    = filterComponent.Value;

                if (filterQueryBuilder.Length > 0)
                {
                    filterQueryBuilder.AppendFormat(LogicalOperatorFormat, andOr);
                }

                if (op.Equals(Names.StartsWithOperator, StringComparison.OrdinalIgnoreCase))
                {
                    filterQueryBuilder.AppendFormat(FunctionOperator, Names.StartsWithOperator, property.Name, value);
                }
                else if (op.Equals(Names.AnyEqualsOperator, StringComparison.OrdinalIgnoreCase))
                {
                    filterQueryBuilder.AppendFormat(AnyEqString, property.Name, Names.EqualToOperator, value);
                }
                else if (property.Type == typeof(Guid))
                {
                    filterQueryBuilder.AppendFormat(OperatorForGuids, property.Name, op, value);
                }
                else if (property.Type == typeof(bool) || property.Type == typeof(int))
                {
                    filterQueryBuilder.AppendFormat(OperatorForOthers, property.Name, op, value);
                }
                else
                {
                    filterQueryBuilder.AppendFormat(OperatorForStrings, property.Name, op, value);
                }
            }

            return(filterQueryBuilder.ToString());
        }
コード例 #3
0
        private void SetComparisonOperators(DataGridViewRow row)
        {
            string propertyName = (string)row.Cells[PropertyColumnName].Value;

            GraphApiEntityType       entity       = GetEntityType(this.resourceComboBox.Text);
            GraphApiProperty         property     = entity.Properties.Single(p => p.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
            DataGridViewComboBoxCell operatorCell = (DataGridViewComboBoxCell)row.Cells[ComparisonOperatorColumnName];
            string operatorValue = operatorCell.Value as string;

            operatorCell.Items.Clear();
            string[] operators = property.GetAllowedComparisonOperators();
            operatorCell.Items.AddRange(operators);

            if (!operators.Contains(operatorValue))
            {
                operatorCell.Value = null;
            }
        }