private object SetHasManyRelationship(object entity,
                                              PropertyInfo[] entityProperties,
                                              RelationshipAttribute attr,
                                              ContextEntity contextEntity,
                                              Dictionary <string, RelationshipData> relationships,
                                              List <DocumentData> included = null)
        {
            var relationshipName = attr.PublicRelationshipName;

            if (relationships.TryGetValue(relationshipName, out RelationshipData relationshipData))
            {
                var data = (List <ResourceIdentifierObject>)relationshipData.ExposedData;

                if (data == null)
                {
                    return(entity);
                }

                var relatedResources = relationshipData.ManyData.Select(r =>
                {
                    var instance = GetIncludedRelationship(r, included, attr);
                    return(instance);
                });

                var convertedCollection = TypeHelper.ConvertCollection(relatedResources, attr.Type);

                attr.SetValue(entity, convertedCollection);

                _jsonApiContext.HasManyRelationshipPointers.Add(attr, convertedCollection);
            }

            return(entity);
        }
Ejemplo n.º 2
0
        private void _addRelationships(DocumentData data, ContextEntity contextEntity, IIdentifiable entity)
        {
            var linkBuilder = new LinkBuilder(_jsonApiContext);

            contextEntity.Relationships.ForEach(r =>
            {
                var relationshipData = new RelationshipData
                {
                    Links = new Links
                    {
                        Self    = linkBuilder.GetSelfRelationLink(contextEntity.EntityName, entity.Id.ToString(), r.RelationshipName),
                        Related = linkBuilder.GetRelatedRelationLink(contextEntity.EntityName, entity.Id.ToString(), r.RelationshipName)
                    }
                };

                if (_hasRelationship(r.RelationshipName))
                {
                    var navigationEntity = _jsonApiContext.ContextGraph
                                           .GetRelationship(entity, r.RelationshipName);

                    if (navigationEntity is IEnumerable)
                    {
                        relationshipData.ManyData = _getRelationships((IEnumerable <object>)navigationEntity, r.RelationshipName);
                    }
                    else
                    {
                        relationshipData.SingleData = _getRelationship(navigationEntity, r.RelationshipName);
                    }
                }

                data.Relationships.Add(r.RelationshipName.Dasherize(), relationshipData);
            });
        }
Ejemplo n.º 3
0
        public static RelationshipAttribute GetRelationshipAttribute <T>(this IResourceGraph resourceGraph,
                                                                         string publicRelationshipName)
        {
            ContextEntity contextEntity = resourceGraph.GetContextEntity(typeof(T));

            return(contextEntity.Relationships.SingleOrDefault(r => r.Is(publicRelationshipName)));
        }
