From 88a4d7edc72f7bee62b7bdf3f6f465b802f93823 Mon Sep 17 00:00:00 2001 From: matt4446 Date: Mon, 19 Mar 2012 00:12:57 +0000 Subject: [PATCH] rest --- Controllers/ServiceController.cs | 75 ++++++ Converter/ClayJsonConverter.cs | 70 ++++++ Layouts/JsonLayout.cs | 106 +++++++++ Layouts/JsonLayoutForms.cs | 96 ++++++++ Layouts/JsonShapes.cs | 94 ++++++++ Properties/AssemblyInfo.cs | 36 +++ Scripts/Web.config | 25 ++ Services/JsonFeedQuery.cs | 382 +++++++++++++++++++++++++++++++ Styles/Web.config | 25 ++ ViewModel/AdminIndexViewModel.cs | 12 + Views/Service/index.cshtml | 8 + Views/Web.config | 41 ++++ 12 files changed, 970 insertions(+) create mode 100644 Controllers/ServiceController.cs create mode 100644 Converter/ClayJsonConverter.cs create mode 100644 Layouts/JsonLayout.cs create mode 100644 Layouts/JsonLayoutForms.cs create mode 100644 Layouts/JsonShapes.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Scripts/Web.config create mode 100644 Services/JsonFeedQuery.cs create mode 100644 Styles/Web.config create mode 100644 ViewModel/AdminIndexViewModel.cs create mode 100644 Views/Service/index.cshtml create mode 100644 Views/Web.config diff --git a/Controllers/ServiceController.cs b/Controllers/ServiceController.cs new file mode 100644 index 0000000..0564132 --- /dev/null +++ b/Controllers/ServiceController.cs @@ -0,0 +1,75 @@ +using System; +using System.Linq; +using System.Text; +using System.Web.Mvc; +using Orchard; +using Orchard.DisplayManagement; +using Orchard.Localization; +using Orchard.Projections.Services; +using Orchard.Security; +using Orchard.Settings; +using Orchard.ContentManagement; +using Orchard.Tokens; +using JsonProjection.Feeds; +using Orchard.UI.Admin; +using Orchard.Themes; +using System.Net; + +namespace JsonProjection.Controllers +{ + public class ServiceController : Controller + { + private readonly IJsonFeedService jsonFeed; + + public ServiceController( + IOrchardServices services, + IShapeFactory shapeFactory, + IJsonFeedService jsonFeed) + { + + this.jsonFeed = jsonFeed; + + Services = services; + + T = NullLocalizer.Instance; + Shape = shapeFactory; + } + + public IOrchardServices Services { get; set; } + + public Localizer T { get; set; } + + public dynamic Shape { get; set; } + + [Admin] + public ActionResult Index() + { + var viewModel = new ViewModel.AdminIndexViewModel(); + viewModel.Items = this.Services.ContentManager.Query().List().ToList(); + + return View(viewModel); + } + + public ActionResult Feed(int id) + { + var feed = this.jsonFeed.Execute(id); + + return Content(feed, "JSON", Encoding.UTF8); + } + + /// + /// + /// + /// + /// + [Themed] + public ActionResult Preview(int id) { + if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries"))) + return new HttpUnauthorizedResult(); + + var feed = this.jsonFeed.Execute(id); + + return Content(feed); + } + } +} diff --git a/Converter/ClayJsonConverter.cs b/Converter/ClayJsonConverter.cs new file mode 100644 index 0000000..4b2ae41 --- /dev/null +++ b/Converter/ClayJsonConverter.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClaySharp; +using Newtonsoft.Json; +using Orchard.DisplayManagement; + +namespace JsonProjection.Converter +{ + //public class ClayJsonConverter : JsonConverter + //{ + // public override bool CanRead + // { + // get + // { + // // TODO: read Clay objects + // return false; + // } + // } + + // public override void WriteJson(JsonWriter writer, IShape value, JsonSerializer serializer) + // { + // //var clay = (IClayBehaviorProvider)value; + + // var members = new Dictionary(); + // ((IClayBehaviorProvider)value).Behavior.GetMembers(() => null, value, members); + + + // // Parse Clay Array + // var e = ((dynamic)value).GetEnumerator(); + // if (e != null && e.MoveNext()) + // { + // writer.WriteStartArray(); + // do + // { + // serializer.Serialize(writer, e.Current); + // } while (e.MoveNext()); + // writer.WriteEndArray(); + // } + + // var members = new Dictionary(); + // clay.Behavior.GetMembers(() => null, clay, members); + + // var memberKeys = members.Keys.Where(key => !key.StartsWith("_")).ToList(); + + // if (memberKeys.Count > 0) + // { + // writer.WriteStartObject(); + // foreach (var key in memberKeys) + // { + // writer.WritePropertyName(key); + // serializer.Serialize(writer, members[key]); + // } + + // writer.WriteEndObject(); + // } + // } + + // public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + // { + // throw new NotImplementedException(); + // } + + // public override bool CanConvert(Type objectType) + // { + // return typeof(Clay).IsAssignableFrom(objectType); + // } + //} +} diff --git a/Layouts/JsonLayout.cs b/Layouts/JsonLayout.cs new file mode 100644 index 0000000..99db060 --- /dev/null +++ b/Layouts/JsonLayout.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using JsonProjection.Converter; +using Newtonsoft.Json; +using Orchard.ContentManagement; +using Orchard.DisplayManagement; +using Orchard.Localization; +using Orchard.Projections.Descriptors.Layout; +using Orchard.Projections.Models; +using Orchard.Projections.Services; + +namespace JsonProjection.Layouts +{ + public class JsonLayout : ILayoutProvider + { + private readonly IContentManager _contentManager; + protected dynamic Shape { get; set; } + + public JsonLayout(IShapeFactory shapeFactory, IContentManager contentManager) + { + _contentManager = contentManager; + Shape = shapeFactory; + T = NullLocalizer.Instance; + } + + public Localizer T { get; set; } + + public void Describe(DescribeLayoutContext describe) + { + describe.For("JSON", T("JSON"), T("JSON Layouts")) + .Element("List", T("JSON List"), T("Organizes content items inside a json array."), + DisplayLayout, + RenderLayout, + "JsonLayout" + ); + } + + public LocalizedString DisplayLayout(LayoutContext context) + { + string order = context.State.Order; + + switch (order) + { + case "ordered": + return T("Ordered Html List"); + case "unordered": + return T("Unordered Html List"); + default: + throw new ArgumentOutOfRangeException("order"); + } + } + + public dynamic RenderLayout(LayoutContext context, IEnumerable layoutComponentResults) + { + int columns = 2;//Convert.ToInt32(context.State.Columns); + bool horizontal = Convert.ToString(context.State.Alignment) != "vertical"; + string rowClass = context.State.RowClass; + string gridClass = context.State.GridClass; + string gridId = context.State.GridId; + + IEnumerable shapes = + //context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content + // ? layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType)) + layoutComponentResults.Select(x => x.Properties); + + //ClayJsonConverter converter = new ClayJsonConverter(); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //using (JsonWriter jsonWriter = new JsonTextWriter(sw)) + //{ + // converter.WriteJson(jsonWriter, shapes, new JsonSerializer() { }); + //} + + return Shape.JsonList(Id: gridId, Horizontal: horizontal, Columns: columns, Items: shapes, Classes: new[] { gridClass }, RowClasses: new[] { rowClass }); + } + + //public dynamic RenderLayout(LayoutContext context, IEnumerable layoutComponentResults) + //{ + // string order = context.State.Order; + // string itemClass = context.State.ItemClass; + // string listClass = context.State.ListClass; + // string listId = context.State.ListId; + + // string listTag = order == "ordered" ? "ol" : "ul"; + + // IEnumerable shapes; + // if (context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content) + // { + // shapes = layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType)); + // } + // else + // { + // shapes = layoutComponentResults.Select(x => x.Properties); + // } + + // var classes = String.IsNullOrEmpty(listClass) ? Enumerable.Empty() : new[] { listClass }; + // var itemClasses = String.IsNullOrEmpty(itemClass) ? Enumerable.Empty() : new[] { itemClass }; + + // return Shape.List(Id: listId, Items: shapes, Tag: listTag, Classes: classes, ItemClasses: itemClasses); + //} + } +} diff --git a/Layouts/JsonLayoutForms.cs b/Layouts/JsonLayoutForms.cs new file mode 100644 index 0000000..e7f0915 --- /dev/null +++ b/Layouts/JsonLayoutForms.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Orchard.Core.Contents.Rules; +using Orchard.DisplayManagement; +using Orchard.Forms.Services; +using Orchard.Localization; + +namespace JsonProjection.Layouts +{ + public class JsonLayoutForms : Orchard.Forms.Services.IFormProvider { + protected dynamic Shape { get; set; } + public Localizer T { get; set; } + + public JsonLayoutForms( + IShapeFactory shapeFactory) { + Shape = shapeFactory; + T = NullLocalizer.Instance; + } + + public void Describe(DescribeContext context) { + //todo: add options: + //1. Include Query definition in json + //2. Require Authorization + //3. Permission stereotype + + Func form = + shape => { + + var f = + Shape.Form( + Id: "JsonLayout", + _Options: Shape.Fieldset( + Title: T("Fields"), + _ValueTrue: + Shape.Checkbox( + Id: "IncludeQueryDefinition", + Title: T("Include Query Definition"), + Checked: true, + Description: T("Include the title of the query in the json results") + ), + _ValueFalse: + Shape.Checkbox( + Id: "RequireAuthorization", + Title: T("Require Authorization"), + Checked: false, + Description: T("Require user to be authorized") + ) + ) + //_Options: Shape.Fieldset( + //Title: T("Alignment"), + //_ValueTrue: Shape.Radio( + // Id: "horizontal", Name: "Alignment", + // Title: T("Horizontal"), Value: "horizontal", + // Checked: true, + // Description: T("Horizontal alignment will place items starting in the upper left and moving right.") + // ), + //_ValueFalse: Shape.Radio( + // Id: "vertical", Name: "Alignment", + // Title: T("Vertical"), Value: "vertical", + // Description: T("Vertical alignment will place items starting in the upper left and moving dowmn.") + // ), + //_Colums: Shape.TextBox( + // Id: "columns", Name: "Columns", + // Title: T("Number of columns/lines "), + // Value: 3, + // Description: T("How many columns (in Horizontal mode) or lines (in Vertical mode) to display in the grid."), + // Classes: new[] { "small-text", "tokenized" } + // ) + //), + + ); + + return f; + }; + + context.Form("JsonLayout", form); + + } + } + + public class JsonLayoutFormsValitator : FormHandler + { + public Localizer T { get; set; } + + public override void Validating(ValidatingContext context) { + if (context.FormName == "JsonLayout") + { + //if (context.ValueProvider.GetValue("Order") == null) { + // context.ModelState.AddModelError("Order", T("You must provide an Order").Text); + //} + } + } + } +} diff --git a/Layouts/JsonShapes.cs b/Layouts/JsonShapes.cs new file mode 100644 index 0000000..6d49209 --- /dev/null +++ b/Layouts/JsonShapes.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Web.Mvc; +using System.Web.Mvc.Html; +using Orchard; +using Orchard.ContentManagement; +using Orchard.DisplayManagement; +using Orchard.Localization; +using Orchard.Mvc.Html; +using Orchard.Utility.Extensions; + +namespace JsonProjection.Layouts +{ + public class JsonShapes : IDependency + { + public JsonShapes() + { + T = NullLocalizer.Instance; + } + + public Localizer T { get; set; } + + [Shape] + public void JsonList(dynamic Display, TextWriter Output, HtmlHelper Html, string Id, bool Horizontal, IEnumerable Items, int Columns, IEnumerable Classes, IDictionary Attributes, IEnumerable RowClasses, IDictionary RowAttributes, IEnumerable CellClasses, IDictionary CellAttributes) + { + if (Items == null) + return; + + var items = Items.ToList(); + var itemsCount = items.Count; + + if (itemsCount < 1) + return; + + IList content = new List(); + + var gridTag = GetTagBuilder("table", Id, Classes, Attributes); + var rowTag = GetTagBuilder("tr", string.Empty, RowClasses, RowAttributes); + var cellTag = GetTagBuilder("td", string.Empty, CellClasses, CellAttributes); + + Output.Write(gridTag.ToString(System.Web.Mvc.TagRenderMode.StartTag)); + + // resolves which item to display in a specific cell + Func seekItem = (row, col) => row * Columns + col; + int maxRows = (itemsCount - 1) / Columns + 1; + int maxCols = Columns; + + if (!Horizontal) + { + seekItem = (row, col) => col * Columns + row; + maxCols = maxRows; + maxRows = Columns; + } + + for (int row = 0; row < maxRows; row++) + { + Output.Write(rowTag.ToString(TagRenderMode.StartTag)); + for (int col = 0; col < maxCols; col++) + { + int index = seekItem(row, col); + Output.Write(cellTag.ToString(TagRenderMode.StartTag)); + if (index < itemsCount) + { + Output.Write(Display(items[index])); + } + else + { + // fill an empty cell + Output.Write(" "); + } + + Output.Write(cellTag.ToString(TagRenderMode.EndTag)); + } + Output.Write(rowTag.ToString(TagRenderMode.EndTag)); + } + + Output.Write(gridTag.ToString(TagRenderMode.EndTag)); + } + + static TagBuilder GetTagBuilder(string tagName, string id, IEnumerable classes, IDictionary attributes) + { + var tagBuilder = new TagBuilder(tagName); + tagBuilder.MergeAttributes(attributes, false); + foreach (var cssClass in classes ?? Enumerable.Empty()) + tagBuilder.AddCssClass(cssClass); + if (!string.IsNullOrWhiteSpace(id)) + tagBuilder.GenerateId(id); + return tagBuilder; + } + + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e76856f --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("JsonProjection")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyProduct("Orchard")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8b2875f7-cda3-49c2-9c54-097ace7cffb3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: SecurityTransparent] diff --git a/Scripts/Web.config b/Scripts/Web.config new file mode 100644 index 0000000..6e8ebec --- /dev/null +++ b/Scripts/Web.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Services/JsonFeedQuery.cs b/Services/JsonFeedQuery.cs new file mode 100644 index 0000000..c3a023a --- /dev/null +++ b/Services/JsonFeedQuery.cs @@ -0,0 +1,382 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Web.Mvc; +using Newtonsoft.Json; +using Orchard; +using Orchard.ContentManagement; +using Orchard.Core.Feeds; +using Orchard.Core.Feeds.Models; +using Orchard.Core.Feeds.StandardBuilders; +using Orchard.DisplayManagement; +using Orchard.Projections.Descriptors.Layout; +using Orchard.Projections.Descriptors.Property; +using Orchard.Projections.Models; +using Orchard.Projections.Services; +using Orchard.Services; +using Orchard.Tokens; + +namespace JsonProjection.Feeds +{ + public interface IJsonFeedService : IDependency + { + bool Authorize(int queryId); + string Execute(int queryId); + } + + public class JsonFeedService : IJsonFeedService + { + private readonly IProjectionManager _projectionManager; + private readonly IEnumerable _htmlFilters; + private readonly ITokenizer tokenizer; + private readonly IDisplayHelperFactory displayHelperFactory; + private readonly IWorkContextAccessor workContextAccessor; + + public JsonFeedService(IOrchardServices services, + IProjectionManager projectionManager, + IEnumerable htmlFilters, + ITokenizer tokenizer, + IWorkContextAccessor workContextAccessor, + IDisplayHelperFactory displayHelperFactory) + { + this.tokenizer = tokenizer; + this.displayHelperFactory = displayHelperFactory; + this.workContextAccessor = workContextAccessor; + Services = services; + + _projectionManager = projectionManager; + _htmlFilters = htmlFilters; + } + + public IOrchardServices Services { get; private set; } + + //public void WriteItem(JsonWriter jsonWriter, IList properties, IEnumerable items) + //{ + // Func seekItem = (row, col) => (row * properties.Count) + col; + // var rows = shapes.Count / properties.Count; + // jsonWriter.WriteStartObject(); + + // for (var i = 0; i < rows; i++) + // { + // jsonWriter.WriteStartObject(); + // for (var c = 0; c < properties.Count; c++) + // { + // jsonWriter.WritePropertyName(properties[c]); + // jsonWriter.WriteNull(); + // //jsonWriter.WriteValue(shapes. + // } + // jsonWriter.WriteEndObject(); + // } + + // jsonWriter.WriteEndArray(); + //} + + //public void QueryProperties(JsonWriter jsonWriter, ProjectionPart projection, IEnumerable items) + //{ + // var shapes = items.Select(contentItem => this._contentManager.BuildDisplay(contentItem, "Summary", null)).ToList(); + + // if (shapes.Count == 0) + // { + // jsonWriter.WriteStartArray(); + // jsonWriter.WriteEndArray(); + + // return; + // } + + // jsonWriter.WriteStartArray(); + + // WriteItem(jsonWriter, new List(){ "Title", "Description" }, shapes); + + // jsonWriter.WriteEndArray(); + + // //for (int row = 0; row < maxRows; row++) + // //{ + // // Output.Write(rowTag.ToString(TagRenderMode.StartTag)); + // // for (int col = 0; col < maxCols; col++) + // // { + // // int index = seekItem(row, col); + // // Output.Write(cellTag.ToString(TagRenderMode.StartTag)); + // // if (index < itemsCount) + // // { + // // Output.Write(Display(items[index])); + // // } + // // else + // // { + // // // fill an empty cell + // // Output.Write(" "); + // // } + + // // Output.Write(cellTag.ToString(TagRenderMode.EndTag)); + // // } + // // Output.Write(rowTag.ToString(TagRenderMode.EndTag)); + // //} + + + // //return string.Empty; + //} + public bool Authorize(int queryId) + { + var projection = this.Services.ContentManager.Query() + .Where(e => e.QueryPartRecord.Id == queryId) + .List() + .FirstOrDefault(); + + return true; + } + + public string Execute(int queryId) + { + var projection = this.Services.ContentManager.Query() + .Where(e => e.QueryPartRecord.Id == queryId) + .List() + .FirstOrDefault(); + + var layout = projection.Record.LayoutRecord; + + LayoutDescriptor layoutDescriptor = layout == null ? null : + _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layout.Category && x.Type == layout.Type); + + var tokens = new Dictionary { { "Content", projection.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(); + var tokenizedDescriptors = fieldDescriptors.Select(fd => new { fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(tokenizer.Replace(fd.Property.State, tokens)) }).ToList(); + + var limit = projection.Record.MaxItems; + var items = _projectionManager.GetContentItems(queryId, 0, limit).ToList(); + + //var container = _contentManager.Get(projection.Record.QueryPartRecord.Id); + + var inspector = new ItemInspector(projection, Services.ContentManager.GetItemMetadata(projection), _htmlFilters); + + StringBuilder sb = new StringBuilder(); + StringWriter sw = new StringWriter(sb); + + var display = displayHelperFactory.CreateHelper(new ViewContext { HttpContext = workContextAccessor.GetContext().HttpContext }, new ViewDataContainer()); + + using (JsonWriter jsonWriter = new JsonTextWriter(sw)) + { + jsonWriter.Formatting = Formatting.Indented; + + jsonWriter.WriteStartObject(); + + jsonWriter.WriteComment("What new hell is this?"); + jsonWriter.WritePropertyName("title"); + jsonWriter.WriteValue(inspector.Title); + jsonWriter.WritePropertyName("description"); + jsonWriter.WriteValue(inspector.Description); + + jsonWriter.WritePropertyName("Items"); + jsonWriter.WriteStartArray(); + foreach (var contentItem in items) + { + var contentItemMetadata = Services.ContentManager.GetItemMetadata(contentItem); + var propertyDescriptors = tokenizedDescriptors.Select(d => + { + var fieldContext = new PropertyContext + { + State = d.State, + Tokens = tokens + }; + + return new { d.Property, Shape = d.Descriptor.Property(fieldContext, contentItem) }; + }); + + var properties = Services.New.Properties( + Items: propertyDescriptors.Select( + pd => Services.New.PropertyWrapper( + Item: pd.Shape, + Property: pd.Property, + ContentItem: contentItem, + ContentItemMetadata: contentItemMetadata + ) + ) + ); + + var itemInspector = new ItemInspector(contentItem, contentItemMetadata, _htmlFilters); + jsonWriter.WriteStartObject(); + //jsonWriter.WriteComment("title"); + //jsonWriter.WritePropertyName("title"); + //jsonWriter.WriteValue(itemInspector.Title); + //jsonWriter.WritePropertyName("description"); + //jsonWriter.WriteValue(itemInspector.Description); + + var propertyShapes = ((IEnumerable)properties.Items) + .Select(e => new { + Property = ((PropertyRecord)e.Property), + Description = ((PropertyRecord)e.Property).Description, + Proxy = e, + Content = Convert.ToString(display(e)) + }) + .ToList(); + + foreach (var field in propertyShapes) + { + jsonWriter.WritePropertyName(field.Description); + jsonWriter.WriteValue(field.Content); + } + + //foreach (var item in properties.Items) + //{ + // json + + // //var groups = layoutComponents.GroupBy( + // // x => + // // { + // // var propertyShape = ((IEnumerable)x.Properties.Items).First(p => ((PropertyRecord)p.Property).Id == groupPropertyId); + // // string key = Convert.ToString(display(propertyShape)); + // // return key; + // // }).Select(x => new { Key = x.Key, Components = x }); + + // //jsonWriter.WritePropertyName(item); + // //jsonWriter.WriteNull(); + //} + + jsonWriter.WriteEndObject(); + } + + jsonWriter.WriteEndArray(); + + jsonWriter.WriteEndObject(); + + } + + return sb.ToString(); + // var projectionId = context.ValueProvider.GetValue("projection"); + // if (projectionId == null) + // return; + + // var limitValue = context.ValueProvider.GetValue("limit"); + // var limit = 20; + // if (limitValue != null) + // limit = (int)limitValue.ConvertTo(typeof(int)); + + // var containerId = (int)projectionId.ConvertTo(typeof(int)); + // var container = _contentManager.Get(containerId); + + // if (container == null) + // { + // return; + // } + + // var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters); + + } + + } + + + + //public class QueryFeedQuery : IFeedQueryProvider, IFeedQuery + //{ + // private readonly IContentManager _contentManager; + // private readonly IProjectionManager _projectionManager; + // private readonly IEnumerable _htmlFilters; + + // public QueryFeedQuery( + // IContentManager contentManager, + // IProjectionManager projectionManager, + // IEnumerable htmlFilters) + // { + // _contentManager = contentManager; + // _projectionManager = projectionManager; + // _htmlFilters = htmlFilters; + // } + + // public FeedQueryMatch Match(FeedContext context) + // { + // var containerIdValue = context.ValueProvider.GetValue("projection"); + // if (containerIdValue == null) + // return null; + + // return new FeedQueryMatch { FeedQuery = this, Priority = 0 }; + // } + + // public void Execute(FeedContext context) + // { + // var projectionId = context.ValueProvider.GetValue("projection"); + // if (projectionId == null) + // return; + + // var limitValue = context.ValueProvider.GetValue("limit"); + // var limit = 20; + // if (limitValue != null) + // limit = (int)limitValue.ConvertTo(typeof(int)); + + // var containerId = (int)projectionId.ConvertTo(typeof(int)); + // var container = _contentManager.Get(containerId); + + // if (container == null) + // { + // return; + // } + + // var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters); + // if (context.Format.ToLower() == "xml") + // { + // StringBuilder sb = new StringBuilder(); + // StringWriter sw = new StringWriter(sb); + + // using (JsonWriter jsonWriter = new JsonTextWriter(sw)) + // { + // jsonWriter.Formatting = Formatting.Indented; + + // jsonWriter.WriteStartObject(); + // jsonWriter.WritePropertyName("CPU"); + // jsonWriter.WriteValue("Intel"); + // jsonWriter.WritePropertyName("PSU"); + // jsonWriter.WriteValue("500W"); + // jsonWriter.WritePropertyName("Drives"); + // jsonWriter.WriteStartArray(); + // jsonWriter.WriteValue("DVD read/writer"); + // jsonWriter.WriteComment("(broken)"); + // jsonWriter.WriteValue("500 gigabyte hard drive"); + // jsonWriter.WriteValue("200 gigabype hard drive"); + // jsonWriter.WriteEnd(); + // jsonWriter.WriteEndObject(); + + // } + + // context.Response.Element = new System.Xml.Linq.XElement( + + + // var link = new XElement("link"); + // context.Response.Element.SetElementValue("title", inspector.Title); + // context.Response.Element.Add(link); + // context.Response.Element.SetElementValue("description", inspector.Description); + + // context.Response.Contextualize(requestContext => + // { + // var urlHelper = new UrlHelper(requestContext); + // var uriBuilder = new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString()) { Path = urlHelper.RouteUrl(inspector.Link) }; + // link.Add(uriBuilder.Uri.OriginalString); + // }); + // } + // else + // { + // context.Builder.AddProperty(context, null, "title", inspector.Title); + // context.Builder.AddProperty(context, null, "description", inspector.Description); + // context.Response.Contextualize(requestContext => + // { + // var urlHelper = new UrlHelper(requestContext); + // context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link)); + // }); + // } + + // var items = _projectionManager.GetContentItems(container.Record.QueryPartRecord.Id, 0, limit).ToList(); + + // foreach (var item in items) + // { + // context.Builder.AddItem(context, item); + // } + // } + //} + + public class ViewDataContainer : IViewDataContainer + { + public ViewDataDictionary ViewData { get; set; } + } +} + + diff --git a/Styles/Web.config b/Styles/Web.config new file mode 100644 index 0000000..6e8ebec --- /dev/null +++ b/Styles/Web.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/ViewModel/AdminIndexViewModel.cs b/ViewModel/AdminIndexViewModel.cs new file mode 100644 index 0000000..5cd60e7 --- /dev/null +++ b/ViewModel/AdminIndexViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace JsonProjection.ViewModel +{ + public class AdminIndexViewModel + { + public IEnumerable Items { get; set; } + } +} diff --git a/Views/Service/index.cshtml b/Views/Service/index.cshtml new file mode 100644 index 0000000..e56a1d1 --- /dev/null +++ b/Views/Service/index.cshtml @@ -0,0 +1,8 @@ +@model JsonProjection.ViewModel.AdminIndexViewModel +

Feeds

+
    + @foreach (var item in Model.Items) + { +
  • @Html.ActionLink(item.Name, "Preview", "Service", new { Id = item.Id }, null)
  • + } +
diff --git a/Views/Web.config b/Views/Web.config new file mode 100644 index 0000000..f9e129f --- /dev/null +++ b/Views/Web.config @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +