Exemple #1
0
 private void BuildSelectClause(StringBuilder queryBuilder, ProjectionPart parameters, List<IReferencePart> references)
 {
     var selectBldr = new StringBuilder("select ");
      parameters.ForEach(param => selectBldr.Append(param.GetSelectPart()));
      references.ForEach(reference => selectBldr.Append(reference.GetSelectParts()));
      queryBuilder.Append(selectBldr.ToString().TrimEnd(','));
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            ProjectionPart contentPart = value as ProjectionPart;
            var            record      = contentPart.Record;
            // dynamic  object corresponding to TicketPartRecord
            dynamic dynamicRecord = new JObject();

            dynamicRecord.ItemsPerPage = record.ItemsPerPage;
            dynamicRecord.MaxItems     = record.MaxItems;
            dynamicRecord.PagerSuffix  = record.PagerSuffix;
            dynamicRecord.Skip         = record.Skip;
            dynamicRecord.DisplayPager = record.DisplayPager;
            dynamicRecord.DisplayPager = record.DisplayPager;

            // layout
            if (record.LayoutRecord != null)
            {
                var     layoutRecord = record.LayoutRecord;
                dynamic layout       = new JObject();
                layout.Id                  = layoutRecord.Id;
                layout.DisplayType         = layoutRecord.DisplayType;
                layout.Category            = layoutRecord.Category;
                layout.Type                = layoutRecord.Type;
                layout.State               = layoutRecord.State;
                dynamicRecord.LayoutRecord = layout;
            }

            // query
            if (record.QueryPartRecord != null)
            {
                var     queryRecord = record.QueryPartRecord;
                dynamic query       = new JObject();
                query.Id = queryRecord.Id;
                dynamicRecord.QueryPartRecord = query;
            }

            // Id
            Utility.WriteProperty("Id", contentPart.Id, writer, serializer);

            Utility.WriteProperty("Record", dynamicRecord, writer, serializer);

            this.WriteCommonFields(writer, contentPart, serializer);

            writer.WriteEnd();
        }
Exemple #3
0
        private object GetFilteredRecords(string id, ProjectionPart part, out string filterDescription, ListQueryModel model, Func<ProjectionPart, object> query) {
            model.Filters = model.Filters ?? new FilterData[] {};

            var filterRecords = CreateFilters(id, model, out filterDescription);
            var filters = part.Record.QueryPartRecord.FilterGroups.First().Filters;
            filterRecords.ForEach(filters.Add);
            try {
                return query(part);
            }

            finally {
                foreach (var record in filterRecords) {
                    filters.Remove(record);
                    if (model.FilterGroupId == 0) {
                        _filterRepository.Delete(record);
                    }
                }
            }
        }
Exemple #4
0
        private IEnumerable <JObject> GetLayoutComponents(ProjectionPart part, int skipCount, int pageCount)
        {
            // query
            var query = part.Record.QueryPartRecord;

            // applying layout
            var layout = part.Record.LayoutRecord;
            var tokens = new Dictionary <string, object> {
                { "Content", part.ContentItem }
            };
            var allFielDescriptors = _projectionManager.DescribeProperties().ToList();
            var fieldDescriptors   = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList();

            fieldDescriptors = fieldDescriptors.Where(c => c != null).ToList();
            var tokenizedDescriptors = fieldDescriptors.Select(fd => new { fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(_tokenizer.Replace(fd.Property.State, tokens)) }).ToList();

            // execute the query
            var contentItems = _projectionManager.GetContentItems(query.Id, skipCount, pageCount).ToList();

            // sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop
            contentItems = contentItems.Where(x => !x.Has <ProjectionPart>()).ToList();

            var layoutComponents = contentItems.Select(
                contentItem => {
                var result          = new JObject();
                result["ContentId"] = contentItem.Id;
                tokenizedDescriptors.ForEach(
                    d => {
                    var fieldContext = new PropertyContext {
                        State  = d.State,
                        Tokens = tokens
                    };
                    var shape         = d.Descriptor.Property(fieldContext, contentItem);
                    string text       = (shape == null) ? string.Empty : shape.ToString();
                    var filedName     = d.Property.GetFiledName();
                    result[filedName] = text;
                });
                return(result);
            }).ToList();

            return(layoutComponents);
        }
Exemple #5
0
        private object GetFilteredRecords(string id, ProjectionPart part, out string filterDescription, ListQueryModel model, Func <ProjectionPart, object> query)
        {
            model.Filters = model.Filters ?? new FilterData[] {};

            var filterRecords = CreateFilters(id, model, out filterDescription);
            var filters       = part.Record.QueryPartRecord.FilterGroups.First().Filters;

            filterRecords.ForEach(filters.Add);
            try {
                return(query(part));
            }

            finally {
                foreach (var record in filterRecords)
                {
                    filters.Remove(record);
                    if (model.FilterGroupId == 0)
                    {
                        _filterRepository.Delete(record);
                    }
                }
            }
        }
Exemple #6
0
        private IEnumerable<JObject> GetLayoutComponents(ProjectionPart part, int skipCount, int pageCount) {
            // query
            var query = part.Record.QueryPartRecord;

            // applying layout
            var layout = part.Record.LayoutRecord;
            var tokens = new Dictionary<string, object> {{"Content", part.ContentItem}};
            var allFielDescriptors = _projectionManager.DescribeProperties().ToList();
            var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new {Descriptor = d, Property = p}).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList();
            fieldDescriptors = fieldDescriptors.Where(c => c != null).ToList();
            var tokenizedDescriptors = fieldDescriptors.Select(fd => new {fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(_tokenizer.Replace(fd.Property.State, tokens))}).ToList();

            // execute the query
            var contentItems = _projectionManager.GetContentItems(query.Id, skipCount, pageCount).ToList();

            // sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop
            contentItems = contentItems.Where(x => !x.Has<ProjectionPart>()).ToList();

            var layoutComponents = contentItems.Select(
                contentItem => {
                    var result = new JObject();
                    result["ContentId"] = contentItem.Id;
                    tokenizedDescriptors.ForEach(
                        d => {
                            var fieldContext = new PropertyContext {
                                State = d.State,
                                Tokens = tokens
                            };
                            var shape = d.Descriptor.Property(fieldContext, contentItem);
                            string text = (shape == null) ? string.Empty : shape.ToString();
                            var filedName = d.Property.GetFiledName();
                            result[filedName] = text;
                        });
                    return result;
                }).ToList();
            return layoutComponents;
        }