Ejemplo n.º 1
0
        /// <summary>
        /// Write the metadata for all data sources of a class
        /// </summary>
        private void WriteDataSourcesMetadata(TypeScriptCodeBuilder b, ClassViewModel model)
        {
            using (b.Block("dataSources:", ','))
            {
                var dataSources = model.ClientDataSources(this.Model);
                foreach (var source in dataSources)
                {
                    WriteDataSourceMetadata(b, model, source);
                }

                // Not sure we need to explicitly declare the default source.
                // We can just use the absense of a data source to represent the default.

                /*
                 * var defaultSource = dataSources.SingleOrDefault(s => s.IsDefaultDataSource);
                 * if (defaultSource != null)
                 * {
                 *  var name = defaultSource.ClientTypeName.ToCamelCase();
                 *  b.Line($"get default() {{ return this.{name} }},");
                 * }
                 * else
                 * {
                 *  using (b.Block($"default:", ','))
                 *  {
                 *      b.StringProp("type", "dataSource");
                 *      b.StringProp("name", "default");
                 *      b.StringProp("displayName", "Default");
                 *      b.Line("params: {}");
                 *  }
                 * }
                 */
            }
        }
Ejemplo n.º 2
0
        protected Type GetDataSourceType(ClassViewModel servedType, ClassViewModel declaredFor, string dataSourceName)
        {
            if (string.IsNullOrEmpty(dataSourceName) || dataSourceName.Equals(DefaultSourceName, InvariantCultureIgnoreCase))
            {
                return(GetDefaultDataSourceType(servedType, declaredFor));
            }

            var dataSourceClassViewModel = declaredFor
                                           .ClientDataSources(reflectionRepository)
                                           .FirstOrDefault(t => t.ClientTypeName.Equals(dataSourceName, InvariantCultureIgnoreCase))
                                           ?? throw new DataSourceNotFoundException(servedType, declaredFor, dataSourceName);

            return(dataSourceClassViewModel.Type.TypeInfo);
        }
Ejemplo n.º 3
0
        protected Type GetDefaultDataSourceType(ClassViewModel servedType, ClassViewModel declaredFor)
        {
            var dataSources   = declaredFor.ClientDataSources(reflectionRepository);
            var defaultSource = dataSources.SingleOrDefault(s => s.IsDefaultDataSource);

            if (defaultSource != null)
            {
                return(defaultSource.Type.TypeInfo);
            }

            // FUTURE: If other kinds of default data sources are created, add them to the DefaultTypes dictionary above.
            var tContext       = reflectionRepository.DbContexts.FirstOrDefault(c => c.Entities.Any(e => e.ClassViewModel.Equals(servedType)));
            var dataSourceType = typeof(IEntityFrameworkDataSource <,>).MakeGenericType(
                servedType.Type.TypeInfo,
                tContext.ClassViewModel.Type.TypeInfo
                );

            return(dataSourceType);
        }