protected virtual ClassTemplate WriteClass(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List <FileTemplate> files) { if (model.BasedOn != null) { this.MapType(model.Language, configuration.Language, model.BasedOn); } ClassTemplate classTemplate = files.AddFile(configuration.RelativePath, configuration.AddHeader) .AddNamespace(nameSpace) .AddClass(model.Name, model.BasedOn?.ToTemplate()) .FormatName(configuration); if (model.BasedOn != null) { this.AddUsing(model.BasedOn, classTemplate, configuration); } configuration.Usings?.ForEach(x => classTemplate.AddUsing(x, null, null)); classTemplate.IsInterface = model.IsInterface; classTemplate.IsAbstract = model.IsAbstract; if (model.IsGeneric) { classTemplate.Generics.AddRange(model.Generics.Where(x => x.Alias != null).Select(x => new ClassGenericTemplate(x.Alias))); } foreach (TypeTransferObject interFace in model.Interfaces) { this.MapType(model.Language, configuration.Language, interFace); classTemplate.BasedOn.Add(new BaseTypeTemplate(classTemplate, Code.Interface(interFace.Name, interFace.Namespace))); this.AddUsing(interFace, classTemplate, configuration); } this.AddFields(model, classTemplate, configuration); this.AddProperties(model, classTemplate, configuration); return(classTemplate); }
//грязный хак void AddConfigurationWithCast <T>(IModelConfiguration <T> hackToInferNeededType, object givenObject, ModelBuilder modelBuilder) where T : BaseModel { var config = givenObject as IModelConfiguration <T>; modelBuilder.AddConfiguration(config); }
/// <inheritdoc/> public AppContext( IModelConfiguration the_model_configuration , IConnectionStringProvider connection_string_provider ) : base(the_model_configuration , connection_string_provider) { InitialiseDatabase(); }
/// <summary> /// Creates and setups a new instance for model obejct wiring. /// </summary> /// <param name="modelInterception">The database model interception settings.</param> public static ModelResolver SetUp(IModelConfiguration modelInterception) { var wiring = new ModelResolver(); modelInterception.Initialize(wiring._container); _instances.Add(wiring); return(wiring); }
/// <summary> /// Captures region navigation resources and configures commands. /// </summary> /// <param name="p_regions">For region navigation.</param> /// <param name="p_configuration">For embedding of a /// <see cref="Location"/> form.</param> public ClientFormViewModel( IRegionManager p_regions, IModelConfiguration <Location> p_configuration) { _regions = p_regions; _locForm = p_configuration; UpdateCommand = new DelegateCommand(OnUpdate); }
/// <summary> /// Captures region navigation resources and configures commands. /// </summary> /// <param name="p_regions">For region navigation.</param> /// <param name="p_configuration">Identifying the configuration view.</param> TherapistSelectionViewModel( IRegionManager p_regions, IModelConfiguration <Therapist> p_configuration) { _regions = p_regions; _configuration = p_configuration; ConfigureCommand = new DelegateCommand(Configure); (this as IModelSubscriber <Therapist>).Updater = new DelegateCommand(OnTherapistChanged); }
protected override ClassTemplate WriteClass(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List <FileTemplate> files) { ClassTemplate classTemplate = base.WriteClass(configuration, model, nameSpace, files); if (model is JsonModelTransferObject && this.jsonConfiguration.Object.WithReader) { ObjectReaderWriter.WriteReader(classTemplate, model, configuration.FormatNames); } return(classTemplate); }
/// <summary> /// Obtains resources for view navigation and command processing. /// </summary> /// <param name="p_provider">For view model wrappers.</param> /// <param name="p_regions">For navigation</param> /// <param name="p_configuration">For access to <see cref="Practice"/> /// configuration.</param> public PracticeExplorerViewModel( IContainerProvider p_provider, IRegionManager p_regions, IModelConfiguration <Practice> p_configuration) { _provider = p_provider; _regions = p_regions; _configuration = p_configuration; EditPracticeCommand = new DelegateCommand(EditPractice); AddHypnotistCommand = new DelegateCommand(AddHypnotist); AddClientCommand = new DelegateCommand(AddClient); (this as IModelSubscriber <Practice>).Updater = new DelegateCommand(UpdatePractice); }
IList <IModelConfiguration> GetMergedConfigurations() { var defaultConfiguration = DefaultModelConfiguration; if (defaultConfiguration == null) { return(ModelConfigurations); } var configurations = new IModelConfiguration[ModelConfigurations.Count + 1]; configurations[0] = new DelegatingModelConfiguration(defaultConfiguration); ModelConfigurations.CopyTo(configurations, 1); return(configurations); }
protected override ClassTemplate WriteClass(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List <FileTemplate> files) { ClassTemplate classTemplate = base.WriteClass(configuration, model, nameSpace, files); if (!model.IsAbstract && !model.IsInterface && configuration.Language.IsTypeScript()) { ConstructorTemplate constructor = classTemplate.AddConstructor(); constructor.WithParameter(Code.Generic("Partial", classTemplate.ToType()), "init", Code.Null()) .WithCode(Code.Static(Code.Type("Object")).Method("assign", Code.This(), Code.Local("init")).Close()); if (classTemplate.BasedOn.Any(x => !x.ToType().IsInterface)) { // TODO: Add super parameters constructor.WithSuper(); } } return(classTemplate); }
protected virtual EnumTemplate WriteEnum(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List <FileTemplate> files) { if (model.EnumValues == null) { throw new InvalidOperationException("Can not write enum without values"); } EnumTemplate enumTemplate = files.AddFile(configuration.RelativePath, configuration.AddHeader) .AddNamespace(nameSpace) .AddEnum(model.Name); foreach (KeyValuePair <string, int> pair in model.EnumValues) { string formattedName = Formatter.FormatProperty(pair.Key, configuration); enumTemplate.Values.Add(new EnumValueTemplate(pair.Key, Code.Number(pair.Value), formattedName)); } return(enumTemplate); }
IList <IModelConfiguration> GetMergedConfigurations() { Contract.Ensures(Contract.Result <IList <IModelConfiguration> >() != null); var defaultConfiguration = DefaultModelConfiguration; if (defaultConfiguration == null) { return(ModelConfigurations); } var configurations = new IModelConfiguration[ModelConfigurations.Count + 1]; configurations[0] = new DelegatingModelConfiguration(defaultConfiguration); ModelConfigurations.CopyTo(configurations, 1); return(configurations); }
protected virtual void WriteModel(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List <FileTemplate> files) { if (model == null) { return; } this.MapType(model.Language, configuration.Language, model); if (model.FromSystem) { return; } if (model.IsEnum) { this.WriteEnum(configuration, model, nameSpace, files); } else { this.WriteClass(configuration, model, nameSpace, files); } }
public virtual List <FileTemplate> Write(IModelConfiguration configuration, IEnumerable <ITransferObject> transferObjects) { if (configuration.Language == null) { throw new InvalidOperationException("Can not write model without language"); } List <FileTemplate> files = new List <FileTemplate>(); List <ModelTransferObject> models = transferObjects.OfType <ModelTransferObject>().ToList(); if (!string.IsNullOrEmpty(configuration.Name)) { models.Where(x => x.Name == "Unknown").ForEach(x => x.Name = configuration.Name); } models.ForEach(model => model.Name = Formatter.FormatClass(model.Name, configuration)); foreach (ModelTransferObject model in models) { string nameSpace = configuration.SkipNamespace ? string.Empty : configuration.Namespace ?? model.Namespace; this.WriteModel(configuration, model, nameSpace, files); } return(files); }
/// <summary> /// Constructor accepts the configuration used to map the entities to a database schema /// and a provider that supplies the connection string /// </summary> /// <param name="the_model_configuration"> /// Configuration that is applied to a <see cref="DbModelBuilder"/>. This builds the is the /// map between entity framework the underlying database schema. /// </param> /// <param name="connection_string_provider"> /// Provider that is used to get the connection string for the context /// </param> public CompositeContext( IModelConfiguration the_model_configuration , IConnectionStringProvider connection_string_provider ) : base(connection_string_provider.connection_string) { model_configuration = Guard.IsNotNull( the_model_configuration, "the_model_configuration" ); }
public GraphDataContext(IModelConfiguration configuration) { this.configuration = configuration; }
public StartAddDefaultExpressionsEventArgs(IModelConfiguration modelConfiguration) { this.Configuration = modelConfiguration; }
public static void AddConfiguration <TEntity>(this ModelBuilder modelBuilder, IModelConfiguration <TEntity> entityConfiguration) where TEntity : BaseModel { modelBuilder.Entity <TEntity>(entityConfiguration.Configure); }
private void SetShouldSerializeProperty(Type type, JsonProperty jsonProperty, MemberInfo member, IModelConfiguration modelConfiguration) { if (type == null) { return; } //Skip if type is not an entity if (!_entitiesMetadata.ContainsKey(type)) { return; } var metadata = _entitiesMetadata[type]; var propIdx = metadata.PropertyNames.ToList().IndexOf(member.Name); //Skip non mapped properties if (propIdx < 0) { return; } var propType = metadata.GetPropertyType(member.Name); var lazyProp = metadata.PropertyLaziness[propIdx]; //Skip properties that are not collection, association and lazy if (!propType.IsCollectionType && !propType.IsAssociationType && !lazyProp) { return; } modelConfiguration.MemberConfigurations.TryGetValue(member.Name, out var memberConfiguration); var canLazyLoad = memberConfiguration?.LazyLoad == true; //Define and set the predicate for check property initialization bool Predicate(object entity) { if (canLazyLoad) { return(true); } if (!NHibernateUtil.IsPropertyInitialized(entity, member.Name)) { return(false); } var propertyValue = metadata.GetPropertyValue(entity, member.Name); return(NHibernateUtil.IsInitialized(propertyValue)); } if (jsonProperty.ShouldSerialize != null) { jsonProperty.ShouldSerialize = o => Predicate(o) && jsonProperty.ShouldSerialize(o); } else { jsonProperty.ShouldSerialize = Predicate; } }
/// <summary> /// Control serialization NHibernate entities by using JsonProperty.ShouldSerialize. /// Serialization should only be attempted on properties that are initialized. /// </summary> /// <param name="member"></param> /// <param name="memberSerialization"></param> /// <param name="type"></param> /// <returns></returns> protected JsonProperty CreateProperty(Type type, MemberInfo member, MemberSerialization memberSerialization, IModelConfiguration modelConfiguration) { var property = CreateProperty(member, memberSerialization); SetShouldSerializeProperty(type, property, member, modelConfiguration); return(property); }
public static IModelConfiguration <T> CastToConfigurationType <T>(IModelConfiguration <T> hackToInferNeededType, object givenObject) where T : BaseModel { return(givenObject as IModelConfiguration <T>); }
public virtual void Write(ConfigurationBase configurationBase, List <ITransferObject> transferObjects, IOutput output) { IModelConfiguration configuration = (IModelConfiguration)configurationBase; this.Write(configuration, transferObjects).ForEach(file => configuration.Language.Write(file, output)); }
/// <summary> /// Установка контейнера типов IoC. /// </summary> /// <param name="configuration"> Конфигурация. </param> public static void SetConfiguration(IModelConfiguration configuration) { _container = new UnityContainer(); configuration.Initialize(_container); ModelConfiguration = configuration; }
internal static void OnModelConfigurationCreated(IModelConfiguration obj) { var handler = ModelConfigurationCreated; handler?.Invoke(obj); }
public override void Configure(IModelConfiguration <User> modelConfiguration) { modelConfiguration.SetDocumentPath("users") .SetPrimaryKey(user => user.UserId); }