Beispiel #1
0
        public static ISelectElement Select <T>(this IXhtmlAnchor hook, Expression <Func <T, object> > propertyName, IEnumerable <IOptionElement> options)
        {
            var et     = new PropertyPathForType <T, object>(propertyName);
            var select = Document.CreateElement <ISelectElement>().Name(et.FullPath);

            //TODOD: Special case multiple values
            options.ForEach(option => select.ChildNodes.Add(option));
            return(select);
        }
Beispiel #2
0
        public static Element ValidationErrors(this IXhtmlAnchor anchor, IList <Error> errors)
        {
            if (errors == null || errors.Count == 0)
            {
                return(null);
            }

            return(new ValidationSummaryControl(errors));
        }
Beispiel #3
0
        public static IInputCheckedElement CheckBox(this IXhtmlAnchor anchor, Expression <Func <bool> > property)
        {
            var et      = new PropertyPathForInstance <bool>(property);
            var element = Document.CreateElement <IInputCheckedElement>("input").InputType(InputType.CheckBox).Name(et.FullPath);

            if ((bool)et.Value)
            {
                element.Checked();
            }
            return(element);
        }
Beispiel #4
0
        // TODO: Need to be moved to the core framework.
        public static void RenderResource(this IXhtmlAnchor anchor, Uri resource)
        {
            var context = new InMemoryCommunicationContext
            {
                Request = new InMemoryRequest
                {
                    HttpMethod = "GET",
                    Uri        = resource,
                    Entity     = new HttpEntity
                    {
                        ContentLength = 0
                    }
                }
            };

            context.Request.Headers["Accept"] = MediaType.XhtmlFragment.ToString();
            var textWriterProvider = anchor.AmbientWriter as ISupportsTextWriter;

            StringBuilder inMemoryRendering = null;

            if (textWriterProvider != null && textWriterProvider.TextWriter != null)
            {
                context.Response = new InMemoryResponse
                {
                    Entity = new TextWriterEnabledEntity(textWriterProvider.TextWriter)
                }
            }
            ;
            else
            {
                inMemoryRendering = new StringBuilder();
                var writer = new StringWriter(inMemoryRendering);
                context.Response = new InMemoryResponse {
                    Entity = new TextWriterEnabledEntity(writer)
                };
            }

            anchor.Resolver.Resolve <IPipeline>().Run(context);

            if (context.Response.Entity.Stream.Length > 0)
            {
                context.Response.Entity.Stream.Position = 0;
                var
                    destinationEncoding =
                    Encoding.GetEncoding(context.Response.Entity.ContentType.CharSet ?? "UTF8");

                var reader = new StreamReader(context.Response.Entity.Stream, destinationEncoding);
                anchor.AmbientWriter.WriteUnencodedString(reader.ReadToEnd());
            }
            else if (inMemoryRendering != null && inMemoryRendering.Length > 0)
            {
                anchor.AmbientWriter.WriteUnencodedString(inMemoryRendering.ToString());
            }
        }
Beispiel #5
0
        public static ISelectElement Select(this IXhtmlAnchor anchor, Expression <Func <object> > property)
        {
            var et = new PropertyPathForInstance <object>(property);

            Type enumType;
            bool isNullable = false;

            if (et.PropertyType.IsGenericType && et.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) && (enumType = et.PropertyType.GetGenericArguments()[0]).IsEnum)
            {
                isNullable = true;
            }
            else if (et.PropertyType.IsEnum)
            {
                enumType = et.PropertyType;
            }
            else
            {
                throw new InvalidOperationException("Cannot automatically generate select entries if the type is not an enumeration or a nullable enumeration.");
            }

            var optionElements = Enum.GetNames(enumType)
                                 .Select(x => Document.CreateElement <IOptionElement>().Value(x)[x]).ToList();

            if (isNullable)
            {
                optionElements.Insert(0, Document.CreateElement <IOptionElement>()[string.Empty]);
            }

            var select = Document.CreateElement <ISelectElement>().Name(et.FullPath);

            optionElements.ForEach(option => select.ChildNodes.Add(option));


            if (et.Value != null)
            {
                var valueToFind = et.Value.ConvertToString();
                foreach (var option in select.ChildNodes.Cast <IOptionElement>())
                {
                    option.Selected = option.Value == valueToFind || option.InnerText == valueToFind;
                }
            }
            else if (isNullable)
            {
                select.ChildNodes.Cast <IOptionElement>().First().Selected();
            }
            return(select);
        }
