示例#1
0
        public static HtmlString InputWithLabelFor <T>(Expression <Func <T, DateTime> > propertySelector,
                                                       string format = "M/D/YYYY", int?labelCols = null, int?inputCols = null, string label = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int stepping = 1)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(DateTimeWithLabel(propertyModel.DisplayNameLabel(label), propertyModel.JsVariableForBinding, format, preserve, stepping, labelCols, inputCols));
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                var resolver = options.SerializerSettings.ContractResolver;
                if (resolver != null)
                {
                    (resolver as DefaultContractResolver).NamingStrategy = null;
                }

                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            ReflectionRepository.AddContext <AppDbContext>();

            RoleMapping.Add("Admin", "S-1-5-4"); // Interactive user.
            RoleMapping.Add("User", "S-1-1-0");  // Everyone who has logged on.
        }
示例#3
0
        public static HtmlString SelectWithLabelFor <T>(Expression <Func <T, Enum> > propertySelector,
                                                        string placeholder = "", int?labelCols = null, int?inputCols = null, string label = null)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(SelectFor(propertySelector, placeholder).AddLabel(propertyModel.DisplayNameLabel(label), labelCols, inputCols));
        }
示例#4
0
        public static HtmlString TextAreaFor <T>(Expression <Func <T, string> > propertySelector,
                                                 int?rows = null, string bindingName = "value")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(TextArea(propertyModel.JsVariableForBinding, bindingName, rows));
        }
示例#5
0
        public static HtmlString TextAreaWithLabelFor <T>(Expression <Func <T, string> > propertySelector,
                                                          int?rows = null, int?labelCols = null, int?inputCols = null, string label = null, string bindingName = "value")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(TextAreaFor(propertySelector, rows).AddLabel(propertyModel.DisplayNameLabel(label), labelCols, inputCols));
        }
示例#6
0
        public static HtmlString InputWithLabelFor <T>(Expression <Func <T, bool?> > propertySelector,
                                                       int?labelCols = null, int?inputCols = null, string label = null, string bindingName = "checked")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(InputFor <T>(propertySelector, bindingName).AddLabel(propertyModel.DisplayNameLabel(label), labelCols, inputCols));
        }
示例#7
0
        public static T IncludeExternal <T, TProperty>(this T obj, Expression <Func <T, TProperty> > propertySelector) where T : class
        {
            var    objViewModel  = ReflectionRepository.GetClassViewModel <T>();
            var    propViewModel = objViewModel.PropertyBySelector(propertySelector);
            string type          = propViewModel.Type.Name;

            if (_repositories.ContainsKey(type))
            {
                var list = _repositories[type] as IEnumerable <TProperty>;
                // Get item from the list
                // Get ID field
                var idProperty = propViewModel.ObjectIdProperty.Wrapper.PropertyInfo;
                // get ID value
                object idValue = idProperty.GetValue(obj);
                if (idValue != null)
                {
                    // Look up object by ID field and ID value.
                    //object objectValue = list.Where($"{propViewModel.ObjectIdProperty.Name} = {idValue}").FirstOrDefault();
                    object objectValue = list.Where($"{propViewModel.PureType.ClassViewModel.PrimaryKey.Name} = {idValue}").FirstOrDefault();
                    // Set the value.
                    propViewModel.Wrapper.PropertyInfo.SetValue(obj, objectValue);
                }
            }

            return(obj);
        }
示例#8
0
        public void LoadContext()
        {
            var models = ReflectionRepository.AddContext <AppDbContext>();

            Assert.Equal(8, models.Count);
            Assert.Equal(5, models.Where(f => f.HasDbSet).Count());
        }
示例#9
0
        public static HtmlString InputFor <T>(Expression <Func <T, DateTime?> > propertySelector,
                                              string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int?stepping = null)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(DateTime(propertyModel.JsVariableForBinding, format, preserve, stepping));
        }
示例#10
0
        public static HtmlString SelectFor <T>(Expression <Func <T, Enum> > propertySelector,
                                               string placeholder = "")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(SelectEnum(propertyModel, placeholder));
        }
示例#11
0
        public static HtmlString InputFor <T>(Expression <Func <T, object> > propertySelector,
                                              string bindingName = "value")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(TextInput(propertyModel.JsVariableForBinding, bindingName));
        }
示例#12
0
        public static ReflectionRepository MakeFromSymbols()
        {
            var rr = new ReflectionRepository();

            rr.DiscoverCoalescedTypes(Symbols.Select(s => new SymbolTypeViewModel(s)));
            return(rr);
        }
示例#13
0
        public static HtmlString SelectFor <T>(Expression <Func <T, string> > propertySelector,
                                               string placeholder = "")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            placeholder = placeholder ?? propertyModel.DisplayName;
            return(SelectString(propertyModel, placeholder));
        }
示例#14
0
        public static ReflectionRepository MakeFromReflection()
        {
            var rr = new ReflectionRepository();

            // Just picking an arbitrary class that should always be in the test assembly.
            rr.AddAssembly <ComplexModel>();
            return(rr);
        }