Ejemplo n.º 4
0
        private DocumentData _getData(ContextEntity contextEntity, IIdentifiable entity)
        {
            var data = new DocumentData
            {
                Type = contextEntity.EntityName,
                Id   = entity.Id.ToString()
            };

            if (_jsonApiContext.IsRelationshipData)
            {
                return(data);
            }

            data.Attributes    = new Dictionary <string, object>();
            data.Relationships = new Dictionary <string, RelationshipData>();

            contextEntity.Attributes.ForEach(attr =>
            {
                data.Attributes.Add(attr.PublicAttributeName, attr.GetValue(entity));
            });

            _addRelationships(data, contextEntity, entity);

            return(data);
        }
        private object _setHasManyRelationship(object entity,
                                               PropertyInfo[] entityProperties,
                                               RelationshipAttribute attr,
                                               ContextEntity contextEntity,
                                               Dictionary <string, RelationshipData> relationships)
        {
            var entityProperty = entityProperties.FirstOrDefault(p => p.Name == attr.InternalRelationshipName);

            if (entityProperty == null)
            {
                throw new JsonApiException("400", $"{contextEntity.EntityType.Name} does not contain an relationsip named {attr.InternalRelationshipName}");
            }

            var relationshipName = attr.PublicRelationshipName;

            if (relationships.TryGetValue(relationshipName, out RelationshipData relationshipData))
            {
                var data = (List <Dictionary <string, string> >)relationshipData.ExposedData;

                if (data == null)
                {
                    return(entity);
                }

                var genericProcessor = _genericProcessorFactor.GetProcessor(attr.Type);
                var ids = relationshipData.ManyData.Select(r => r["id"]);
                genericProcessor.SetRelationships(entity, attr, ids);
            }

            return(entity);
        }
        private List <ResourceObject> IncludeRelationshipChain(
            List <ResourceObject> included, ContextEntity parentEntity, IIdentifiable parentResource, string[] relationshipChain, int relationshipChainIndex)
        {
            var requestedRelationship = relationshipChain[relationshipChainIndex];
            var relationship          = parentEntity.Relationships.FirstOrDefault(r => r.PublicRelationshipName == requestedRelationship);

            if (relationship == null)
            {
                throw new JsonApiException(400, $"{parentEntity.EntityName} does not contain relationship {requestedRelationship}");
            }

            var navigationEntity = _jsonApiContext.ResourceGraph.GetRelationshipValue(parentResource, relationship);

            if (navigationEntity is IEnumerable hasManyNavigationEntity)
            {
                foreach (IIdentifiable includedEntity in hasManyNavigationEntity)
                {
                    included = AddIncludedEntity(included, includedEntity);
                    included = IncludeSingleResourceRelationships(included, includedEntity, relationship, relationshipChain, relationshipChainIndex);
                }
            }
            else
            {
                included = AddIncludedEntity(included, (IIdentifiable)navigationEntity);
                included = IncludeSingleResourceRelationships(included, (IIdentifiable)navigationEntity, relationship, relationshipChain, relationshipChainIndex);
            }

            return(included);
        }
Ejemplo n.º 7
0
        private List <DocumentData> GetIncludedEntities(ContextEntity contextEntity, IIdentifiable entity)
        {
            var included = new List <DocumentData>();

            contextEntity.Relationships.ForEach(r =>
            {
                if (!RelationshipIsIncluded(r.PublicRelationshipName))
                {
                    return;
                }

                var navigationEntity = _jsonApiContext.ContextGraph.GetRelationship(entity, r.InternalRelationshipName);

                if (navigationEntity is IEnumerable hasManyNavigationEntity)
                {
                    foreach (IIdentifiable includedEntity in hasManyNavigationEntity)
                    {
                        AddIncludedEntity(included, includedEntity);
                    }
                }
                else
                {
                    AddIncludedEntity(included, (IIdentifiable)navigationEntity);
                }
            });

            return(included);
        }
        private object SetHasManyRelationship(object entity,
                                              PropertyInfo[] entityProperties,
                                              HasManyAttribute attr,
                                              ContextEntity contextEntity,
                                              Dictionary <string, RelationshipData> relationships,
                                              List <ResourceObject> included = null)
        {
            var relationshipName = attr.PublicRelationshipName;

            if (relationships.TryGetValue(relationshipName, out RelationshipData relationshipData))
            {
                if (relationshipData.IsHasMany == false || relationshipData.ManyData == null)
                {
                    return(entity);
                }

                var relatedResources = relationshipData.ManyData.Select(r =>
                {
                    var instance = GetIncludedRelationship(r, included, attr);
                    return(instance);
                });

                var convertedCollection = TypeHelper.ConvertCollection(relatedResources, attr.DependentType);

                attr.SetValue(entity, convertedCollection);
                /// todo: as a part of the process of decoupling JADNC (specifically
                /// through the decoupling IJsonApiContext), we now no longer need to
                /// store the updated relationship values in this property. For now
                /// just assigning null as value, will remove this property later as a whole.
                /// see #512
                _jsonApiContext.HasManyRelationshipPointers.Add(attr, null);
            }

            return(entity);
        }
        public ResourceObject GetData(ContextEntity contextEntity, IIdentifiable entity, IResourceDefinition resourceDefinition = null)
        {
            var data = new ResourceObject
            {
                Type = contextEntity.EntityName,
                Id   = entity.StringId
            };

            if (_jsonApiContext.IsRelationshipPath)
            {
                return(data);
            }

            data.Attributes = new Dictionary <string, object>();

            var resourceAttributes = resourceDefinition?.GetOutputAttrs(entity) ?? contextEntity.Attributes;

            resourceAttributes.ForEach(attr =>
            {
                var attributeValue = attr.GetValue(entity);
                if (ShouldIncludeAttribute(attr, attributeValue))
                {
                    data.Attributes.Add(attr.PublicAttributeName, attributeValue);
                }
            });

            if (contextEntity.Relationships.Count > 0)
            {
                AddRelationships(data, contextEntity, entity);
            }

            return(data);
        }
        private object SetHasOneRelationship(object entity,
                                             PropertyInfo[] entityProperties,
                                             HasOneAttribute attr,
                                             ContextEntity contextEntity,
                                             Dictionary <string, RelationshipData> relationships,
                                             List <DocumentData> included = null)
        {
            var relationshipName = attr.PublicRelationshipName;

            if (relationships.TryGetValue(relationshipName, out RelationshipData relationshipData) == false)
            {
                return(entity);
            }

            var rio = (ResourceIdentifierObject)relationshipData.ExposedData;

            var foreignKey         = attr.IdentifiablePropertyName;
            var foreignKeyProperty = entityProperties.FirstOrDefault(p => p.Name == foreignKey);

            if (foreignKeyProperty == null && rio == null)
            {
                return(entity);
            }

            SetHasOneForeignKeyValue(entity, attr, foreignKeyProperty, rio);
            SetHasOneNavigationPropertyValue(entity, attr, rio, included);

            return(entity);
        }
