Example #1
0
        /// <summary>
        /// Gets the ModelPropertyInfo collection for all the properties of a Model.
        /// </summary>
        /// <param name="targetType">The Model target type.</param>
        /// <returns></returns>
        private static List <ModelPropertyInfo> GetModelProperties(Type targetType)
        {
            var modelPropertyInfos = new List <ModelPropertyInfo>();
            var properties         = targetType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var property in properties)
            {
                var attributes        = property.GetCustomAttributes(false);
                var modelPropertyInfo = new ModelPropertyInfo
                {
                    Name           = property.Name,
                    PropertyInfo   = property,
                    IsRequired     = (property.PropertyType == typeof(Int32)) || ModelReflectionHelper.CheckHasRequiredAttribute(attributes),
                    Length         = ModelReflectionHelper.GetLenghtAttribute(attributes),
                    ExtXType       = ModelReflectionHelper.GetExtXType(property, attributes),
                    Label          = ModelReflectionHelper.GetLabel(attributes) ?? property.Name,
                    DropDownSource = ModelReflectionHelper.GetDropDownAttribute(attributes),
                    Mapping        = ModelReflectionHelper.GetMappingAttribute(attributes)
                };

                modelPropertyInfos.Add(modelPropertyInfo);
            }

            ModelReflector.ProcessDropDowns(modelPropertyInfos);

            return(modelPropertyInfos);
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            var js = new StringBuilder();

#if !DEBUG
            var minifier = new Microsoft.Ajax.Utilities.Minifier();
#endif
            context.Response.ContentType = "text/javascript";

            // ReSharper disable RedundantAssignment
            var cachedStaticFilesResult = MemoryCache.Default.Get("ED47.Stack.Reflector.Static") as string;
            // ReSharper restore RedundantAssignment
#if DEBUG
            //Disable caching during development to make debugging easier
            cachedStaticFilesResult = null;
#endif
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
            if (cachedStaticFilesResult == null)
            // ReSharper restore ConditionIsAlwaysTrueOrFalse
            {
                var staticScriptBuilder = new StringBuilder();
                staticScriptBuilder.AppendLine("/*==================  STATIC SCRIPTS ==================*/");
                ReflectorHandler.AppendStaticScripts(staticScriptBuilder);
                staticScriptBuilder.AppendLine("/*=====================================================*/");
                cachedStaticFilesResult = staticScriptBuilder.ToString();
            }

            js.Append(cachedStaticFilesResult);

            var assemblyNames = context.Request.QueryString["assemblyName"];

            if (String.IsNullOrWhiteSpace(assemblyNames))
            {
                context.Response.ContentType = "text/javascript";
                #if !DEBUG
                context.Response.Write(minifier.MinifyJavaScript(js.ToString()));
                #else
                context.Response.Write(js.ToString());
                #endif
                return;
            }

            var assemblyNameArray = assemblyNames.Split(';');

            foreach (var assemblyName in assemblyNameArray)
            {
                var cacheKey = "ED47.Stack.Reflector?assemblyName=" + assemblyName;
                // ReSharper disable RedundantAssignment
                var cachedResult = MemoryCache.Default.Get(cacheKey) as string;
                // ReSharper restore RedundantAssignment
#if DEBUG
                cachedResult = null; //Disable caching during development to make debugging easier
#endif
                // ReSharper disable ConditionIsAlwaysTrueOrFalse
                if (cachedResult == null)
                // ReSharper restore ConditionIsAlwaysTrueOrFalse
                {
                    cachedResult = ApiReflector.GenerateControllerScript(assemblyName) + ModelReflector.GenerateModelScript(assemblyName);
                    MemoryCache.Default.Add(new CacheItem(cacheKey, cachedResult),
                                            new CacheItemPolicy {
                        Priority = CacheItemPriority.NotRemovable
                    });
                }
                js.Append(cachedResult);
            }
#if DEBUG
            context.Response.Write(js.ToString());
#else
            context.Response.Write(minifier.MinifyJavaScript(js.ToString()));
#endif
        }