Beispiel #6
0
        public static ISelectElement Select(this IXhtmlAnchor hook, Expression <Func <object> > propertyName, IEnumerable <IOptionElement> options)
        {
            var et = new PropertyPathForInstance <object>(propertyName);


            var select = Document.CreateElement <ISelectElement>().Name(et.FullPath);

            //TODOD: Special case multiple values
            if (et.Value != null)
            {
                var valueToFind = et.Value.ConvertToString();
                foreach (var option in options)
                {
                    option.Selected = option.Value == valueToFind || option.InnerText == valueToFind;
                }
            }
            options.ForEach(option => select.ChildNodes.Add(option));
            return(select);
        }
Beispiel #7
0
        public static UnencodedOutput RenderUserControl(this IXhtmlAnchor anchor, string vpath, object parameters)
        {
            var control = DependencyManager.GetService(BuildManager.GetCompiledType(vpath)) as Control;

            if (parameters != null)
            {
                var keyValues = parameters.ToProperties();

                AssignPropertiesToControl(control, keyValues);
            }
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            var dummyPage = new Page();

            dummyPage.Controls.Add(control);

            HttpContext.Current.Server.Execute(dummyPage, writer, true);

            return((UnencodedOutput)builder.ToString());
        }
Beispiel #8
0
 public static ISelectElement Select(this IXhtmlAnchor hook, Expression <Func <object> > propertyName, IDictionary <string, string> options)
 {
     return(Select(hook, propertyName, options.Select(kv => Document.CreateElement <IOptionElement>().Value(kv.Key)[kv.Value]).ToList()));
 }
Beispiel #9
0
 public static ISelectElement Select(this IXhtmlAnchor hook, Expression <Func <object> > propertyName, IEnumerable <string> options)
 {
     return(Select(hook, propertyName, options.Select(val => Document.CreateElement <IOptionElement>()[val]).ToList()));
 }
Beispiel #10
0
 public static IInputTextElement Password <T>(this IXhtmlAnchor hook, Expression <Func <T, object> > property)
 {
     return(TextBox <T>(hook, property).InputType(InputType.Password));
 }
Beispiel #11
0
        public static ITextAreaElement TextArea <T>(this IXhtmlAnchor hook, Expression <Func <T, object> > property)
        {
            var expressionTree = new PropertyPathForType <T, object>(property);

            return(Document.CreateElement <ITextAreaElement>().Name(expressionTree.FullPath));
        }
Beispiel #12
0
        public static ITextAreaElement TextArea(this IXhtmlAnchor hook, Expression <Func <object> > property)
        {
            var expressionTree = new PropertyPathForInstance <object>(property);

            return(Document.CreateElement <ITextAreaElement>().Name(expressionTree.FullPath)[expressionTree.Value.ConvertToString()]);
        }
Beispiel #13
0
 public static IInputTextElement TextBox(this IXhtmlAnchor hook, Expression <Func <object> > property)
 {
     return(FillNameValue(Document.CreateElement <IInputTextElement>("input").InputType(InputType.Text), property));
 }
Beispiel #14
0
 public static UnencodedOutput RenderUserControl(this IXhtmlAnchor anchor, string vpath)
 {
     return(RenderUserControl(anchor, vpath, null));
 }
Beispiel #15
0
 public static void RenderResource(this IXhtmlAnchor anchor, object resource)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
 public static IAElement Link(this IXhtmlAnchor anchor, object instance)
 {
     return(Document.CreateElement <IAElement>().Href(instance.CreateUri()));
 }
Beispiel #17
0
 public static IAElement Link <T>(this IXhtmlAnchor anchor)
 {
     return(Document.CreateElement <IAElement>().Href(anchor.Uris.CreateUriFor <T>()));
 }
Beispiel #18
0
 public static IFormElement Form <TResource>(this IXhtmlAnchor anchor)
 {
     return(new FormElement(IsUriMethodOverrideActive(anchor.Resolver)).Action(anchor.Uris.CreateUriFor <TResource>()));
 }
Beispiel #19
0
 public static IFormElement Form(this IXhtmlAnchor anchor, object resourceInstance)
 {
     return(new FormElement(IsUriMethodOverrideActive(anchor.Resolver)).Action(resourceInstance.CreateUri()));
 }