Ejemplo n.º 11
0
        private object SetEntityAttributes(
            object entity, ContextEntity contextEntity, Dictionary <string, object> attributeValues)
        {
            if (attributeValues == null || attributeValues.Count == 0)
            {
                return(entity);
            }

            foreach (var attr in contextEntity.Attributes)
            {
                if (attributeValues.TryGetValue(attr.PublicAttributeName, out object newValue))
                {
                    if (attr.IsImmutable)
                    {
                        continue;
                    }
                    var convertedValue = ConvertAttrValue(newValue, attr.PropertyInfo.PropertyType);
                    attr.SetValue(entity, convertedValue);
                    /// todo: as a part of the process of decoupling JADNC (specifically
                    /// through the decoupling IJsonApiContext), we now no longer need to
                    /// store the updated relationship values in this property. For now
                    /// just assigning null as value, will remove this property later as a whole.
                    /// see #512
                    _jsonApiContext.AttributesToUpdate[attr] = null;
                }
            }

            return(entity);
        }
Ejemplo n.º 12
0
        public void DeclarationRangeTest()
        {
            Context context = new Context();
            var     decl    = context.Declare <Employee>().Min(2).Max(4);
            List <ContextEntity> entities = new List <ContextEntity>();

            // 0
            Assert.IsFalse(decl.Validate(entities), "Expected non-valid result.");

            // 1
            entities.Add(ContextEntity.Create(new Employee()));
            Assert.IsFalse(decl.Validate(entities), "Expected non-valid result.");

            // 2
            entities.Add(ContextEntity.Create(new Employee()));
            Assert.IsTrue(decl.Validate(entities), "Expected valid result.");

            // 3
            entities.Add(ContextEntity.Create(new Employee()));
            Assert.IsTrue(decl.Validate(entities), "Expected valid result.");

            // 4
            entities.Add(ContextEntity.Create(new Employee()));
            Assert.IsTrue(decl.Validate(entities), "Expected valid result.");

            // 5
            entities.Add(ContextEntity.Create(new Employee()));
            Assert.IsFalse(decl.Validate(entities), "Expected no-valid result.");
        }
