/// <summary>Creates specific entity type serializer settings.</summary> public static JsonSerializerSettings CreateEntitySerializerSettingsDefault(IEntityConfig entityConfig) { var settings = CreateDefaultSerializerSettingsDefault(); settings.ContractResolver = new EntityContractResolver(entityConfig.EntityType, entityConfig.IgnoredMembers); return(settings); }
public static IEnumerable <IResourceConfig> GetResourceDependencies( this IEntityConfig config) => config .Dependencies .Select(d => d.Resource) .Concat(config.NestedResources.SelectMany(GetResourceDependencies)) .Where(r => r != config);
private TSetupEntityCollection GetSetupEntityCollection(IEntityConfig config) { TSetupEntityCollection entityCollection = new TSetupEntityCollection(); entityCollection.EntityCollection = new List <TSetupEntity>(); // City entity TSetupEntity entity1 = new TSetupEntity() { EntityName = "City", EntityQueryCollection = new List <TSetupEntityQuery>() { GetSetupEntityQuery("City", EntityQueryType.FindByKey, config), GetSetupEntityQuery("City", EntityQueryType.FindByString, config) } }; // Order entity TSetupEntity entity2 = new TSetupEntity() { EntityName = "Order", EntityQueryCollection = new List <TSetupEntityQuery>() { GetSetupEntityQuery("Order", EntityQueryType.FindByKey, config), GetSetupEntityQuery("Order", EntityQueryType.FindByString, config), GetSetupEntityQuery("Order", EntityQueryType.FindByParentKey, config, "City") } }; entityCollection.EntityCollection.Add(entity1); entityCollection.EntityCollection.Add(entity2); return(entityCollection); }
public void AddIfRequired(IEntityConfig config) { if (!Current.ContainsDispatch(config)) { config.Accept(new AddVisitor(), this); } }
public string GetId(IEntityConfig config) { var id = config.DefaultIdStr(); Dependencies.GetOrAdd(id, config); return(id); }
public void Register(IEntityConfig config) { readerWriterLock.EnterWriteLock(); try { var documentType = config.DocumentType; var entityType = config.EntityType; if (entityTypeMap.ContainsKey(entityType)) { throw new ConfigurationException( "Duplicate registration of entity type {0}. You should revise your configuration code.", entityType); } if (documentTypeMap.ContainsKey(documentType)) { throw new ConfigurationException( "Duplicate registration of document type '{0}' (was for {1} and now for {2}). " + "You should revise your document type conventions.", documentType, documentTypeMap[documentType].EntityType, entityType); } documentTypeMap[documentType] = config; entityTypeMap[entityType] = config; } finally { readerWriterLock.ExitWriteLock(); } }
public static NestedResourceConfig <TModel, TParenModel> CreateConfig <TModel, TParenModel>( this NestedResourceStrategy <TModel, TParenModel> strategy, IEntityConfig <TParenModel> parent, string name, Func <TModel> createModel) where TModel : class where TParenModel : class => new NestedResourceConfig <TModel, TParenModel>(strategy, parent, name, createModel);
public void ShouldSerializeTimeSpan() { entity = Entity.CreateStandard(); config = MockEntityConfig(documentType: "entity", entityType: typeof(Entity)); var document = serializer.ConvertToJson(entity, config, throwOnError: true); Assert.Equal(4 * 60 * 60 * 1000, (int)document["timeZoneOffset"]); }
/// <summary>Retrives entity identifier throwing execption it could not be retrived.</summary> public static string GetId(this IEntityConfig entityConfig, object entity) { var id = entityConfig.GetId(entity); if (id == null && !entityConfig.IsIdMemberPresent) { throw new ConfigurationException("Entity ID colud not be retrived using current configuration."); } return(id); }
private static void GenerateIdIfNeeded(object entity, IEntityConfig entityConfiguration, IIdGenerator idGenerator) { var id = entityConfiguration.GetId(entity); if (id == null) { var generatedId = idGenerator.GenerateId(); Debug.Assert(!string.IsNullOrEmpty(generatedId)); entityConfiguration.SetId(entity, generatedId); } }
public void UpdateNested <TModel>(IEntityConfig <TModel> config, TModel model) where TModel : class { var nestedResourceContext = new NestedResourceContext <TModel>(this, model); foreach (var nestedConfig in config.NestedResources) { nestedConfig.Accept( new SetNestedModelVisitor <TModel>(), nestedResourceContext); } }
public static IEnumerable <string> GetIdFromSubscription(this IEntityConfig config) { var resourceGroupId = new[] { ResourceType.ResourceGroups, config.GetResourceGroupName() }; return(config.ResourceGroup == null ? resourceGroupId : resourceGroupId.Concat(config.GetProvidersId())); }
public NestedResourceConfig( NestedResourceStrategy <TModel, TParenModel> strategy, IEntityConfig <TParenModel> parent, string name, Func <TModel> createModel) { Strategy = strategy; Name = name; Parent = parent; CreateModel = createModel; }
/// <summary>Implements basic check and convertion logic for ConvertFromJson method.</summary> protected static object CheckAndConvertFromJson( IEntityConfig entityConfig, JsonObject source, bool throwOnError, Func <JsonObject, object> convert) { var documentObject = source.DeepClone(); var documentId = documentObject.GetPrimitiveProperty <string>(Document.IdPropertyName); var revision = documentObject.GetPrimitiveProperty <string>(Document.RevisionPropertyName); var documentType = documentObject.GetPrimitiveProperty <string>(Document.TypePropertyName); if (documentType != null) { documentObject.Remove(Document.TypePropertyName); } if (documentType.HasNoValue()) { return(LogAndThrowIfNeeded <object>(throwOnError, new DocumentTypeMissingException(documentObject.ToString()))); } if (entityConfig.DocumentType != documentType) { return(LogAndThrowInvalidOperationExceptionIfNeeded <object>( throwOnError, "Deserializing document's type {0} does not match type {1} in configuration.", documentType, entityConfig.DocumentType )); } if (string.IsNullOrWhiteSpace(documentId)) { return(LogAndThrowIfNeeded <object>(throwOnError, new DocumentIdMissingException(documentObject.ToString()))); } if (string.IsNullOrWhiteSpace(revision)) { return(LogAndThrowIfNeeded <object>(throwOnError, new DocumentRevisionMissingException(documentObject.ToString()))); } var entityId = entityConfig.ConvertDocumentIdToEntityId(documentId); if (string.IsNullOrWhiteSpace(entityId)) { return(LogAndThrowInvalidOperationExceptionIfNeeded <object>( throwOnError, "IEntityConfig.ConvertDocumentIdToEntityId() should not ever return null, empty or whitespace string." )); } var entity = convert(documentObject); entityConfig.SetId(entity, entityId); entityConfig.SetRevision(entity, revision); return(entity); }
public void ShouldSetRevPropertyOnJObject() { config = MockEntityConfig(mock => { mock.Setup( ec => ec.GetRevision(entity)).Returns("rev.1"); mock.Setup(ec => ec.IsRevisionPresent).Returns(true); }); var document = serializer.ConvertToJson(entity, config, true); Assert.Equal("rev.1", (string)document["_rev"]); }
/// <inheritdoc /> public override object ConvertFromJson(IEntityConfig entityConfig, JsonObject source, bool throwOnError) { if (entityConfig == null) throw new ArgumentNullException("entityConfig"); if (source == null) throw new ArgumentNullException("source"); return CheckAndConvertFromJson( entityConfig, source, throwOnError, doc => ConvertFromJsonInternal(entityConfig.EntityType, doc, entitySerializers.Get(entityConfig), throwOnError) ); }
public NestedResourceConfig( IEntityConfig <TParenModel> parent, NestedResourceStrategy <TModel, TParenModel> strategy, string name, Func <IEngine, TModel> createModel, IEnumerable <IEntityConfig> dependencies) { Parent = parent; Strategy = strategy; Name = name; CreateModel = createModel; _Dependencies = dependencies; parent.AddNested(this); }
/// <summary> /// Creates a new Queue, Topic and or Subscription. /// </summary> /// <param name="config">The config with the creation details, <see cref="ServiceBusEntityConfig"/>.</param> /// <exception cref="NullReferenceException"></exception> public async Task CreateEntity(IEntityConfig config) { if (!(config is ServiceBusEntityConfig sbConfig)) { throw new InvalidOperationException("ServiceBusCreateEntityConfig is required "); } if (sbConfig.EntityType == EntityType.Topic) { await Task.Run(() => ManagerClient.CreateTopicIfNotExists(sbConfig.EntityName, sbConfig.EntitySubscriptionName, sbConfig.SqlFilter)); } else { await Task.Run(() => ManagerClient.CreateQueueIfNotExists(sbConfig.EntityName)); } }
public void ShouldThrowIfSelfReferencingEntityDetected() { entity = new SelfReferencingEntity { Component = new SelfReferencingComponent { SubEntity = new SelfReferencingEntity() } }; config = MockEntityConfig( documentType: "selfReferencingEntity", entityType: typeof(SelfReferencingEntity) ); var exception = Assert.Throws <InvalidOperationException>(() => serializer.ConvertToJson(entity, config, true)); Assert.Contains(typeof(SelfReferencingEntity).Name, exception.Message); }
/// <inheritdoc /> public override object ConvertFromJson(IEntityConfig entityConfig, JsonObject source, bool throwOnError) { if (entityConfig == null) { throw new ArgumentNullException("entityConfig"); } if (source == null) { throw new ArgumentNullException("source"); } return(CheckAndConvertFromJson( entityConfig, source, throwOnError, doc => ConvertFromJsonInternal(entityConfig.EntityType, doc, entitySerializers.Get(entityConfig), throwOnError) )); }
/// <inheritdoc /> public override JsonObject ConvertToJson(object sourceEntity, IEntityConfig entityConfig, bool throwOnError) { if (sourceEntity == null) { throw new ArgumentNullException("sourceEntity"); } if (entityConfig == null) { throw new ArgumentNullException("entityConfig"); } return(CheckAndConvertToJson( sourceEntity, entityConfig, throwOnError, () => (JsonObject)ConvertToJsonInternal(sourceEntity, entitySerializers.Get(entityConfig), throwOnError) )); }
private DocumentEntity( IEntityConfig entityConfiguration, ISerializer serializer, object entity, Document document = null) { if (entityConfiguration == null) { throw new ArgumentNullException("entityConfiguration"); } if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; Document = document; this.entityConfiguration = entityConfiguration; this.serializer = serializer; }
protected void OnButtonViewEntityClicked(object sender, EventArgs e) { IEntityConfig entityConfig = DomainConfiguration.GetEntityConfig(subjectType); if (entityConfig.SimpleDialog) { EntityEditSimpleDialog.RunSimpleDialog(this.Toplevel as Window, SubjectType, Subject); return; } ITdiTab mytab = DialogHelper.FindParentTab(this); if (mytab == null) { logger.Warn("Родительская вкладка не найдена."); return; } ITdiTab dlg = entityConfig.CreateDialog(Subject); mytab.TabParent.AddTab(dlg, mytab); }
protected void FillNameCollections(IEntityConfig entityConfig, ISet <String> memberNamesToIgnore, ISet <String> explicitBasicMemberNames, IList <IMemberConfig> embeddedMembers, IMap <String, IMemberConfig> nameToMemberConfig, IMap <String, IRelationConfig> nameToRelationConfig) { foreach (IMemberConfig memberConfig in entityConfig.GetMemberConfigIterable()) { String memberName = memberConfig.Name; if (memberConfig.Ignore) { memberNamesToIgnore.Add(memberName); memberNamesToIgnore.Add(memberName + "Specified"); continue; } explicitBasicMemberNames.Add(memberName); String[] parts = memberName.Split(dot); bool isEmbeddedMember = parts.Length > 1; if (isEmbeddedMember) { embeddedMembers.Add(memberConfig); memberNamesToIgnore.Add(parts[0]); memberNamesToIgnore.Add(parts[0] + "Specified"); continue; } nameToMemberConfig.Put(memberName, memberConfig); } foreach (IRelationConfig relationConfig in entityConfig.GetRelationConfigIterable()) { String relationName = relationConfig.Name; nameToRelationConfig.Put(relationName, relationConfig); } }
public static string DefaultIdStr(this IEntityConfig config) => config.GetIdFromSubscription().IdToString();
public void ShouldThrowOnUncompatibleEntityAndEntityConfig() { entity = new User(); config = MockEntityConfig(documentType: "simpleEntity", entityType: typeof(Entity)); Assert.Throws<InvalidOperationException>(() => serializer.ConvertToJson(entity, config, true)); }
public bool CurrentMatch(IEntityConfig config) => Current.ContainsDispatch(config) && config.NestedResources.All(CurrentMatch);
static SubResource GetSubResourceReference( this IEngine engine, IEntityConfig config) => config == null ? null : new SubResource { Id = engine.GetId(config) };
/// <summary>Registers entity configuration.</summary> public Settings Register(IEntityConfig entityConfig) { entityRegistry.Register(entityConfig); return this; }
internal static IEnumerable <string> GetProvidersId(this IEntityConfig config) => new[] { "providers" }.Concat(config.GetIdFromResourceGroup());
public string GetId(IEntityConfig config) => new[] { ResourceId.Subscriptions, _SubscriptionId } .Concat(config.GetIdFromSubscription()) .IdToString();
/// <inheritdoc /> public override JsonObject ConvertToJson(object sourceEntity, IEntityConfig entityConfig, bool throwOnError) { if (sourceEntity == null) throw new ArgumentNullException("sourceEntity"); if (entityConfig == null) throw new ArgumentNullException("entityConfig"); return CheckAndConvertToJson( sourceEntity, entityConfig, throwOnError, () => (JsonObject)ConvertToJsonInternal(sourceEntity, entitySerializers.Get(entityConfig), throwOnError) ); }
/// <summary>Creates specific entity type serializer settings.</summary> public static JsonSerializerSettings CreateEntitySerializerSettingsDefault(IEntityConfig entityConfig) { var settings = CreateDefaultSerializerSettingsDefault(); settings.ContractResolver = new EntityContractResolver(entityConfig.EntityType, entityConfig.IgnoredMembers); return settings; }
public void ShouldThrowIfConvertDocumentIdToEntityIdReturnsNullEmptyOrWightspaceString(string invalidEntityId) { config = MockEntityConfig( mock => mock.Setup(ec => ec.ConvertDocumentIdToEntityId(It.IsAny<string>())).Returns(invalidEntityId)); Assert.Throws<InvalidOperationException>(() => serializer.ConvertFromJson(config, CreateDoc(), true)); }
public static string GetResourceGroupName(this IEntityConfig config) => config.ResourceGroup?.Name ?? config.Name;
public void ShouldThrowIfSelfReferencingEntityDetected() { entity = new SelfReferencingEntity { Component = new SelfReferencingComponent { SubEntity = new SelfReferencingEntity() } }; config = MockEntityConfig( documentType: "selfReferencingEntity", entityType: typeof(SelfReferencingEntity) ); var exception = Assert.Throws<InvalidOperationException>(() => serializer.ConvertToJson(entity, config, true)); Assert.Contains(typeof(SelfReferencingEntity).Name, exception.Message); }
public void Register(IEntityConfig config) { readerWriterLock.EnterWriteLock(); try { var documentType = config.DocumentType; var entityType = config.EntityType; if (entityTypeMap.ContainsKey(entityType)) throw new ConfigurationException( "Duplicate registration of entity type {0}. You should revise your configuration code.", entityType); if(documentTypeMap.ContainsKey(documentType)) throw new ConfigurationException( "Duplicate registration of document type '{0}' (was for {1} and now for {2}). " + "You should revise your document type conventions.", documentType, documentTypeMap[documentType].EntityType, entityType); documentTypeMap[documentType] = config; entityTypeMap[entityType] = config; } finally { readerWriterLock.ExitWriteLock(); } }
public void ShouldThrowIfEntityIdIsNullEmptyOrWhitespace(string invalidEntityId) { config = MockEntityConfig( mock => mock.Setup(ec => ec.GetId(entity)).Returns(invalidEntityId)); Assert.Throws<InvalidOperationException>(() => serializer.ConvertToJson(entity, config, true)); }
public void SetUp() { _entityConfig = new T(); }
public void ShouldSerializeTimeSpan() { entity = Entity.CreateStandard(); config = MockEntityConfig(documentType: "entity", entityType: typeof (Entity)); var document = serializer.ConvertToJson(entity, config, throwOnError: true); Assert.Equal(4*60*60*1000, (int)document["timeZoneOffset"]); }