예제 #1
0
        private void AddTypeAndAttributesRecursivly(DBContext myDBContext, GraphDBType type, ref HashSet<GraphDBType> types)
        {
            if (!type.IsUserDefined) return;

            foreach (var ptype in myDBContext.DBTypeManager.GetAllParentTypes(type, true, false))
            {
                if (!types.Contains(ptype))
                {
                    types.Add(ptype);
                    foreach (var attr in type.GetAllAttributes(ta => !ta.IsBackwardEdge, myDBContext, false))
                    {
                        AddTypeAndAttributesRecursivly(myDBContext, attr.GetDBType(myDBContext.DBTypeManager), ref types);
                    }
                }

                //types.UnionWith(myDBContext.DBTypeManager.GetAllParentTypes(type, true, false));

            }
        }
예제 #2
0
        private IEnumerable<TypeAttribute> GetSpecialAttributes(GraphDBType type)
        {

            if (!_SpecialAttributesByType.ContainsKey(type))
            {
                _SpecialAttributesByType.Add(type, type.GetAllAttributes(t => t is ASpecialTypeAttribute, _DBContext).ToList());
            }

            return _SpecialAttributesByType[type];

        }
예제 #3
0
        public override Exceptional Execute(DBContext dbContext, GraphDBType graphDBType)
        {
            var listOfTypeAttributes = new Dictionary<TypeAttribute, GraphDBType>();
            var retExcept = new Exceptional();
            var existingTypeAttributes = graphDBType.GetAllAttributes(dbContext);

            foreach (var attr in _ListOfAttributes)
            {
                var createExcept = attr.CreateTypeAttribute(dbContext);

                if (!createExcept.Success())
                {
                    retExcept.PushIExceptional(createExcept);
                }

                if (existingTypeAttributes.Exists(item => item.Name == createExcept.Value.Name))
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_AttributeAlreadyExists(createExcept.Value.Name)));
                }

                var attrType = dbContext.DBTypeManager.GetTypeByName(attr.AttributeType.Name);

                if (attrType == null)
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_TypeDoesNotExist(attr.AttributeType.Name)));
                    return retExcept;
                }

                if (attrType.IsUserDefined)
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_InvalidReferenceAssignmentOfUndefAttr()));
                    return retExcept;
                }

                createExcept.Value.DBTypeUUID = attrType.UUID;
                createExcept.Value.RelatedGraphDBTypeUUID = graphDBType.UUID;

                graphDBType.AddAttribute(createExcept.Value, dbContext.DBTypeManager, true);

                var flushExcept = dbContext.DBTypeManager.FlushType(graphDBType);

                if (!flushExcept.Success())
                {
                    retExcept.PushIExceptional(flushExcept);
                }

                listOfTypeAttributes.Add(createExcept.Value, attrType);
            }

            var dbobjects = dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(graphDBType, dbContext.DBTypeManager), dbContext);

            foreach (var item in dbobjects)
            {
                if (!item.Success())
                {
                    retExcept.PushIExceptional(item);
                }
                else
                {
                    var undefAttrExcept = item.Value.GetUndefinedAttributePayload(dbContext.DBObjectManager);

                    if (!undefAttrExcept.Success())
                    {
                        retExcept.PushIExceptional(undefAttrExcept);
                    }

                    foreach (var attr in listOfTypeAttributes)
                    {
                        IObject value;

                        if (undefAttrExcept.Value.TryGetValue(attr.Key.Name, out value))
                        {
                            var typeOfOperator = GraphDBTypeMapper.ConvertGraph2CSharp(attr.Value.Name);

                            if (GraphDBTypeMapper.IsAValidAttributeType(attr.Value, typeOfOperator, dbContext, value))
                            {
                                item.Value.AddAttribute(attr.Key.UUID, value);

                                var removeExcept = item.Value.RemoveUndefinedAttribute(attr.Key.Name, dbContext.DBObjectManager);

                                if (!removeExcept.Success())
                                {
                                    retExcept.PushIExceptional(removeExcept);
                                }

                                var flushExcept = dbContext.DBObjectManager.FlushDBObject(item.Value);

                                if (!flushExcept.Success())
                                {
                                    retExcept.PushIExceptional(flushExcept);
                                }
                            }
                            else
                            {
                                retExcept.PushIExceptional(new Exceptional(new Error_InvalidUndefAttrType(attr.Key.Name, attr.Value.Name)));
                            }
                        }
                    }
                }
            }

            return Exceptional.OK;
        }
예제 #4
0
        private IEnumerable<TypeAttribute> GetBackwardEdgeAttributes(GraphDBType type)
        {

            if (!_BackwardEdgeAttributesByType.ContainsKey(type))
            {
                _BackwardEdgeAttributesByType.Add(type, type.GetAllAttributes(t => t.IsBackwardEdge, _DBContext).ToList());
            }

            return _BackwardEdgeAttributesByType[type];

        }