Ejemplo n.º 13
0
        private List <DocumentData> _getIncludedEntities(ContextEntity contextEntity, IIdentifiable entity)
        {
            var included = new List <DocumentData>();

            contextEntity.Relationships.ForEach(r =>
            {
                if (!_relationshipIsIncluded(r.InternalRelationshipName))
                {
                    return;
                }

                var navigationEntity = _jsonApiContext.ContextGraph.GetRelationship(entity, r.InternalRelationshipName);

                if (navigationEntity is IEnumerable)
                {
                    foreach (var includedEntity in (IEnumerable)navigationEntity)
                    {
                        included.Add(_getIncludedEntity((IIdentifiable)includedEntity));
                    }
                }
                else
                {
                    included.Add(_getIncludedEntity((IIdentifiable)navigationEntity));
                }
            });

            return(included);
        }
Ejemplo n.º 14
0
        public async Task HandleContext(StatementBase statement, IStatementBaseEntity newStatement, CancellationToken cancellationToken)
        {
            if (statement.Context != null)
            {
                newStatement.Context = _mapper.Map <ContextEntity>(statement.Context);
                ContextEntity context = newStatement.Context;
                if (context.Instructor != null)
                {
                    var instructor = (AgentEntity)await _mediator.Send(UpsertActorCommand.Create(statement.Context.Instructor), cancellationToken);

                    context.InstructorId = instructor.AgentId;
                    context.Instructor   = null;
                }
                if (context.Team != null)
                {
                    var team = (AgentEntity)await _mediator.Send(UpsertActorCommand.Create(statement.Context.Team), cancellationToken);

                    context.TeamId = team.AgentId;
                    context.Team   = null;
                }

                if (context.ContextActivities != null)
                {
                    foreach (var contextActivity in context.ContextActivities)
                    {
                        Iri id       = new Iri(contextActivity.Activity.Id);
                        var activity = await _mediator.Send(UpsertActivityCommand.Create(id), cancellationToken);

                        contextActivity.Activity   = null;
                        contextActivity.ActivityId = activity.ActivityId;
                    }
                }
            }
        }
