Пример #1
0
        //
        // GET: /Test/

        public ActionResult Index()
        {
            var sw          = new StringWriter();
            var files       = Context.Current.Resolve <IFileSystem>();
            var expressions = new List <ContentRegistration>();

            foreach (
                var file in files.GetFiles("~/Dinamico/Themes/Default/Views/ContentPages/").Where(f => f.Name.EndsWith(".cshtml")))
            {
                var cctx = new ControllerContext(ControllerContext.HttpContext, new RouteData(), new ContentPagesController());
                cctx.RouteData.Values.Add("controller", "DynamicPages");
                var v = ViewEngines.Engines.FindView(cctx, file.VirtualPath, null);

                if (v.View == null)
                {
                    sw.Write(string.Join(", ", v.SearchedLocations.ToArray()));
                }
                else
                {
                    var temp = new ContentPage();
                    cctx.RequestContext.RouteData.ApplyCurrentPath(new PathData(temp));
                    var vdd = new ViewDataDictionary {
                        Model = temp
                    };
                    var re = new ContentRegistration(new DefinitionMap().GetOrCreateDefinition(typeof(ContentPage)).Clone());
                    RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);
                    v.View.Render(new ViewContext(cctx, v.View, vdd, new TempDataDictionary(), sw), sw);
                    expressions.Add(re);
                }
            }
            return(View(expressions));
        }
Пример #2
0
		//
		// GET: /Test/

		public ActionResult Index()
		{
			StringWriter sw = new StringWriter();
			IFileSystem files = N2.Context.Current.Resolve<IFileSystem>();
			List<ContentRegistration> expressions = new List<ContentRegistration>();
			foreach (var file in files.GetFiles("~/Dinamico/Themes/Default/Views/ContentPages/").Where(f => f.Name.EndsWith(".cshtml")))
			{
				var cctx = new ControllerContext(ControllerContext.HttpContext, new RouteData(), new ContentPagesController());
				cctx.RouteData.Values.Add("controller", "DynamicPages");
				var v = ViewEngines.Engines.FindView(cctx, file.VirtualPath, null);

				if (v.View == null)
					sw.Write(string.Join(", ", v.SearchedLocations.ToArray()));
				else
				{
					var temp = new ContentPage();
					cctx.RequestContext.RouteData.ApplyCurrentPath(new N2.Web.PathData(temp));
					var vdd = new ViewDataDictionary { Model = temp };
					var re = new ContentRegistration(new DefinitionMap().GetOrCreateDefinition(typeof(ContentPage)).Clone());
					N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);
					v.View.Render(new ViewContext(cctx, v.View, vdd, new TempDataDictionary(), sw), sw);
					expressions.Add(re);
				}
			}
			return View(expressions);
		}
        //
        // GET: /Test/

        public ActionResult Index()
        {
            StringWriter sw    = new StringWriter();
            IFileSystem  files = N2.Context.Current.Resolve <IFileSystem>();
            List <ContentRegistration> expressions = new List <ContentRegistration>();

            foreach (var file in files.GetFiles("~/Views/DynamicPages/").Where(f => f.Name.EndsWith(".cshtml")))
            {
                var cctx = new ControllerContext(ControllerContext.HttpContext, new RouteData(), new ContentPagesController());
                cctx.RouteData.Values.Add("controller", "DynamicPages");
                var v = ViewEngines.Engines.FindView(cctx, file.VirtualPath, null);

                if (v.View == null)
                {
                    sw.Write(string.Join(", ", v.SearchedLocations.ToArray()));
                }
                else
                {
                    var vdd = new ViewDataDictionary {
                        Model = new ContentPage()
                    };
                    var re = new ContentRegistration();
                    vdd["RegistrationExpression"] = re;
                    v.View.Render(new ViewContext(cctx, v.View, vdd, new TempDataDictionary(), sw), sw);
                    expressions.Add(re);
                }
            }
            return(View(expressions));
        }
Пример #4
0
        private static void FakeModel(ViewContentHelper content, ContentRegistration re)
        {
            if (content.Html.ViewContext.ViewData.Model == null)
            {
                var    modelType = content.Html.GetType().GetGenericArguments()[0];
                object model;
                if (modelType.IsAssignableFrom(re.ContentType) && !re.ContentType.IsAbstract)
                {
                    model = Activator.CreateInstance(re.ContentType);
                }
                else if (typeof(ContentItem).IsAssignableFrom(modelType) && !modelType.IsAbstract)
                {
                    model = Activator.CreateInstance(modelType);
                }
                else if (modelType.IsGenericType && typeof(IEnumerable <>).IsAssignableFrom(modelType.GetGenericTypeDefinition()))
                {
                    model = Array.CreateInstance(modelType.GetGenericTypeDefinition().MakeArrayType(), 0);
                }
                else
                {
                    return;
                }

                content.Html.ViewContext.ViewData.Model = content.Html.ViewData.Model = model;
            }
        }
Пример #5
0
		public void SetUp()
		{
			var item = new RegisterHelperTestsItem();
			definition = new ItemDefinition(item.GetType());
			var re = new ContentRegistration(definition);
			
			var html = new HtmlHelper(new ViewContext { HttpContext = new Fakes.FakeHttpContext("/") }, MockRepository.GenerateStub<IViewDataContainer>());
			RegistrationExtensions.SetRegistrationExpression(html.ViewContext.HttpContext, re);
			helper = new RegisterHelper(html);
		}
Пример #6
0
        public static ContentRegistration EndContainer(this ContentRegistration re)
        {
            if (re == null)
            {
                return(re);
            }

            re.Context.ContainerName = null;
            return(re);
        }
Пример #7
0
        public RegisteringDisplayRenderer(HtmlHelper html, string propertyName, ContentRegistration registration)
            : base(propertyName, registration)
        {
            Context         = new RenderingContext();
            Context.Content = html.CurrentItem();
            var template = html.ResolveService <IDefinitionManager>().GetTemplate(Context.Content);

            if (template != null)
            {
                Context.Displayable = template.Definition.Displayables.FirstOrDefault(d => d.Name == propertyName);
            }
            Context.Html         = html;
            Context.PropertyName = propertyName;
        }
Пример #8
0
        public void SetUp()
        {
            var item = new RegisterHelperTestsItem();

            definition = new ItemDefinition(item.GetType());
            var re = new ContentRegistration(definition);

            var html = new HtmlHelper(new ViewContext {
                HttpContext = new Fakes.FakeHttpContext("/")
            }, MockRepository.GenerateStub <IViewDataContainer>());

            RegistrationExtensions.SetRegistrationExpression(html.ViewContext.HttpContext, re);
            helper = new RegisterHelper(html);
        }
Пример #9
0
        public static ContentRegistration Container(this ContentRegistration re, string name, Action <ContentRegistration> registration)
        {
            if (re == null)
            {
                return(re);
            }

            string previousContainerName = re.Context.ContainerName;

            re.Context.ContainerName = name;
            if (registration != null)
            {
                registration(re);
                re.Context.ContainerName = previousContainerName;
            }

            return(re);
        }
Пример #10
0
        public static ContentRegistration FieldSet(this ContentRegistration re, string containerName, string legend, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.FieldSetContainerAttribute(containerName, legend, re.Context.NextSortOrder(sortOrder)));

            if (registration != null)
            {
                using (re.Context.BeginContainer(containerName))
                {
                    registration(re);
                }
            }

            return(re);
        }
Пример #11
0
        public static ContentRegistration FieldSet(this ContentRegistration re, string containerName, string legend, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.FieldSetContainerAttribute(containerName, legend, re.NextSortOrder(sortOrder)));

            string previousContainerName = re.ContainerName;

            re.ContainerName = containerName;
            if (registration != null)
            {
                registration(re);
                re.ContainerName = previousContainerName;
            }

            return(re);
        }
Пример #12
0
        //// containables

        public static ContentRegistration Tab(this ContentRegistration re, string containerName, string tabText, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.TabContainerAttribute(containerName, tabText, re.Context.NextSortOrder(sortOrder)));

            string previousContainerName = re.Context.ContainerName;

            re.Context.ContainerName = containerName;
            if (registration != null)
            {
                registration(re);
                re.Context.ContainerName = previousContainerName;
            }

            return(re);
        }
Пример #13
0
		private ContentRegistration RenderViewForRegistration(VirtualFile file, Type modelType, ControllerContext cctx, ViewEngineResult result)
		{
			var re = new ContentRegistration(map.CreateDefinition(modelType, N2.Web.Url.RemoveAnyExtension(file.Name)));
			re.IsDefined = false;
			re.Context.TouchedPaths.Add(file.VirtualPath);

			using (StringWriter sw = new StringWriter())
			{
				var vdd = new ViewDataDictionary();
				cctx.Controller.ViewData = vdd;
				N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);

				try
				{
					logger.DebugFormat("Rendering view {0} for registrations", file.VirtualPath);
					result.View.Render(new ViewContext(cctx, result.View, vdd, new TempDataDictionary(), sw), sw);
					logger.DebugFormat("Rendered view {0}, editables = {1}, defined = {2}", file.VirtualPath, re.Definition.Editables.Count, re.IsDefined);
				}
				catch (Exception ex)
				{
					logger.Error(file.VirtualPath, ex);
					if (re.IsDefined)
						throw;
					return null;
				}
				finally
				{
					N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, null);
				}

				if (re.IsDefined)
				{
					return re;
				}
				return null;
			}
		}
Пример #14
0
        //
        // GET: /Test/
        public ActionResult Index()
        {
            StringWriter sw = new StringWriter();
            IFileSystem files = N2.Context.Current.Resolve<IFileSystem>();
            List<ContentRegistration> expressions = new List<ContentRegistration>();
            foreach (var file in files.GetFiles("~/Views/DynamicPages/").Where(f => f.Name.EndsWith(".cshtml")))
            {
                var cctx = new ControllerContext(ControllerContext.HttpContext, new RouteData(), new ContentPagesController());
                cctx.RouteData.Values.Add("controller", "DynamicPages");
                var v = ViewEngines.Engines.FindView(cctx, file.VirtualPath, null);

                if (v.View == null)
                    sw.Write(string.Join(", ", v.SearchedLocations.ToArray()));
                else
                {
                    var vdd = new ViewDataDictionary { Model = new ContentPage() };
                    var re = new ContentRegistration();
                    vdd["RegistrationExpression"] = re;
                    v.View.Render(new ViewContext(cctx, v.View, vdd, new TempDataDictionary(), sw), sw);
                    expressions.Add(re);
                }
            }
            return View(expressions);
        }
Пример #15
0
 public void SetUp()
 {
     registration = new ContentRegistration(new DefinitionMap().GetOrCreateDefinition(typeof(EmptyItem)));
 }
Пример #16
0
 public EditableBuilder(string propertyName, ContentRegistration re)
     : base(propertyName, re)
 {
     this.PropertyName = propertyName;
     this.Registration = re;
 }
Пример #17
0
 public void SetUp()
 {
     registration             = new ContentRegistration();
     registration.ContentType = typeof(EmptyItem);
     sourceDefinition         = new DefinitionMap().GetOrCreateDefinition(registration.ContentType);
 }
Пример #18
0
        private ViewTemplateDescription RenderViewForRegistration(VirtualFile file, Type modelType, ControllerContext cctx, ViewEngineResult result)
        {
            var re = new ContentRegistration();
            re.ContentType = modelType;
            re.Template = N2.Web.Url.RemoveAnyExtension(file.Name);
            re.IsDefined = false;
            using (StringWriter sw = new StringWriter())
            {
                var vdd = new ViewDataDictionary();
                cctx.Controller.ViewData = vdd;
                vdd["RegistrationExpression"] = re;

                try
                {
                    result.View.Render(new ViewContext(cctx, result.View, vdd, new TempDataDictionary(), sw), sw);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                    if (re.IsDefined)
                        throw;
                    return null;
                }

                if (re.IsDefined)
                {
                    return new ViewTemplateDescription
                    {
                        Registration = re,
                        Definition = GetOrCreateDefinition(re),
                        TouchedPaths = new[] { file.VirtualPath }.Union(re.TouchedPaths)
                    };
                }
                return null;
            }
        }
Пример #19
0
 private ItemDefinition GetOrCreateDefinition(ContentRegistration re)
 {
     var definition = map.GetOrCreateDefinition(re.ContentType, re.Template);
     return definition;
 }
Пример #20
0
        private ContentRegistration RegisterPart(PartDefinitionPage pd)
        {
            var def = DefinitionMap.Instance.GetOrCreateDefinition(typeof(ContentPart), pd.Title);             // no extensions

            // registration - compare Dinamico views  @{ Content.Define(re => ... ) }
            var re = new ContentRegistration(def)
            {
                Definition  = { TemplateKey = pd.Name, Description = pd.Description },
                Context     = { GlobalSortOffset = pd.PartSortOrder },
                ContentType = def.ItemType,
                Title       = pd.Title,
                IconUrl     = pd.IconUrl
            };

            //if (!string.IsNullOrEmpty(pd.Definition))
            //{
            //    var jsd = new JavaScriptRegistration();
            //    jsd.Eval(re, pd.Definition);
            //}

            foreach (var attrDef in pd.Attributes)
            {
                AbstractEditableAttribute attr = null;
                var name = RemoveSpecialCharacters(attrDef.Title);
                switch (attrDef.PartType)
                {
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.RichText:
                    attr = new EditableTextAttribute {
                        TextMode = TextBoxMode.MultiLine, Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Number:
                    attr = new EditableNumberAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.CheckBox:
                    attr = new EditableCheckBoxAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Url:
                    attr = new EditableUrlAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Image:
                    attr = new EditableImageAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

#if TODO // use a better mechanism to find available types/attrs
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Category:
                    attr = new EditableCategorySelectionAttribute("ID:" + name)
                    {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Product:
                    attr = new EditableProductMultiSelectionAttribute("Id:" + name)
                    {
                        Name = name, Title = attrDef.Title
                    };
                    break;
#endif
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Text:
                default:
                    attr = new EditableTextAttribute {
                        TextMode = TextBoxMode.SingleLine, Name = name, Title = attrDef.Title
                    };
                    break;
                    //throw new ArgumentOutOfRangeException();
                }
                if (!string.IsNullOrEmpty(attrDef.DefaultValue))
                {
                    attr.DefaultValue = attrDef.DefaultValue;
                }

                attr.HelpText = attrDef.HelpText;

                re.Add(attr);
            }

            re.IsDefined = true;
            re.Finalize();
            return(re);
        }
Пример #21
0
 public void SetUp()
 {
     registration = new ContentRegistration();
     registration.ContentType = typeof(EmptyItem);
     sourceDefinition = new DefinitionMap().GetOrCreateDefinition(registration.ContentType);
 }
Пример #22
0
 public UnencodedRegisteringDisplayRenderer(RenderingContext context, ContentRegistration registration)
     : base(context, registration)
 {
 }
Пример #23
0
 public static void SetRegistrationExpression(HttpContextBase httpContext, ContentRegistration re)
 {
     httpContext.Items[RegistrationExpressionKey] = re;
 }
 public void SetUp()
 {
     registration = new ContentRegistration();
     registration.ContentType = typeof(EmptyItem);
 }
Пример #25
0
		public static void SetRegistrationExpression(HttpContextBase httpContext, ContentRegistration re)
		{
			httpContext.Items[RegistrationExpressionKey] = re;
		}
Пример #26
0
 public RegisteringDisplayRenderer(RenderingContext context, ContentRegistration registration)
     : base(context.PropertyName, registration)
 {
     this.Context = context;
 }
Пример #27
0
 public virtual RegisteringDisplayRenderer <T> Create <T>(Rendering.RenderingContext context, ContentRegistration re) where T : IEditable
 {
     return(new RegisteringDisplayRenderer <T>(context, re));
 }
Пример #28
0
 public void SetUp()
 {
     registration = new ContentRegistration(new DefinitionMap().GetOrCreateDefinition(typeof(EmptyItem)));
 }
		private ContentRegistration RegisterPart(PartDefinitionPage pd)
		{
			var def = DefinitionMap.Instance.GetOrCreateDefinition(typeof(ContentPart), pd.Title); // no extensions

			// registration - compare Dinamico views  @{ Content.Define(re => ... ) }
			var re = new ContentRegistration(def)
			    {
			        Definition = {TemplateKey = pd.Name, Description = pd.Description},
			        Context = {GlobalSortOffset = pd.PartSortOrder},
			        ContentType = def.ItemType,
			        Title = pd.Title,
			        IconUrl = pd.IconUrl
			    };

		    //if (!string.IsNullOrEmpty(pd.Definition))
			//{
			//    var jsd = new JavaScriptRegistration();
			//    jsd.Eval(re, pd.Definition);
			//}

			foreach (var attrDef in pd.Attributes)
			{
				AbstractEditableAttribute attr = null;
				var name = RemoveSpecialCharacters(attrDef.Title);
				switch (attrDef.PartType)
				{
					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.RichText:
						attr = new EditableTextAttribute { TextMode = TextBoxMode.MultiLine, Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Number:
						attr = new EditableNumberAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.CheckBox:
						attr = new EditableCheckBoxAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Url:
						attr = new EditableUrlAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Image:
						attr = new EditableImageAttribute { Name = name, Title = attrDef.Title };
						break;

#if TODO // use a better mechanism to find available types/attrs
                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Category:
                        attr = new EditableCategorySelectionAttribute("ID:" + name) { Name = name, Title = attrDef.Title };
                        break;

                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Product:
                        attr = new EditableProductMultiSelectionAttribute("Id:" + name) { Name = name, Title = attrDef.Title };
                        break;
#endif
                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Text:
                    default:
                        attr = new EditableTextAttribute { TextMode = TextBoxMode.SingleLine, Name = name, Title = attrDef.Title };
                        break;
                    //throw new ArgumentOutOfRangeException();
				}
				if (!string.IsNullOrEmpty(attrDef.DefaultValue))
					attr.DefaultValue = attrDef.DefaultValue;

				attr.HelpText = attrDef.HelpText;

				re.Add(attr);
			}

			re.IsDefined = true;
			re.Finalize();
			return re; 
		}
Пример #30
0
 public Builder(string propertyName, ContentRegistration re)
 {
     this.PropertyName = propertyName;
     this.Registration = re;
 }