示例#15
0
        public static HtmlString SelectForManyToMany <T>(Expression <Func <T, object> > propertySelector, string placeholder = "", string prefix = "", string areaName = "", int pageSize = 25)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            if (propertyModel != null)
            {
                return(SelectForManyToMany(propertyModel, placeholder, prefix, areaName, pageSize));
            }
            return(HtmlString.Empty);
        }
示例#16
0
 public CompositeGeneratorServices(
     CoalesceConfiguration config,
     ReflectionRepository reflectionRepository,
     GenerationContext generationContext,
     IServiceProvider serviceProvider,
     ILoggerFactory loggerFactory)
     : base(config, reflectionRepository, generationContext, loggerFactory)
 {
     ServiceProvider = serviceProvider;
 }
示例#17
0
        public static HtmlString DisplayHtml <T>(Expression <Func <T, object> > propertySelector)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            string result = string.Format(@"
                <div class=""form-control-static"" data-bind=""html: {0}()""></div>",
                                          propertyModel.JsVariableForBinding);

            return(new HtmlString(result));
        }
示例#18
0
        public static HtmlString SelectForObject <T>(Expression <Func <T, object> > propertySelector,
                                                     string placeholder = "", string prefix = "")
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            if (propertyModel != null)
            {
                return(SelectObject(propertyModel, placeholder, prefix, propertyModel.ObjectIdProperty == null ? !propertyModel.IsRequired : !propertyModel.ObjectIdProperty.IsRequired));
            }
            return(HtmlString.Empty);
        }
示例#19
0
 public GeneratorServices(
     CoalesceConfiguration config,
     ReflectionRepository reflectionRepository,
     GenerationContext generationContext,
     ILoggerFactory loggerFactory)
 {
     CoalesceConfiguration = config;
     ReflectionRepository  = reflectionRepository;
     GenerationContext     = generationContext;
     LoggerFactory         = loggerFactory;
 }
示例#20
0
        public DatabaseFixtureInMemory()
        {
            ReflectionRepository.AddContext <DbContext>();
            var dbOptionBuilder = new DbContextOptionsBuilder();

            dbOptionBuilder.UseInMemoryDatabase();
            Db = new AppDbContext(dbOptionBuilder.Options);
            // Wipe the database out first;
            //Db.Database.EnsureDeleted();
            // Add some data to it.
            SampleData.Initialize(Db);
        }
示例#21
0
 protected BaseApiController()
 {
     // Set up a ViewModel so we can check out this object.
     ClassViewModel = ReflectionRepository.GetClassViewModel(typeof(T), null, ApiName);
     if (typeof(T) == typeof(TDto) || typeof(TDto).Name.EndsWith("DtoGen"))
     {
         DtoViewModel = ClassViewModel;
     }
     else
     {
         DtoViewModel = ReflectionRepository.GetClassViewModel(typeof(TDto), null, ApiName);
     }
 }
示例#22
0
        /// <summary>
        /// Finds an object based on key after an include has been done.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static T FindItem <T>(this IQueryable <T> query, object id)
        {
            var classViewModel = ReflectionRepository.GetClassViewModel(typeof(T));

            if (classViewModel.PrimaryKey.Type.IsString)
            {
                return(query.Where(string.Format("{0} = \"{1}\"", classViewModel.PrimaryKey.Name, id)).First());
            }
            else
            {
                return(query.Where(string.Format("{0} = {1}", classViewModel.PrimaryKey.Name, id)).First());
            }
        }
示例#23
0
        public SecurityTests()
        {
            _process     = Processes.StartDotNet();
            _dataContext = DependencyProvider.ProjectContext(@"..\..\..\..\..\Coalesce.Domain");

            IModelTypesLocator typeLocator = DependencyProvider.ModelTypesLocator(_dataContext);
            ModelType          dataModel   = ValidationUtil.ValidateType("AppDbContext", "dataContext", typeLocator, throwWhenNotFound: false);

            _models = ReflectionRepository
                      .AddContext((INamedTypeSymbol)dataModel.TypeSymbol)
                      .Where(m => m.PrimaryKey != null)
                      .ToList();
        }
示例#24
0
        /// <summary>
        /// Asynchronously finds an object based on key after an include has been done.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async static Task <T> FindItemAsync <T>(this IQueryable <T> query, object id)
        {
            var classViewModel = ReflectionRepository.GetClassViewModel(typeof(T));

            if (classViewModel.PrimaryKey.Type.IsString)
            {
                return(await query.Where($@"{classViewModel.PrimaryKey.Name} = ""{id}""").FirstAsync());
            }
            else
            {
                return(await query.Where(string.Format("{0} = {1}", classViewModel.PrimaryKey.Name, id)).FirstAsync());
            }
        }
示例#25
0
        public void ModelViewAttributes()
        {
            ReflectionRepository.AddContext <AppDbContext>();

            var caseProduct = ReflectionRepository.GetClassViewModel <CaseProduct>();
            var person      = ReflectionRepository.GetClassViewModel <Person>();

            Assert.NotNull(caseProduct);

            Assert.True(person.WillCreateApiController);
            Assert.True(person.WillCreateViewController);

            Assert.False(caseProduct.WillCreateViewController);
            Assert.False(caseProduct.WillCreateViewController);
        }
示例#26
0
        /// <summary>
        /// Includes immediate children, as well as the other side of many-to-many relationships.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        public static IQueryable <T> IncludeChildren <T>(this IQueryable <T> query) where T : class, new()
        {
            var model = ReflectionRepository.GetClassViewModel <T>();

            foreach (var prop in model.Properties.Where(f => !f.IsStatic && !f.IsInternalUse && f.PureType.HasClassViewModel && f.PureType.ClassViewModel.HasDbSet && !f.HasNotMapped))
            {
                if (prop.IsManytoManyCollection)
                {
                    query = query.IncludeString(prop.Name + "." + prop.ManyToManyCollectionProperty.Name);
                }
                else
                {
                    query = query.IncludeString(prop.Name);
                }
            }
            return(query);
        }
示例#27
0
        /// <summary>
        /// Gets a list of all the complex types used in the models.
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public IEnumerable <ClassViewModel> ComplexTypes(List <ClassViewModel> models)
        {
            Dictionary <string, ClassViewModel> complexTypes = new Dictionary <string, ClassViewModel>();

            foreach (var model in models)
            {
                foreach (var prop in model.Properties.Where(f => f.IsComplexType))
                {
                    if (!complexTypes.ContainsKey(prop.Name))
                    {
                        var ctModel = ReflectionRepository.GetClassViewModel(prop.Type);
                        complexTypes.Add(prop.Name, ctModel);
                    }
                }
            }

            return(complexTypes.Values);
        }
示例#28
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionName = "DefaultConnection";

            Console.WriteLine($"Connection Name: {connectionName}");

            string connString = Configuration.GetConnectionString(connectionName);

            Console.WriteLine($"Connection String: {connString}");

            // Add Entity Framework services to the services
            services.AddSingleton <IConfigurationRoot, IConfigurationRoot>(sp => Configuration);
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connString).
                                                 ConfigureWarnings(warnings =>
            {
                warnings.Log(CoreEventId.IncludeIgnoredWarning);
                warnings.Log(RelationalEventId.OpeningConnection);
                warnings.Log(RelationalEventId.PossibleIncorrectResultsUsingLikeOperator);
                warnings.Log(RelationalEventId.PossibleUnintendedUseOfEqualsWarning);
                warnings.Log(RelationalEventId.QueryClientEvaluationWarning);
            }));
            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                var resolver = options.SerializerSettings.ContractResolver;
                if (resolver != null)
                {
                    (resolver as DefaultContractResolver).NamingStrategy = null;
                }

                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            //services.AddIdentity<ApplicationUser, IdentityRole>()
            //    .AddEntityFrameworkStores<AppDbContext>()
            //    .AddDefaultTokenProviders();

            ReflectionRepository.AddContext <AppDbContext>();
        }
示例#29
0
        /// <summary>
        /// Includes sub objects from the graph based on IIncludeExternal method on class.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="include"></param>
        /// <returns></returns>
        public static IEnumerable <T> IncludesExternal <T>(this IEnumerable <T> query, string includes = null) where T : class, new()
        {
            T   obj  = new T();
            var objT = obj as IIncludeExternal <T>;

            if (objT != null)
            {
                return(objT.IncludeExternal(query, includes));
            }
            else
            {
                var model = ReflectionRepository.GetClassViewModel <T>();
                foreach (var prop in model.Properties.Where(f => !f.IsInternalUse && f.IsExternal))
                {
                    // TODO: need to figure out how to do this without a <T>
                    //query = query.IncludeExternal(prop);
                }
            }
            return(query);
        }
示例#30
0
        public void ModelView()
        {
            ReflectionRepository.AddContext <AppDbContext>();

            var person = ReflectionRepository.GetClassViewModel <Person>();

            Assert.NotNull(person);

            Assert.True(person.PropertyByName(nameof(Person.Name)).IsListText);
            Assert.NotNull(person.PropertyByName(nameof(Person.LastName)).MinLength);
            Assert.Equal(3, person.PropertyByName(nameof(Person.LastName)).MinLength.Value);

            Assert.NotNull(person.PropertyByName("BirthDate"));
            Assert.NotNull(person.PropertyBySelector <Person, DateTime?>(f => f.BirthDate));
            Assert.NotNull(person.PropertyByName(nameof(Person.BirthDate)));
            Assert.True(person.PropertyByName(nameof(Person.BirthDate)).Type.IsDate);
            Assert.True(person.PropertyByName(nameof(Person.BirthDate)).Type.IsDateTime);
            Assert.False(person.PropertyByName(nameof(Person.BirthDate)).Type.IsDateTimeOffset);

            Assert.True(person.PropertyByName(nameof(Person.BirthDate)).IsDateOnly);
        }