Ejemplo n.º 15
0
        private DocumentData GetData(ContextEntity contextEntity, IIdentifiable entity)
        {
            var data = new DocumentData
            {
                Type = contextEntity.EntityName,
                Id   = entity.StringId
            };

            if (_jsonApiContext.IsRelationshipData)
            {
                return(data);
            }

            data.Attributes = new Dictionary <string, object>();

            contextEntity.Attributes.ForEach(attr =>
            {
                if (ShouldIncludeAttribute(attr))
                {
                    data.Attributes.Add(attr.PublicAttributeName, attr.GetValue(entity));
                }
            });

            if (contextEntity.Relationships.Count > 0)
            {
                AddRelationships(data, contextEntity, entity);
            }

            return(data);
        }
        private object _setEntityAttributes(
            object entity, ContextEntity contextEntity, Dictionary <string, object> attributeValues)
        {
            if (attributeValues == null || attributeValues.Count == 0)
            {
                return(entity);
            }

            var entityProperties = entity.GetType().GetProperties();

            foreach (var attr in contextEntity.Attributes)
            {
                var entityProperty = entityProperties.FirstOrDefault(p => p.Name == attr.InternalAttributeName);

                if (entityProperty == null)
                {
                    throw new ArgumentException($"{contextEntity.EntityType.Name} does not contain an attribute named {attr.InternalAttributeName}", nameof(entity));
                }

                object newValue;
                if (attributeValues.TryGetValue(attr.PublicAttributeName, out newValue))
                {
                    var convertedValue = TypeHelper.ConvertType(newValue, entityProperty.PropertyType);
                    entityProperty.SetValue(entity, convertedValue);
                }
            }

            return(entity);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Recursively goes through the included relationships from JsonApiContext,
        /// translates them to the corresponding hook containers and fires the
        /// BeforeRead hook (if implemented)
        /// </summary>
        void RecursiveBeforeRead(ContextEntity contextEntity, List <string> relationshipChain, ResourcePipeline pipeline, List <PrincipalType> calledContainers)
        {
            var target       = relationshipChain.First();
            var relationship = contextEntity.Relationships.FirstOrDefault(r => r.PublicRelationshipName == target);

            if (relationship == null)
            {
                throw new JsonApiException(400, $"Invalid relationship {target} on {contextEntity.EntityName}",
                                           $"{contextEntity.EntityName} does not have a relationship named {target}");
            }

            if (!calledContainers.Contains(relationship.DependentType))
            {
                calledContainers.Add(relationship.DependentType);
                var container = _executorHelper.GetResourceHookContainer(relationship.DependentType, ResourceHook.BeforeRead);
                if (container != null)
                {
                    CallHook(container, ResourceHook.BeforeRead, new object[] { pipeline, true, null });
                }
            }
            relationshipChain.RemoveAt(0);
            if (relationshipChain.Any())
            {
                RecursiveBeforeRead(_graph.GetContextEntity(relationship.DependentType), relationshipChain, pipeline, calledContainers);
            }
        }
Ejemplo n.º 18
0
        private object SetRelationships(
            object entity,
            ContextEntity contextEntity,
            Dictionary <string, RelationshipData> relationships,
            List <ResourceObject> included = null,
            List <string> includePaths     = null)
        {
            if (relationships == null || relationships.Count == 0)
            {
                return(entity);
            }

            var entityProperties = entity.GetType().GetProperties();

            foreach (var attr in contextEntity.Relationships)
            {
                var paths = includePaths?.Where(x => x.Equals(attr.PublicRelationshipName) || x.StartsWith($"{attr.PublicRelationshipName}."))
                            .ToList();
                if (paths != null && paths.Count > 0)
                {
                    entity = attr.IsHasOne
                        ? SetHasOneRelationship(entity, entityProperties, (HasOneAttribute)attr, contextEntity, relationships, included, paths)
                        : SetHasManyRelationship(entity, entityProperties, (HasManyAttribute)attr, contextEntity, relationships, included, paths);
                }
            }

            return(entity);
        }
Ejemplo n.º 19
0
 public CarController(ILogger <CarController> logger, ContextEntity context)
 {
     _logger  = logger;
     _context = new CarRepositoryEntity(context);
     _save    = new CarSaveService(_context);
     _list    = new CarListService(_context);
     _delete  = new CarDeleteService(_context);
 }
Ejemplo n.º 20
0
        /// <summary>Creates a new, empty ContextEntity object.</summary>
        /// <returns>A new, empty ContextEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new ContextEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewContext
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
 public CarCategoryController(ILogger <CarCategoryController> logger, ContextEntity context)
 {
     _logger  = logger;
     _context = new BaseEntityRepository <CarCategory>(context);
     _save    = new CategorySaveService(_context);
     _delete  = new CategoryDeleteService(_context);
     _list    = new CategoryListService(_context);
 }
Ejemplo n.º 22
0
        public ResourceObject GetData(ContextEntity contextEntity, IIdentifiable entity,
                                      IResourceDefinition resourceDefinition = null)
        {
            ResourceObject resourceObj = _internalBuilder.GetData(contextEntity, entity, resourceDefinition);

            UpdateResourceObject(resourceObj);
            return(resourceObj);
        }
 public CarModelController(ILogger <CarModelController> logger, ContextEntity context)
 {
     _logger  = logger;
     _context = new BaseRegisterSQLRepository <CarModel>();
     _save    = new CarModelSaveService(_context);
     _delete  = new CarModelDeleteService(_context);
     _list    = new CarModelListService(_context);
 }
Ejemplo n.º 24
0
        public static string GetPublicRelationshipName <T>(this IResourceGraph resourceGraph,
                                                           string internalPropertyName)
        {
            ContextEntity contextEntity = resourceGraph.GetContextEntity(typeof(T));

            return(contextEntity.Relationships
                   .SingleOrDefault(r => r.InternalRelationshipName == internalPropertyName)?.PublicRelationshipName);
        }
Ejemplo n.º 25
0
 public CarBrandController(ILogger <CarBrandController> logger, ContextEntity context)
 {
     _logger  = logger;
     _context = new BaseEntityRepository <CarBrand>(context);
     _save    = new CarBrandSaveService(_context);
     _delete  = new CarBrandDeleteService(_context);
     _list    = new CarBrandListService(_context);
 }
 public CarController(ILogger <CarController> logger, ContextEntity context)
 {
     _logger           = logger;
     _context          = new CarRepositorySQLDriver();
     _save             = new CarSaveService(_context);
     _list             = new CarListService(_context);
     _delete           = new CarDeleteService(_context);
     _listCarAvailable = new ListAvailableCarsService(_context);
 }
Ejemplo n.º 27
0
 public OperatorController(ILogger <OperatorController> logger, ContextEntity context)
 {
     _logger           = logger;
     this._context     = new OperatorRepositoryEntity(context);
     this._userSave    = new OperatorSaveService(_context);
     this._userList    = new OperatorListService(_context);
     this._clientLogin = new OperatorLoginService(_context);
     this._userDelete  = new OperatorDeleteService(_context);
 }
 public BaseRepositorioEscritaInjector(
     ContextEntity context,
     INotificador notificador,
     IBancoLeituraSincronizador bancoLeituraSincronizador)
 {
     Context     = context;
     Notificador = notificador;
     BancoLeituraSincronizador = bancoLeituraSincronizador;
 }
 public ClientController(ILogger <ClientController> logger, ContextEntity context)
 {
     _logger      = logger;
     _context     = new ClientRepositoryEntity(context);
     _userSave    = new ClientSaveService(_context);
     _userList    = new ClientListService(_context);
     _clientLogin = new ClientLoginService(_context);
     _userDelete  = new ClientDeleteService(_context);
 }
 public ChecklistController(ILogger <ChecklistController> logger, ContextEntity context)
 {
     _logger             = logger;
     _context            = new ChecklistRepositoryEntity(context);
     _contextAppointment = new AppointmentRepositoryEntity(context);
     _save   = new CheckListSaveService(_contextAppointment);
     _list   = new ChekListListService(_context);
     _delete = new CheckListDeleteService(_context);
 }
Ejemplo n.º 31
0
 /// <summary> Removes the sync logic for member _context</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncContext(bool signalRelatedEntity, bool resetFKFields)
 {
     base.PerformDesetupSyncRelatedEntity( _context, new PropertyChangedEventHandler( OnContextPropertyChanged ), "Context", AttributeEntity.Relations.ContextEntityUsingContextId, true, signalRelatedEntity, "Attribute", resetFKFields, new int[] { (int)AttributeFieldIndex.ContextId } );
     _context = null;
 }
Ejemplo n.º 32
0
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected AttributeEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _attributeValue = (policyDB.CollectionClasses.AttributeValueCollection)info.GetValue("_attributeValue", typeof(policyDB.CollectionClasses.AttributeValueCollection));
            _alwaysFetchAttributeValue = info.GetBoolean("_alwaysFetchAttributeValue");
            _alreadyFetchedAttributeValue = info.GetBoolean("_alreadyFetchedAttributeValue");
            _decisionNode = (policyDB.CollectionClasses.DecisionNodeCollection)info.GetValue("_decisionNode", typeof(policyDB.CollectionClasses.DecisionNodeCollection));
            _alwaysFetchDecisionNode = info.GetBoolean("_alwaysFetchDecisionNode");
            _alreadyFetchedDecisionNode = info.GetBoolean("_alreadyFetchedDecisionNode");
            _queryValue = (policyDB.CollectionClasses.QueryValueCollection)info.GetValue("_queryValue", typeof(policyDB.CollectionClasses.QueryValueCollection));
            _alwaysFetchQueryValue = info.GetBoolean("_alwaysFetchQueryValue");
            _alreadyFetchedQueryValue = info.GetBoolean("_alreadyFetchedQueryValue");
            _decisionNodeCollectionViaDecisionNode = (policyDB.CollectionClasses.DecisionNodeCollection)info.GetValue("_decisionNodeCollectionViaDecisionNode", typeof(policyDB.CollectionClasses.DecisionNodeCollection));
            _alwaysFetchDecisionNodeCollectionViaDecisionNode = info.GetBoolean("_alwaysFetchDecisionNodeCollectionViaDecisionNode");
            _alreadyFetchedDecisionNodeCollectionViaDecisionNode = info.GetBoolean("_alreadyFetchedDecisionNodeCollectionViaDecisionNode");
            _decisionNodeCollectionViaAttributeValue = (policyDB.CollectionClasses.DecisionNodeCollection)info.GetValue("_decisionNodeCollectionViaAttributeValue", typeof(policyDB.CollectionClasses.DecisionNodeCollection));
            _alwaysFetchDecisionNodeCollectionViaAttributeValue = info.GetBoolean("_alwaysFetchDecisionNodeCollectionViaAttributeValue");
            _alreadyFetchedDecisionNodeCollectionViaAttributeValue = info.GetBoolean("_alreadyFetchedDecisionNodeCollectionViaAttributeValue");
            _queryCollectionViaQueryValue = (policyDB.CollectionClasses.QueryCollection)info.GetValue("_queryCollectionViaQueryValue", typeof(policyDB.CollectionClasses.QueryCollection));
            _alwaysFetchQueryCollectionViaQueryValue = info.GetBoolean("_alwaysFetchQueryCollectionViaQueryValue");
            _alreadyFetchedQueryCollectionViaQueryValue = info.GetBoolean("_alreadyFetchedQueryCollectionViaQueryValue");
            _attributeType = (AttributeTypeEntity)info.GetValue("_attributeType", typeof(AttributeTypeEntity));
            if(_attributeType!=null)
            {
                _attributeType.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _attributeTypeReturnsNewIfNotFound = info.GetBoolean("_attributeTypeReturnsNewIfNotFound");
            _alwaysFetchAttributeType = info.GetBoolean("_alwaysFetchAttributeType");
            _alreadyFetchedAttributeType = info.GetBoolean("_alreadyFetchedAttributeType");
            _context = (ContextEntity)info.GetValue("_context", typeof(ContextEntity));
            if(_context!=null)
            {
                _context.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _contextReturnsNewIfNotFound = info.GetBoolean("_contextReturnsNewIfNotFound");
            _alwaysFetchContext = info.GetBoolean("_alwaysFetchContext");
            _alreadyFetchedContext = info.GetBoolean("_alreadyFetchedContext");

            base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());

            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
Ejemplo n.º 33
0
        /// <summary> Retrieves the related entity of type 'ContextEntity', using a relation of type 'n:1'</summary>
        /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
        /// <returns>A fetched entity of type 'ContextEntity' which is related to this entity.</returns>
        public virtual ContextEntity GetSingleContext(bool forceFetch)
        {
            if( ( !_alreadyFetchedContext || forceFetch || _alwaysFetchContext) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)
            {
                bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(AttributeEntity.Relations.ContextEntityUsingContextId);

                ContextEntity newEntity = new ContextEntity();
                if(base.ParticipatesInTransaction)
                {
                    base.Transaction.Add(newEntity);
                }
                bool fetchResult = false;
                if(performLazyLoading)
                {
                    fetchResult = newEntity.FetchUsingPK(this.ContextId);
                }
                if(fetchResult)
                {
                    if(base.ActiveContext!=null)
                    {
                        newEntity = (ContextEntity)base.ActiveContext.Get(newEntity);
                    }
                    this.Context = newEntity;
                }
                else
                {
                    if(_contextReturnsNewIfNotFound)
                    {
                        if(performLazyLoading || (!performLazyLoading && (_context == null)))
                        {
                            this.Context = newEntity;
                        }
                    }
                    else
                    {
                        this.Context = null;
                    }
                }
                _alreadyFetchedContext = fetchResult;
                if(base.ParticipatesInTransaction && !fetchResult)
                {
                    base.Transaction.Remove(newEntity);
                }
            }
            return _context;
        }
Ejemplo n.º 34
0
 /// <summary> setups the sync logic for member _context</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncContext(IEntity relatedEntity)
 {
     if(_context!=relatedEntity)
     {
         DesetupSyncContext(true, true);
         _context = (ContextEntity)relatedEntity;
         base.PerformSetupSyncRelatedEntity( _context, new PropertyChangedEventHandler( OnContextPropertyChanged ), "Context", AttributeEntity.Relations.ContextEntityUsingContextId, true, ref _alreadyFetchedContext, new string[] {  } );
     }
 }
Ejemplo n.º 35
0
        /// <summary> Initializes the class members</summary>
        private void InitClassMembers()
        {
            _attributeValue = new policyDB.CollectionClasses.AttributeValueCollection(new AttributeValueEntityFactory());
            _attributeValue.SetContainingEntityInfo(this, "Attribute");
            _alwaysFetchAttributeValue = false;
            _alreadyFetchedAttributeValue = false;
            _decisionNode = new policyDB.CollectionClasses.DecisionNodeCollection(new DecisionNodeEntityFactory());
            _decisionNode.SetContainingEntityInfo(this, "Attribute");
            _alwaysFetchDecisionNode = false;
            _alreadyFetchedDecisionNode = false;
            _queryValue = new policyDB.CollectionClasses.QueryValueCollection(new QueryValueEntityFactory());
            _queryValue.SetContainingEntityInfo(this, "Attribute");
            _alwaysFetchQueryValue = false;
            _alreadyFetchedQueryValue = false;
            _decisionNodeCollectionViaDecisionNode = new policyDB.CollectionClasses.DecisionNodeCollection(new DecisionNodeEntityFactory());
            _alwaysFetchDecisionNodeCollectionViaDecisionNode = false;
            _alreadyFetchedDecisionNodeCollectionViaDecisionNode = false;
            _decisionNodeCollectionViaAttributeValue = new policyDB.CollectionClasses.DecisionNodeCollection(new DecisionNodeEntityFactory());
            _alwaysFetchDecisionNodeCollectionViaAttributeValue = false;
            _alreadyFetchedDecisionNodeCollectionViaAttributeValue = false;
            _queryCollectionViaQueryValue = new policyDB.CollectionClasses.QueryCollection(new QueryEntityFactory());
            _alwaysFetchQueryCollectionViaQueryValue = false;
            _alreadyFetchedQueryCollectionViaQueryValue = false;
            _attributeType = null;
            _attributeTypeReturnsNewIfNotFound = true;
            _alwaysFetchAttributeType = false;
            _alreadyFetchedAttributeType = false;
            _context = null;
            _contextReturnsNewIfNotFound = true;
            _alwaysFetchContext = false;
            _alreadyFetchedContext = false;

            PerformDependencyInjection();

            // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
            // __LLBLGENPRO_USER_CODE_REGION_END
            OnInitClassMembersComplete();
        }
Ejemplo n.º 36
0
        /// <summary>Creates a new, empty ContextEntity object.</summary>
        /// <returns>A new, empty ContextEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new ContextEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewContext
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }